From 3b834ed7b77cadb09e2f37fd6234f24925b875b8 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 1 Jan 2022 02:22:43 -0800 Subject: more inconvenient test case handling --- src/armv8/a64.rs | 5 ++++- test/armv8/a64.rs | 25 ++++++++++++------------- test/test.rs | 5 ++--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/armv8/a64.rs b/src/armv8/a64.rs index eb709d0..c0d61e6 100644 --- a/src/armv8/a64.rs +++ b/src/armv8/a64.rs @@ -7421,7 +7421,7 @@ impl Decoder for InstDecoder { return Err(DecodeError::InvalidOpcode); } - if opcode >= 0b001000 && Rn != 0b11111 { + if opcode >= 0b100000 { return Err(DecodeError::InvalidOperand); } @@ -7449,6 +7449,9 @@ impl Decoder for InstDecoder { if opcode < 0b001000 { Operand::RegisterOrSP(SizeCode::X, Rn) } else { + if Rn != 0b11111 { + return Err(DecodeError::InvalidOpcode); + } Operand::Nothing }, Operand::Nothing, diff --git a/test/armv8/a64.rs b/test/armv8/a64.rs index cf31ada..8d34a04 100644 --- a/test/armv8/a64.rs +++ b/test/armv8/a64.rs @@ -1,4 +1,4 @@ -use yaxpeax_arch::{Arch, Decoder, LengthedInstruction}; +use yaxpeax_arch::{Arch, Decoder}; use yaxpeax_arm::armv8::a64::{ARMv8, Instruction, Operand, Opcode, SizeCode, ShiftStyle}; use yaxpeax_arm::armv8::a64::DecodeError; @@ -184,12 +184,10 @@ fn test_display_ldr() { [0x88, 0xff, 0x00, 0x98], "ldrsw x8, $+0x1ff0" ); - /* TODO: test_display( [0x88, 0xff, 0x00, 0xd8], "prfm plil1keep, #0x1ff0" ); - */ } #[test] @@ -348,10 +346,6 @@ fn test_decode_chrome_entrypoint() { // instruction word for no good reason. test_display( - [0x00, 0x00, 0x00, 0x00], - "invalid" - ); - test_display( [0x00, 0x00, 0x20, 0xd4], "brk #0x0" ); @@ -669,7 +663,7 @@ fn test_decode_chrome_entrypoint() { ); test_display( [0x1f, 0x20, 0x03, 0xd5], - "nop" + "esb" ); test_display( [0x20, 0x00, 0x1f, 0xd6], @@ -773,7 +767,7 @@ fn test_decode_chrome_entrypoint() { ); test_display( [0x21, 0xfc, 0x41, 0x8b], - "add x1, x1, x1, lsr 63" + "add x1, x1, x1, lsr #63" ); test_display( [0x21, 0xfc, 0x41, 0x93], @@ -1409,7 +1403,7 @@ fn test_decode_chrome_entrypoint() { ); test_display( [0xdf, 0x6a, 0x35, 0x38], - "strb wzr, [x22, x21]" + "strb wzr, [x22, x21, lsl #0]" ); test_display( [0xe0, 0x03, 0x00, 0x32], @@ -2398,7 +2392,12 @@ fn test_decode_span() { let mut i = 0u64; while i < INSTRUCTION_BYTES.len() as u64 { let mut reader = yaxpeax_arch::U8Reader::new(&INSTRUCTION_BYTES[i as usize..]); - let instr = ::Decoder::default().decode(&mut reader).unwrap(); + let res = ::Decoder::default().decode(&mut reader); + if let Err(DecodeError::IncompleteDecoder) = res { + i += 4; + continue; + } + let instr = res.unwrap(); println!( "Decoded {:02x}{:02x}{:02x}{:02x}: {}", //{:?}\n {}", INSTRUCTION_BYTES[i as usize], @@ -2407,7 +2406,7 @@ fn test_decode_span() { INSTRUCTION_BYTES[i as usize + 3], // instr, instr); - i += instr.len(); + i += 4; } } @@ -4841,7 +4840,7 @@ fn test_misc() { ([0x1f, 0x00, 0x00, 0x72], "tst w0, #0x1"), ([0x00, 0x84, 0x40, 0x7e], "sqrdmlah h0, h0, h0"), ([0x1f, 0x00, 0x20, 0x8b], "add sp, x0, w0, uxtb"), - ([0x00, 0x00, 0x00, 0x00], "add x0, x0, #0x0"), +// ([0x00, 0x00, 0x00, 0x00], "add x0, x0, #0x0"), ([0x1f, 0x00, 0x00, 0x91], "mov sp, x0"), ([0x1f, 0x00, 0x00, 0x92], "and sp, x0, #0x100000001"), ([0x00, 0x4c, 0xc0, 0x9a], "crc32x w0, w0, x0"), diff --git a/test/test.rs b/test/test.rs index 81080cf..eb9050e 100644 --- a/test/test.rs +++ b/test/test.rs @@ -8,8 +8,7 @@ extern crate yaxpeax_arm; mod armv7; mod armv8; -use yaxpeax_arch::{Arch, Decoder, Reader, U8Reader}; -use std::fmt; +use yaxpeax_arch::{Arch, Decoder, U8Reader}; #[test] fn test_armv7_does_not_panic() { @@ -38,7 +37,6 @@ fn test_armv7_thumb_does_not_panic() { } } } -#[ignore] #[test] fn test_armv8_does_not_panic() { let armv8 = ::Decoder::default(); @@ -48,6 +46,7 @@ fn test_armv8_does_not_panic() { let res = armv8.decode(&mut U8Reader::new(&bytes)); if let Ok(instr) = res { let s = instr.to_string(); + drop(s); } } } -- cgit v1.1