void nt_sleep(DWORD milliseconds)
{
static NTSTATUS(__stdcall *NtDelayExecution)(BOOL Alertable, PLARGE_INTEGER DelayInterval) = (NTSTATUS(__stdcall*)(BOOL, PLARGE_INTEGER)) GetProcAddress(GetModuleHandleA(("ntdll.dll")), ("NtDelayExecution"));
static NTSTATUS(__stdcall *ZwSetTimerResolution)(IN ULONG RequestedResolution, IN BOOLEAN Set, OUT PULONG ActualResolution) = (NTSTATUS(__stdcall*)(ULONG, BOOLEAN, PULONG)) GetProcAddress(GetModuleHandleA(("ntdll.dll")), ("ZwSetTimerResolution"));
static bool once = true;
printf("ZwSetTimerResolution %p\n",ZwSetTimerResolution);
if (once && ZwSetTimerResolution!=NULL) {
ULONG actualResolution;
ZwSetTimerResolution(1, true, &actualResolution);
once = false;
}
LARGE_INTEGER interval;
interval.QuadPart = -1 * (int)(milliseconds * 10000);
printf("NtDelayExecution %p\n",NtDelayExecution);
if(NtDelayExecution!=NULL)
{
NtDelayExecution(false, &interval);
}
}
windows上使用底层的sleep函数
最新推荐文章于 2025-07-26 21:45:25 发布
本文介绍了一种在Windows环境下使用NtDll.dll中的NtDelayExecution和ZwSetTimerResolution函数来实现精确延时的方法。通过GetProcAddress获取所需函数的地址,并展示了如何设置定时分辨率及延迟执行。
1124

被折叠的 条评论
为什么被折叠?



