仅使用系统调用而不是 windows dll 制作程序
Make a program using only system-calls not windows dll's
我正在尝试使程序使用系统调用而不是 dll 的 (kernel32.dll
,ntdll.dll
)。
例如,我知道 windows 10 64 位中的 0x2C (44) 系统调用是 NtTerminateProcess
购买 that 网页。另外,当我反汇编 ntdll.dll
时,我发现代码:
NtTerminateProcess:
mov r10, rcx
mov eax, 44
test byte [abs 7FFE0308h], 01h ;also what is in that memory address?
jnz label
syscall
ret
label:
int 46 ;and why the 46 (the 2Eh windows NT interrupt) is here
ret
我的问题是如何以这种方式终止程序?
直接执行系统调用不是一个好主意,因为这不是 stable ABI。理论上,这些数字可以在服务包甚至是普通更新之间改变。
在 32 位 Windows 上使用的指令在所有系统上也不相同!
Windows NT 和 2000 总是使用 int 2e
。 Windows XP started using SysEnter
/SysCall
when running on "newer" Intel/AMD CPUs (Pentium II, AMD K7, and later). Because Windows XP also supported older CPUs, it used a little helper function (SystemCallStub
) to enter kernel mode. This function (and later, the address of this function) 存储在位于 0x7ffe0000.
的所有名为 _KUSER_SHARED_DATA
的进程都可以访问的内存页中
仍然支持原始的int 2e
方法,但我不确定为什么64位Windows会费心检查使用哪种方法,因为它运行的每个CPU都支持SysCall
。我的Windows8机不检查:
0:000> uf ntdll!NtTerminateProcess
ntdll!ZwTerminateProcess:
000007ff`1ad52ea0 4c8bd1 mov r10,rcx
000007ff`1ad52ea3 b82a000000 mov eax,2Ah
000007ff`1ad52ea8 0f05 syscall
000007ff`1ad52eaa c3 ret
无论如何,这些只是实现细节,它们可以随时更改。有关按 Windows 内核版本细分的 x64 NT 系统调用编号的逆向工程 table,请参阅 https://j00ru.vexillium.org/syscalls/nt/64/。 (请勿在portable代码中使用,仅用于满足您对Windows and/or asm如何工作的好奇心的实验。)
int 2e
可能有点慢,所以如果你想保持 "portable".
我正在尝试使程序使用系统调用而不是 dll 的 (kernel32.dll
,ntdll.dll
)。
例如,我知道 windows 10 64 位中的 0x2C (44) 系统调用是 NtTerminateProcess
购买 that 网页。另外,当我反汇编 ntdll.dll
时,我发现代码:
NtTerminateProcess:
mov r10, rcx
mov eax, 44
test byte [abs 7FFE0308h], 01h ;also what is in that memory address?
jnz label
syscall
ret
label:
int 46 ;and why the 46 (the 2Eh windows NT interrupt) is here
ret
我的问题是如何以这种方式终止程序?
直接执行系统调用不是一个好主意,因为这不是 stable ABI。理论上,这些数字可以在服务包甚至是普通更新之间改变。
在 32 位 Windows 上使用的指令在所有系统上也不相同!
Windows NT 和 2000 总是使用 int 2e
。 Windows XP started using SysEnter
/SysCall
when running on "newer" Intel/AMD CPUs (Pentium II, AMD K7, and later). Because Windows XP also supported older CPUs, it used a little helper function (SystemCallStub
) to enter kernel mode. This function (and later, the address of this function) 存储在位于 0x7ffe0000.
_KUSER_SHARED_DATA
的进程都可以访问的内存页中
仍然支持原始的int 2e
方法,但我不确定为什么64位Windows会费心检查使用哪种方法,因为它运行的每个CPU都支持SysCall
。我的Windows8机不检查:
0:000> uf ntdll!NtTerminateProcess
ntdll!ZwTerminateProcess:
000007ff`1ad52ea0 4c8bd1 mov r10,rcx
000007ff`1ad52ea3 b82a000000 mov eax,2Ah
000007ff`1ad52ea8 0f05 syscall
000007ff`1ad52eaa c3 ret
无论如何,这些只是实现细节,它们可以随时更改。有关按 Windows 内核版本细分的 x64 NT 系统调用编号的逆向工程 table,请参阅 https://j00ru.vexillium.org/syscalls/nt/64/。 (请勿在portable代码中使用,仅用于满足您对Windows and/or asm如何工作的好奇心的实验。)
int 2e
可能有点慢,所以如果你想保持 "portable".