From d0e2efeb9a8bfacb836cf47d04e22dee7a27b825 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Mon, 31 Aug 2026 14:32:34 +0200 Subject: [PATCH] Add MemoryReadUnsafe API --- TitanEngine/TitanEngine.Debugger.Memory.cpp | 13 +++++++++++++ TitanEngine/TitanEngine.def | 1 + TitanEngine/definitions.h | 1 + 3 files changed, 15 insertions(+) diff --git a/TitanEngine/TitanEngine.Debugger.Memory.cpp b/TitanEngine/TitanEngine.Debugger.Memory.cpp index eb9acbe..63ef71d 100644 --- a/TitanEngine/TitanEngine.Debugger.Memory.cpp +++ b/TitanEngine/TitanEngine.Debugger.Memory.cpp @@ -323,6 +323,19 @@ __declspec(dllexport) bool TITCALL Replace(LPVOID MemoryStart, DWORD MemorySize, } } +__declspec(dllexport) bool TITCALL MemoryReadUnsafe(HANDLE hProcess, LPCVOID lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesRead) +{ + SIZE_T bytesRead = 0; + auto transferred = lpNumberOfBytesRead ? lpNumberOfBytesRead : &bytesRead; + if(!hProcess || !lpBaseAddress || !lpBuffer || !nSize) + { + SetLastError(ERROR_INVALID_PARAMETER); + *transferred = 0; + return false; + } + return !!ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, transferred); +} + //what should this function do: //- do all possible effort to read memory //- filter out breakpoints diff --git a/TitanEngine/TitanEngine.def b/TitanEngine/TitanEngine.def index fd51a08..b552675 100644 --- a/TitanEngine/TitanEngine.def +++ b/TitanEngine/TitanEngine.def @@ -54,6 +54,7 @@ ConvertVAtoFileOffsetEx ConvertFileOffsetToVA ConvertFileOffsetToVAEx MemoryReadSafe +MemoryReadUnsafe MemoryWriteSafe MemoryQuerySafe MemoryAllocSafe diff --git a/TitanEngine/definitions.h b/TitanEngine/definitions.h index b799ff7..51f9289 100644 --- a/TitanEngine/definitions.h +++ b/TitanEngine/definitions.h @@ -74,6 +74,7 @@ __declspec(dllexport) ULONG_PTR TITCALL ConvertVAtoFileOffsetEx(ULONG_PTR FileMa __declspec(dllexport) ULONG_PTR TITCALL ConvertFileOffsetToVA(ULONG_PTR FileMapVA, ULONG_PTR AddressToConvert, bool ReturnType); __declspec(dllexport) ULONG_PTR TITCALL ConvertFileOffsetToVAEx(ULONG_PTR FileMapVA, DWORD FileSize, ULONG_PTR ImageBase, ULONG_PTR AddressToConvert, bool ReturnType); __declspec(dllexport) bool TITCALL MemoryReadSafe(HANDLE hProcess, LPVOID lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesRead); +__declspec(dllexport) bool TITCALL MemoryReadUnsafe(HANDLE hProcess, LPCVOID lpBaseAddress, LPVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesRead); __declspec(dllexport) bool TITCALL MemoryWriteSafe(HANDLE hProcess, LPVOID lpBaseAddress, LPCVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesWritten); __declspec(dllexport) SIZE_T TITCALL MemoryQuerySafe(HANDLE hProcess, LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SIZE_T dwLength); __declspec(dllexport) LPVOID TITCALL MemoryAllocSafe(HANDLE hProcess, LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);