/* Copyright (C) 2018 de4dot@gmail.com This file is part of Iced. Iced is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Iced is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Iced. If not, see . */ #if (!NO_GAS_FORMATTER || !NO_INTEL_FORMATTER || !NO_MASM_FORMATTER || !NO_NASM_FORMATTER) && !NO_FORMATTER using System; namespace Iced.Intel { /// /// Formatter options /// public abstract class FormatterOptions { /// /// Prefixes are upper cased /// public bool UpperCasePrefixes { get; set; } /// /// Mnemonics are upper cased /// public bool UpperCaseMnemonics { get; set; } /// /// Registers are upper cased /// public bool UpperCaseRegisters { get; set; } /// /// Keywords are upper cased (eg. BYTE PTR, SHORT) /// public bool UpperCaseKeywords { get; set; } /// /// Upper case other stuff, eg. {z}, {sae}, {rd-sae} /// public bool UpperCaseOther { get; set; } /// /// Everything is upper cased, except numbers and their prefixes/suffixes /// public bool UpperCaseAll { get; set; } /// /// Character index (0-based) where the first operand is formatted. Can be set to 0 to format it immediately after the mnemonic. /// At least one space or tab is always added betewen the mnemonic and the first operand. /// public int FirstOperandCharIndex { get; set; } /// /// Size of a tab character or <= 0 to use spaces /// public int TabSize { get; set; } /// /// Add a space after the operand separator, eg. "rax, rcx" vs "rax,rcx" /// public bool SpaceAfterOperandSeparator { get; set; } /// /// Add a space after the open memory bracket, eg. "[ rax]" vs "[rax]" /// public bool SpaceAfterMemoryOpenBracket { get; set; } /// /// Add a space before the close memory bracket, eg. "[rax ]" vs "[rax]" /// public bool SpaceBeforeMemoryCloseBracket { get; set; } /// /// Add spaces between memory operand "+" and "-" operators, eg. "[rax + rcx]" vs "[rax+rcx]" /// public bool SpacesBetweenMemoryAddOperators { get; set; } /// /// Add spaces between memory operand "*" operator, eg. "[rax * 4]" vs "[rax*4]" /// public bool SpacesBetweenMemoryMulOperators { get; set; } /// /// Show memory operand scale value before the index register, eg. "[4*rax]" vs "[rax*4]" /// public bool ScaleBeforeIndex { get; set; } /// /// Always show the scale value even if it's *1, eg. "[rax+rcx*1]" vs "[rax+rcx]" /// public bool AlwaysShowScale { get; set; } /// /// Always show the effective segment register. If the option is false, only show the segment register if /// there's a segment override prefix. Eg. "ds:[rax]" vs "[rax]" /// public bool AlwaysShowSegmentRegister { get; set; } /// /// Show zero displacements, eg. '[rcx*2+0]' vs '[rcx*2]' /// public bool ShowZeroDisplacements { get; set; } /// /// Hex number prefix or null/empty string, eg. "0x" /// public string HexPrefix { get; set; } /// /// Hex number suffix or null/empty string, eg. "h" /// public string HexSuffix { get; set; } /// /// Size of a digit group. Used if is true /// public int HexDigitGroupSize { get; set; } = 4; /// /// Decimal number prefix or null/empty string /// public string DecimalPrefix { get; set; } /// /// Decimal number suffix or null/empty string /// public string DecimalSuffix { get; set; } /// /// Size of a digit group. Used if is true /// public int DecimalDigitGroupSize { get; set; } = 3; /// /// Octal number prefix or null/empty string /// public string OctalPrefix { get; set; } /// /// Octal number suffix or null/empty string /// public string OctalSuffix { get; set; } /// /// Size of a digit group. Used if is true /// public int OctalDigitGroupSize { get; set; } = 4; /// /// Binary number prefix or null/empty string /// public string BinaryPrefix { get; set; } /// /// Binary number suffix or null/empty string /// public string BinarySuffix { get; set; } /// /// Size of a digit group. Used if is true /// public int BinaryDigitGroupSize { get; set; } = 4; /// /// Digit separator or null/empty string /// public string DigitSeparator { get; set; } = "_"; /// /// Enables digit separators, see , , , , /// public bool AddDigitSeparators { get; set; } /// /// Use shortest possible hexadecimal/octal/binary numbers, eg. 0xA/0Ah instead of eg. 0x0000000A/0000000Ah. /// This option has no effect on branch targets, use . /// public bool ShortNumbers { get; set; } = true; /// /// Use upper case hex digits /// public bool UpperCaseHex { get; set; } = true; /// /// Small hex numbers (-9 .. 9) are shown in decimal /// public bool SmallHexNumbersInDecimal { get; set; } = true; /// /// Add a leading zero to numbers if there's no prefix and the number begins with hex digits A-F, eg. Ah vs 0Ah /// public bool AddLeadingZeroToHexNumbers { get; set; } = true; /// /// Number base /// public NumberBase NumberBase { get => (NumberBase)numberBase; set { if (value < 0 || value > NumberBase.Binary) throw new ArgumentOutOfRangeException(nameof(value)); numberBase = (byte)value; } } byte numberBase = (byte)NumberBase.Hexadecimal; /// /// Don't add leading zeroes to branch offsets, eg. 'je 123h' vs 'je 00000123h'. Used by call near, call far, jmp near, jmp far, jcc, loop, loopcc, xbegin /// public bool ShortBranchNumbers { get; set; } /// /// Show immediate operands as signed numbers, eg. 'mov eax,FFFFFFFF' vs 'mov eax,-1' /// public bool SignedImmediateOperands { get; set; } /// /// Displacements are signed numbers, eg. 'mov al,[eax-2000h]' vs 'mov al,[eax+0FFFFE000h]' /// public bool SignedMemoryDisplacements { get; set; } = true; /// /// Sign extend memory displacements to the address size (16-bit, 32-bit, 64-bit), eg. 'mov al,[eax+12h]' vs 'mov al,[eax+00000012h]' /// public bool SignExtendMemoryDisplacements { get; set; } /// /// Always show the memory size, even when not needed eg. "mov al,[rax]" vs "mov al,byte ptr [rax]". /// This is ignored by the GAS (AT&T) formatter. /// public bool AlwaysShowMemorySize { get; set; } /// /// true to show RIP relative addresses as '[rip+12345678h]', false to show RIP relative addresses as '[1029384756AFBECDh]' /// public bool RipRelativeAddresses { get; set; } /// /// Shows near, short, etc if it's a branch instruction, eg. 'je short 1234h' vs 'je 1234h' /// public bool ShowBranchSize { get; set; } = true; /// /// Use pseudo instructions, eg. vcmpngesd vs vcmpsd+imm8 /// public bool UsePseudoOps { get; set; } = true; } /// /// Number base /// public enum NumberBase { /// /// Hex numbers (base 16) /// Hexadecimal, /// /// Decimal numbers (base 10) /// Decimal, /// /// Octal numbers (base 8) /// Octal, /// /// Binary numbers (base 2) /// Binary, } } #endif