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.

child.s 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright Yann Weber <asmsh@yannweb.net>
  2. # This file is part of asmsh.
  3. #
  4. # asmsh is free software: you can redistribute it and/or modify it under the
  5. # terms of the GNU General Public License as published by the Free Software
  6. # Foundation, either version 3 of the License, or any later version.
  7. #
  8. # asmsh is distributed in the hope that it will be useful, but WITHOUT ANY
  9. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  11. # details.
  12. #
  13. # You should have received a copy of the GNU General Public License along
  14. # with asmsh. If not, see <https://www.gnu.org/licenses/>.
  15. .ifndef MAP_SIZE
  16. .set MAP_LEN, 0x1000
  17. .endif
  18. .file "child64.s"
  19. .comm map_len 8
  20. .section .text
  21. .global _start
  22. map_exec:
  23. _start:
  24. mov %rsp, %r15
  25. mov $MAP_LEN, %r14
  26. movq %r14, (map_len)
  27. lea redo(%rip), %rax
  28. push %rax # redo addr
  29. pushq $MAP_LEN # map size
  30. mov $0x9, %rax # MMAP
  31. xor %rdi, %rdi
  32. mov (%rsp), %rsi # 1 page map
  33. #mov $(0x1|0x2), %rdx # PROT_READ | PROT_WRITE
  34. mov $(0x1|0x4|0x2), %rdx # PROT_READ | PROT_EXEC | PROT_WRITE
  35. mov $(0x20 | 0x1), %r10 # MAP_ANONYMOUS | MAP_SHARED
  36. mov $-1, %r8 # fd
  37. xor %r9, %r9
  38. syscall
  39. push %rax
  40. cmp $0, %rax
  41. jle .errmap
  42. redo:
  43. jmp *(%rsp)
  44. .err:
  45. mov $60, %rax # sys_exit
  46. mov $3, %rdi
  47. syscall
  48. .errmap:
  49. mov $60, %rax # sys_exit
  50. mov $1, %rdi
  51. syscall
  52. ## PAUSE SYSCALL example
  53. #mov $60, %rax
  54. #xor %rdi, %rdi
  55. #syscall