if (hSnapshot == INVALID_HANDLE_VALUE) {
return 0;
}
pe32.dwSize = sizeof(PROCESSENTRY32W);
if (!Process32FirstW(hSnapshot, &pe32)) {
CloseHandle(hSnapshot);
return 0;
}
do {
if (_wcsicmp(pe32.szExeFile, process_name) == 0) {
CloseHandle(hSnapshot);
return pe32.th32ProcessID;
}
} while (Process32NextW(hSnapshot, &pe32));
CloseHandle(hSnapshot);
return 0;
}
unsigned long long get_base_address(DWORD pid, const wchar_t* module_name) {
MODULEENTRY32W me32;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid);
if (hSnapshot == INVALID_HANDLE_VALUE) {
return 0;
}
me32.dwSize = sizeof(MODULEENTRY32W);
if (!Module32FirstW(hSnapshot, &me32)) {
CloseHandle(hSnapshot);
return 0;
}
unsigned long long base_address = 0;
do {
if (_wcsicmp(me32.szModule, module_name) == 0) {
base_address = (unsigned long long)me32.modBaseAddr;
break;
}
} while (Module32NextW(hSnapshot, &me32));
CloseHandle(hSnapshot);
return base_address;
}
bool get_section_info(HANDLE hProcess, unsigned long long base_addr, const char* section_name, SectionInfo& section_info) {
IMAGE_DOS_HEADER dos_header;
if (!ReadProcessMemory(hProcess, (LPCVOID)base_addr, &dos_header, sizeof(dos_header), NULL)) {
return false;
}
IMAGE_NT_HEADERS64 nt_headers;
if (!ReadProcessMemory(hProcess, (LPCVOID)(base_addr + dos_header.e_lfanew), &nt_headers, sizeof(nt_headers), NULL)) {
return false;
}
unsigned long long section_offset = base_addr + dos_header.e_lfanew + sizeof(IMAGE_NT_HEADERS64);
DWORD section_count = nt_headers.FileHeader.NumberOfSections;
IMAGE_SECTION_HEADER* section_headers = new (std::nothrow) IMAGE_SECTION_HEADER[section_count];
if (!section_headers) {
return false;
}
if (!ReadProcessMemory(hProcess, (LPCVOID)section_offset, section_headers, sizeof(IMAGE_SECTION_HEADER) * section_count, NULL)) {
delete[] section_headers;
return false;
}
bool found = false;
for (DWORD i = 0; i < section_count; i++) {
if (strncmp((char*)section_headers[i].Name, section_name, IMAGE_SIZEOF_SHORT_NAME) == 0) {
section_info.start = base_addr + section_headers[i].VirtualAddress;
DWORD aligned_size = section_headers[i].Misc.VirtualSize;
if (aligned_size % nt_headers.OptionalHeader.SectionAlignment != 0) {
aligned_size = (aligned_size + nt_headers.OptionalHeader.SectionAlignment - 1)
& ~(nt_headers.OptionalHeader.SectionAlignment - 1);
}
section_info.end = section_info.start + aligned_size;
section_info.size = aligned_size;
section_info.original_start = nt_headers.OptionalHeader.ImageBase + section_headers[i].VirtualAddress;
found = true;
break;
}
}
delete[] section_headers;
return found;
Assistant
}
unsigned long long find_string_in_section(HANDLE hProcess, const SectionInfo& section_info, const char* string_to_search) {
SIZE_T string_length = strlen(string_to_search);
unsigned long long addr = section_info.start;
const SIZE_T CHUNK_SIZE = 1024 * 1024;
while (addr < section_info.end) {
MEMORY_BASIC_INFORMATION mbi;
if (!VirtualQueryEx(hProcess, (LPCVOID)addr, &mbi, sizeof(mbi))) {
break;
}
SIZE_T read_size = min(CHUNK_SIZE, mbi.RegionSize);
char* buffer = new (std::nothrow) char[read_size];
if (!buffer) {
break;
}
SIZE_T bytesRead;
if (ReadProcessMemory(hProcess, (LPCVOID)addr, buffer, read_size, &bytesRead) && bytesRead > 0) {
for (SIZE_T i = 0; i < bytesRead - string_length; i++) {
if (memcmp(buffer + i, string_to_search, string_length) == 0) {
unsigned long long string_addr = addr + i;
delete[] buffer;
return string_addr;
}
}
}
delete[] buffer;
addr += read_size;
}
return 0;
}
unsigned long long find_reference_in_data_section(HANDLE hProcess, const SectionInfo& section_info, unsigned long long string_addr) {
unsigned long long addr = section_info.start;
const SIZE_T CHUNK_SIZE = 1024 * 1024;
while (addr < section_info.end) {
MEMORY_BASIC_INFORMATION mbi;
if (!VirtualQueryEx(hProcess, (LPCVOID)addr, &mbi, sizeof(mbi))) {
break;
}
SIZE_T read_size = min(CHUNK_SIZE, mbi.RegionSize);
read_size = read_size - (read_size % sizeof(unsigned long long));
unsigned long long* buffer = new (std::nothrow) unsigned long long[read_size / sizeof(unsigned long long)];
if (!buffer) {
break;
}
SIZE_T bytesRead;
if (ReadProcessMemory(hProcess, (LPCVOID)addr, buffer, read_size, &bytesRead) && bytesRead > 0) {
SIZE_T numElements = bytesRead / sizeof(unsigned long long);
for (SIZE_T i = 0; i < numElements; i++) {
if (buffer[i] == string_addr) {
unsigned long long reference_addr = addr + i * sizeof(unsigned long long);
delete[] buffer;
return reference_addr;
}
}
}
delete[] buffer;
addr += read_size;
}
return 0;
const char* gameSettings[] = {
"fVATSMaxChance",
"fVATSChancePerceptionMultiplier",
"fVATSMaxEngageDistance",
"fVATSChanceRaycastVisibilityMinimum",
"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",
"ihealth"
};
FILE* log_file;
if (_wfopen_s(&log_file, L"memscan.log", L"w") != 0) {
wprintf(L"Could not open log file for writing\n");
return 1;
}
DWORD pid = get_process_id_by_name(process_name);
if (pid == 0) {
fprintf(log_file, "Process not found\n");
fclose(log_file);
return 1;
}
HANDLE hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, pid);
if (hProcess == NULL) {
fprintf(log_file, "Failed to open process. Error: %lu\n", GetLastError());
fclose(log_file);
return 1;
}
unsigned long long base_addr = get_base_address(pid, module_name);
if (base_addr == 0) {
fprintf(log_file, "Failed to get base address\n");
CloseHandle(hProcess);
fclose(log_file);
return 1;
}
SectionInfo rdata_info, data_info;
if (!get_section_info(hProcess, base_addr, ".rdata", rdata_info)) {
fprintf(log_file, "Failed to get .rdata section info\n");
CloseHandle(hProcess);
fclose(log_file);
return 1;
}
if (!get_section_info(hProcess, base_addr, ".data", data_info)) {
fprintf(log_file, "Failed to get .data section info\n");
CloseHandle(hProcess);
fclose(log_file);
return 1;
}
fprintf(log_file, "$gameSettings = [\n");
for (const char* string_to_search : gameSettings) {
unsigned long long string_addr = find_string_in_section(hProcess, rdata_info, string_to_search);
if (string_addr != 0) {
unsigned long long reference_addr = find_reference_in_data_section(hProcess, data_info, string_addr);
if (reference_addr != 0) {
unsigned long long relative_reference_offset = reference_addr - base_addr;
unsigned long long ida_reference_addr = 0x140000000 + relative_reference_offset;
fprintf(log_file, " \"%s\" => 0x%llx,\n", string_to_search, ida_reference_addr);
}
}
}
fprintf(log_file, "];\n");
CloseHandle(hProcess);
fclose(log_file);
return 0;
}
it use to subtract 0x10 from the base to get its offset but now its changed unsigned long long rdata_section_start, rdata_section_end;
if (!get_section_limits(hProcess, base_addr, ".rdata", rdata_section_start, rdata_section_end)) {
CloseHandle(hProcess);
fclose(log_file);
return 1;
}
unsigned long long data_section_start, data_section_end;
if (!get_section_limits(hProcess, base_addr, ".data", data_section_start, data_section_end)) {
CloseHandle(hProcess);
fclose(log_file);
return 1;
}
fprintf(log_file, "$gameSettings = [\n");
for (const char* string_to_search : gameSettings) {
unsigned long long string_addr = find_string_in_section(hProcess, rdata_section_start, rdata_section_end, string_to_search);
if (string_addr == 0) {
continue;
}
unsigned long long reference_addr = find_reference_in_data_section(hProcess, data_section_start, data_section_end, string_addr);
if (reference_addr == 0) {
continue;
}
unsigned long long function_pointer = reference_addr - 0x10;
unsigned long long offset = function_pointer - base_addr;
fprintf(log_file, " \"%s\" => 0x%llx,\n", string_to_search, offset);
i have an offset below and what it linked to insaide of ida id like you to check and tell me if the program is working right
fVATSMaxChance" => 0x1457e7010
.data:00000001457E6FFE 00 db 0
.data:00000001457E6FFF 00 db 0
.data:00000001457E7000 00 00 BE 42 00 00 00 00 qword_1457E7000 dq 42BE0000h ; DATA XREF: sub_1401862A0+D↑r
.data:00000001457E7008 00 00 00 00 00 00 00 00 qword_1457E7008 dq 0 ; DATA XREF: sub_1401862A0+14↑w
.data:00000001457E7010 C0 db 0C0h ; OFF64 SEGDEF [_rdata,1440DD5C0]
.data:00000001457E7011 D5 db 0D5h
.data:00000001457E7012 0D db 0Dh
.data:00000001457E7013 44 db 44h ; D
.data:00000001457E7014 01 db 1
.data:00000001457E7015 00 db 0
.data:00000001457E7016 00 db 0
.data:00000001457E7017 00 db 0
.rdata:00000001440DD5BC 00 db 0
.rdata:00000001440DD5BD 00 db 0
.rdata:00000001440DD5BE 00 db 0
.rdata:00000001440DD5BF 00 db 0
.rdata:00000001440DD5C0 66 db 66h ; f
.rdata:00000001440DD5C1 56 db 56h ; V
.rdata:00000001440DD5C2 41 db 41h ; A
.rdata:00000001440DD5C3 54 db 54h ; T
.rdata:00000001440DD5C4 53 db 53h ; S
.rdata:00000001440DD5C5 4D db 4Dh ; M
.rdata:00000001440DD5C6 61 db 61h ; a
.rdata:00000001440DD5C7 78 db 78h ; x
.rdata:00000001440DD5C8 43 db 43h ; C
.rdata:00000001440DD5C9 68 db 68h ; h
.rdata:00000001440DD5CA 61 db 61h ; a
.rdata:00000001440DD5CB 6E db 6Eh ; n
.rdata:00000001440DD5CC 63 db 63h ; c
.rdata:00000001440DD5CD 65 db 65h ; e
.rdata:00000001440DD5CE 00 db 0
.rdata:00000001440DD5CF 00 db 0
Yes, based on the information you've provided, your program appears to be working correctly.
Let's walk through the steps to verify this:
Finding the String in .rdata Section:
Your program searches the .rdata section for the string "fVATSMaxChance". According to the disassembly you've provided:
This address matches the location of the string in the .rdata section. So at 0x1457E7010, there's a pointer to the string "fVATSMaxChance".
Adjusting the Address for IDA Pro:
Your code calculates the IDA reference address:
unsigned long long relative_reference_offset = reference_addr - base_addr;
unsigned long long ida_reference_addr = 0x140000000 + relative_reference_offset;
This adjusts the address to match the layout as seen in IDA Pro, which often uses a base address of 0x140000000 for 64-bit Windows executables.
Verifying the Offset Calculation:
The calculation seems appropriate. You're finding the relative offset from the module's base address and adding it to 0x140000000 to get the IDA address.
Understanding the Removed Subtraction of 0x10:
In your previous code, you subtracted 0x10 from the reference_addr:
unsigned long long function_pointer = reference_addr - 0x10;
unsigned long long offset = function_pointer - base_addr;
This might have been necessary if the structure you're accessing starts 0x10 bytes before the reference address. However, based on the disassembly, the actual pointer to the string is at 0x1457E7010, and subtracting 0x10 might not be necessary or correct in the current context.
Comparing with the Disassembly:
Your program's output:
"fVATSMaxChance" => 0x1457E7010
Matches the disassembly address where the pointer to the string is located. The value at that address is indeed a pointer to the string "fVATSMaxChance" in the .rdata section.
Conclusion:
Your program correctly:
Finds the string in the .rdata section.
Finds a reference to that string in the .data section.
Calculates the correct addresses to match those seen in IDA Pro.
Outputs the correct address for the game setting.
Additional Notes:
Subtracting 0x10: The previous subtraction of 0x10 might have been relevant in a different version of the executable or if the data structures have changed. Since the current data layout shows the pointer at 0x1457E7010 without any offset, removing the subtraction makes sense.
Address Adjustments: Always ensure that the base addresses align with how IDA Pro or other disassemblers view the executable. Since you're adding 0x140000000 to the relative offset, any discrepancies in base addresses could cause misalignments.
Recommendation:
Since the program is producing correct results, you can proceed with it as is.
If you encounter other addresses where subtracting 0x10 seems necessary, consider adding logic to handle such cases based on the specific data structures involved.