From 61513023aff4d3312287bb0fb55ea931997dfddb Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 6 Jul 2021 16:42:24 -0700 Subject: update yaxpeax_arch and bump version to 0.1.0 --- test/armv7.rs | 23 +++++++++++++++++------ test/armv7/thumb.rs | 29 ++++++++++++++++++++++++----- test/armv8/a64.rs | 9 ++++++--- 3 files changed, 47 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/armv7.rs b/test/armv7.rs index 6257f5b..7feb774 100644 --- a/test/armv7.rs +++ b/test/armv7.rs @@ -6,7 +6,8 @@ mod thumb; type InstDecoder = ::Decoder; fn test_invalid_under(decoder: &InstDecoder, data: [u8; 4]) { - match decoder.decode(data.to_vec()) { + let mut reader = yaxpeax_arch::U8Reader::new(&data[..]); + match decoder.decode(&mut reader) { Err(_) => { }, Ok(inst) => { panic!( @@ -19,7 +20,13 @@ fn test_invalid_under(decoder: &InstDecoder, data: [u8; 4]) { } fn test_display_under(decoder: &InstDecoder, data: [u8; 4], expected: &'static str) { - let instr = decoder.decode(data.to_vec()).unwrap_or_else(|_| panic!("failed to decode {:02x}{:02x}{:02x}{:02x}", data[0], data[1], data[2], data[3])); + let mut reader = yaxpeax_arch::U8Reader::new(&data[..]); + let instr = match decoder.decode(&mut reader) { + Err(e) => { + panic!("failed to decode {:02x}{:02x}{:02x}{:02x}: {}", data[0], data[1], data[2], data[3], e) + }, + Ok(instr) => instr, + }; let displayed = format!("{}", instr); assert!( displayed == expected, @@ -30,7 +37,8 @@ fn test_display_under(decoder: &InstDecoder, data: [u8; 4], expected: &'static s } fn test_decode(data: [u8; 4], expected: Instruction) { - let instr = InstDecoder::default().decode(data.to_vec()).unwrap(); + let mut reader = yaxpeax_arch::U8Reader::new(&data[..]); + let instr = InstDecoder::default().decode(&mut reader).unwrap(); assert!( instr == expected, "decode error for {:02x}{:02x}{:02x}{:02x}:\n decoded: {:?}\n expected: {:?}\n", @@ -76,7 +84,8 @@ fn test_arm_security_extensions(data: [u8; 4], expected: &'static str) { } fn test_nonconformant(data: [u8; 4]) { - let result = InstDecoder::default().decode(data.to_vec()); + let mut reader = yaxpeax_arch::U8Reader::new(&data[..]); + let result = InstDecoder::default().decode(&mut reader); assert!( result == Err(DecodeError::Nonconforming), "got bad result: {:?} from {:#x?}", result, data @@ -84,7 +93,8 @@ fn test_nonconformant(data: [u8; 4]) { } fn test_display(data: [u8; 4], expected: &'static str) { - let instr = InstDecoder::default().decode(data.to_vec()).unwrap(); + let mut reader = yaxpeax_arch::U8Reader::new(&data[..]); + let instr = InstDecoder::default().decode(&mut reader).unwrap(); let text = format!("{}", instr); assert!( text == expected, @@ -693,7 +703,8 @@ static INSTRUCTION_BYTES: [u8; 4 * 60] = [ fn test_decode_span() { let mut i = 0u32; while i < INSTRUCTION_BYTES.len() as u32 { - let instr = InstDecoder::default().decode(INSTRUCTION_BYTES[(i as usize)..].iter().cloned()).unwrap(); + let mut reader = yaxpeax_arch::U8Reader::new(&INSTRUCTION_BYTES[(i as usize)..]); + let instr = InstDecoder::default().decode(&mut reader).unwrap(); println!( "Decoded {:02x}{:02x}{:02x}{:02x}: {}", //{:?}\n {}", INSTRUCTION_BYTES[i as usize], diff --git a/test/armv7/thumb.rs b/test/armv7/thumb.rs index b603925..4c5c4a1 100644 --- a/test/armv7/thumb.rs +++ b/test/armv7/thumb.rs @@ -5,7 +5,8 @@ type InstDecoder = ::Decoder; #[allow(dead_code)] fn test_invalid_under(decoder: &InstDecoder, data: &[u8]) { - match decoder.decode(data.to_vec()) { + let mut reader = yaxpeax_arch::U8Reader::new(&data[..]); + match decoder.decode(&mut reader) { Err(_) => { }, Ok(inst) => { panic!( @@ -19,7 +20,13 @@ fn test_invalid_under(decoder: &InstDecoder, data: &[u8]) { #[allow(dead_code)] fn test_display_under(decoder: &InstDecoder, data: [u8; 4], expected: &'static str) { - let instr = decoder.decode(data.to_vec()).unwrap_or_else(|_| panic!("failed to decode {:#x?}", data)); + let mut reader = yaxpeax_arch::U8Reader::new(&data[..]); + let instr = match decoder.decode(&mut reader) { + Err(e) => { + panic!("failed to decode {:#x?}: {}", data, e) + } + Ok(instr) => instr, + }; let displayed = format!("{}", instr); assert!( displayed == expected, @@ -31,7 +38,13 @@ fn test_display_under(decoder: &InstDecoder, data: [u8; 4], expected: &'static s #[allow(dead_code)] fn test_decode(data: &[u8], expected: Instruction) { - let instr = InstDecoder::default_thumb().decode(data.to_vec()).unwrap(); + let mut reader = yaxpeax_arch::U8Reader::new(data); + let instr = match InstDecoder::default_thumb().decode(&mut reader) { + Err(e) => { + panic!("failed to decode {:#x?}: {}", data, e) + } + Ok(instr) => instr, + }; assert!( instr == expected, "decode error for {:#x?}:\n decoded: {:?}\n expected: {:?}\n", @@ -42,11 +55,17 @@ fn test_decode(data: &[u8], expected: Instruction) { #[allow(dead_code)] fn test_invalid(data: &[u8]) { - test_invalid_under(&InstDecoder::default(), data); + test_invalid_under(&InstDecoder::default_thumb(), data); } fn test_display(data: &[u8], expected: &'static str) { - let instr = InstDecoder::default_thumb().decode(data.to_vec()).unwrap(); + let mut reader = yaxpeax_arch::U8Reader::new(data); + let instr = match InstDecoder::default_thumb().decode(&mut reader) { + Err(e) => { + panic!("failed to decode {:#x?}: {}", data, e) + } + Ok(instr) => instr, + }; let text = format!("{}", instr); assert!( text == expected, diff --git a/test/armv8/a64.rs b/test/armv8/a64.rs index 90e6d6a..35a255d 100644 --- a/test/armv8/a64.rs +++ b/test/armv8/a64.rs @@ -2,7 +2,8 @@ use yaxpeax_arch::{Arch, Decoder, LengthedInstruction}; use yaxpeax_arm::armv8::a64::{ARMv8, Instruction, Operand, Opcode, SizeCode, ShiftStyle}; fn test_decode(data: [u8; 4], expected: Instruction) { - let instr = ::Decoder::default().decode(data.to_vec()).unwrap(); + let mut reader = yaxpeax_arch::U8Reader::new(&data[..]); + let instr = ::Decoder::default().decode(&mut reader).unwrap(); assert!( instr == expected, "decode error for {:02x}{:02x}{:02x}{:02x}:\n decoded: {:?}\n expected: {:?}\n", @@ -12,7 +13,8 @@ fn test_decode(data: [u8; 4], expected: Instruction) { } fn test_display(data: [u8; 4], expected: &'static str) { - let instr = ::Decoder::default().decode(data.to_vec()).unwrap(); + let mut reader = yaxpeax_arch::U8Reader::new(&data[..]); + let instr = ::Decoder::default().decode(&mut reader).unwrap(); let text = format!("{}", instr); assert!( text == expected, @@ -2313,7 +2315,8 @@ static INSTRUCTION_BYTES: [u8; 4 * 61] = [ fn test_decode_span() { let mut i = 0u64; while i < INSTRUCTION_BYTES.len() as u64 { - let instr = ::Decoder::default().decode(INSTRUCTION_BYTES[(i as usize)..].iter().cloned()).unwrap(); + let mut reader = yaxpeax_arch::U8Reader::new(&INSTRUCTION_BYTES[i as usize..]); + let instr = ::Decoder::default().decode(&mut reader).unwrap(); println!( "Decoded {:02x}{:02x}{:02x}{:02x}: {}", //{:?}\n {}", INSTRUCTION_BYTES[i as usize], -- cgit v1.1