Skip to content

jhswartz/mle-x86

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

MACHINE LANGUAGE ENCODER / x86

  MLE macros for x86 relative offset calculation.


INSTALLATION

  # mkdir -p /usr/share/mle
  # cp -a x86 /usr/share/mle/


USAGE

  The following program, an mli/amd64 demo, illustrates the use of
  the 8-bit relative-offset calculator macro provided.

  $ cat demo/src/echo.src
  [ . x86 ]
  
  Magic:
          90

  Start:
          # Gather argc, and skip argv[0].
          59                                    # pop rcx
          5e                                    # pop rsi
          56 5f                                 # mov rsi rdi

          # Terminate if argc <= 1.
          83 f9 01                              # cmp 1 ecx
          7e [ rel8 Terminate ]                 # jle Terminate

  Echo:
          # Quit if the next argument is NULL.
          5e                                    # pop rsi
          85 f6                                 # test esi esi
          74 [ rel8 Quit ]                      # jz Quit

          # Get the length of the string.
          56 5f                                 # mov rsi rdi
          31 c0                                 # xor eax eax
          6a ff 59                              # mov -1 rcx
          f2 ae                                 # repnz scasb
          f7 d1                                 # not ecx

  Delimit:
          # Overwrite the NUL terminator with SPACE.
          48 ff cf                              # dec rdi
          c6 07 20                              # mov ' ' (rdi)

          # More arguments to print?
          39 04 24                              # cmp eax (rsp)
          75 [ rel8 Print ]                     # jnz Print

  Terminate:
          # Replace the SPACE with LF instead.
          c6 07 0a                              # mov '\n' (rdi)

  Print:
          # write(STDOUT_FILENO, buffer, length);
          89 ca                                 # mov ecx edx
          6a 01 5f                              # mov STDOUT_FILENO rdi
          8b c7                                 # mov SYS_WRITE rax
          0f 05                                 # syscall

          # Continue.
          eb [ rel8 Echo ]                      # jmp Echo

  Quit:
          31 ff                                 # mov EXIT_SUCCESS rdi
          6a 3c 58                              # mov SYS_EXIT rax
          0f 05                                 # syscall


  $ mle < demo/src/echo.src > demo/bin/echo
  $ chmod 755 demo/bin/echo
  $ ls -al demo/bin/echo
  -rwxr-xr-x 1 user user 58 Dec 28 22:47 demo/bin/echo

  $ demo/bin/echo slanderous braille bros apathetically denouncing crayfish.
  slanderous braille bros apathetically denouncing crayfish.


SEE ALSO

  https://github.com/jhswartz/mle
  https://github.com/jhswartz/mli-amd64


AUTHOR

  Justin Swartz <justin.swartz@risingedge.co.za>

About

MLE macros for x86 relative offset calculation.

Resources

Stars

Watchers

Forks