public SymbolOptionsTestCase(string hexBytes, int bitness, string formattedString, SymbolTestFlags flags) { HexBytes = hexBytes; Bitness = bitness; FormattedString = formattedString; Flags = flags; }
void TestIt(string hexBytes, int bitness, string formattedString, SymbolTestFlags flags) { var decoder = Decoder.Create(bitness, new ByteArrayCodeReader(hexBytes)); decoder.IP = bitness switch { 16 => DecoderConstants.DEFAULT_IP16, 32 => DecoderConstants.DEFAULT_IP32, 64 => DecoderConstants.DEFAULT_IP64, _ => throw new InvalidOperationException(), }; decoder.Decode(out var instruction); var resolver = new TestSymbolResolver { tryGetSymbol = (in Instruction instruction, int operand, int instructionOperand, ulong address, int addressSize, out SymbolResult symbol) => { if (instructionOperand == 1 && (flags & SymbolTestFlags.Symbol) != 0) { symbol = new SymbolResult(address, "symbol", FormatterTextKind.Data, (flags & SymbolTestFlags.Signed) != 0 ? SymbolFlags.Signed : SymbolFlags.None); return(true); } symbol = default; return(false); }, }; var formatter = (MasmFormatter)FormatterFactory.Create_Resolver(resolver).formatter; formatter.Options.MasmSymbolDisplInBrackets = (flags & SymbolTestFlags.SymbolDisplInBrackets) != 0; formatter.Options.MasmDisplInBrackets = (flags & SymbolTestFlags.DisplInBrackets) != 0; formatter.Options.RipRelativeAddresses = (flags & SymbolTestFlags.Rip) != 0; formatter.Options.ShowZeroDisplacements = (flags & SymbolTestFlags.ShowZeroDisplacements) != 0; formatter.Options.MasmAddDsPrefix32 = (flags & SymbolTestFlags.NoAddDsPrefix32) == 0; var output = new StringOutput(); formatter.Format(instruction, output); var actualFormattedString = output.ToStringAndReset(); #pragma warning disable xUnit2006 // Do not use invalid string equality check // Show the full string without ellipses by using Equal<string>() instead of Equal() Assert.Equal <string>(formattedString, actualFormattedString); #pragma warning restore xUnit2006 // Do not use invalid string equality check }
public SymbolResolver(SymbolTestFlags flags) => this.flags = flags;