Guest User

Untitled

a guest
May 27th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <windows.h>
  2. #include <intrin.h>
  3. #include <iostream>
  4.  
  5. int main(int argc, const char *argv[])
  6. {
  7. std::cout << "Starting..." << std::endl;
  8.  
  9. if(FALSE == IsDebuggerPresent())
  10. {
  11. PROCESS_INFORMATION pi;
  12. STARTUPINFOA si;
  13.  
  14. std::cout << "Ill debug! :)" << std::endl;
  15.  
  16. memset(&si, 0, sizeof(si));
  17.  
  18. si.cb = sizeof(si);
  19.  
  20. if(FALSE == CreateProcessA(argv[0], NULL, NULL, NULL, FALSE, DEBUG_PROCESS | CREATE_SUSPENDED, NULL, NULL, &si, &pi))
  21. {
  22. std::cout << "Failed to create process" << std::endl;
  23. return 0;
  24. }
  25.  
  26. std::cout << "Process started!" << std::endl;
  27. ResumeThread(pi.hThread);
  28.  
  29. for(;;)
  30. {
  31. DEBUG_EVENT dbg;
  32.  
  33. if(FALSE == WaitForDebugEvent(&dbg, INFINITE))
  34. {
  35. std::cout << "GG" << std::endl;
  36. return 0;
  37. }
  38.  
  39. if(EXCEPTION_DEBUG_EVENT == dbg.dwDebugEventCode)
  40. {
  41. const EXCEPTION_RECORD &e = dbg.u.Exception.ExceptionRecord;
  42.  
  43. std::cout << "Exception code: " << std::hex << e.ExceptionCode << " @ 0x" << e.ExceptionAddress << std::endl;
  44. }
  45.  
  46. ContinueDebugEvent(dbg.dwProcessId, dbg.dwThreadId, DBG_EXCEPTION_NOT_HANDLED);
  47. }
  48. }
  49. else
  50. {
  51. __try
  52. {
  53. //
  54. // Raise int3, this simulates the behaviour of a VEH debugger
  55. //
  56. std::cout << "Rasing #bp" << std::endl;
  57. __debugbreak();
  58. }
  59. __except(EXCEPTION_EXECUTE_HANDLER)
  60. {
  61. __try
  62. {
  63. //
  64. // Raise trap fault, also to simuate a VEH debugger
  65. //
  66. std::cout << "Raising #tf" << std::endl;
  67. __writeeflags(__readeflags() | 0x100);
  68. }
  69. __except(EXCEPTION_EXECUTE_HANDLER)
  70. {
  71. std::cout << "All is good" << std::endl;
  72. ExitThread(0);
  73. }
  74. }
  75. }
  76.  
  77. std::cout << "The world is broken" << std::endl;
  78.  
  79. return 0;
  80. }
Add Comment
Please, Sign In to add comment