From d6a0398a284db9d1712e95314302167ecb02624c Mon Sep 17 00:00:00 2001 From: notcpuid Date: Thu, 2 Nov 2023 15:10:30 +0300 Subject: [PATCH] use native api instead of standard winapi fix update_offsets.py add multiprocessor compilations change linking method --- memory-external/memory-external.vcxproj | 8 +++++-- memory-external/memory/memory.hpp | 29 +++++++++++++++++++++---- offsets/update_offsets.py | 12 +++++----- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/memory-external/memory-external.vcxproj b/memory-external/memory-external.vcxproj index 9f314e2..7aeb126 100644 --- a/memory-external/memory-external.vcxproj +++ b/memory-external/memory-external.vcxproj @@ -177,12 +177,14 @@ NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpp20 + true + MultiThreaded Console true true - true + false gdiplus.lib;wininet.lib;%(AdditionalDependencies) @@ -195,12 +197,14 @@ NDEBUG;_UC;_CONSOLE;%(PreprocessorDefinitions) true stdcpp20 + MultiThreaded + true Console true true - true + false gdiplus.lib;wininet.lib;%(AdditionalDependencies) diff --git a/memory-external/memory/memory.hpp b/memory-external/memory/memory.hpp index baf8bd0..8704b50 100644 --- a/memory-external/memory/memory.hpp +++ b/memory-external/memory/memory.hpp @@ -9,6 +9,21 @@ #include #include +typedef NTSTATUS(WINAPI* pNtReadVirtualMemory)(HANDLE ProcessHandle, PVOID BaseAddress, PVOID Buffer, ULONG NumberOfBytesToRead, PULONG NumberOfBytesRead); +typedef NTSTATUS(WINAPI* pNtWriteVirtualMemory)(HANDLE ProcessHandle, PVOID BaseAddress, PVOID Buffer, ULONG NumberOfBytesToWrite, PULONG NumberOfBytesWritten); + +class pMemory { + +public: + pMemory() { + pfnNtReadVirtualMemory = (pNtReadVirtualMemory)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtReadVirtualMemory"); + pfnNtWriteVirtualMemory = (pNtWriteVirtualMemory)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtWriteVirtualMemory"); + } + + pNtReadVirtualMemory pfnNtReadVirtualMemory; + pNtWriteVirtualMemory pfnNtWriteVirtualMemory; +}; + struct ProcessModule { uintptr_t base, size; @@ -50,7 +65,9 @@ public: bool read_raw(uintptr_t address, void* buffer, size_t size) { SIZE_T bytesRead; - if (ReadProcessMemory(this->handle_, reinterpret_cast(address), buffer, size, &bytesRead)) + pMemory cMemory; + + if (cMemory.pfnNtReadVirtualMemory(this->handle_, (PVOID)(address), buffer, static_cast(size), (PULONG)&bytesRead)) { return bytesRead == size; } @@ -60,20 +77,24 @@ public: template void write(uintptr_t address, T value) { - WriteProcessMemory(handle_, (void*)address, &value, sizeof(T), 0); + pMemory cMemory; + cMemory.pfnNtWriteVirtualMemory(handle_, (void*)address, &value, sizeof(T), 0); } template T read(uintptr_t address) { T buffer{}; - ReadProcessMemory(handle_, (void*)address, &buffer, sizeof(T), 0); + pMemory cMemory; + + cMemory.pfnNtReadVirtualMemory(handle_, (void*)address, &buffer, sizeof(T), 0); return buffer; } void write_bytes(uintptr_t addr, std::vector patch) { - WriteProcessMemory(handle_, (void*)addr, &patch[0], patch.size(), 0); + pMemory cMemory; + cMemory.pfnNtWriteVirtualMemory(handle_, (void*)addr, &patch[0], patch.size(), 0); } uintptr_t read_multi_address(uintptr_t ptr, std::vector offsets) diff --git a/offsets/update_offsets.py b/offsets/update_offsets.py index 568d86b..3338983 100644 --- a/offsets/update_offsets.py +++ b/offsets/update_offsets.py @@ -5,7 +5,7 @@ import re source_url = "https://github.com/a2x/cs2-dumper/raw/main/generated/offsets.json" commits_url = "https://api.github.com/repos/a2x/cs2-dumper/commits" -dest_path = "./offsets/offsets.json" +dest_path = "./offsets.json" # Fetch the source JSON source_response = requests.get(source_url) @@ -33,12 +33,12 @@ if dest_data["build_number"] == int(build_number): dest_data["build_number"] = int(build_number) -dest_data["dwBuildNumber"] = source_data["Engine2Dll"]["data"]["dwBuildNumber"]["value"] -dest_data["dwLocalPlayer"] = source_data["ClientDll"]["data"]["dwLocalPlayerPawn"]["value"] -dest_data["dwEntityList"] = source_data["ClientDll"]["data"]["dwEntityList"]["value"] -dest_data["dwViewMatrix"] = source_data["ClientDll"]["data"]["dwViewMatrix"]["value"] +dest_data["dwBuildNumber"] = source_data["engine_2dll"]["data"]["dwBuildNumber"]["value"] +dest_data["dwLocalPlayer"] = source_data["client_dll"]["data"]["dwLocalPlayerPawn"]["value"] +dest_data["dwEntityList"] = source_data["client_dll"]["data"]["dwEntityList"]["value"] +dest_data["dwViewMatrix"] = source_data["client_dll"]["data"]["dwViewMatrix"]["value"] with open(dest_path, 'w') as dest_file: json.dump(dest_data, dest_file, indent=4) -print("Offsets updated in the local file.") # We dont exit so we know that the game has been updated and that we have to commit the new offsets +print("Offsets updated in the local file.") # We dont exit so we know that the game has been updated and that we have to commit the new offsets \ No newline at end of file