示例#1
0
        private IntPtr MakeHookStub(MemoryBuffer buffer, IcedPatcher patcher, byte[] asmCode, byte[] originalCode, long jumpBackAddress, AsmHookBehaviour behaviour)
        {
            var bytes        = new List <byte>(asmCode.Length + originalCode.Length);
            var jmpBackBytes = Utilities.AssembleAbsoluteJump((IntPtr)jumpBackAddress, _is64Bit);

            switch (behaviour)
            {
            case AsmHookBehaviour.ExecuteFirst:
                bytes.AddRange(asmCode);
                bytes.AddRange(patcher.EncodeForNewAddress(buffer.Properties.WritePointer + bytes.Count));
                break;

            case AsmHookBehaviour.ExecuteAfter:
                bytes.AddRange(patcher.EncodeForNewAddress(buffer.Properties.WritePointer + bytes.Count));
                bytes.AddRange(asmCode);
                break;

            case AsmHookBehaviour.DoNotExecuteOriginal:
                bytes.AddRange(asmCode);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(behaviour), behaviour, null);
            }

            bytes.AddRange(jmpBackBytes);
            return(buffer.Add(bytes.ToArray(), 1)); // Buffer is pre-aligned
        }
示例#2
0
        private IntPtr MakeOriginalStub(MemoryBuffer buffer, IcedPatcher patcher, byte[] originalCode, long jumpBackAddress)
        {
            var bytes        = new List <byte>(originalCode.Length);
            var jmpBackBytes = Utilities.AssembleAbsoluteJump((IntPtr)jumpBackAddress, _is64Bit);

            bytes.AddRange(patcher.EncodeForNewAddress(buffer.Properties.WritePointer));
            bytes.AddRange(jmpBackBytes);
            return(buffer.Add(bytes.ToArray(), 1)); // Buffer is pre-aligned
        }
示例#3
0
        private nuint MakeOriginalStub(MemoryBuffer buffer, IcedPatcher patcher, byte[] originalCode, nuint jumpBackAddress)
        {
            var bytes = new List <byte>(originalCode.Length);

            bytes.AddRange(patcher.EncodeForNewAddress(buffer.Properties.WritePointer));

            var jmpBackBytes = Utilities.AssembleRelativeJump(buffer.Properties.WritePointer + (nuint)bytes.Count, jumpBackAddress, _is64Bit);

            bytes.AddRange(jmpBackBytes);
            return(buffer.Add(bytes.ToArray(), 1)); // Buffer is pre-aligned
        }