Advertisement
waliedassar

ZwClose (Anti-Debug)

Aug 22nd, 2012
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. //http://waleedassar.blogspot.com - (@waleedassar)
  2. int __cdecl handler(EXCEPTION_RECORD* pRec,void* est_frame,CONTEXT* pContext)
  3. {
  4.     if(pRec->ExceptionCode==0xC0000235||pRec->ExceptionCode==0xC0000008)
  5.     {
  6.         MessageBox(0,"Debugger detected","waliedassar",0);
  7.         ExitProcess(-1);
  8.     }
  9.     return ExceptionContinueSearch;
  10. }
  11. int main(int argc, char* argv[])
  12. {
  13. bool OKAY=false;
  14. //change "c:\\olly.exe" to any file you guarantee it exists on disk.
  15. HANDLE h=CreateFile("c:\\olly.exe",GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
  16. if(h!=INVALID_HANDLE_VALUE)
  17. {
  18.     if(SetHandleInformation(h,HANDLE_FLAG_PROTECT_FROM_CLOSE,HANDLE_FLAG_PROTECT_FROM_CLOSE)) OKAY=true;
  19. }
  20.  
  21. __asm
  22. {
  23.         push offset handler
  24.         push dword ptr fs:[0x0]
  25.         mov dword ptr fs:[0x0],esp
  26. }
  27.  
  28. //Close a protected handle
  29. CloseHandle(h);
  30.  
  31. //Close an invalid handle
  32. CloseHandle((HANDLE)0xCECECECE);
  33.  
  34. __asm
  35. {
  36.         pop dword ptr fs:[0x0]
  37.         add esp,0x4
  38. }
  39.  
  40. MessageBox(0,"No debugger","waliedassar",0);
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement