ReadProcessMemory() private method

private ReadProcessMemory ( SafeProcessHandle hProcess, IntPtr lpBaseAddress, [ buffer, uint size, UInt32 &lpNumberOfBytesRead ) : bool
hProcess SafeProcessHandle
lpBaseAddress System.IntPtr
buffer [
size uint
lpNumberOfBytesRead System.UInt32
return bool
Beispiel #1
0
        public void PrintDebugString(OUTPUT_DEBUG_STRING_INFO outputDbgStrInfo)
        {
            using (SafeProcessHandle hProcess = Process.OpenProcess(ProcessAccessFlags.VmRead, false, pid))
            {
                if (hProcess.IsInvalid)
                {
                    throw new ArgumentException(String.Format("Unable to open process {0}, error {x:8}", pid, Marshal.GetLastWin32Error()));
                }

                var dbgString = new byte[outputDbgStrInfo.nDebugStringLength];

                uint numberOfBytesRead;
                var  result = Process.ReadProcessMemory(hProcess, outputDbgStrInfo.lpDebugStringData, dbgString, outputDbgStrInfo.nDebugStringLength, out numberOfBytesRead);

                if (result)
                {
                    if (outputDbgStrInfo.fUnicode == 0)
                    {
                        Console.WriteLine("Debug String: {0}", Encoding.ASCII.GetString(dbgString));
                    }
                    else
                    {
                        Console.WriteLine("Debug String: {0}", Encoding.Unicode.GetString(dbgString));
                    }
                }
            }
        }
Beispiel #2
0
        public void PrintDebugString(OUTPUT_DEBUG_STRING_INFO outputDbgStrInfo)
        {
            var dbgString = new byte[outputDbgStrInfo.nDebugStringLength];

            uint numberOfBytesRead;
            var  result = ProcessNativeMethod.ReadProcessMemory(hProcess, outputDbgStrInfo.lpDebugStringData, dbgString, outputDbgStrInfo.nDebugStringLength, out numberOfBytesRead);

            if (result)
            {
                if (outputDbgStrInfo.fUnicode == 0)
                {
                    Console.WriteLine("Debug String: {0}", Encoding.ASCII.GetString(dbgString));
                }
                else
                {
                    Console.WriteLine("Debug String: {0}", Encoding.Unicode.GetString(dbgString));
                }
            }
        }