public string ReadUniString(IntPtr address, int length = 0) { if (length == 0) { for (int i = 0; i < 100; i++) { if (Read <ushort>(address + i * 2) == 0) { if (i < 1) { throw new Exception("Invalid unicode string length"); } else { length = i; } break; } } } byte[] buffer = new byte[length * 2]; IntPtr ptrBytesRead; MemoryAPI.ReadProcessMemory(m_hProcess, address, buffer, (uint)(length * 2), out ptrBytesRead); return(Encoding.Unicode.GetString(buffer)); }
public void CloseProcess() { int iRetValue = MemoryAPI.CloseHandle(m_hProcess); if (iRetValue == 0) { throw new Exception("CloseHandle failed"); } }
public byte[] ReadByteArray(IntPtr address, uint size) { byte[] buffer = new byte[size]; IntPtr ptrBytesRead; MemoryAPI.ReadProcessMemory(m_hProcess, address, buffer, size, out ptrBytesRead); return(buffer); }
public bool WriteString(IntPtr address, string value) { Encoding ascii = Encoding.GetEncoding("us-ascii"); byte[] buffer = ascii.GetBytes(value.ToCharArray()); IntPtr ptrBytesWrote; return(MemoryAPI.WriteProcessMemory(m_hProcess, address, buffer, (uint)ascii.GetByteCount(value.ToCharArray()), out ptrBytesWrote)); }
public T Read <T>(IntPtr address, int structSize = 0) { if (structSize == 0) { structSize = Marshal.SizeOf(typeof(T)); } byte[] bytes = new byte[structSize]; IntPtr numRead = IntPtr.Zero; MemoryAPI.ReadProcessMemory(m_hProcess, address, bytes, (uint)bytes.Length, out numRead); GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); T structure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); handle.Free(); return(structure); }
public string ReadString(IntPtr address, int length = 0) { if (length == 0) { for (int i = 0; i < 100; i++) { if (Read <byte>(address + i) == 0) { length = i; break; } } } byte[] buffer = new byte[length]; IntPtr ptrBytesRead; MemoryAPI.ReadProcessMemory(m_hProcess, address, buffer, (uint)length, out ptrBytesRead); Encoding ascii = Encoding.GetEncoding("us-ascii"); return(ascii.GetString(buffer)); }
public void OpenProcess() { m_hProcess = MemoryAPI.OpenProcess(MemoryAPI.PROCESS_VM_ALL_ACCESS, 1, (uint)m_Process.Id); }