Пример #1
0
        public SendHook()
        {
            long address;

            if (Environment.Is64BitProcess)
            {
                instructionLength = 12;

                originalInstruction = new byte[instructionLength];
                hookInstruction = new byte[instructionLength];

                address = Globals.SendAddresses[1];

                hookInstruction[0] = 0x48;
                hookInstruction[1] = 0xB8;
                hookInstruction[10] = 0xFF;
                hookInstruction[11] = 0xE0;
            }
            else
            {
                instructionLength = 5;

                originalInstruction = new byte[instructionLength];
                hookInstruction = new byte[instructionLength];

                address = Globals.SendAddresses[0];

                hookInstruction[0] = 0xE9;
            }

            originalInstruction = new byte[instructionLength];
            hookInstruction = new byte[instructionLength];

            originalDelegate = Marshal.GetDelegateForFunctionPointer(new IntPtr(address + Memory.BaseAddress), typeof(ClientSendDummy)) as ClientSendDummy;

            Console.WriteLine("Initialize Send hook...");

            // Assign function pointers
            originalFunction = Marshal.GetFunctionPointerForDelegate(originalDelegate);
            hookFunction = Marshal.GetFunctionPointerForDelegate(hookDelegate);

            // Store original & hook instructions
            Buffer.BlockCopy(Memory.Read(originalFunction, instructionLength), 0, originalInstruction, 0, instructionLength);

            if (Environment.Is64BitProcess)
                Buffer.BlockCopy(BitConverter.GetBytes(hookFunction.ToInt64()), 0, hookInstruction, 2, 8);
            else
            {
                var hookOffset = hookFunction.ToInt64() - (originalFunction.ToInt64() + instructionLength);

                Buffer.BlockCopy(BitConverter.GetBytes((uint)hookOffset), 0, hookInstruction, 1, 4);
            }

            Memory.Write(originalFunction, hookInstruction);

            Console.WriteLine("Send hook successfully initialized");
        }