protected uint GetProcessId() { var autoPid = new AutoIntPtr <uint>(); NativeMethods.GetWindowThreadProcessId(Handle, autoPid); return(autoPid.Value); }
public TRet Read <TRet>(IntPtr lpBaseAddress, int readLength, Func <byte[], TRet> convert) { using (var buffer = new AutoIntPtr <byte[]>(readLength)) using (var numberOfBytesRead = new AutoIntPtr <int>()) { ReadProcessMemory(HProcess, lpBaseAddress, buffer, (uint)readLength, numberOfBytesRead); return(convert(buffer.Value)); } }
public void Test2() { AutoIntPtr <byte[]> intptr; intptr = new AutoIntPtr <byte[]>(5).Then(x => x.Value = new[] { (byte)20, (byte)12, (byte)4, (byte)16 }); Assert.Equal(new[] { (byte)20, (byte)12, (byte)4, (byte)16, (byte)0 }, intptr.Value); intptr = new AutoIntPtr <byte[]>(2); Assert.Throws <ArgumentOutOfRangeException>(() => intptr.Value = new[] { (byte)20, (byte)12, (byte)4, (byte)16 }); }
static void Main(string[] args) { Console.WriteLine("DebuggerApp..."); var process = Process.Start(new ProcessStartInfo { FileName = "CppConsoleApp.exe", UseShellExecute = true, }); var memory = new NWin32.MemoryAccessor((uint)process.Id); var buffer = new AutoIntPtr <byte[]>(88).Then(x => x.Value = memory.Buffer(0x4113A7, 88)); NativeMethods.Disassemble(new IntPtr(0x4113A7), 88, buffer); }
public void Write <TWrite>(IntPtr lpBaseAddress, TWrite value) { AutoIntPtr <TWrite> buffer; if (typeof(TWrite).IsArray) { buffer = new AutoIntPtr <TWrite>((value as Array).Length); } else { buffer = new AutoIntPtr <TWrite>(); } using (var numberOfBytesWritten = new AutoIntPtr <int>()) { buffer.Value = value; WriteProcessMemory(HProcess, lpBaseAddress, buffer, (uint)buffer.Length, numberOfBytesWritten); } }
public void Test1() { var intptr = new AutoIntPtr <int>().Then(x => x.Value = 416); Assert.Equal(416, intptr.Value); }