Пример #1
0
        private void Write(Arm64InstructionOperand op, MachineInstructionWriter writer)
        {
            switch (op.Type)
            {
            case Arm64InstructionOperandType.Register:
                writer.Write(A64Registers.RegisterByCapstoneID[op.RegisterValue.Value].Name);
                return;

            case Arm64InstructionOperandType.Immediate:
                if (IsJump())
                {
                    writer.Write("${0:X16}", op.ImmediateValue.Value);
                }
                else
                {
                    WriteImmediateValue(op.ImmediateValue.Value, writer);
                    if (op.Shifter != null)
                    {
                        this.WriteShift(op, writer);
                    }
                }
                return;
            }
            throw new NotImplementedException(op.Type.ToString());
        }
Пример #2
0
        private void WriteShift(Arm64InstructionOperand op, MachineInstructionWriter writer)
        {
            switch (op.Shifter.Type)
            {
            case Arm64ShifterType.ASR: WriteImmShift("asr", op.Shifter.Value, writer); break;

            case Arm64ShifterType.LSL: WriteImmShift("lsl", op.Shifter.Value, writer); break;

            case Arm64ShifterType.LSR: WriteImmShift("lsr", op.Shifter.Value, writer); break;

            case Arm64ShifterType.MSL: WriteImmShift("msl", op.Shifter.Value, writer); break;

            case Arm64ShifterType.ROR: WriteImmShift("ror", op.Shifter.Value, writer); break;

            case Arm64ShifterType.Invalid: break;
            }
        }
        /// <summary>
        ///     Convert a Native ARM64 Instruction Operand to an ARM64 Instruction Operand.
        /// </summary>
        /// <param name="this">
        ///     A native ARM64 instruction operand.
        /// </param>
        /// <param name="instruction">
        ///     The instruction the operand belongs to.
        /// </param>
        /// <returns>
        ///     An ARM64 instruction operand.
        /// </returns>
        public static Arm64InstructionOperand AsArm64InstructionOperand(this NativeArm64InstructionOperand @this, Arm64Instruction instruction)
        {
            var @object = new Arm64InstructionOperand();
            @object.Extender = @this.ManagedExtender;
            @object.Shifter = @this.Shifter.AsArm64Shifter();
            @object.Type = @this.ManagedType;
            @object.VectorArrangementSpecifier = @this.ManagedVectorArrangementSpecifier;
            @object.VectorElementSizeSpecifier = @this.ManagedVectorElementSizeSpecifier;
            @object.VectorIndex = @this.VectorIndex;
            switch (@object.Type) {
                case Arm64InstructionOperandType.CImmediate:
                    @object.ImmediateValue = @this.Value.Immediate;

                    break;
                case Arm64InstructionOperandType.FloatingPoint:
                    @object.FloatingPointValue = @this.Value.FloatingPoint;
                    break;
                case Arm64InstructionOperandType.Immediate:
                    @object.ImmediateValue = @this.Value.Immediate;

                    break;
                case Arm64InstructionOperandType.MemoryBarrierOperation:
                    @object.MemoryBarrierOperation = @this.Value.ManagedMemoryBarrierOperation;

                    break;
                case Arm64InstructionOperandType.Memory:
                    @object.MemoryValue = @this.Value.Memory.AsArm64InstructionMemoryOperandValue();

                    break;
                case Arm64InstructionOperandType.MrsRegister:
                    @object.MrsRegisterValue = (Arm64MrsRegister) @this.Value.Register;

                    break;
                case Arm64InstructionOperandType.MsrRegister:
                    @object.MsrRegisterValue = (Arm64MsrRegister) @this.Value.Register;

                    break;
                case Arm64InstructionOperandType.PState:
                    @object.PState = @this.Value.ManagedPState;

                    break;
                case Arm64InstructionOperandType.PrefetchOperation:
                    @object.PrefetchOperation = @this.Value.ManagedPrefetchOperation;

                    break;
                case Arm64InstructionOperandType.Register:
                    @object.RegisterValue = @this.Value.ManagedRegister;

                    break;
                case Arm64InstructionOperandType.SysOperation:
                    switch (instruction) {
                        case Arm64Instruction.AT:
                            @object.AtInstructionOperation = (Arm64AtInstructionOperation) @this.Value.SysOperation;

                            break;
                        case Arm64Instruction.DC:
                            @object.DcInstructionOperation = (Arm64DcInstructionOperation) @this.Value.SysOperation;

                            break;
                        case Arm64Instruction.IC:
                            @object.IcInstructionOperation = (Arm64IcInstructionOperation) @this.Value.SysOperation;

                            break;
                        case Arm64Instruction.TLBI:
                            @object.TlbiInstructionOperation = (Arm64TlbiInstructionOperation) @this.Value.SysOperation;

                            break;
                    }

                    break;
            }

            return @object;
        }
        /// <summary>
        ///     Convert a Native ARM64 Instruction Operand to an ARM64 Instruction Operand.
        /// </summary>
        /// <param name="this">
        ///     A native ARM64 instruction operand.
        /// </param>
        /// <param name="instruction">
        ///     The instruction the operand belongs to.
        /// </param>
        /// <returns>
        ///     An ARM64 instruction operand.
        /// </returns>
        public static Arm64InstructionOperand AsArm64InstructionOperand(this NativeArm64InstructionOperand @this, Arm64Instruction instruction)
        {
            var @object = new Arm64InstructionOperand();

            @object.Extender = @this.ManagedExtender;
            @object.Shifter  = @this.Shifter.AsArm64Shifter();
            @object.Type     = @this.ManagedType;
            @object.VectorArrangementSpecifier = @this.ManagedVectorArrangementSpecifier;
            @object.VectorElementSizeSpecifier = @this.ManagedVectorElementSizeSpecifier;
            @object.VectorIndex = @this.VectorIndex;
            switch (@object.Type)
            {
            case Arm64InstructionOperandType.CImmediate:
                @object.ImmediateValue = @this.Value.Immediate;

                break;

            case Arm64InstructionOperandType.FloatingPoint:
                @object.FloatingPointValue = @this.Value.FloatingPoint;
                break;

            case Arm64InstructionOperandType.Immediate:
                @object.ImmediateValue = @this.Value.Immediate;

                break;

            case Arm64InstructionOperandType.MemoryBarrierOperation:
                @object.MemoryBarrierOperation = @this.Value.ManagedMemoryBarrierOperation;

                break;

            case Arm64InstructionOperandType.Memory:
                @object.MemoryValue = @this.Value.Memory.AsArm64InstructionMemoryOperandValue();

                break;

            case Arm64InstructionOperandType.MrsRegister:
                @object.MrsRegisterValue = (Arm64MrsRegister)@this.Value.Register;

                break;

            case Arm64InstructionOperandType.MsrRegister:
                @object.MsrRegisterValue = (Arm64MsrRegister)@this.Value.Register;

                break;

            case Arm64InstructionOperandType.PState:
                @object.PState = @this.Value.ManagedPState;

                break;

            case Arm64InstructionOperandType.PrefetchOperation:
                @object.PrefetchOperation = @this.Value.ManagedPrefetchOperation;

                break;

            case Arm64InstructionOperandType.Register:
                @object.RegisterValue = @this.Value.ManagedRegister;

                break;

            case Arm64InstructionOperandType.SysOperation:
                switch (instruction)
                {
                case Arm64Instruction.AT:
                    @object.AtInstructionOperation = (Arm64AtInstructionOperation)@this.Value.SysOperation;

                    break;

                case Arm64Instruction.DC:
                    @object.DcInstructionOperation = (Arm64DcInstructionOperation)@this.Value.SysOperation;

                    break;

                case Arm64Instruction.IC:
                    @object.IcInstructionOperation = (Arm64IcInstructionOperation)@this.Value.SysOperation;

                    break;

                case Arm64Instruction.TLBI:
                    @object.TlbiInstructionOperation = (Arm64TlbiInstructionOperation)@this.Value.SysOperation;

                    break;
                }

                break;
            }

            return(@object);
        }