Skip to content
TheChatArchiveThe Chat Archive
o1-mini-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

#include <windows.h> #include <tlhelp32.h> #include <stdio.h> #include <string> #include…

  1. User

    #include <windows.h> #include <tlhelp32.h> #include <stdio.h> #include #include #include #include #include #include <psapi.h> // For GetModuleInformation #include // For strncmp #include // For std::setw #include

    // Constants const uintptr_t OFFSET_ADJUSTMENT = 0x10; // Adjust based on analysis

    // Function to log messages to console and optionally to a file void log_message(FILE* log_file, bool log_to_file, const char* format, ...) { va_list args; va_start(args, format);

    // Output to console
    vprintf(format, args);
    
    if (log_to_file && log_file != NULL) {
        // Make a copy of args for file logging
        va_list args_copy;
        va_copy(args_copy, args);
        vfprintf(log_file, format, args_copy);
        va_end(args_copy);
        fflush(log_file);
    }
    
    va_end(args);
    

    }

    // Function to get the Process ID (PID) by process name DWORD get_process_id_by_name(const std::string& process_name, FILE* log_file) { PROCESSENTRY32A pe32; pe32.dwSize = sizeof(PROCESSENTRY32A); HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

    if (hSnapshot == INVALID_HANDLE_VALUE) {
        log_message(log_file, false, "Error: Unable to create tool help snapshot. Error Code: %lu\n", GetLastError());
        return 0;
    }
    
    if (!Process32FirstA(hSnapshot, &pe32)) {
        log_message(log_file, false, "Error: Unable to retrieve information on the first process. Error Code: %lu\n", GetLastError());
        CloseHandle(hSnapshot);
        return 0;
    }
    
    do {
        if (_stricmp(pe32.szExeFile, process_name.c_str()) == 0) {
            CloseHandle(hSnapshot);
            log_message(log_file, false, "Process '%s' found with PID %u\n", process_name.c_str(), pe32.th32ProcessID);
            return pe32.th32ProcessID;
        }
    } while (Process32NextA(hSnapshot, &pe32));
    
    CloseHandle(hSnapshot);
    log_message(log_file, false, "Error: Process '%s' not found\n", process_name.c_str());
    return 0;
    

    }

    // Function to get the base address of the main module (e.g., Fallout76.exe) uintptr_t get_base_address(DWORD pid, FILE* log_file) { MODULEENTRY32A me32; me32.dwSize = sizeof(MODULEENTRY32A); HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid);

    if (hSnapshot == INVALID_HANDLE_VALUE) {
        log_message(log_file, false, "Error: Unable to create module snapshot. Error Code: %lu\n", GetLastError());
        return 0;
    }
    
    if (!Module32FirstA(hSnapshot, &me32)) {
        log_message(log_file, false, "Error: Unable to retrieve information on the first module. Error Code: %lu\n", GetLastError());
        CloseHandle(hSnapshot);
        return 0;
    }
    
    uintptr_t base_address = reinterpret_cast<uintptr_t>(me32.modBaseAddr);
    CloseHandle(hSnapshot);
    log_message(log_file, false, "Base address of the main module: 0x%p\n", (void*)base_address);
    return base_address;
    

    }

    // Function to get the start and end addresses of a specific section (e.g., .data or .rdata) bool get_section_limits(HANDLE hProcess, uintptr_t base_addr, const char* section_name, uintptr_t& section_start, uintptr_t& section_end, bool& is64Bit) { IMAGE_DOS_HEADER dos_header; if (!ReadProcessMemory(hProcess, (LPCVOID)base_addr, &dos_header, sizeof(dos_header), NULL)) { return false; }

    if (dos_header.e_magic != IMAGE_DOS_SIGNATURE) {
        return false;
    }
    
    IMAGE_NT_HEADERS32 nt_headers32;
    IMAGE_NT_HEADERS64 nt_headers64;
    
    // Read the magic number to determine 32 or 64 bit
    WORD magic;
    if (!ReadProcessMemory(hProcess, (LPCVOID)(base_addr + dos_header.e_lfanew + offsetof(IMAGE_NT_HEADERS, OptionalHeader)), &magic, sizeof(magic), NULL)) {
        return false;
    }
    
    if (magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
        is64Bit = true;
        // Read entire IMAGE_NT_HEADERS64
        if (!ReadProcessMemory(hProcess, (LPCVOID)(base_addr + dos_header.e_lfanew), &nt_headers64, sizeof(nt_headers64), NULL)) {
            return false;
        }
        // Allocate memory for section headers
        std::unique_ptr<IMAGE_SECTION_HEADER[]> section_headers(new IMAGE_SECTION_HEADER[nt_headers64.FileHeader.NumberOfSections]);
        SIZE_T bytes_read = 0;
        if (!ReadProcessMemory(
            hProcess,
            (LPCVOID)(base_addr + dos_header.e_lfanew + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + sizeof(IMAGE_OPTIONAL_HEADER64)),
            section_headers.get(),
            sizeof(IMAGE_SECTION_HEADER) * nt_headers64.FileHeader.NumberOfSections,
            &bytes_read) || bytes_read != sizeof(IMAGE_SECTION_HEADER) * nt_headers64.FileHeader.NumberOfSections) {
            return false;
        }
    
        // Iterate through sections to find the desired one
        for (unsigned int i = 0; i < nt_headers64.FileHeader.NumberOfSections; ++i) {
            if (strncmp(reinterpret_cast<char*>(section_headers[i].Name), section_name, IMAGE_SIZEOF_SHORT_NAME) == 0) {
                section_start = base_addr + section_headers[i].VirtualAddress;
                section_end = section_start + section_headers[i].Misc.VirtualSize;
                return true;
            }
        }
    }
    else if (magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
        is64Bit = false;
        // Read entire IMAGE_NT_HEADERS32
        if (!ReadProcessMemory(hProcess, (LPCVOID)(base_addr + dos_header.e_lfanew), &nt_headers32, sizeof(nt_headers32), NULL)) {
            return false;
        }
        // Allocate memory for section headers
        std::unique_ptr<IMAGE_SECTION_HEADER[]> section_headers(new IMAGE_SECTION_HEADER[nt_headers32.FileHeader.NumberOfSections]);
        SIZE_T bytes_read = 0;
        if (!ReadProcessMemory(
            hProcess,
            (LPCVOID)(base_addr + dos_header.e_lfanew + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + sizeof(IMAGE_OPTIONAL_HEADER32)),
            section_headers.get(),
            sizeof(IMAGE_SECTION_HEADER) * nt_headers32.FileHeader.NumberOfSections,
            &bytes_read) || bytes_read != sizeof(IMAGE_SECTION_HEADER) * nt_headers32.FileHeader.NumberOfSections) {
            return false;
        }
    
        // Iterate through sections to find the desired one
        for (unsigned int i = 0; i < nt_headers32.FileHeader.NumberOfSections; ++i) {
            if (strncmp(reinterpret_cast<char*>(section_headers[i].Name), section_name, IMAGE_SIZEOF_SHORT_NAME) == 0) {
                section_start = base_addr + section_headers[i].VirtualAddress;
                section_end = section_start + section_headers[i].Misc.VirtualSize;
                return true;
            }
        }
    }
    else {
        return false; // Unknown format
    }
    
    return false; // Section not found
    

    }

    // Function to find the address of a given ANSI string within a memory section uintptr_t find_string_in_section(HANDLE hProcess, uintptr_t section_start, uintptr_t section_end, const std::string& target_string, FILE* log_file) { SIZE_T section_size = section_end - section_start; std::unique_ptr<BYTE[]> buffer(new BYTE[section_size]); SIZE_T bytes_read = 0;

    // Read the entire section into the buffer
    if (!ReadProcessMemory(hProcess, (LPCVOID)section_start, buffer.get(), section_size, &bytes_read)) {
        log_message(log_file, false, "Error: Unable to read memory section at 0x%p\n", (void*)section_start);
        return 0;
    }
    
    if (bytes_read < section_size) {
        log_message(log_file, false, "Warning: Read fewer bytes (%llu) than expected (%llu)\n", bytes_read, section_size);
    }
    
    // Search for the target string within the buffer
    for (SIZE_T i = 0; i <= bytes_read - target_string.length(); ++i) {
        if (memcmp(buffer.get() + i, target_string.c_str(), target_string.length()) == 0) {
            // Ensure the string is null-terminated
            if (i + target_string.length() < bytes_read && buffer[i + target_string.length()] == '\0') {
                uintptr_t string_addr = section_start + i;
                log_message(log_file, false, "Found string '%s' at address 0x%p\n", target_string.c_str(), (void*)string_addr);
                return string_addr;
            }
        }
    }
    
    log_message(log_file, false, "String '%s' not found in section 0x%p - 0x%p\n", target_string.c_str(), (void*)section_start, (void*)section_end);
    return 0;
    

    }

    // Function to find the address that references a given string address (i.e., where a pointer points to string_addr) uintptr_t find_pointer_to_address(HANDLE hProcess, uintptr_t section_start, uintptr_t section_end, uintptr_t target_address, bool is64Bit, FILE* log_file) { SIZE_T pointer_size = is64Bit ? sizeof(uintptr_t) : sizeof(unsigned long); SIZE_T section_size = section_end - section_start; std::unique_ptr<BYTE[]> buffer(new BYTE[section_size]); SIZE_T bytes_read = 0;

    // Read the entire section into the buffer
    if (!ReadProcessMemory(hProcess, (LPCVOID)section_start, buffer.get(), section_size, &bytes_read)) {
        log_message(log_file, false, "Error: Unable to read memory section at 0x%p\n", (void*)section_start);
        return 0;
    }
    
    if (bytes_read < section_size) {
        log_message(log_file, false, "Warning: Read fewer bytes (%llu) than expected (%llu)\n", bytes_read, section_size);
    }
    
    // Iterate through the buffer to find instances of target_address
    for (SIZE_T i = 0; i <= bytes_read - pointer_size; ++i) {
        uintptr_t potential_ptr = 0;
    
        if (is64Bit) {
            memcpy(&potential_ptr, buffer.get() + i, sizeof(uintptr_t));
        }
        else {
            unsigned long temp_ptr = 0;
            memcpy(&temp_ptr, buffer.get() + i, sizeof(unsigned long));
            potential_ptr = static_cast<uintptr_t>(temp_ptr);
        }
    
        if (potential_ptr == target_address) {
            uintptr_t pointer_addr = section_start + i;
            log_message(log_file, false, "Found pointer to address 0x%p at 0x%p\n", (void*)target_address, (void*)pointer_addr);
            return pointer_addr;
        }
    }
    
    log_message(log_file, false, "Pointer to address 0x%p not found in section 0x%p - 0x%p\n", (void*)target_address, (void*)section_start, (void*)section_end);
    return 0;
    

    }

    int main() { // Define target process and settings const std::string process_name = "Fallout76.exe"; const std::vectorstd::string gameSettings = { "fVATSMaxChance", "fVATSChancePerceptionMultiplier", "fVATSMaxEngageDistance", "fVATSChanceRaycastVisibilityMininmum", "fVATSPingCost", "fVATSCriticalChargeBase", "fVATSCriticalChargeBonusMult", "fVATSCriticalChargeLimit", "fVATSCriticalChargeMult", "fPlayerAutoReloadDelaySec", "bDisablePlayerCollision", "fAVDCarryWeightBase", "fAbsolutePlayerInventoryWeightLimit", "fInvisibilityMaxRefraction", "fInvisibilityMinRefraction", "fJetpackThrustInitial", "fJetpackThrustSustained", "fJetpackTimeToSustained", "bJetpackInitialThrustOnlyOnTakeoff", "fAimStabilityCrouchedScopeMult", "fPropModScaleWeapDurability", "fLockpickSkillSweetSpotBase", "fSweetSpotEasy", "fSweetSpotAverage", "fSweetSpotHard", "fSweetSpotVeryHard", "iHackingMinWords", "iHackingMaxWords", "fCombatMusicNearCombatInnerRadius", "fCombatMusicNearCombatOuterRadius", "fCombatMusicPlayerTargetedThreatRatio", "pkKeywords", "fAttackActionPointCost", "fspeed", "fweight", "iDurability", "ihealth", "bHoldInputToPower", "fMinPowerPerShot", "poAmmo", "paAimModel", "ppOverrideProjectile", "uNumProjectiles", "vaActorValues" };

    // Open log file
    FILE* log_file = nullptr;
    if (fopen_s(&log_file, "memscan.log", "w") != 0) {
        printf("Could not open log file for writing\n");
        return 1;
    }
    
    // Log start time
    time_t t = time(NULL);
    struct tm tm_info;
    if (localtime_s(&tm_info, &t) != 0) {
        log_message(log_file, false, "Error: Could not get local time.\n");
        fclose(log_file);
        return 1;
    }
    log_message(log_file, true, "Memory scan started at: %04d-%02d-%02d %02d:%02d:%02d\n",
        tm_info.tm_year + 1900, tm_info.tm_mon + 1, tm_info.tm_mday,
        tm_info.tm_hour, tm_info.tm_min, tm_info.tm_sec);
    
    // Get Process ID
    DWORD pid = get_process_id_by_name(process_name, log_file);
    if (pid == 0) {
        log_message(log_file, true, "Exiting program.\n");
        fclose(log_file);
        return 1;
    }
    
    // Get Base Address
    uintptr_t base_addr = get_base_address(pid, log_file);
    if (base_addr == 0) {
        log_message(log_file, true, "Exiting program.\n");
        fclose(log_file);
        return 1;
    }
    
    // Open Process with necessary permissions
    HANDLE hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, pid);
    if (hProcess == NULL) {
        log_message(log_file, true, "Error: Could not open process %d. Error Code: %lu\n", pid, GetLastError());
        fclose(log_file);
        return 1;
    }
    
    // Determine if the process is 64-bit or 32-bit
    BOOL isWow64 = FALSE;
    if (!IsWow64Process(hProcess, &isWow64)) {
        log_message(log_file, true, "Error: Unable to determine process architecture. Error Code: %lu\n", GetLastError());
        CloseHandle(hProcess);
        fclose(log_file);
        return 1;
    }
    
    BOOL is64Bit = FALSE;
    SYSTEM_INFO systemInfo;
    GetNativeSystemInfo(&systemInfo);
    if (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
        systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ARM64) {
        is64Bit = !isWow64;
    }
    
    log_message(log_file, true, "Target process is %s-bit.\n", is64Bit ? "64" : "32");
    
    // Get .data section limits
    uintptr_t data_start = 0, data_end = 0;
    bool data_is64Bit = is64Bit;
    if (!get_section_limits(hProcess, base_addr, ".data", data_start, data_end, data_is64Bit)) {
        log_message(log_file, true, "Error: Could not find .data section.\n");
        CloseHandle(hProcess);
        fclose(log_file);
        return 1;
    }
    log_message(log_file, true, ".data section: Start = 0x%p, End = 0x%p\n", (void*)data_start, (void*)data_end);
    
    // Get .rdata section limits
    uintptr_t rdata_start = 0, rdata_end = 0;
    bool rdata_is64Bit = is64Bit;
    if (!get_section_limits(hProcess, base_addr, ".rdata", rdata_start, rdata_end, rdata_is64Bit)) {
        log_message(log_file, true, "Error: Could not find .rdata section.\n");
        CloseHandle(hProcess);
        fclose(log_file);
        return 1;
    }
    log_message(log_file, true, ".rdata section: Start = 0x%p, End = 0x%p\n", (void*)rdata_start, (void*)rdata_end);
    
    // Begin logging results
    fprintf(log_file, "\n$gameSettings = {\n");
    
    // Iterate through each string in gameSettings
    for (const auto& setting : gameSettings) {
        log_message(log_file, true, "\nProcessing string: '%s'\n", setting.c_str());
    
        // Step 1: Search for the string in .data and .rdata sections
        uintptr_t string_addr = 0;
    
        // Search in .data
        string_addr = find_string_in_section(hProcess, data_start, data_end, setting, log_file);
    
        // If not found in .data, search in .rdata
        if (string_addr == 0) {
            string_addr = find_string_in_section(hProcess, rdata_start, rdata_end, setting, log_file);
        }
    
        if (string_addr == 0) {
            log_message(log_file, true, "Error: String '%s' not found in any section.\n", setting.c_str());
            continue;
        }
    
        // Step 2: Search for references (pointers) to string_addr in .data and .rdata sections
        uintptr_t load_addr = 0;
    
        // Search in .data
        load_addr = find_pointer_to_address(hProcess, data_start, data_end, string_addr, is64Bit, log_file);
    
        // If not found in .data, search in .rdata
        if (load_addr == 0) {
            load_addr = find_pointer_to_address(hProcess, rdata_start, rdata_end, string_addr, is64Bit, log_file);
        }
    
        if (load_addr == 0) {
            log_message(log_file, true, "Error: Reference to string '%s' not found.\n", setting.c_str());
            continue;
        }
    
        // Step 3: Calculate function pointer by subtracting OFFSET_ADJUSTMENT
        uintptr_t func_ptr = load_addr - OFFSET_ADJUSTMENT;
        log_message(log_file, true, "Function pointer for '%s': 0x%p\n", setting.c_str(), (void*)func_ptr);
    
        // Step 4: Calculate offset relative to base address
        uintptr_t offset = func_ptr - base_addr;
        log_message(log_file, true, "Offset for '%s': 0x%p\n", setting.c_str(), (void*)offset);
    
        // Log the result in the log file
        fprintf(log_file, "    \"%s\" => 0x%p,\n", setting.c_str(), (void*)offset);
    }
    
    fprintf(log_file, "};\n\n");
    
    // Log end time
    t = time(NULL);
    if (localtime_s(&tm_info, &t) != 0) {
        log_message(log_file, false, "Error: Could not get local time.\n");
    }
    else {
        log_message(log_file, true, "Memory scan ended at: %04d-%02d-%02d %02d:%02d:%02d\n",
            tm_info.tm_year + 1900, tm_info.tm_mon + 1, tm_info.tm_mday,
            tm_info.tm_hour, tm_info.tm_min, tm_info.tm_sec);
    }
    
    // Cleanup
    CloseHandle(hProcess);
    fclose(log_file);
    
    return 0;
    

    }

  2. Assistant

    Your C++ program is designed to scan the memory of a running process (Fallout76.exe) to locate specific strings and their corresponding function pointers within the process's memory space. Here's a detailed breakdown of what your code does, potential issues, and suggestions for improvement.

    Overview of the Program

    1. Process Identification:

      • The program identifies the target process (Fallout76.exe) by enumerating all running processes and matching the process name.
      • It retrieves the Process ID (PID) and the base address of the main module (Fallout76.exe) within that process.
    2. Memory Section Identification:

      • The program locates the .data and .rdata sections of the target process's main module. These sections typically contain initialized data and read-only data (like strings), respectively.
    3. String and Pointer Scanning:

      • For each string in the gameSettings vector, the program searches for its presence within the .data and .rdata sections.
      • Once a string is found, the program searches for pointers that reference the address of that string within the same sections.
      • It calculates a function pointer by subtracting an OFFSET_ADJUSTMENT value from the located pointer address.
      • Finally, it computes the offset of the function pointer relative to the base address of the module and logs this information.
    4. Logging:

      • The program logs its activities to both the console and a log file (memscan.log), capturing details like the presence of strings, their addresses, and corresponding function pointers.

    Detailed Breakdown

    1. Process Identification:

    • get_process_id_by_name Function:

      • Uses CreateToolhelp32Snapshot and iterates through processes using Process32FirstA and Process32NextA.
      • Compares each process's executable name (case-insensitive) to the target process name.
      • Returns the PID if found; otherwise, logs an error.
    • get_base_address Function:

      • Uses CreateToolhelp32Snapshot to take a snapshot of the modules within the target process.
      • Iterates through modules using Module32FirstA and presumably stops at the first module (assumed to be the main module).
      • Retrieves the base address (modBaseAddr) of the main module.

    2. Memory Section Identification:

    • get_section_limits Function:
      • Reads the IMAGE_DOS_HEADER and verifies the DOS signature.
      • Determines whether the target process is 32-bit or 64-bit by checking the IMAGE_NT_OPTIONAL_HDR magic number.
      • Reads the IMAGE_NT_HEADERS accordingly and retrieves section headers.
      • Searches for the specified section name (e.g., .data, .rdata) and calculates the start and end addresses based on VirtualAddress and VirtualSize.

    3. String and Pointer Scanning:

    • find_string_in_section Function:

      • Reads the entire specified memory section into a buffer using ReadProcessMemory.
      • Scans the buffer for the target string, ensuring it is null-terminated.
      • Returns the address of the found string.
    • find_pointer_to_address Function:

      • Reads the entire specified memory section into a buffer.
      • Scans for occurrences where pointers within the section match the target string's address.
      • Returns the address where the pointer is found.
    • Main Logic:

      • Iterates through each string in gameSettings.
      • Searches for each string in .data and .rdata sections.
      • For each found string, searches for pointers referencing it.
      • Calculates func_ptr by subtracting OFFSET_ADJUSTMENT from the pointer's address.
      • Determines the offset of func_ptr relative to the base address of the module.

    4. Logging:

    • Logs are written to both the console and a log file, capturing significant steps and any errors encountered during the scanning process.

    Potential Issues and Suggestions

    1. Reliability of OFFSET_ADJUSTMENT:

      • Issue: The OFFSET_ADJUSTMENT is set as a constant (0x10), which may not be accurate across different versions or builds of the target application.
      • Suggestion: Instead of hardcoding this value, consider calculating it dynamically or making it configurable. This adjustment is crucial for accurately determining function pointers.
    2. Error Handling:

      • Issue: While the program logs errors, it often continues execution even after encountering critical failures (e.g., failing to find a section or open the process).
      • Suggestion: Implement more robust error handling by halting execution or attempting recovery when encountering non-recoverable errors.
    3. Efficiency:

      • Issue: Reading entire sections into memory can be memory-intensive, especially for large sections.
      • Suggestion: Implement chunk-based reading and scanning to handle large memory sections more efficiently.
    4. Security and Permissions:

      • Issue: Accessing another process's memory requires appropriate permissions. Running this program without sufficient privileges will fail.
      • Suggestion: Ensure the program runs with administrative privileges. Additionally, be aware of security implications and ensure compliance with software terms of service.
    5. Architecture Compatibility:

      • Issue: The program determines if the target process is 64-bit or 32-bit but may not handle cross-architecture scenarios (e.g., 32-bit process on a 64-bit system) robustly.
      • Suggestion: Test the program in different environments to ensure compatibility. Use IsWow64Process effectively to handle cross-architecture scenarios.
    6. String Matching:

      • Issue: The program looks for exact matches of strings with null termination. If the target application uses different encoding (e.g., Unicode) or has variations in string storage, this might fail.
      • Suggestion: Extend the search capability to handle different encodings and variations. For example, implement Unicode string searching if necessary.
    7. Logging Enhancements:

      • Issue: Currently, the log file uses a mix of fprintf and log_message. This can lead to inconsistent logging behavior.
      • Suggestion: Standardize logging by using a single consistent method, preferably encapsulating logging functionality to handle different outputs seamlessly.
    8. Resource Management:

      • Issue: The program opens handles (hSnapshot, hProcess) and files but relies on manual closure. Exceptions or early returns might lead to resource leaks.
      • Suggestion: Use RAII (Resource Acquisition Is Initialization) principles by encapsulating handles and file pointers within classes that automatically manage resource lifetimes.
    9. Magic Number Calculation:

      • Issue: The magic number is read using an offsetof on the IMAGE_NT_HEADERS. However, since IMAGE_NT_HEADERS can be either 32-bit or 64-bit, using IMAGE_NT_HEADERS directly can be misleading.
      • Suggestion: Instead of using offsetof, separate the logic to handle 32-bit and 64-bit headers distinctly. Ensure accurate reading based on the architecture.
    10. Offset Representation:

      • Issue: The offset is printed using 0x%p, which typically expects a pointer. Using uintptr_t might be better represented with 0x%llx or similar, depending on the architecture.
      • Suggestion: Adjust the format specifiers to match the data types accurately. For example:
        log_message(log_file, true, "Offset for '%s': 0x%llx\n", setting.c_str(), static_cast<unsigned long long>(offset));
        

    Code Improvements and Best Practices

    1. Use RAII for Resource Management: Encapsulate handles using smart pointers or custom RAII classes to ensure they are automatically closed, even if exceptions occur.

      #include <memory>
      
      struct HandleDeleter {
          void operator()(HANDLE handle) const {
              if (handle && handle != INVALID_HANDLE_VALUE) {
                  CloseHandle(handle);
              }
          }
      };
      
      using unique_handle = std::unique_ptr<std::remove_pointer<HANDLE>::type, HandleDeleter>;
      

      Use unique_handle instead of raw HANDLE types.

    2. Modularize Code: Break down the main function into smaller, reusable functions to improve readability and maintainability.

    3. Enhanced Logging: Implement a dedicated logging class that handles different log levels (INFO, ERROR, DEBUG) and supports log rotation if needed.

    4. Configuration File: Externalize constants like OFFSET_ADJUSTMENT and the list of gameSettings into a configuration file or command-line arguments to make the program more flexible.

    5. Unicode Support: If the target application uses Unicode strings, modify the string searching functions to handle wide characters (wchar_t) appropriately.

    6. Dynamic Offset Adjustment: Implement a mechanism to calculate OFFSET_ADJUSTMENT dynamically by analyzing patterns or using symbol information if available.

    7. Use More Robust String Search Algorithms: Implement efficient string search algorithms (like Boyer-Moore) to reduce the scanning time, especially for large memory sections.

    8. Error Reporting: Use more descriptive error messages and possibly throw exceptions for critical failures to separate normal logging from error handling.

    Ethical and Legal Considerations

    Before using or distributing this program, consider the following:

    • Legal Implications:

      • Modifying or reading another application's memory can violate its terms of service or licensing agreements.
      • Unauthorized memory manipulation can be considered unethical or illegal, especially for online games like Fallout 76.
    • Security Risks:

      • Running such programs with elevated privileges can expose your system to security vulnerabilities.
      • Ensure that the program does not inadvertently introduce security holes or interact maliciously with the target process.
    • Respect Developer Intent:

      • Developers often obfuscate or protect their application memory spaces to prevent cheating, reverse engineering, or tampering.
      • Respect the developers' efforts and the user community by avoiding unauthorized modifications.

    Conclusion

    Your program effectively demonstrates how to scan a target process's memory to locate specific strings and their related function pointers. By addressing the potential issues and implementing the suggested improvements, you can enhance the program's reliability, efficiency, and maintainability. Always ensure that such activities comply with legal standards and respect the intellectual property and security considerations of the target application.

    If you encounter specific issues or have particular questions about certain parts of the code, feel free to ask!