示例#1
0
        public void Hook(IntPtr toHook, IntPtr ourFunc, int len, bool _64bit = true)
        {
            int oldProtect;

            MemoryApi.VirtualProtectEx(ProcessHandle, toHook, len, MemoryApi.PAGE_READWRITE, out oldProtect);

            var emptyBytes = new byte[len];

            for (int i = 0; i < len; i++)
            {
                emptyBytes[i] = 0x90;
            }
            WriteBytes(toHook, emptyBytes);



            byte[] byte_jump_delta = BitConverter.GetBytes((ulong)ourFunc - (ulong)toHook - (ulong)5);
            byte[] managedArray    = new byte[5];
            managedArray[0] = 0xE9;
            for (int i = 0; i < 4; i++)
            {
                managedArray[i + 1] = byte_jump_delta[i];
            }



            WriteBytes(toHook, managedArray);


            MemoryApi.VirtualProtectEx(ProcessHandle, toHook, len, oldProtect, out oldProtect);
        }
示例#2
0
        public void WriteBytes(IntPtr MemoryAddress, byte[] Buffer)
        {
            int oldProtect;

            MemoryApi.VirtualProtectEx(ProcessHandle, (IntPtr)MemoryAddress, Buffer.Length, MemoryApi.PAGE_READWRITE, out oldProtect);

            IntPtr ptrBytesWritten;

            MemoryApi.WriteProcessMemory(ProcessHandle, MemoryAddress, Buffer, Buffer.Length, out ptrBytesWritten);

            int oldProtect2;

            MemoryApi.VirtualProtectEx(ProcessHandle, (IntPtr)MemoryAddress, Buffer.Length, oldProtect, out oldProtect2);
        }