Push me and then just touch me
This commit is contained in:
parent
cb154fad80
commit
fe2a0dab79
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,3 @@
|
||||
./main*
|
||||
main
|
||||
main_hello
|
||||
*.o
|
||||
|
||||
97
main.nasm
Normal file
97
main.nasm
Normal file
@ -0,0 +1,97 @@
|
||||
; Comments start with a semicolon!
|
||||
BITS 64 ;
|
||||
CPU X64 ;
|
||||
|
||||
section .rodata
|
||||
|
||||
sun_path: db "/tmp/.X11-unix/X0", 0
|
||||
static sun_path:data
|
||||
|
||||
section .text
|
||||
|
||||
%define AF_UNIX 1
|
||||
%define SOCK_STREAM 1
|
||||
|
||||
%define SYSCALL_WRITE 1
|
||||
%define SYSCALL_SOCKET 41
|
||||
%define SYSCALL_CONNECT 42
|
||||
%define SYSCALL_EXIT 60
|
||||
|
||||
|
||||
|
||||
global _start
|
||||
|
||||
; Create a UNIX domain socket and connect to the X11 server.
|
||||
; @returns the socket file descriptor
|
||||
x11_connect_to_server:
|
||||
static x11_connect_to_server:function
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
||||
; Open a Unix socket: socket(2)
|
||||
mov rax, SYSCALL_SOCKET
|
||||
mov rdi, AF_UNIX ; Unix socket
|
||||
mov rsi, SOCK_STREAM ; TCP like
|
||||
mov rdx, 0 ; Automatic protocol
|
||||
syscall
|
||||
|
||||
cmp rax, 0 ; Check if we made the socket
|
||||
jle die
|
||||
|
||||
mov rdi, rax ; Store the socket fs in rdi for the remainder of the function
|
||||
|
||||
sub rsp, 112 ; Store the struct sockaddr_un on the stack
|
||||
|
||||
mov WORD [rsp], AF_UNIX ; Set the sockaddr_un.sun_family to AF_UNIX
|
||||
; Fil lsoccaddr_un.sun_path with: "/tmp/.X11-unix/X0"
|
||||
lea rsi, sun_path
|
||||
mov r12, rdi ; Save the socket fd from rdi to r12
|
||||
lea rdi, [rsp + 2]
|
||||
cld
|
||||
mov ecx, 19
|
||||
rep movsb ; Copy.
|
||||
|
||||
; Connect ot the server
|
||||
mov rax, SYSCALL_CONNECT
|
||||
mov rdi, r12
|
||||
lea rsi, [rsp]
|
||||
%define SIZEOF_SOCKADDR_UN 2+108
|
||||
mov rdx, SIZEOF_SOCKADDR_UN
|
||||
syscall
|
||||
|
||||
cmp rax, 0
|
||||
jne die
|
||||
|
||||
mov rax, rdi
|
||||
|
||||
add rsp, 112
|
||||
|
||||
pop rbp
|
||||
ret
|
||||
|
||||
; Send the handshake to the X11 server and read the returned system information
|
||||
; @param rdi The socket fd
|
||||
; @returns The window root id (uint32_t) in rax
|
||||
x11_send_handshake:
|
||||
static x11_send_handshake:function
|
||||
push rdp
|
||||
mov rbp, rsp
|
||||
|
||||
sub rsp, 1<<15
|
||||
mov BYTE [rsp + 0], 'l' ; Tell X11 we are little endian
|
||||
mov WORD [rsp + 2], 11; Set the major version to 11
|
||||
|
||||
; Send the
|
||||
|
||||
die:
|
||||
mov rax, SYSCALL_EXIT
|
||||
mov rdi, 1
|
||||
syscall
|
||||
|
||||
_start:
|
||||
call x11_connect_to_server
|
||||
|
||||
; Exit the program
|
||||
mov rax, SYSCALL_EXIT
|
||||
mov rdi, 0
|
||||
syscall
|
||||
Loading…
x
Reference in New Issue
Block a user