| 21 | } |
| 22 | |
| 23 | bool PE::save(std::string path) |
| 24 | { |
| 25 | // create a new file for writing our protected.exe to |
| 26 | HANDLE hOutputFile = CreateFileA(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 27 | |
| 28 | if (hOutputFile == INVALID_HANDLE_VALUE) |
| 29 | { |
| 30 | std::cerr << "error while creating output file: " << std::endl; |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | // write our protected.exe bytes to new file |
| 35 | DWORD bytesWritten = 0; |
| 36 | if (!WriteFile(hOutputFile, bytes.data(), bytes.size(), &bytesWritten, NULL)) |
| 37 | { |
| 38 | std::cerr << "error while writing to output file: " << std::endl; |
| 39 | CloseHandle(hOutputFile); |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | CloseHandle(hOutputFile); |
| 44 | return 1; |
| 45 | } |
| 46 | |
| 47 | void PE::addFunctionByRva(DWORD startRva, DWORD endRva) |
| 48 | { |