diff --git a/main.cpp b/main.cpp index 16e5c6f..40ca66f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,8 @@ #include #include + #include "memory.hpp" +#include "ifexist.hpp" using namespace std; @@ -8,21 +10,13 @@ Injector inj; DWORD pid; -bool DoesFileExist(const char* name) { - if (FILE* file = fopen(name, "r")) { - fclose(file); - return true; - } - else { - return false; - } -} +//now it's global +LPVOID ntOpenFile = GetProcAddress(LoadLibraryW(L"ntdll"), "NtOpenFile"); void bypass() { // Restore original NtOpenFile from external process //credits: Daniel KrupiƱski(pozdro dla ciebie byczku <3) - LPVOID ntOpenFile = GetProcAddress(LoadLibraryW(L"ntdll"), "NtOpenFile"); if (ntOpenFile) { char originalBytes[5]; memcpy(originalBytes, ntOpenFile, 5); @@ -31,6 +25,24 @@ void bypass() else { cout << "Unable to bypass :(\n"; + Sleep(2000); + exit(-1); + } +} + +void Backup() +{ + if (ntOpenFile) { + //So, when I patching first 5 bytes I need to backup them to 0? (I think) + char originalBytes[5]; + memcpy(originalBytes, ntOpenFile, 5); + WriteProcessMemory(inj.process, ntOpenFile, originalBytes, 0, NULL); + } + else + { + cout << "Unable to backup :(\n"; + Sleep(2000); + exit(-1); } } @@ -49,18 +61,20 @@ int main() inj.clientDLL = inj.GetModule(pid, "client.dll"); if (DoesFileExist("cheat.dll")) { - bypass(); + bypass(); if (inj.inject(pid, "cheat.dll")) { cout << "module injected!\n\n" << endl; + Backup(); Sleep(2000); exit(0); } else { cout << "Injection failed!\n\n" << endl; + Backup(); Sleep(2000); - exit(0); + exit(-1); } } @@ -68,7 +82,7 @@ int main() { cout << "cannot find cheat.dll\n\n"; Sleep(2000); - exit(0); + exit(-1); } return 0;