-
Notifications
You must be signed in to change notification settings - Fork 0
jhswartz/mle
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
MACHINE LANGUAGE ENCODER Write machine language with labels and macros. USAGE mle < SOURCE > CODE INSTALLATION # cp -a mle /usr/bin/mle # chown root:root /usr/bin/mle # chmod 755 /usr/bin/mle EXAMPLE This example produces an mli binary for a Linux/amd64 target. $ cat demo/amd64-linux-pwd.src Magic: 90 Start: # Allocate 2048 bytes on the stack. 48 31 f6 # xor %rsi, %rsi 66 be 00 08 # mov $2048, %si 48 29 f4 # sub %rsi, %rsp # getcwd(buffer, 2048); 48 89 e7 # mov %rsp, %rdi 6a 4f # push SYS_GETCWD 58 # pop %rax 0f 05 # syscall # Get the buffered string length. 48 31 c0 # xor %rax, %rax 48 31 c9 # xor %rcx, %rcx 48 ff c9 # dec %rcx f2 ae # repnz scasb 48 89 ca # mov %rdx, %rcx 48 f7 d2 # not %rdx # Replace the NUL terminator with NL. 48 ff cf # dec %rdi b0 0a # mov $'\n', %al 88 07 # mov %al, (rdi) # write(STDOUT_FILENO, buffer, strlen(buffer)) 48 89 e6 # mov %rsp, %rsi 6a 01 # push $STDOUT_FILENO 5f # pop %rdi 6a 01 # push $SYS_WRITE 58 # pop %rax 0f 05 # syscall # Deallocate the buffer. 66 81 c4 00 08 # add $2048, %sp # exit(EXIT_SUCCESS); 6a 00 # push $EXIT_SUCCESS 5f # pop %rdi 6a 3c # push $SYS_EXIT 58 # pop %rax 0f 05 # syscall $ mle < demo/amd64-linux-pwd.src > /tmp/pwd $ chmod 755 /tmp/pwd $ ls -al /tmp/pwd -rwxr-xr-x 1 user user 67 Oct 14 21:46 /tmp/pwd $ cd /tmp $ strace ./pwd execve("./pwd", ["./pwd"], 0x7fffc10fa780 /* 47 vars */) = 0 open("./pwd", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0755, st_size=67, ...}) = 0 mmap(NULL, 67, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x7fcf656f3000 getcwd("/tmp", 2048) = 5 write(1, "/tmp\n", 5/tmp ) = 5 exit(0) = ? +++ exited with 0 +++ SEE ALSO http://github.com/jhswartz/mli http://github.com/jhswartz/mle-x86 AUTHOR Justin Swartz <justin.swartz@risingedge.co.za>
About
Write machine language with labels and macros.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published