예제 #1
0
        public static T GetStructFromProcess <T>(Process Process, IntPtr Address) where T : struct
        {
            IntPtr ProcessHandle = OpenProcess(PROCESS_VM_READ, false, Process.Id);

            int bytesrecieved = 0;

            byte[] buffer = new byte[Marshal.SizeOf(typeof(T))];
            bool   Ok     = ReadProcessMemory(ProcessHandle.ToInt32(), Address.ToInt32(), buffer, buffer.Length, ref bytesrecieved);

            if (!Ok)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return(MarshalHelper.DeserializeMsg <T>(buffer));
        }
예제 #2
0
        public static T WriteStructToProcess <T>(Process Process, IntPtr Address, T Data) where T : struct
        {
            IntPtr ProcessHandle = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, false, Process.Id);

            IntPtr byteswritten = IntPtr.Zero;

            byte[] buffer = SerializeMessage <T>(Data);
            bool   Ok     = WriteProcessMemory(ProcessHandle, Address, buffer, buffer.Length, out byteswritten);

            if (!Ok)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return(MarshalHelper.DeserializeMsg <T>(buffer));
        }