BASED ON THE CODE AND THE INFO BELOW IT DOES THIS SEEM TO BE WORKING CORRECTLY #include…
- User
BASED ON THE CODE AND THE INFO BELOW IT DOES THIS SEEM TO BE WORKING CORRECTLY #include <stdio.h> #include <stdlib.h> #include <windows.h> #include <tlhelp32.h> #include <psapi.h> #include #include
// Structure to hold section information struct SectionInfo { unsigned long long start; unsigned long long end; unsigned long long size; unsigned long long original_start; // Start address as seen in IDA };
// Function to get process ID by name DWORD get_process_id_by_name(const wchar_t* process_name) { PROCESSENTRY32W pe32; HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
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;}
// Function to get the base address of a module in a given process 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;}
// Function to get section information 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) { // Calculate precise section start including alignment section_info.start = base_addr + section_headers[i].VirtualAddress; // Calculate aligned size 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; // Calculate original address using precise ImageBase section_info.original_start = nt_headers.OptionalHeader.ImageBase + section_headers[i].VirtualAddress; found = true; break; } } delete[] section_headers; return found; - Assistant