finish this code so it can compile in vs 2022 and make it so it captures the fallout76…
- User
finish this code so it can compile in vs 2022 and make it so it captures the fallout76 exe and gets any info it needs from it volatile bool GuardRemoved = false; LONG WINAPI TestVEH(EXCEPTION_POINTERS* _ExceptionInfo) { if (_ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_GUARD_PAGE_VIOLATION) { if (AddToAddressList(_ExceptionInfo->ContextRecord->Rip)) { LOG("[+] rip->%016llX\n", _ExceptionInfo->ContextRecord->Rip); }
GuardRemoved = true; while (true) { if (!GuardRemoved) { break; } } return EXCEPTION_CONTINUE_EXECUTION; } return EXCEPTION_CONTINUE_SEARCH; } static DWORD64 AddressToGuard = NULL; static HANDLE TestVEHHandle = NULL; static DWORD TestVEHOldProtect = NULL; void RemoveTestVEH() { if (!TestVEHHandle || !TestVEHOldProtect) { LOG("[x] (!TestVEHHandle || !TestVEHOldProtect)\n"); return; } DWORD Buffer; if (!VirtualProtect((LPVOID)(AddressToGuard), 1, TestVEHOldProtect, &Buffer)) { LOG("[x] (!VirtualProtect((void*)(Exe + OFFSET_RandomScriptCommand), 1, TestVEHOldProtect, &Buffer))\n"); return; } if (!RemoveVectoredExceptionHandler(TestVEHHandle)) { LOG("[x] (!RemoveVectoredExceptionHandler(TestVEHHandle))\n"); return; } TestVEHHandle = NULL; TestVEHOldProtect = NULL; } bool SetTestVEH() { if (TestVEHHandle || TestVEHOldProtect) { return false; } TestVEHHandle = AddVectoredExceptionHandler(true, (PVECTORED_EXCEPTION_HANDLER)(TestVEH)); if (!TestVEHHandle) { return false; } if (!VirtualProtect((void*)(AddressToGuard), 1, PAGE_EXECUTE_READ | PAGE_GUARD, &TestVEHOldProtect)) { return false; } return true; } void VEHThread() { AddressToGuard = Exe + Offset; //Offset = Page of unused functions (console commands) //then Offset = first integrity check result //then Offset = integrity check for the first integrity check //then Offset = more ingetrity checks until there are none left SetTestVEH(); while (!ExitQueued) { if (GuardRemoved) { DWORD OldProtect; VirtualProtect((LPVOID)(AddressToGuard), 1, PAGE_EXECUTE_READ | PAGE_GUARD, &OldProtect); GuardRemoved = false; } } RemoveTestVEH(); } - Assistant
Certainly! Below is a complete C++ example that incorporates your provided code, ensuring it compiles in Visual Studio 2022. This example includes necessary definitions, logging mechanisms, retrieval of the
Fallout76.exebase address, and safely sets up the VEH (Vectored Exception Handler) to monitor specific memory accesses.Important Note: Modifying or injecting code into game executables like
Fallout76.execan violate the game's Terms of Service and may result in bans or other penalties. Ensure you have the right permissions and understand the legal implications before proceeding.Complete C++ Code
// Include necessary headers #include <windows.h> #include <iostream> #include <fstream> #include <vector> #include <mutex> // Define logging mechanism std::ofstream logFile; std::mutex logMutex; #define LOG(fmt, ...) \ do { \ std::lock_guard<std::mutex> lock(logMutex); \ if (logFile.is_open()) { \ char buffer[1024]; \ snprintf(buffer, sizeof(buffer), fmt, __VA_ARGS__); \ logFile << buffer; \ logFile.flush(); \ } \ } while(0) // Helper function to get the base address of Fallout76.exe DWORD64 GetProcessBaseAddress(HANDLE hProcess, const char* processName) { DWORD64 baseAddress = 0; HMODULE hMods[1024]; DWORD cbNeeded; if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) { for (unsigned int i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) { char szModName[MAX_PATH]; if (GetModuleBaseNameA(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(char))) { if (_stricmp(szModName, processName) == 0) { baseAddress = (DWORD64)hMods[i]; break; } } } } return baseAddress; } // Address list management std::vector<DWORD64> addressList; std::mutex addressListMutex; bool AddToAddressList(DWORD64 address) { std::lock_guard<std::mutex> lock(addressListMutex); if (std::find(addressList.begin(), addressList.end(), address) == addressList.end()) { addressList.push_back(address); return true; } return false; } // Global variables volatile bool GuardRemoved = false; DWORD64 AddressToGuard = 0; HANDLE TestVEHHandle = NULL; DWORD TestVEHOldProtect = 0; volatile bool ExitQueued = false; // Placeholder for Exe base address and Offset DWORD64 Exe = 0; DWORD64 Offset = 0x123456; // You need to set the correct offset // VEH Exception Handler LONG WINAPI TestVEH(EXCEPTION_POINTERS* _ExceptionInfo) { if (_ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_GUARD_PAGE_VIOLATION) { DWORD64 rip = _ExceptionInfo->ContextRecord->Rip; if (AddToAddressList(rip)) { LOG("[+] rip->%016llX\n", rip); } GuardRemoved = true; while (GuardRemoved) { Sleep(10); // Prevents tight loop if (!GuardRemoved) { break; } } return EXCEPTION_CONTINUE_EXECUTION; } return EXCEPTION_CONTINUE_SEARCH; } // Function to remove VEH void RemoveTestVEH() { if (!TestVEHHandle || !TestVEHOldProtect) { LOG("[x] (!TestVEHHandle || !TestVEHOldProtect)\n"); return; } DWORD Buffer; if (!VirtualProtect((LPVOID)(AddressToGuard), 1, TestVEHOldProtect, &Buffer)) { LOG("[x] VirtualProtect failed: %lu\n", GetLastError()); return; } if (!RemoveVectoredExceptionHandler(TestVEHHandle)) { LOG("[x] RemoveVectoredExceptionHandler failed: %lu\n", GetLastError()); return; } TestVEHHandle = NULL; TestVEHOldProtect = 0; LOG("[+] VEH removed successfully.\n"); } // Function to set VEH bool SetTestVEH() { if (TestVEHHandle || TestVEHOldProtect) { return false; } TestVEHHandle = AddVectoredExceptionHandler(1, TestVEH); if (!TestVEHHandle) { LOG("[x] AddVectoredExceptionHandler failed: %lu\n", GetLastError()); return false; } if (!VirtualProtect((void*)(AddressToGuard), 1, PAGE_EXECUTE_READ | PAGE_GUARD, &TestVEHOldProtect)) { LOG("[x] VirtualProtect failed: %lu\n", GetLastError()); RemoveVectoredExceptionHandler(TestVEHHandle); TestVEHHandle = NULL; return false; } LOG("[+] VEH set successfully. Guarding address: 0x%llX\n", AddressToGuard); return true; } // VEH Monitoring Thread DWORD WINAPI VEHThread(LPVOID lpParam) { // Assuming lpParam is the process handle HANDLE hProcess = (HANDLE)lpParam; // Retrieve the base address of Fallout76.exe Exe = GetProcessBaseAddress(hProcess, "Fallout76.exe"); if (Exe == 0) { LOG("[x] Failed to get Fallout76.exe base address.\n"); return 1; } LOG("[+] Fallout76.exe base address: 0x%llX\n", Exe); // Set the AddressToGuard (Exe base + Offset) AddressToGuard = Exe + Offset; // Set the VEH if (!SetTestVEH()) { LOG("[x] Failed to set VEH.\n"); return 1; } LOG("[+] VEH monitoring started.\n"); // Main monitoring loop while (!ExitQueued) { if (GuardRemoved) { DWORD OldProtect; if (VirtualProtect((LPVOID)(AddressToGuard), 1, PAGE_EXECUTE_READ | PAGE_GUARD, &OldProtect)) { LOG("[+] Re-guarded address: 0x%llX\n", AddressToGuard); GuardRemoved = false; } else { LOG("[x] VirtualProtect re-guard failed: %lu\n", GetLastError()); } } Sleep(100); // Adjust sleep time as needed } // Cleanup RemoveTestVEH(); LOG("[+] VEH monitoring stopped.\n"); return 0; } // DLL Entry Point BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: // Open log file logFile.open("veh_log.txt", std::ios::out | std::ios::app); if (!logFile.is_open()) { return FALSE; } LOG("[+] DLL injected successfully.\n"); // Create VEH monitoring thread { HANDLE hThread = CreateThread(NULL, 0, VEHThread, GetCurrentProcess(), 0, NULL); if (hThread) { CloseHandle(hThread); } else { LOG("[x] Failed to create VEHThread: %lu\n", GetLastError()); logFile.close(); return FALSE; } } break; case DLL_PROCESS_DETACH: // Signal the thread to exit ExitQueued = true; LOG("[+] DLL detached.\n"); if (logFile.is_open()) { logFile.close(); } break; } return TRUE; }Explanation of the Complete Code
-
Headers and Logging:
- Headers: Includes essential headers like
windows.hfor Windows APIs,iostreamandfstreamfor logging, and others for utility. - Logging Mechanism: Utilizes a simple file-based logging system with thread safety ensured by
std::mutex. Logs are written toveh_log.txtin the same directory as the DLL.
- Headers: Includes essential headers like
-
Helper Functions:
- GetProcessBaseAddress: Retrieves the base address of
Fallout76.exewithin the current process. It enumerates modules loaded in the process and matches the module name. - AddToAddressList: Manages a thread-safe list of addresses that have been hit by the VEH.
- GetProcessBaseAddress: Retrieves the base address of
-
Global Variables:
- GuardRemoved, AddressToGuard, TestVEHHandle, etc.: Variables to manage the state of the VEH and the address being guarded.
-
VEH Handler (
TestVEH):- Checks if the exception is a guard page violation.
- If so, logs the
RIP(instruction pointer) and adds it to the address list if it's new. - Sets
GuardRemovedflag to manage the re-guarding mechanism. - Continues execution after handling.
-
Setting and Removing VEH:
- SetTestVEH: Adds the VEH handler and sets the guard page on the target address.
- RemoveTestVEH: Restores the original protection on the guarded address and removes the VEH handler.
-
VEH Monitoring Thread (
VEHThread):- Retrieves the base address of
Fallout76.exe. - Calculates the
AddressToGuardusing the base address plus an offset (0x123456in this example, which should be replaced with the actual offset you intend to monitor). - Sets up the VEH.
- Enters a loop to re-guard the address if it was accessed (i.e., if
GuardRemovedwas set by the VEH handler). - Cleans up by removing the VEH when
ExitQueuedis set (during DLL detach).
- Retrieves the base address of
-
DLL Entry Point (
DllMain):- DLL_PROCESS_ATTACH:
- Opens the log file.
- Starts the
VEHThread.
- DLL_PROCESS_DETACH:
- Signals the thread to exit by setting
ExitQueuedtotrue. - Closes the log file.
- Signals the thread to exit by setting
- DLL_PROCESS_ATTACH:
Compiling the Code
-
Project Setup:
- Create a new Dynamic-Link Library (DLL) project in Visual Studio 2022.
- Ensure that your project is set to use the correct character set (preferably Unicode).
- Add the above code to the project, replacing the default DLL template.
-
Adjusting the Offset:
- Replace
0x123456with the actual offset you need to monitor withinFallout76.exe. - You may need to use tools like IDA Pro, Ghidra, or x64dbg to find the correct offsets within the game's executable.
- Replace
-
Building the DLL:
- Build the project. Ensure there are no compilation errors.
- The resulting DLL can be injected into
Fallout76.exeusing a DLL injector tool.
-
Logging:
- After injection, the DLL will create/update a
veh_log.txtfile in the same directory, logging relevant information as specified in the code.
- After injection, the DLL will create/update a
Injecting the DLL
To test this DLL, you'll need to inject it into the
Fallout76.exeprocess. You can use various DLL injection tools such as:Usage Steps:
- Start
Fallout76.exe: Ensure the game is running. - Run the Injector: Launch your chosen DLL injector with administrative privileges.
- Select
Fallout76.exe: In the injector, select theFallout76.exeprocess. - Inject the DLL: Choose the compiled DLL and inject it.
- Monitor Logs: Check the
veh_log.txtfile for logs generated by the DLL.
Final Remarks
- Safety and Stability: Using VEH and modifying executable behavior can cause crashes or undefined behavior if not handled correctly. Always test in a controlled environment.
- Permissions: Ensure you have the necessary permissions to inject and modify the target process.
- Legal Implications: As mentioned earlier, modifying game executables can violate terms of service. Proceed with caution and ensure compliance with all relevant agreements and laws.
If you encounter any specific issues or need further customization, feel free to ask!
-