/// <summary> /// 读4字节内存 /// </summary> /// <param name="hwnd"></param> /// <param name="hAddr"></param> /// <param name="outData"></param> /// <returns></returns> unsafe public bool Read4Byte(IntPtr hwnd, int hAddr, out Int32 outData) { byte[] out_byte = new byte[4]; IntPtr dataPrt = Marshal.AllocHGlobal(out_byte.Length); int ip = new int(); int o_sta = W_API.ReadProcessMemory(hwnd, hAddr, (byte *)dataPrt, 4, out ip); Marshal.Copy((IntPtr)dataPrt, out_byte, 0, out_byte.Length); Marshal.FreeHGlobal(dataPrt); if (o_sta == 0) { outData = 0; return(false); } UInt32 temp = 0; temp |= (UInt32)out_byte[0]; temp |= ((UInt32)out_byte[1]) << 8; temp |= ((UInt32)out_byte[2]) << 16; temp |= ((UInt32)out_byte[3]) << 24; outData = (Int32)temp; return(true); }
/// <summary> /// 读2字节内存 /// </summary> /// <param name="hwnd"></param> /// <param name="hAddr"></param> /// <param name="outData"></param> /// <returns></returns> unsafe public bool Read2Byte(IntPtr hwnd, int hAddr, out UInt16 outData) { byte[] out_byte = new byte[2]; IntPtr dataPrt = Marshal.AllocHGlobal(out_byte.Length); int ip = new int(); int o_sta = W_API.ReadProcessMemory(hwnd, hAddr, (byte *)dataPrt, 2, out ip); Marshal.Copy((IntPtr)dataPrt, out_byte, 0, out_byte.Length); Marshal.FreeHGlobal(dataPrt); if (o_sta == 0) { outData = 0; return(false); } UInt16 temp = 0; temp |= out_byte[0]; temp |= (UInt16)(out_byte[1] << 8); outData = (UInt16)temp; return(true); }
/// <summary> /// 读多个字节内存 /// </summary> /// <param name="hwnd"></param> /// <param name="hAddr"></param> /// <param name="readLen"></param> /// <param name="outData"></param> /// <returns></returns> unsafe public bool ReadBytes(IntPtr hwnd, int hAddr, uint readLen, byte *outData) { int ip = new int(); int o_sta = W_API.ReadProcessMemory(hwnd, hAddr, outData, readLen, out ip); if (o_sta == 0) { outData = null; return(false); } return(true); }