Skip to content

Instantly share code, notes, and snippets.

@mesaleh
Last active August 29, 2015 14:17
Show Gist options
  • Save mesaleh/1458d222a275ea1d5078 to your computer and use it in GitHub Desktop.
Save mesaleh/1458d222a275ea1d5078 to your computer and use it in GitHub Desktop.
/*
http://moustafasaleh.blogspot.com/ (@msaleh83)
Example of using ZwDelayExecution Windows internal API by importing ntdll.lib
compile:
cl ZwDelayExecution2.cpp kernel32.lib ntdll.lib user32.lib
gcc ZwDelayExecution2.cpp -o ZwDelayExecution1.exe -lntdll
*/
#define UNICODE
#define _UNICODE
#include <windows.h>
#pragma comment(linker,"/entry:main") // for CL
extern "C"
{
DWORD __stdcall ZwDelayExecution(BOOLEAN, __int64*);
}
int foo()
{
MessageBox(0,L"Before the delay",L"@msaleh83",0);
__int64 x = -20000000; // sleep for 2 seconds (100 ns granuality)
ZwDelayExecution(FALSE, &x);
MessageBox(0,L"After the delay",L"@msaleh83",0);
return 0;
}
int main(int argc, char* argv[]) {
foo();
ExitProcess(0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment