Reverse installer prototype

Source: Internet
Author: User
  1. # Include <Windows. h>
  2. # Include <stdlib. h>
  3. # Include <tchar. h>
  4. # Include <iostream. h>
  5. BOOL DeleteFolder (LPCTSTR lpszPath)
  6. {
  7. SHFILEOPSTRUCT FileOp;
  8. ZeroMemory (void *) & FileOp, sizeof (SHFILEOPSTRUCT ));
  9. FileOp. fFlags = FOF_NOCONFIRMATION;
  10. FileOp. hNameMappings = NULL;
  11. FileOp. hwnd = NULL;
  12. FileOp. lpszProgressTitle = NULL;
  13. FileOp. pFrom = lpszPath;
  14. Fileop. PTO = NULL;
  15. Fileop. wfunc = fo_delete;
  16. Return shfileoperation (& fileop) = 0;
  17. }
  18. Int main ()
  19. {
  20. If (_ argc = 1)
  21. {
  22. // Original EXE: spawn clone EXE to delete this exe
  23. // Copy this EXEcutable image into the user's temp directory
  24. Char del;
  25. Cout <"delete self or not? (Y/n)/n ";
  26. Cin> del;
  27. If (del = 'n ')
  28. Return 0;
  29. TCHAR szPathOrig [_ MAX_PATH], szPathClone [_ MAX_PATH];
  30. Getmodulefilename (null, szpathorig, _ max_path );
  31. Gettemppath (_ max_path, szpathclone );
  32. Gettempfilename (szpathclone, _ text ("Del"), 0, szpathclone );
  33. Copyfile (szpathorig, szpathclone, false );
  34. // *** Note ***:
  35. // Open the clone EXE using file_flag_delete_on_close
  36. Handle hfile = createfile (szpathclone, 0, file_assist_read, null, open_existing, file_flag_delete_on_close, null );
  37. // Spawn the clone EXE passing it our EXE's Process Handle
  38. // And the full path name to the original EXE file.
  39. Tchar szcmdline [512];
  40. Handle hprocessorig = OpenProcess (synchronize, true, getcurrentprocessid ());
  41. Wsprintf (szcmdline, _ text ("% S % d/" % S/""), szpathclone, hprocessorig, szpathorig );
  42. Startupinfo Si;
  43. Zeromemory (& Si, sizeof (SI ));
  44. Si. cb = sizeof (SI );
  45. Process_information PI;
  46. CreateProcess (null, szcmdline, null, null, true, 0, null, null, & Si, & PI );
  47. Closehandle (hprocessorig );
  48. Closehandle (hfile );
  49. // This original process can now terminate.
  50. }
  51. Else
  52. {
  53. // Clone EXE: When original EXE terminates, delete it
  54. Handle hprocessorig = (handle) _ ttoi (_ targv [1]);
  55. WaitForSingleObject (hProcessOrig, INFINITE );
  56. CloseHandle (hProcessOrig );
  57. Char str [256];
  58. Memset (str, 0,256 );
  59. Strcpy (str ,__ targv [2]);
  60. Int len = strlen (str );
  61. While (true)
  62. {
  63. If (str [len] = '//')
  64. {
  65. Str [len] = '/0 ';
  66. Break;
  67. }
  68. Str [len] = '/0 ';
  69. Len --;
  70. }
  71. DeleteFolder (str );
  72. // DeleteFile (_ targv [2]);
  73. // Delete the clone one
  74. SHELLEXECUTEINFO sei;
  75. TCHAR szModule [MAX_PATH], szComspec [MAX_PATH], szParams [MAX_PATH];
  76. // Obtain the file path name
  77. If (GetModuleFileName (0, szModule, MAX_PATH )! = 0 )&&
  78. (Getdomainpathname (szModule, szModule, MAX_PATH )! = 0 )&&
  79. (GetEnvironmentVariable ("COMSPEC", szComspec, MAX_PATH )! = 0 ))
  80. {// Set command line parameters.
  81. Lstrcpy (szParams, "/c del"); FindWindow (NULL, NULL );
  82. Lstrcat (szParams, szModule );
  83. Lstrcat (szParams, "> nul ");
  84. // Initialize the SHELLEXECUTEINFO structure member
  85. Sei. cbSize = sizeof (sei); // set the type size.
  86. // Process handle in the Command window, which is set when the ShellExecuteEx function is executed.
  87. Sei. hwnd = 0;
  88. Sei. lpVerb = "Open"; // The execution action is "Open execution ".
  89. Sei. lpFile = szComspec; // full path name of the execution program file.
  90. Sei. lpParameters = szParams; // execution parameters.
  91. Sei. lpDirectory = 0;
  92. // Display mode. Hide the mode to prevent the command window from appearing.
  93. Sei. nShow = SW_HIDE;
  94. // Set SellExecuteEx to exit after the function is complete.
  95. Sei. fmask = see_mask_nocloseprocess;
  96. // Create an execution command window process.
  97. If (shellexecuteex (& SEI ))
  98. {// Set the execution level of the command line process to idle, which gives the program enough time to exit from the memory.
  99. Setpriorityclass (SEI. hprocess, idle_priority_class );
  100. // Set the execution level of the program process to real-time execution. This program immediately obtains the CPU execution right and quickly exits.
  101. Setpriorityclass (getcurrentprocess (), realtime_priority_class );
  102. Setthreadpriority (getcurrentthread (), thread_priority_time_critical );
  103. }
  104. }
  105. }
  106. // Insert code here to remove the subdirectory too (if desired ).
  107. // The system will delete the clone EXE automatically
  108. // Because it was opened with FILE_FLAG_DELETE_ON_CLOSE
  109. Return (0 );
  110. }

The anti-installation prototype was rewritten by referring to two articles on the Internet. Thank you for sharing your experience.

There are at least two difficulties for the anti-Installer: one is to delete yourself, and the other is to delete the folder where you are located.

On the "webnumen technology life blog", I found a method for the program to delete itself, but it still cannot be implemented to let the program delete its own folder, even if you run the compiled program in vc6.0, you can delete the Debug folder where you are located. However, if you run a generated program directly, you cannot delete your own folder. At most, you can delete all the files and folders in the same directory as yourself.

Therefore, I found the "C + excellent exploration column" and solved the second difficulty by referring to his code.

The idea is to copy your own attachment to the temporary directory, start the attachment, pass your ID and path as parameters to the attachment, and let yourself exit normally. The appendix to be started is to delete the folder where the original program is located based on the parameters passed to the original program. Delete others and then kill yourself. For details about how to kill yourself, refer to "webnumen technology life blog"

 

Webnumen technology life blog
Http://webnumen.blog.hexun.com/19268347_d.html
C + refined Column
Http://blog.csdn.net/dpfordor/archive/2008/01/10/2032954.aspx

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.