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.

syscall64.md 2.2KB

5 anni fa
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ---
  2. title: "Syscall64"
  3. description: "Doing direct syscalls on all platforms"
  4. draft: false
  5. ---
  6. A slightly hacky way (C macros) to do direct syscalls on either x86 or x64 windows,
  7. without any code change.
  8. http://vcs.wacked.codes/wacked/syscall64
  9. Use with this:
  10. ```
  11. ;http://blogs.msdn.com/b/oldnewthing/archive/2004/01/14/58579.aspx
  12. format ms coff
  13. include 'u:\fasm\INCLUDE\win32wx.inc'
  14. public _syscall64
  15. section '.text' code readable executable
  16. ; Converts the arguments and then executes SYSCALL
  17. ; 1. Param: Count of args to pass to syscall
  18. ; 2. Param: Syscall id
  19. ; 3. - X. Param: Params for syscall
  20. _syscall64:
  21. ; Those registers are pushed here so that the LEAVE instr cleans up the converted params without me needing to
  22. ; calc how much space those needed. Seriously what's 4*3 again?
  23. push edi
  24. push ebx
  25. push edx ; used by the x64 code
  26. push ebp
  27. mov ebp, esp
  28. ; Alloc space for params
  29. mov ecx, [ebp + 4*3 + 0x08] ; cnt
  30. cmp ecx, 4 ; Reserve shadow space
  31. jge @f
  32. mov ecx, 4
  33. @@:
  34. shl ecx, 3
  35. sub esp, ecx
  36. and esp, 0xFFFFFFF0 ; Align stack
  37. ; Convert params to x64
  38. mov edi, esp ; Destination
  39. mov ecx, [ebp + 4*3 + 0x08] ; Count
  40. lea ebx, [ebp + 4*3 + 0x10] ; Source for params
  41. CONVERT_PARAMS_LOOP:
  42. test ecx, ecx
  43. je @f
  44. mov eax, [ebx]
  45. stosd ; mov dword[edi], dword[eax] edi += 4
  46. mov eax, 0
  47. stosd ; [edi] = 0 edi += 4
  48. add ebx, 4 ; srcPtr++
  49. dec ecx ; cnt--
  50. jmp CONVERT_PARAMS_LOOP
  51. @@:
  52. ;mov eax, [ebp + 4*3 + 0x0C] ; Get syscall id
  53. call 0x33:X64_START
  54. X86_RETURN_FROM_X64:
  55. leave
  56. pop edx
  57. pop ebx
  58. pop edi
  59. ret
  60. ;align 16
  61. X64_START:
  62. use64
  63. mov eax, dword [ebp + 0x18] ; Get syscall id (4*3 = saved registers, )
  64. ; Get args from shadow space
  65. mov rcx, [rsp + 8]
  66. mov rdx , [rsp + 0x10]
  67. mov r8, [rsp + 0x18]
  68. mov r9, [rsp + 0x20]
  69. mov r10,rcx
  70. syscall
  71. use32
  72. retf
  73. ```