Exemplo n.º 1
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            int instrCodeSize = GetCodeSize(instr.CodeSize);
            var flags         = instrCodeSize == 0 || (instrCodeSize & codeSize) != 0 ? InstrOpInfoFlags.MemSize_Nothing : InstrOpInfoFlags.MemSize_Normal | InstrOpInfoFlags.ShowNoMemSize_ForceSize;

            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Exemplo n.º 2
0
        public static MasmFormatterOptions ToMasm(this IMasmDisassemblySettings settings)
        {
            var options = new MasmFormatterOptions();

            CopyBase(options, settings);
            return(options);
        }
Exemplo n.º 3
0
 public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info = new InstrOpInfo(mnemonic, ref instr, InstrOpInfoFlags.None);
     if (options.UsePseudoOps)
     {
         int index;
         int imm = instr.Immediate8;
         if (imm == 0)
         {
             index = 0;
         }
         else if (imm == 1)
         {
             index = 1;
         }
         else if (imm == 0x10)
         {
             index = 2;
         }
         else if (imm == 0x11)
         {
             index = 3;
         }
         else
         {
             index = -1;
         }
         if (index >= 0)
         {
             info.Mnemonic = pseudo_ops[index];
             info.OpCount--;
         }
     }
 }
Exemplo n.º 4
0
 public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info = new InstrOpInfo(mnemonic, ref instr, flags);
     Debug.Assert(info.Op1Register == (int)Register.ST0);
     Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
     info.Op1Register = (byte)Registers.Register_ST;
 }
Exemplo n.º 5
0
 public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info = new InstrOpInfo(mnemonic, ref instr, flags);
     Debug.Assert(info.OpCount == 3);
     if (options.UsePseudoOps && info.Op0Kind == InstrOpKind.Register && info.Op1Kind == InstrOpKind.Register && info.Op0Register == info.Op1Register)
     {
         info.OpCount--;
         info.Op1Kind = info.Op2Kind;
     }
 }
Exemplo n.º 6
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            var flags = this.flags;

            if (instr.HasPrefixRepne)
            {
                flags |= InstrOpInfoFlags.BndPrefix;
            }
            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Exemplo n.º 7
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            var flags = InstrOpInfoFlags.None;

            if (instr.CodeSize != codeSize && instr.CodeSize != CodeSize.Unknown)
            {
                flags |= InstrOpInfoFlags.ShowNoMemSize_ForceSize;
            }
            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Exemplo n.º 8
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            info = new InstrOpInfo(mnemonic, ref instr, flags);
            int imm = instr.Immediate8;

            if (options.UsePseudoOps && (uint)imm < (uint)pseudo_ops.Length)
            {
                info.OpCount--;
                info.Mnemonic = pseudo_ops[imm];
            }
        }
Exemplo n.º 9
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            var flags = InstrOpInfoFlags.None;

            if (instr.HasPrefixRepne)
            {
                flags |= InstrOpInfoFlags.BndPrefix;
            }
            var mnemonic = mnemonics[(int)instr.CodeSize];

            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Exemplo n.º 10
0
        void Verify_default_formatter_options()
        {
            var options = new MasmFormatterOptions();

            Assert.False(options.UpperCasePrefixes);
            Assert.False(options.UpperCaseMnemonics);
            Assert.False(options.UpperCaseRegisters);
            Assert.False(options.UpperCaseKeywords);
            Assert.False(options.UpperCaseDecorators);
            Assert.False(options.UpperCaseAll);
            Assert.Equal(0, options.FirstOperandCharIndex);
            Assert.Equal(0, options.TabSize);
            Assert.False(options.SpaceAfterOperandSeparator);
            Assert.False(options.SpaceAfterMemoryBracket);
            Assert.False(options.SpaceBetweenMemoryAddOperators);
            Assert.False(options.SpaceBetweenMemoryMulOperators);
            Assert.False(options.ScaleBeforeIndex);
            Assert.False(options.AlwaysShowScale);
            Assert.False(options.AlwaysShowSegmentRegister);
            Assert.False(options.ShowZeroDisplacements);
            Assert.Null(options.HexPrefix);
            Assert.Equal("h", options.HexSuffix);
            Assert.Equal(4, options.HexDigitGroupSize);
            Assert.Null(options.DecimalPrefix);
            Assert.Null(options.DecimalSuffix);
            Assert.Equal(3, options.DecimalDigitGroupSize);
            Assert.Null(options.OctalPrefix);
            Assert.Equal("o", options.OctalSuffix);
            Assert.Equal(4, options.OctalDigitGroupSize);
            Assert.Null(options.BinaryPrefix);
            Assert.Equal("b", options.BinarySuffix);
            Assert.Equal(4, options.BinaryDigitGroupSize);
            Assert.Null(options.DigitSeparator);
            Assert.False(options.LeadingZeroes);
            Assert.True(options.UpperCaseHex);
            Assert.True(options.SmallHexNumbersInDecimal);
            Assert.True(options.AddLeadingZeroToHexNumbers);
            Assert.Equal(NumberBase.Hexadecimal, options.NumberBase);
            Assert.True(options.BranchLeadingZeroes);
            Assert.False(options.SignedImmediateOperands);
            Assert.True(options.SignedMemoryDisplacements);
            Assert.False(options.SignExtendMemoryDisplacements);
            Assert.Equal(MemorySizeOptions.Default, options.MemorySizeOptions);
            Assert.False(options.RipRelativeAddresses);
            Assert.True(options.ShowBranchSize);
            Assert.True(options.UsePseudoOps);
            Assert.False(options.ShowSymbolAddress);
            Assert.True(options.AddDsPrefix32);
            Assert.True(options.SymbolDisplInBrackets);
            Assert.True(options.DisplInBrackets);
        }
Exemplo n.º 11
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            const InstrOpInfoFlags flags = InstrOpInfoFlags.None;

            info = new InstrOpInfo(mnemonic, ref instr, flags);
            if (Register.EAX <= (Register)info.Op0Register && (Register)info.Op0Register <= Register.R15D)
            {
                info.Op0Register = (byte)((Register)info.Op0Register - Register.EAX + Register.AX);
            }
            if (Register.EAX <= (Register)info.Op1Register && (Register)info.Op1Register <= Register.R15D)
            {
                info.Op1Register = (byte)((Register)info.Op1Register - Register.EAX + Register.AX);
            }
        }
Exemplo n.º 12
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            string mnemonic;

            if (instr.CodeSize == codeSize)
            {
                mnemonic = mnemonics[(int)CodeSize.Unknown];
            }
            else
            {
                mnemonic = mnemonics[(int)codeSize];
            }
            info = new InstrOpInfo(mnemonic, ref instr, InstrOpInfoFlags.None);
        }
Exemplo n.º 13
0
 public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info          = default;
     info.Mnemonic = mnemonic;
     Debug.Assert(instr.OpCount == 2);
     Debug.Assert(instr.Op0Kind == OpKind.Register && instr.Op0Register == Register.ST0);
     if (!pseudoOp || !(options.UsePseudoOps && instr.Op1Register == Register.ST1))
     {
         info.OpCount = 1;
         Debug.Assert(InstrOpKind.Register == 0);
         //info.Op0Kind = InstrOpKind.Register;
         Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
         info.Op0Register = (byte)instr.Op1Register;
     }
 }
Exemplo n.º 14
0
 public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
 {
     info          = default;
     info.Mnemonic = mnemonic;
     info.OpCount  = 3;
     info.Op0Kind  = InstrOpKind.Register;
     Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
     info.Op0Register = (byte)reg1;
     info.Op1Kind     = InstrOpKind.Register;
     Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
     info.Op1Register = (byte)reg2;
     info.Op2Kind     = InstrOpKind.Register;
     Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
     info.Op2Register = (byte)reg3;
 }
Exemplo n.º 15
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            Debug.Assert(instr.OpCount == 3);

            OpKind shortFormOpKind;

            switch (instr.CodeSize)
            {
            case CodeSize.Unknown:
                shortFormOpKind = instr.Op0Kind;
                break;

            case CodeSize.Code16:
                shortFormOpKind = OpKind.MemorySegDI;
                break;

            case CodeSize.Code32:
                shortFormOpKind = OpKind.MemorySegEDI;
                break;

            case CodeSize.Code64:
                shortFormOpKind = OpKind.MemorySegRDI;
                break;

            default:
                throw new InvalidOperationException();
            }

            bool shortForm = instr.Op0Kind == shortFormOpKind && instr.PrefixSegment == Register.None;

            if (!shortForm)
            {
                info = new InstrOpInfo(mnemonic, ref instr, flags);
            }
            else
            {
                info          = default;
                info.Flags    = flags;
                info.Mnemonic = mnemonic;
                info.OpCount  = 2;
                info.Op0Kind  = (InstrOpKind)instr.Op1Kind;
                Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
                info.Op0Register = (byte)instr.Op1Register;
                info.Op1Kind     = (InstrOpKind)instr.Op2Kind;
                Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
                info.Op1Register = (byte)instr.Op2Register;
            }
        }
Exemplo n.º 16
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            const InstrOpInfoFlags flags = 0;

            if (options.UsePseudoOps && (instr.Op0Register == Register.ST1 || instr.Op1Register == Register.ST1))
            {
                info          = default;
                info.Mnemonic = mnemonic;
            }
            else
            {
                info = new InstrOpInfo(mnemonic, ref instr, flags);
                Debug.Assert(info.Op1Register == (int)Register.ST0);
                Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
                info.Op1Register = (byte)Registers.Register_ST;
            }
        }
Exemplo n.º 17
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            OpKind shortFormOpKind;

            switch (instr.CodeSize)
            {
            case CodeSize.Unknown:
                shortFormOpKind = instr.Op1Kind;
                break;

            case CodeSize.Code16:
                shortFormOpKind = OpKind.MemoryESDI;
                break;

            case CodeSize.Code32:
                shortFormOpKind = OpKind.MemoryESEDI;
                break;

            case CodeSize.Code64:
                shortFormOpKind = OpKind.MemoryESRDI;
                break;

            default:
                throw new InvalidOperationException();
            }

            bool shortForm = instr.Op1Kind == shortFormOpKind && instr.PrefixSegment == Register.None;

            if (!shortForm)
            {
                info          = default;
                info.Flags    = flags;
                info.Mnemonic = mnemonic_args;
                info.OpCount  = 1;
                info.Op0Kind  = (InstrOpKind)instr.Op1Kind;
            }
            else
            {
                info          = default;
                info.Flags    = flags;
                info.Mnemonic = mnemonic_no_args;
            }
        }
Exemplo n.º 18
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            var    flags = InstrOpInfoFlags.None;
            string mnemonic;

            if (instr.CodeSize == codeSize || instr.CodeSize == CodeSize.Unknown)
            {
                mnemonic = this.mnemonic;
            }
            else
            {
                mnemonic = mnemonic2;
            }
            if (!forceNoMemSize)
            {
                flags |= InstrOpInfoFlags.ShowNoMemSize_ForceSize;
            }
            info = new InstrOpInfo(mnemonic, ref instr, flags);
        }
Exemplo n.º 19
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            int instrCodeSize = GetCodeSize(instr.CodeSize);

            if (instrCodeSize == 0 || (instrCodeSize & codeSize) != 0)
            {
                info = new InstrOpInfo(mnemonic, ref instr, InstrOpInfoFlags.None);
            }
            else
            {
                info          = default;
                info.Mnemonic = "xchg";
                info.OpCount  = 2;
                info.Op0Kind  = InstrOpKind.Register;
                info.Op1Kind  = InstrOpKind.Register;
                Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
                info.Op0Register = (byte)register;
                Debug.Assert(InstrOpInfo.TEST_RegisterBits == 8);
                info.Op1Register = (byte)register;
            }
        }
Exemplo n.º 20
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            Register baseReg;

            switch (instr.CodeSize)
            {
            case CodeSize.Unknown:
                baseReg = instr.MemoryBase;
                break;

            case CodeSize.Code16:
                baseReg = Register.BX;
                break;

            case CodeSize.Code32:
                baseReg = Register.EBX;
                break;

            case CodeSize.Code64:
                baseReg = Register.RBX;
                break;

            default:
                throw new InvalidOperationException();
            }

            bool shortForm = instr.MemoryBase == baseReg && instr.PrefixSegment == Register.None;

            if (!shortForm)
            {
                info = new InstrOpInfo(mnemonic_args, ref instr, InstrOpInfoFlags.ShowNoMemSize_ForceSize | InstrOpInfoFlags.IgnoreIndexReg);
            }
            else
            {
                info          = default;
                info.Mnemonic = mnemonic_no_args;
            }
        }
Exemplo n.º 21
0
        public void TestOptions()
        {
            var options = new MasmFormatterOptions();

            TestOptionsBase(options);
        }
Exemplo n.º 22
0
 public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info) =>
 info = new InstrOpInfo(mnemonic, ref instr, flags);
Exemplo n.º 23
0
        public override void GetOpInfo(MasmFormatterOptions options, ref Instruction instr, out InstrOpInfo info)
        {
            var mnemonic = mnemonics[(int)instr.CodeSize];

            info = new InstrOpInfo(mnemonic, ref instr, InstrOpInfoFlags.None);
        }