A shell that runs x86_64 assembly
c
x86-64
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /**@page asmsh
  2. @brief A shell that runs assembly
  3. @section SYNOPSIS
  4. asmsh [OPTIONS]...
  5. @section DESCRIPTION
  6. A shell designed to run assembly (for the moment only x86_64 is supported).
  7. A simple programm is spawned by the shell, and each instructions are runned in the
  8. subprocess environment.
  9. @section man_ui USER INTERFACE
  10. For the moment, the UI is implemented using GNU readline with basic support for
  11. completion (using tab).
  12. The prompt is composed like "asmsh@RIPVAL > " where RIPVAL is the RIP register (
  13. Instruction Pointer ) value in hexadecimal.
  14. Other readline(3) features are available like up arrow to display previous commands,
  15. C^R for history search, etc.
  16. @section INSTRUCTIONS
  17. The shell uses the GNU as compiler from binutils, the instructions syntax
  18. follows GAS syntax.
  19. For the moment GAS can only be used with the AT&T syntax.
  20. Details on x86 syntax can be found in GAS documentation at
  21. <pre>
  22. [https://sourceware.org/binutils/docs-2.40/as.html#i386_002dSyntax]
  23. </pre>
  24. The list & names of the registers can be found at the same place
  25. <pre>
  26. [https://sourceware.org/binutils/docs-2.40/as.html#i386_002dRegs]
  27. </pre>
  28. The list & documentation of the instructions for the x86_64 platform can be
  29. found in the 1st volume of "AMD64 Architecture Programmer’s Manual", in section
  30. 3.3 Instruction summary
  31. <pre>
  32. [https://www.amd.com/en/support/tech-docs/amd64-architecture-programmers-manual-volumes-1-5]
  33. </pre>
  34. Or in the Intel's equivalent document, namely the
  35. "Intel® 64 and IA-32 Architectures Software Developer’s Manual"
  36. <pre>
  37. [https://cdrdv2-public.intel.com/774494/325462-sdm-vol-1-2abcd-3abcd.pdf]
  38. </pre>
  39. @subsection man_reljmp Relative jumps
  40. For the moment there is no way to define symbols, so jumps can only be relative to
  41. the current address. The current address is expressed with the '.' character in an
  42. expression.
  43. Relative jumps can be expressed using the syntax :
  44. <pre>
  45. jmp . - 8
  46. jnz . + 32
  47. loop . - 4
  48. </pre>
  49. @par Labels
  50. Labels can be defined to ease relative jumps using the ".label" command.
  51. Labels are used using "@NAME" notation, they are substituted with
  52. ". SIGN OFFSET" with SIGN and OFFSET calculated from RIP value.
  53. @par Example
  54. The instruction "loop @lbl" could be transformed in "loop . - 8"
  55. @section shell_cmds COMMANDS
  56. @par .breakpoint [CMD] [OPTS...]
  57. Handle breakpoint with different subcommands :
  58. - add (implicit) add a breakpoint at given address (or RIP value if no address given)
  59. - del remove a breakpoint at given address (or RIP)
  60. - list list all breakpoints
  61. @par .bytecode
  62. Compile an instruction and display it's bytecode
  63. @par .flags
  64. Display the CPU flags
  65. @par .help [COMMAND]
  66. Display the builtin help or the help of the command gioven as argument
  67. @par .label [NAME] [ADDR]
  68. Handle labels :
  69. - if no name given all labels are displayed.
  70. - if a name is given without address, a label is set at RIP value
  71. - if address is 0, the label is deleted
  72. @par .maps
  73. Display process memory maps
  74. @par .quit
  75. Exit the shell
  76. @par .regs
  77. Display the CPU registers values
  78. @par .syscalls
  79. Print syscalls names and numbers
  80. @par .reset
  81. Reset the shell (spawn a new process)
  82. @section Files
  83. @par ~/.local/share/asmsh/asmsh.history
  84. The command history file
  85. @section EXAMPLES
  86. @subsection example_exit Exit with a specific status
  87. <pre>
  88. asmsh@0x7f55d2433000 > mov $60, \%rax
  89. asmsh@0x7f55d2433005 > mov $0x2a, \%rdi
  90. asmsh@0x7f55d243300a > syscall
  91. Child exited with status 42
  92. Exit with status 42
  93. </pre>
  94. @subsection example_hello Print a message to stdout
  95. <pre>
  96. asmsh@0x7f6e312e5000 > mov $0x0a6f6c6c, \%rax
  97. asmsh@0x7f6e312e5005 > shl $(8*2), \%rax
  98. asmsh@0x7f6e312e5009 > or $0x6548, \%rax
  99. asmsh@0x7f6e312e500f > push \%rax
  100. asmsh@0x7f6e312e5010 > mov $1, \%rax
  101. asmsh@0x7f6e312e5015 > mov \%rax, \%rdi
  102. asmsh@0x7f6e312e5018 > mov \%rsp, \%rsi
  103. asmsh@0x7f6e312e501b > mov $6, \%rdx
  104. asmsh@0x7f6e312e5020 > syscall
  105. Hello
  106. asmsh@0x7f6e312e5022 >
  107. </pre>
  108. @subsection example_loop Make a loop and use commands
  109. <pre>
  110. asmsh@0x7f3020bec000 > .regs \%rbx
  111. rbx: 0000000000000000
  112. asmsh@0x7f3020bec000 > mov $6, \%rcx
  113. asmsh@0x7f3020bec005 > add $0xb, \%rbx
  114. asmsh@0x7f3020bec009 > .breakpoint after loop . -4
  115. INFO: Set breakpoint @ 00007F3020BEC00B
  116. asmsh@0x7f3020bec005 > .run
  117. INFO: Breakpoint 00007f3020bec00b reached
  118. asmsh@0x7f3020bec00b > .regs \%rbx
  119. rbx: 0000000000000042
  120. </pre>
  121. @subsection label_loop Make a loop using a label
  122. <pre>
  123. asmsh@0x7f0fadb73000 > mov $27, \%rcx
  124. asmsh@0x7f0fadb73005 > .label print
  125. INFO: Label '@print' 00007f0fadb73005 added
  126. asmsh@0x7f0fadb73005 > push \%rcx
  127. asmsh@0x7f0fadb73006 > mov $27,\%rbx
  128. asmsh@0x7f0fadb7300b > sub \%rcx, \%rbx
  129. asmsh@0x7f0fadb7300e > add $0x0a40, \%rbx
  130. asmsh@0x7f0fadb73015 > push \%rbx
  131. asmsh@0x7f0fadb73016 > mov $1, \%rax
  132. asmsh@0x7f0fadb7301b > mov \%rax, \%rdi
  133. asmsh@0x7f0fadb7301e > mov \%rsp, \%rsi
  134. asmsh@0x7f0fadb73021 > mov $2, \%rdx
  135. asmsh@0x7f0fadb73026 > syscall
  136. @
  137. asmsh@0x7f0fadb73028 > pop \%rbx
  138. asmsh@0x7f0fadb73029 > pop \%rcx
  139. asmsh@0x7f0fadb7302a > .breakpoint after loop @print
  140. INFO: Set breakpoint @ 00007F0FADB7302C
  141. asmsh@0x7f0fadb73005 > .run
  142. [...]
  143. </pre>
  144. @section TODO TODOLIST
  145. @todo Implement command for memory read/dump
  146. @todo Implement write without exec
  147. @todo Implement function declaration
  148. @todo Implement a command to run until syscall only (and another for run until
  149. breakpoint or syscall ?)
  150. @todo Rationalise commands argument parsing (at the moment .breakpoints allready uses special stuff :/)
  151. @todo Enhance support for labels & far/abs jump
  152. @todo Implement a script run mode without the prompt & without readline
  153. @section AUTHOR
  154. Written by Yann Weber &lt;yann.weber@members.fsf.org&gt;
  155. @section COPYRIGHT
  156. Copyright © 2023 Weber Yann License GPLv3+: GNU GPL version 3 or later
  157. &lt;http://gnu.org/licenses/gpl.html>.
  158. This is free software: you are free to change and redistribute it.
  159. There is NO WARRANTY, to the extent permitted by law.
  160. */
  161. /**@mainpage
  162. * @brief Asmsh a shell that runs assembly
  163. *
  164. * @section Description
  165. *
  166. * A simple programm is spawned by the shell, and each instructions are runned in the
  167. * subprocess environment.
  168. */