A shell that runs x86_64 assembly
c
x86-64
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

asmsh.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 UI
  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. @section INSTRUCTIONS
  15. The shell uses the GNU as compiler from binutils, the instructions syntax
  16. follows GAS syntax.
  17. For the moment GAS can only be used with the AT&T syntax.
  18. Details on x86 syntax can be found in GAS documentation at
  19. <pre>
  20. [https://sourceware.org/binutils/docs-2.40/as.html#i386_002dSyntax]
  21. </pre>
  22. The list & names of the registers can be found at the same place
  23. <pre>
  24. [https://sourceware.org/binutils/docs-2.40/as.html#i386_002dRegs]
  25. </pre>
  26. The list & documentation of the instructions for the x86_64 platform can be
  27. found in the 1st volume of "AMD64 Architecture Programmer’s Manual", in section
  28. 3.3 Instruction summary
  29. <pre>
  30. [https://www.amd.com/en/support/tech-docs/amd64-architecture-programmers-manual-volumes-1-5]
  31. </pre>
  32. Or in the Intel's equivalent document, namely the
  33. "Intel® 64 and IA-32 Architectures Software Developer’s Manual"
  34. <pre>
  35. [https://cdrdv2-public.intel.com/774494/325462-sdm-vol-1-2abcd-3abcd.pdf]
  36. </pre>
  37. @subsection man_reljmp Relative jumps
  38. For the moment there is no way to define symbols, so jumps can only be relative to
  39. the current address. The current address is expressed with the '.' character in an
  40. expression.
  41. Relative jumps can be expressed using the syntax :
  42. <pre>
  43. jmp . - 8
  44. jnz . + 32
  45. </pre>
  46. @section shell_cmds COMMANDS
  47. @par .bytecode
  48. Compile an instruction and display it's bytecode
  49. @par .flags
  50. Display the CPU flags
  51. @par .help [COMMAND]
  52. Display the builtin help or the help of the command gioven as argument
  53. @par .maps
  54. Display process memory maps
  55. @par .quit
  56. Exit the shell
  57. @par .regs
  58. Display the CPU registers values
  59. @par .syscalls
  60. Print syscalls names and numbers
  61. @par .reset
  62. Reset the shell (spawn a new process)
  63. @section EXAMPLES
  64. @subsection example_exit Exit with a specific status
  65. <pre>
  66. asmsh@0x7f55d2433000 > mov $60, \%rax
  67. asmsh@0x7f55d2433005 > mov $0x2a, \%rdi
  68. asmsh@0x7f55d243300a > syscall
  69. Child exited with status 42
  70. Exit with status 42
  71. </pre>
  72. @subsection example_hello Print a message to stdout
  73. <pre>
  74. asmsh@0x7f6e312e5000 > mov $0x0a6f6c6c, \%rax
  75. asmsh@0x7f6e312e5005 > shl $(8*2), \%rax
  76. asmsh@0x7f6e312e5009 > or $0x6548, \%rax
  77. asmsh@0x7f6e312e500f > push \%rax
  78. asmsh@0x7f6e312e5010 > mov $1, \%rax
  79. asmsh@0x7f6e312e5015 > mov \%rax, \%rdi
  80. asmsh@0x7f6e312e5018 > mov \%rsp, \%rsi
  81. asmsh@0x7f6e312e501b > mov $6, \%rdx
  82. asmsh@0x7f6e312e5020 > syscall
  83. Hello
  84. asmsh@0x7f6e312e5022 >
  85. </pre>
  86. @section TODO TODOLIST
  87. @todo Implement breakpoints
  88. @todo Implement symbols for jumps
  89. @todo Implement write without exec
  90. @todo Implement function declaration
  91. @todo Implement command for memory read/dump
  92. @todo Add switch between intel's & AT&T's syntaxes.
  93. @todo Add support for label declarations & references
  94. @section AUTHOR
  95. Written by Yann Weber &lt;yann.weber@members.fsf.org&gt;
  96. @section COPYRIGHT
  97. Copyright © 2023 Weber Yann License GPLv3+: GNU GPL version 3 or later
  98. &lt;http://gnu.org/licenses/gpl.html>.
  99. This is free software: you are free to change and redistribute it.
  100. There is NO WARRANTY, to the extent permitted by law.
  101. */
  102. /**@mainpage
  103. * @brief Asmsh a shell that runs assembly
  104. *
  105. * @section Description
  106. *
  107. * A simple programm is spawned by the shell, and each instructions are runned in the
  108. * subprocess environment.
  109. */