Пример #1
0
        public T ExecuteRemoteCode <T>(IntPtr Address) where T : struct
        {
            lock ("codeExecution")
            {
                int threadId;
                var h = Kernel32.CreateRemoteThread(ProcessHandle, IntPtr.Zero, 0, Address, IntPtr.Zero, 0, out threadId);
                if (h == IntPtr.Zero)
                {
                    throw new MemoryException("Failed to create remote thread");
                }

                remoteThreads.Add(threadId);

                if (Kernel32.WaitForSingleObject(h, (uint)WaitResult.INFINITE) != WaitResult.WAIT_OBJECT_0)
                {
                    throw new MemoryException("Failed to wait for remote thread");
                }

                remoteThreads.Remove(threadId);

                uint exitCode;
                if (!Kernel32.GetExitCodeThread(h, out exitCode))
                {
                    throw new MemoryException("Failed to obtain exit code");
                }

                return(MagicHelpers.ReinterpretObject <T>(exitCode));
            }
        }
Пример #2
0
        public void Write <T>(IntPtr Address, T Value)
        {
            var bytes = MagicHelpers.ObjectToBytes(Value);

            WriteBytes(Address, bytes);
        }
Пример #3
0
        public void Write <T>(IntPtr addr, T value)
        {
            var bytes = MagicHelpers.ObjectToBytes(value);

            WriteBytes(addr, bytes);
        }
Пример #4
0
 public T Read <T>(IntPtr Address) where T : struct
 => MagicHelpers.ReinterpretObject <T>(ReadBytes(Address, Marshal.SizeOf(typeof(T))));
Пример #5
0
        public T Read <T>(IntPtr addr) where T : struct
        {
            var buf = ReadBytes(addr, Marshal.SizeOf(typeof(T)));

            return(MagicHelpers.ReinterpretObject <T>(buf));
        }