public static extern IntPtr CreateICW(string lpszDriver, string lpszDevice, string lpszOutput, SafeMemoryHandle devmodePtr);
public static extern int GetThreadId(SafeMemoryHandle hThread);
public static extern bool GetPrinterW(SafeWinSpoolPrinterHandle printer, uint dwLevel, SafeMemoryHandle pPrinter, uint dwBuf, ref uint dwNeeded);
public static extern bool GetExitCodeThread(SafeMemoryHandle hThread, out IntPtr lpExitCode);
public static extern bool GetThreadContext(SafeMemoryHandle hThread, ref ThreadContext lpContext);
public static extern bool WriteProcessMemory(SafeMemoryHandle hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, out int lpNumberOfBytesWritten);
public static extern bool ReadProcessMemory(SafeMemoryHandle hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out int lpNumberOfBytesRead);
internal static extern bool VirtualProtectEx(SafeMemoryHandle hProcess, IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);
public static extern int NtQueryInformationProcess(SafeMemoryHandle processHandle, ProcessInformationClass infoclass, ref ProcessBasicInformation processinfo, int length, IntPtr bytesread);
/// <summary> /// Initializes a new instance of the <see cref="LocalProcessMemory" /> class. /// </summary> /// <param name="handle">The process.</param> public LocalProcessMemory(SafeMemoryHandle handle) : base(handle) { }
/// <summary> /// Initializes a new instance of the <see cref="ExternalProcessMemory" /> class. /// </summary> /// <param name="handle">The open handle to the process which contains the memory of interest.</param> public ExternalProcessMemory(SafeMemoryHandle handle) : base(handle) { }
internal static extern bool VirtualFreeEx(SafeMemoryHandle hProcess, IntPtr dwAddress, int nSize, MemoryFreeType dwFreeType);
internal static extern IntPtr VirtualAllocEx(SafeMemoryHandle hProcess, uint dwAddress, int nSize, MemoryAllocationType dwAllocationType, MemoryProtectionType dwProtect);
/// <summary> /// Retrieves information about a range of pages within the virtual address space of a specified process. /// </summary> /// <param name="processHandle">A handle to the process whose memory information is queried.</param> /// <param name="addressFrom">A pointer to the starting address of the region of pages to be queried.</param> /// <param name="addressTo">A pointer to the ending address of the region of pages to be queried.</param> /// <returns>A collection of <see cref="MemoryBasicInformation32" /> structures.</returns> public static IEnumerable <MemoryBasicInformation64> Query(SafeMemoryHandle processHandle, IntPtr addressFrom, IntPtr addressTo) { // Check if the handle is valid HandleManipulator.ValidateAsArgument(processHandle, "processHandle"); // Convert the addresses to Int64 var numberFrom = addressFrom.ToInt64(); var numberTo = addressTo.ToInt64(); // The first address must be lower than the second if (numberFrom >= numberTo) { throw new ArgumentException("The starting address must be lower than the ending address.", "addressFrom"); } // Create the variable storing the result of the call of VirtualQueryEx int ret; // Enumerate the memory pages do { // Allocate the structure to store information of memory var memoryInfo = new MemoryBasicInformation64(); if (!Environment.Is64BitProcess) { // Get the next memory page ret = Kernel32.VirtualQueryEx(processHandle, new IntPtr(numberFrom), out memoryInfo, MarshalType <MemoryBasicInformation64> .Size); } else { // Allocate the structure to store information of memory MemoryBasicInformation32 memoryInfo32; // Get the next memory page ret = Kernel32.VirtualQueryEx(processHandle, new IntPtr(numberFrom), out memoryInfo32, MarshalType <MemoryBasicInformation32> .Size); // Copy from the 32 bit struct to the 64 bit struct memoryInfo.AllocationBase = memoryInfo32.AllocationBase; memoryInfo.AllocationProtect = memoryInfo32.AllocationProtect; memoryInfo.BaseAddress = memoryInfo32.BaseAddress; memoryInfo.Protect = memoryInfo32.Protect; memoryInfo.RegionSize = memoryInfo32.RegionSize; memoryInfo.State = memoryInfo32.State; memoryInfo.Type = memoryInfo32.Type; } // Increment the starting address with the size of the page numberFrom += memoryInfo.RegionSize; // Return the memory page if (memoryInfo.State != MemoryStateFlags.Free) { yield return(memoryInfo); } } while (numberFrom < numberTo && ret != 0); }
public static extern uint NtQueryInformationThread(SafeMemoryHandle hwnd, uint infoclass, ref ThreadBasicInformation threadinfo, int length, IntPtr bytesread);
private static extern unsafe bool ReadProcessMemory(SafeMemoryHandle hProcess, IntPtr lpBaseAddress, void* lpBuffer, int dwSize, out int lpNumberOfBytesRead);
public static bool Free(SafeMemoryHandle handle, IntPtr address) { return(NativeMethods.VirtualFreeEx(handle, address, 0, MemoryReleaseFlags.Release)); }
public static extern bool SetThreadContext(SafeMemoryHandle hThread, [MarshalAs(UnmanagedType.Struct)] ref ThreadContext lpContext);
public static extern int SuspendThread(SafeMemoryHandle hThread);
public static extern int ResumeThread(SafeMemoryHandle hThread);
public static extern bool TerminateThread(SafeMemoryHandle hThread, int dwExitCode);
public static extern int GetProcessId(SafeMemoryHandle hProcess);
public static extern IntPtr VirtualAllocEx(SafeMemoryHandle hProcess, IntPtr lpAddress, int dwSize, MemoryAllocationFlags flAllocationType, MemoryProtectionFlags flProtect);
public static extern bool GetThreadSelectorEntry(SafeMemoryHandle hThread, int dwSelector, out LdtEntry lpSelectorEntry);
public static extern bool VirtualFreeEx(SafeMemoryHandle hProcess, IntPtr lpAddress, int dwSize, MemoryReleaseFlags dwFreeType);
public static extern SafeMemoryHandle CreateRemoteThread(SafeMemoryHandle hProcess, IntPtr lpThreadAttributes, int dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, ThreadCreationFlags dwCreationFlags, out int lpThreadId);
public static extern bool VirtualProtectEx(SafeMemoryHandle hProcess, IntPtr lpAddress, int dwSize, MemoryProtectionFlags flNewProtect, out MemoryProtectionFlags lpflOldProtect);
public static extern uint DeviceCapabilitiesW(string pDevice, string pPort, DeviceCapability fwCapabilities, SafeMemoryHandle pOutput, SafeMemoryHandle pDevMode);
public static extern int VirtualQueryEx(SafeMemoryHandle hProcess, IntPtr lpAddress, out MemoryBasicInformation lpBuffer, int dwLength);
public static extern uint CreateStreamOnHGlobal(SafeMemoryHandle hGlobal, bool fDeleteOnRelease, out IStream ppstm);
public static extern WaitValues WaitForSingleObject(SafeMemoryHandle hHandle, uint dwMilliseconds);
private static unsafe void PerfTestKnownSpellsRPMDirect(SafeMemoryHandle processHandle, IntPtr imgbase) { int numRead; int numSpells = 0; ReadProcessMemory(processHandle, imgbase + (int) LocalPlayerNumKnownSpells, &numSpells, 4, out numRead); }