Exemplo n.º 1
0
 /// <summary>
 /// This method is called if you don't override any of the other virtual methods. It should return true if
 /// <paramref name="symbol"/> was updated. If false is returned, <paramref name="options"/> can be updated to
 /// override the default number formatting options.
 /// </summary>
 /// <param name="operand">Operand number, 0-based. This is a formatter operand and isn't necessarily the same as an instruction operand.</param>
 /// <param name="instruction">Instruction</param>
 /// <param name="address">Address</param>
 /// <param name="addressSize">Size of <paramref name="address"/> in bytes</param>
 /// <param name="symbol">Updated with symbol information if this method returns true</param>
 /// <param name="options">Number formatting options if this method returns false</param>
 /// <returns></returns>
 protected virtual bool TryGetSymbol(int operand, ref Instruction instruction, ulong address, int addressSize, out SymbolResult symbol, ref NumberFormattingOptions options)
 {
     symbol = default;
     return(false);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Updates <paramref name="symbol"/> with the symbol and returns true, else it returns false and can update <paramref name="options"/>
 /// to override the default number formatting options
 /// </summary>
 /// <param name="operand">Operand number, 0-based. This is a formatter operand and isn't necessarily the same as an instruction operand.</param>
 /// <param name="instruction">Instruction</param>
 /// <param name="address">Address</param>
 /// <param name="addressSize">Size of <paramref name="address"/> in bytes</param>
 /// <param name="symbol">Updated with symbol information if this method returns true</param>
 /// <param name="showBranchSize">true if branch info (short, near ptr, far ptr) should be shown</param>
 /// <param name="options">Number formatting options if this method returns false</param>
 /// <returns></returns>
 public virtual bool TryGetBranchSymbol(int operand, ref Instruction instruction, ulong address, int addressSize, out SymbolResult symbol, ref bool showBranchSize, ref NumberFormattingOptions options) =>
 TryGetSymbol(operand, ref instruction, address, addressSize, out symbol, ref options);
Exemplo n.º 3
0
 /// <summary>
 /// Formats a <see cref="ulong"/>
 /// </summary>
 /// <param name="value">Value</param>
 /// <returns></returns>
 public string FormatUInt64(ulong value) => FormatUInt64(value, NumberFormattingOptions.CreateImmediateInternal(Options));
Exemplo n.º 4
0
 /// <summary>
 /// Gets a symbol and returns true. If it returns false, <paramref name="options"/> can be updated to override
 /// the default number formatting options.
 ///
 /// This method gets called even if the memory operand has no displacement, eg. [eax].
 /// </summary>
 /// <param name="operand">Operand number, 0-based. This is a formatter operand and isn't necessarily the same as an instruction operand.</param>
 /// <param name="instruction">Instruction</param>
 /// <param name="displacement">Displacement. If it's RIP-relative addressing, this is the absolute address (rip/eip + displ)</param>
 /// <param name="displacementSize">Size of <paramref name="displacement"/> in bytes</param>
 /// <param name="ripRelativeAddresses">true to use RIP relative addresses</param>
 /// <param name="symbol">Updated with symbol information if this method returns true</param>
 /// <param name="options">Number formatting options if this method returns false</param>
 /// <returns></returns>
 public virtual bool TryGetDisplSymbol(int operand, ref Instruction instruction, ulong displacement, int displacementSize, ref bool ripRelativeAddresses, out SymbolResult symbol, ref NumberFormattingOptions options) =>
 TryGetSymbol(operand, ref instruction, displacement, displacementSize, out symbol, ref options);
Exemplo n.º 5
0
 /// <summary>
 /// Formats a <see cref="ushort"/>
 /// </summary>
 /// <param name="value">Value</param>
 /// <returns></returns>
 public string FormatUInt16(ushort value) => FormatUInt16(value, NumberFormattingOptions.CreateImmediateInternal(Options));
Exemplo n.º 6
0
 /// <summary>
 /// Formats a <see cref="uint"/>
 /// </summary>
 /// <param name="value">Value</param>
 /// <returns></returns>
 public string FormatUInt32(uint value) => FormatUInt32(value, NumberFormattingOptions.CreateImmediateInternal(Options));
Exemplo n.º 7
0
 /// <summary>
 /// Gets a symbol and returns true. If it returns false, <paramref name="options"/> can be updated to override
 /// the default number formatting options.
 /// </summary>
 /// <param name="operand">Operand number, 0-based. This is a formatter operand and isn't necessarily the same as an instruction operand.</param>
 /// <param name="code">Code value</param>
 /// <param name="immediate">Immediate value</param>
 /// <param name="symbol">Updated with symbol information if this method returns true</param>
 /// <param name="options">Number formatting options if this method returns false</param>
 /// <returns></returns>
 public virtual bool TryGetImmediateSymbol(int operand, Code code, ulong immediate, out SymbolResult symbol, ref NumberFormattingOptions options) =>
 TryGetSymbol(operand, code, immediate, out symbol, ref options);
Exemplo n.º 8
0
 public string FormatUInt32(ref NumberFormattingOptions options, uint value) => FormatUnsignedInteger(ref options, value, 32, options.ShortNumbers, options.SmallHexNumbersInDecimal);
Exemplo n.º 9
0
 /// <summary>
 /// This method is called if you don't override any of the other virtual methods. It should return true if
 /// <paramref name="symbol"/> was updated. If false is returned, <paramref name="options"/> can be updated to
 /// override the default number formatting options.
 /// </summary>
 /// <param name="operand">Operand number, 0-based. This is a formatter operand and isn't necessarily the same as an instruction operand.</param>
 /// <param name="code">Code value</param>
 /// <param name="address">Address</param>
 /// <param name="symbol">Updated with symbol information if this method returns true</param>
 /// <param name="options">Number formatting options if this method returns false</param>
 /// <returns></returns>
 protected virtual bool TryGetSymbol(int operand, Code code, ulong address, out SymbolResult symbol, ref NumberFormattingOptions options)
 {
     symbol = default;
     return(false);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Updates <paramref name="symbol"/> with the symbol and returns true, else it returns false and can update <paramref name="options"/>
 /// to override the default number formatting options
 /// </summary>
 /// <param name="operand">Operand number, 0-based. This is a formatter operand and isn't necessarily the same as an instruction operand.</param>
 /// <param name="code">Code value, eg. a call, jmp, jcc, xbegin</param>
 /// <param name="address">Address</param>
 /// <param name="symbol">Updated with symbol information if this method returns true</param>
 /// <param name="showBranchSize">true if branch info (short, near ptr, far ptr) should be shown</param>
 /// <param name="options">Number formatting options if this method returns false</param>
 /// <returns></returns>
 public virtual bool TryGetBranchSymbol(int operand, Code code, ulong address, out SymbolResult symbol, ref bool showBranchSize, ref NumberFormattingOptions options) =>
 TryGetSymbol(operand, code, address, out symbol, ref options);
Exemplo n.º 11
0
 /// <summary>
 /// Gets a symbol and returns true. If it returns false, <paramref name="options"/> can be updated to override
 /// the default number formatting options.
 ///
 /// This method gets called even if the memory operand has no displacement, eg. [eax].
 /// </summary>
 /// <param name="operand">Operand number, 0-based. This is a formatter operand and isn't necessarily the same as an instruction operand.</param>
 /// <param name="code">Code value</param>
 /// <param name="displacement">Displacement. If it's RIP-relative addressing, this is the absolute address (rip/eip + displ)</param>
 /// <param name="ripRelativeAddresses">true to use RIP relative addresses</param>
 /// <param name="symbol">Updated with symbol information if this method returns true</param>
 /// <param name="options">Number formatting options if this method returns false</param>
 /// <returns></returns>
 public virtual bool TryGetDisplSymbol(int operand, Code code, ulong displacement, ref bool ripRelativeAddresses, out SymbolResult symbol, ref NumberFormattingOptions options) =>
 TryGetSymbol(operand, code, displacement, out symbol, ref options);
Exemplo n.º 12
0
        string FormatUnsignedInteger(ref NumberFormattingOptions options, ulong value, int valueSize, bool shortNumbers, bool smallHexNumbersInDecimal)
        {
            string rawNumber;
            string prefix, suffix;
            int    digitGroupSize;
            string digitSeparator;

            switch ((NumberBase)options.numberBaseByteValue)
            {
            case NumberBase.Hexadecimal:
                if (smallHexNumbersInDecimal && value <= SmallPositiveNumber)
                {
                    digitGroupSize = formatterOptions.DecimalDigitGroupSize;
                    digitSeparator = options.DigitSeparator;
                    prefix         = formatterOptions.DecimalPrefix;
                    suffix         = formatterOptions.DecimalSuffix;
                    rawNumber      = smallDecimalValues[(int)value];
                }
                else
                {
                    digitGroupSize = options.DigitGroupSize;
                    digitSeparator = options.DigitSeparator;
                    prefix         = options.Prefix;
                    suffix         = options.Suffix;
                    rawNumber      = ToHexadecimal(value, shortNumbers ? 0 : (valueSize + 3) >> 2, options.UpperCaseHex, options.AddLeadingZeroToHexNumbers && string.IsNullOrEmpty(prefix));
                }
                break;

            case NumberBase.Decimal:
                digitGroupSize = options.DigitGroupSize;
                digitSeparator = options.DigitSeparator;
                prefix         = options.Prefix;
                suffix         = options.Suffix;
                rawNumber      = value.ToString();
                break;

            case NumberBase.Octal:
                digitGroupSize = options.DigitGroupSize;
                digitSeparator = options.DigitSeparator;
                prefix         = options.Prefix;
                suffix         = options.Suffix;
                rawNumber      = ToOctal(value, shortNumbers ? 0 : (valueSize + 2) / 3);
                if (prefix == "0")
                {
                    // The prefix is part of the number so that a digit separator can be placed
                    // between the "prefix" and the rest of the number, eg. "0" + "1234" with
                    // digit separator "`" and group size = 2 is "0`12`34" and not "012`34".
                    // Other prefixes, eg. "0o" prefix: 0o12`34 and never 0o`12`34.
                    if (rawNumber[0] != '0')
                    {
                        rawNumber = prefix + rawNumber;
                    }
                    prefix = null;
                }
                break;

            case NumberBase.Binary:
                digitGroupSize = options.DigitGroupSize;
                digitSeparator = options.DigitSeparator;
                prefix         = options.Prefix;
                suffix         = options.Suffix;
                rawNumber      = ToBinary(value, shortNumbers ? 0 : valueSize);
                break;

            default:
                throw new InvalidOperationException();
            }

            if (options.AddDigitSeparators && digitGroupSize > 0 && !string.IsNullOrEmpty(digitSeparator))
            {
                rawNumber = AddDigitSeparators(rawNumber, digitGroupSize, digitSeparator);
            }

            if (!string.IsNullOrEmpty(prefix))
            {
                if (!string.IsNullOrEmpty(suffix))
                {
                    return(prefix + rawNumber + suffix);
                }
                return(prefix + rawNumber);
            }
            else if (!string.IsNullOrEmpty(suffix))
            {
                return(rawNumber + suffix);
            }
            else
            {
                return(rawNumber);
            }
        }
Exemplo n.º 13
0
 public string FormatUInt64(ref NumberFormattingOptions options, ulong value, bool shortNumbers) => FormatUnsignedInteger(ref options, value, 64, shortNumbers, options.SmallHexNumbersInDecimal);
Exemplo n.º 14
0
 /// <summary>
 /// Returns true if <paramref name="symbol"/> was updated with a symbol. <paramref name="symbolSelector"/> can be set to default value
 /// if it should be formatted as a number. <paramref name="options"/> is used if this method returns false or if <paramref name="symbolSelector"/>
 /// has the default value.
 /// </summary>
 /// <param name="operand">Operand number, 0-based. This is a formatter operand and isn't necessarily the same as an instruction operand.</param>
 /// <param name="instruction">Instruction</param>
 /// <param name="selector">Selector/segment</param>
 /// <param name="address">Address</param>
 /// <param name="addressSize">Size of <paramref name="address"/> in bytes</param>
 /// <param name="symbolSelector">Updated with the selector symbol or with the default value if it should be formatted as a number</param>
 /// <param name="symbol">Updated with symbol information if this method returns true</param>
 /// <param name="showBranchSize">true if branch info (short, near ptr, far ptr) should be shown</param>
 /// <param name="options">Number formatting options if this method returns false or if <paramref name="symbolSelector"/> has the default value</param>
 /// <returns></returns>
 public virtual bool TryGetFarBranchSymbol(int operand, ref Instruction instruction, ushort selector, uint address, int addressSize, out SymbolResult symbolSelector, out SymbolResult symbol, ref bool showBranchSize, ref NumberFormattingOptions options)
 {
     symbolSelector = default;
     return(TryGetSymbol(operand, ref instruction, address, addressSize, out symbol, ref options));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Formats a <see cref="byte"/>
 /// </summary>
 /// <param name="value">Value</param>
 /// <returns></returns>
 public string FormatUInt8(byte value) => FormatUInt8(value, NumberFormattingOptions.CreateImmediateInternal(Options));
Exemplo n.º 16
0
 /// <summary>
 /// Gets a symbol and returns true. If it returns false, <paramref name="options"/> can be updated to override
 /// the default number formatting options.
 /// </summary>
 /// <param name="operand">Operand number, 0-based. This is a formatter operand and isn't necessarily the same as an instruction operand.</param>
 /// <param name="instruction">Instruction</param>
 /// <param name="immediate">Immediate value</param>
 /// <param name="immediateSize">Size of <paramref name="immediate"/> in bytes</param>
 /// <param name="symbol">Updated with symbol information if this method returns true</param>
 /// <param name="options">Number formatting options if this method returns false</param>
 /// <returns></returns>
 public virtual bool TryGetImmediateSymbol(int operand, ref Instruction instruction, ulong immediate, int immediateSize, out SymbolResult symbol, ref NumberFormattingOptions options) =>
 TryGetSymbol(operand, ref instruction, immediate, immediateSize, out symbol, ref options);
Exemplo n.º 17
0
 public string FormatUInt8(ref NumberFormattingOptions options, byte value) => FormatUnsignedInteger(ref options, value, 8, options.ShortNumbers, options.SmallHexNumbersInDecimal);