private protected void TestBase(int bitness, string hexBytes, int operand, int elementIndex, ulong expectedValue, VARegisterValueProviderImpl getRegValue) { var decoder = Decoder.Create(bitness, new ByteArrayCodeReader(hexBytes)); switch (bitness) { case 16: decoder.InstructionPointer = DecoderConstants.DEFAULT_IP16; break; case 32: decoder.InstructionPointer = DecoderConstants.DEFAULT_IP32; break; case 64: decoder.InstructionPointer = DecoderConstants.DEFAULT_IP64; break; default: throw new InvalidOperationException(); } var instr = decoder.Decode(); ulong value1 = instr.GetVirtualAddress(operand, elementIndex, getRegValue); Assert.Equal(expectedValue, value1); ulong value2 = instr.GetVirtualAddress(operand, elementIndex, (register, elementIndex2, elementSize) => getRegValue.GetRegisterValue(register, elementIndex2, elementSize)); Assert.Equal(expectedValue, value2); }
void VATests(VirtualAddressTestCase tc) { var decoder = Decoder.Create(tc.Bitness, new ByteArrayCodeReader(tc.HexBytes), tc.DecoderOptions); decoder.IP = tc.Bitness switch { 16 => DecoderConstants.DEFAULT_IP16, 32 => DecoderConstants.DEFAULT_IP32, 64 => DecoderConstants.DEFAULT_IP64, _ => throw new InvalidOperationException(), }; var instruction = decoder.Decode(); var getRegValue = new VARegisterValueProviderImpl(tc.RegisterValues); var getRegValueFail = new VARegisterValueProviderImpl(Array.Empty <(Register register, int elementIndex, int elementSize, ulong value)>()); var factory = new InstructionInfoFactory(); var info = factory.GetInfo(instruction); var usedMem = info.GetUsedMemory().Skip(tc.UsedMemIndex).First(); bool b1 = usedMem.TryGetVirtualAddress(tc.ElementIndex, getRegValue, out ulong value1); Assert.True(b1); Assert.Equal(tc.ExpectedValue, value1); bool b2 = usedMem.TryGetVirtualAddress(tc.ElementIndex, out ulong value2, (Register register, int elementIndex, int elementSize, out ulong value) => getRegValue.TryGetRegisterValue(register, elementIndex, elementSize, out value)); Assert.True(b2); Assert.Equal(tc.ExpectedValue, value2); ulong value3 = usedMem.GetVirtualAddress(tc.ElementIndex, getRegValue); Assert.Equal(tc.ExpectedValue, value3); ulong value4 = usedMem.GetVirtualAddress(tc.ElementIndex, (register, elementIndex2, elementSize) => getRegValue.GetRegisterValue(register, elementIndex2, elementSize)); Assert.Equal(tc.ExpectedValue, value4); Assert.False(usedMem.TryGetVirtualAddress(tc.ElementIndex, out ulong value5, (Register register, int elementIndex, int elementSize, out ulong value) => { value = 0; return(false); })); Assert.Equal(0UL, value5); Assert.False(usedMem.TryGetVirtualAddress(tc.ElementIndex, getRegValueFail, out ulong value6)); Assert.Equal(0UL, value6); }
private protected void TestBase(int bitness, string hexBytes, int operand, int elementIndex, ulong expectedValue, VARegisterValueProviderImpl getRegValue) { 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(), }; var instruction = decoder.Decode(); ulong value1 = instruction.GetVirtualAddress(operand, elementIndex, getRegValue); Assert.Equal(expectedValue, value1); ulong value2 = instruction.GetVirtualAddress(operand, elementIndex, (register, elementIndex2, elementSize) => getRegValue.GetRegisterValue(register, elementIndex2, elementSize)); Assert.Equal(expectedValue, value2); }
void VATests(VirtualAddressTestCase tc) { var decoder = Decoder.Create(tc.Bitness, new ByteArrayCodeReader(tc.HexBytes)); decoder.IP = tc.Bitness switch { 16 => DecoderConstants.DEFAULT_IP16, 32 => DecoderConstants.DEFAULT_IP32, 64 => DecoderConstants.DEFAULT_IP64, _ => throw new InvalidOperationException(), }; var instruction = decoder.Decode(); var getRegValue = new VARegisterValueProviderImpl(tc.RegisterValues); ulong value1 = instruction.GetVirtualAddress(tc.Operand, tc.ElementIndex, getRegValue); Assert.Equal(tc.ExpectedValue, value1); ulong value2 = instruction.GetVirtualAddress(tc.Operand, tc.ElementIndex, (register, elementIndex2, elementSize) => getRegValue.GetRegisterValue(register, elementIndex2, elementSize)); Assert.Equal(tc.ExpectedValue, value2); }