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 --- src/armv7/thumb.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/armv7') diff --git a/src/armv7/thumb.rs b/src/armv7/thumb.rs index 3c480af..8017f01 100644 --- a/src/armv7/thumb.rs +++ b/src/armv7/thumb.rs @@ -1,9 +1,12 @@ // use yaxpeax_arch::{Arch, AddressDiff, Decoder, LengthedInstruction}; +use yaxpeax_arch::Arch; +use armv7::ARMv7; use armv7::ConditionCode; use armv7::DecodeError; use armv7::CReg; use armv7::Reg; +use armv7::Reader; use armv7::RegShift; use armv7::Operand; use armv7::Opcode; @@ -97,20 +100,20 @@ fn DecodeImmShift(reg: u8, ty: u8, imm5: u8) -> RegShift { } #[allow(non_snake_case)] -pub fn decode_into>(decoder: &InstDecoder, inst: &mut Instruction, bytes: T) -> Result<(), DecodeError> { +pub fn decode_into::Address, ::Word>>(decoder: &InstDecoder, inst: &mut Instruction, words: &mut T) -> Result<(), ::DecodeError> { // these are cleared in `armv7::InstDecoder::decode_into`. // they must be reset when switching out of thumb decoding or decoding a new thumb instruction, // which that `decode_into` is the entrypoint for in all cases. // inst.set_w(false); // inst.set_wide(false); inst.set_thumb(true); - let mut iter = bytes.into_iter(); - let instr: u16 = - ((iter.next().ok_or(DecodeError::ExhaustedInput)? as u16) ) | - ((iter.next().ok_or(DecodeError::ExhaustedInput)? as u16) << 8 ); + let mut word_bytes = [0u8; 2]; + words.next_n(&mut word_bytes)?; + let word = u16::from_le_bytes(word_bytes); + let instr = word; let mut instr2 = bitarr![Lsb0, u16; 0u16; 16]; - instr2[0..16].store(instr); + instr2[0..16].store(word); let opword = instr2[11..].load::(); @@ -122,9 +125,9 @@ pub fn decode_into>(decoder: &InstDecoder, inst: &mut I // 32b instruction - `A6-228, 32-bit Thumb instruction encoding` // opword low bits 01, 10, and 11 correspond to `op1` in table `A6-9` - let lower: u16 = - ((iter.next().ok_or(DecodeError::ExhaustedInput)? as u16) ) | - ((iter.next().ok_or(DecodeError::ExhaustedInput)? as u16) << 8 ); + let mut word_bytes = [0u8; 2]; + words.next_n(&mut word_bytes)?; + let lower = u16::from_le_bytes(word_bytes); let mut lower2 = bitarr![Lsb0, u16; 0u16; 16]; lower2[0..16].store(lower); -- cgit v1.1