Guest User

Untitled

a guest
Apr 27th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <Windows.h>
  5.  
  6. enum {OK, CANT_OPEN};
  7.  
  8. int patch (TCHAR* fname)
  9. {
  10.     char first_patch[2]  = {0x90, 0x90};    // NOP NOP
  11.     char second_patch[2] = {0xEB, 0x07};    // JMP 40124C
  12.     HANDLE hFile = CreateFile(fname,
  13.                               FILE_ALL_ACCESS, NULL,
  14.                               NULL, OPEN_EXISTING,
  15.                               FILE_ATTRIBUTE_NORMAL, NULL);
  16.     if (hFile == INVALID_HANDLE_VALUE)
  17.         return CANT_OPEN;
  18.  
  19.     int SizeFile  = GetFileSize(hFile, NULL);
  20.     HANDLE MhFile = CreateFileMapping(hFile, 0, PAGE_READWRITE, 0, SizeFile, 0);
  21.     HANDLE View   = MapViewOfFile(MhFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
  22.  
  23.     UnmapViewOfFile(View);
  24.     CloseHandle(hFile);
  25.     CloseHandle(MhFile);
  26.     return OK;
  27. }
  28.  
  29. int main (int argc, char *argv[])
  30. {
  31.     TCHAR* default_fname = "CRACKME.EXE";
  32.  
  33.     if (argc > 1)
  34.     {
  35.         default_fname = argv[1];
  36.     }
  37.  
  38.     patch(default_fname);
  39.  
  40.     std::cout << default_fname << std::endl;
  41.     return 0;
  42. }
Add Comment
Please, Sign In to add comment