Example #1
0
        public static OpCode DecodeOpCode(IMemoryManager memory, ulong address, ExecutionMode mode)
        {
            int opCode = memory.Read <int>(address);

            InstDescriptor inst;

            OpCodeTable.MakeOp makeOp;

            if (mode == ExecutionMode.Aarch64)
            {
                (inst, makeOp) = OpCodeTable.GetInstA64(opCode);
            }
            else
            {
                if (mode == ExecutionMode.Aarch32Arm)
                {
                    (inst, makeOp) = OpCodeTable.GetInstA32(opCode);
                }
                else /* if (mode == ExecutionMode.Aarch32Thumb) */
                {
                    (inst, makeOp) = OpCodeTable.GetInstT32(opCode);
                }
            }

            if (makeOp != null)
            {
                return((OpCode)makeOp(inst, address, opCode));
            }
            else
            {
                return(new OpCode(inst, address, opCode));
            }
        }
Example #2
0
        public IntPtr Apply(IMemoryManager memory, IntPtr address)
        {
            switch (Type)
            {
            case LeaType.Byte:
                return((IntPtr)memory.Read <byte>(address));

            case LeaType.Word:
                return((IntPtr)memory.Read <ushort>(address));

            case LeaType.Dword:
                return((IntPtr)memory.Read <uint>(address));

            case LeaType.E8:
                // 4 = <call instruction size> - <E8>
                return(address + 4 + memory.Read <int>(address));

            case LeaType.SimpleAddress:
                return(address);

            case LeaType.Cmp:
                return(address + 5 + memory.Read <int>(address));

            case LeaType.RelativePlus8:
                return(address + 8 + memory.Read <int>(address));

            default:
                throw new InvalidDataException("Unknown " + nameof(LeaType));
            }
        }