Decoder CreateDecoder(int codeSize, string hexBytes) { Decoder decoder; var codeReader = new ByteArrayCodeReader(hexBytes); switch (codeSize) { case 16: decoder = Decoder.Create16(codeReader); decoder.InstructionPointer = DecoderConstants.DEFAULT_IP16; break; case 32: decoder = Decoder.Create32(codeReader); decoder.InstructionPointer = DecoderConstants.DEFAULT_IP32; break; case 64: decoder = Decoder.Create64(codeReader); decoder.InstructionPointer = DecoderConstants.DEFAULT_IP64; break; default: throw new ArgumentOutOfRangeException(nameof(codeSize)); } Assert.Equal(codeSize, decoder.Bitness); return(decoder); }
void Decode_multiple_instrs_with_one_instance() { var reader16 = new DecodeMultipleCodeReader(); var reader32 = new DecodeMultipleCodeReader(); var reader64 = new DecodeMultipleCodeReader(); var decoderDict16 = new Dictionary <DecoderOptions, Decoder>(); var decoderDict32 = new Dictionary <DecoderOptions, Decoder>(); var decoderDict64 = new Dictionary <DecoderOptions, Decoder>(); foreach (var info in DecoderTestUtils.GetDecoderTests(needHexBytes: true, includeOtherTests: false)) { var data = HexUtils.ToByteArray(info.HexBytes); var decoder = Decoder.Create(info.Bitness, new ByteArrayCodeReader(data), info.Options); Decoder decoderAll; switch (info.Bitness) { case 16: decoder.InstructionPointer = DecoderConstants.DEFAULT_IP16; reader16.SetArray(data); if (!decoderDict16.TryGetValue(info.Options, out decoderAll)) { decoderDict16.Add(info.Options, decoderAll = Decoder.Create16(reader16, info.Options)); } break; case 32: decoder.InstructionPointer = DecoderConstants.DEFAULT_IP32; reader32.SetArray(data); if (!decoderDict32.TryGetValue(info.Options, out decoderAll)) { decoderDict32.Add(info.Options, decoderAll = Decoder.Create32(reader32, info.Options)); } break; case 64: decoder.InstructionPointer = DecoderConstants.DEFAULT_IP64; reader64.SetArray(data); if (!decoderDict64.TryGetValue(info.Options, out decoderAll)) { decoderDict64.Add(info.Options, decoderAll = Decoder.Create64(reader64, info.Options)); } break; default: throw new InvalidOperationException(); } decoderAll.InstructionPointer = decoder.InstructionPointer; var instr1 = decoder.Decode(); var instr2 = decoderAll.Decode(); Assert.Equal(info.Code, instr1.Code); Assert.True(Instruction.TEST_BitByBitEquals(instr1, instr2)); } }
void Decode_multiple_instrs_with_one_instance() { var reader16 = new DecodeMultipleCodeReader(); var reader32 = new DecodeMultipleCodeReader(); var reader64 = new DecodeMultipleCodeReader(); var decoderAll16 = Decoder.Create16(reader16); var decoderAll32 = Decoder.Create32(reader32); var decoderAll64 = Decoder.Create64(reader64); foreach (var info in DecoderTestUtils.GetDecoderTests(needHexBytes: true, includeOtherTests: false)) { var data = HexUtils.ToByteArray(info.HexBytes); var decoder = Decoder.Create(info.Bitness, new ByteArrayCodeReader(data)); Decoder decoderAll; switch (info.Bitness) { case 16: decoder.InstructionPointer = DecoderConstants.DEFAULT_IP16; reader16.SetArray(data); decoderAll = decoderAll16; break; case 32: decoder.InstructionPointer = DecoderConstants.DEFAULT_IP32; reader32.SetArray(data); decoderAll = decoderAll32; break; case 64: decoder.InstructionPointer = DecoderConstants.DEFAULT_IP64; reader64.SetArray(data); decoderAll = decoderAll64; break; default: throw new InvalidOperationException(); } decoderAll.InstructionPointer = decoder.InstructionPointer; var instr1 = decoder.Decode(); var instr2 = decoderAll.Decode(); Assert.Equal(info.Code, instr1.Code); Assert.True(Instruction.TEST_BitByBitEquals(ref instr1, ref instr2)); } }