Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions STROOP.Win32/NativeMethodWrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
UIntPtr lpNumberOfBytesRead;
try
{
return PInvoke.ReadProcessMemory(

Check warning on line 17 in STROOP.Win32/NativeMethodWrappers.cs

View workflow job for this annotation

GitHub Actions / debug-build

This call site is reachable on all platforms. 'PInvoke.ReadProcessMemory(HANDLE, void*, void*, nuint, nuint*)' is only supported on: 'windows' 5.1.2600 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
(HANDLE)hProcess,
(void*)lpBaseAddress,
(void*)Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0),
Expand All @@ -34,7 +34,7 @@
var gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try
{
return PInvoke.WriteProcessMemory(

Check warning on line 37 in STROOP.Win32/NativeMethodWrappers.cs

View workflow job for this annotation

GitHub Actions / debug-build

This call site is reachable on all platforms. 'PInvoke.WriteProcessMemory(HANDLE, void*, void*, nuint, nuint*)' is only supported on: 'windows' 5.1.2600 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
(HANDLE)hProcess,
(void*)lpBaseAddress,
(void*)Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0),
Expand All @@ -52,20 +52,22 @@
PSAPI_WORKING_SET_EX_INFORMATION tmp;
tmp.VirtualAddress = (HANDLE)lpBaseAddress;
uint setInfoSize = (uint)Marshal.SizeOf(typeof(PSAPI_WORKING_SET_EX_INFORMATION));
var result = PInvoke.QueryWorkingSetEx((HANDLE)hProcess, &tmp, setInfoSize);

Check warning on line 55 in STROOP.Win32/NativeMethodWrappers.cs

View workflow job for this annotation

GitHub Actions / debug-build

This call site is reachable on all platforms. 'PInvoke.QueryWorkingSetEx(HANDLE, void*, uint)' is only supported on: 'windows' 6.0.6000 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
wsInfo = tmp;
return result;
}

public static unsafe bool GetSymbolAddress(SafeHandle hProcess, string name, out ulong address)
{
var symbol = new SYMBOL_INFO
{
MaxNameLen = 2000,
SizeOfStruct = 88,
};
var result = PInvoke.SymFromName(hProcess, name, &symbol);
address = symbol.Address;
const int MAX_NAME_LENGTH = 2000;

// See https://learn.microsoft.com/en-us/windows/win32/debug/retrieving-symbol-information-by-name
var symbol = (SYMBOL_INFO*)Marshal.AllocHGlobal(Marshal.SizeOf<SYMBOL_INFO>() + MAX_NAME_LENGTH * sizeof(CHAR) + (sizeof(ulong) - 1) / sizeof(ulong));
symbol->MaxNameLen = MAX_NAME_LENGTH;
symbol->SizeOfStruct = (uint)sizeof(SYMBOL_INFO);
var result = PInvoke.SymFromName(hProcess, name, symbol);
address = symbol->Address;
Marshal.FreeHGlobal((IntPtr)symbol);
return result;
}
}
Loading