/*
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 {
///
/// Used by a to resolve symbols
///
public interface ISymbolResolver {
///
/// Tries to resolve a symbol. It returns true if was updated.
///
/// Operand number, 0-based. This is a formatter operand and isn't necessarily the same as an instruction operand.
/// Instruction operand number, 0-based, or -1 if it's an operand created by the formatter.
/// Instruction
/// Address
/// Size of in bytes
/// Updated with symbol information if this method returns true
///
bool TryGetSymbol(int operand, int instructionOperand, ref Instruction instruction, ulong address, int addressSize, out SymbolResult symbol);
}
///
/// Symbol flags
///
[Flags]
public enum SymbolFlags : uint {
///
/// No bit is set
///
None = 0,
///
/// It's a symbol relative to a register, eg. a struct offset `[ebx+some_struct.field1]`. If this is
/// cleared, it's the address of a symbol.
///
Relative = 0x00000001,
///
/// It's a signed symbol and it should be displayed as '-symbol' or 'reg-symbol' instead of 'symbol' or 'reg+symbol'
///
Signed = 0x00000002,
}
///
/// The result of resolving a symbol
///
public readonly struct SymbolResult {
///
/// The address of the symbol
///
public readonly ulong Address;
///
/// Contains the symbol
///
public readonly TextInfo Text;
///
/// Symbol flags
///
public readonly SymbolFlags Flags;
///
/// Constructor
///
/// The address of the symbol
/// Symbol
public SymbolResult(ulong address, string text) {
Address = address;
Text = new TextInfo(text, FormatterOutputTextKind.Label);
Flags = 0;
}
///
/// Constructor
///
/// The address of the symbol
/// Symbol
/// Color
public SymbolResult(ulong address, string text, FormatterOutputTextKind color) {
Address = address;
Text = new TextInfo(text, color);
Flags = 0;
}
///
/// Constructor
///
/// The address of the symbol
/// Symbol
/// Color
/// Symbol flags
public SymbolResult(ulong address, string text, FormatterOutputTextKind color, SymbolFlags flags) {
Address = address;
Text = new TextInfo(text, color);
Flags = flags;
}
///
/// Constructor
///
/// The address of the symbol
/// Symbol
public SymbolResult(ulong address, TextInfo text) {
Address = address;
Text = text;
Flags = 0;
}
///
/// Constructor
///
/// The address of the symbol
/// Symbol
/// Symbol flags
public SymbolResult(ulong address, TextInfo text, SymbolFlags flags) {
Address = address;
Text = text;
Flags = flags;
}
}
///
/// Contains one or more s (text and color)
///
public readonly struct TextInfo {
///
/// true if this is the default instance
///
public bool IsDefault => TextArray == null && Text.Text == null;
///
/// The text and color unless is non-null
///
public readonly TextPart Text;
///
/// Text and color or null if should be used
///
public readonly TextPart[] TextArray;
///
/// Constructor
///
/// Text
/// Color
public TextInfo(string text, FormatterOutputTextKind color) {
Text = new TextPart(text, color);
TextArray = null;
}
///
/// Constructor
///
/// Text
public TextInfo(TextPart text) {
Text = text;
TextArray = null;
}
///
/// Constructor
///
/// All text parts
public TextInfo(TextPart[] text) {
Text = default;
TextArray = text;
}
}
///
/// Contains text and colors
///
public readonly struct TextPart {
///
/// Text
///
public readonly string Text;
///
/// Color
///
public readonly FormatterOutputTextKind Color;
///
/// Constructor
///
/// Text
/// Color
public TextPart(string text, FormatterOutputTextKind color) {
Text = text;
Color = color;
}
}
}
#endif