From 8713eca470b00a7afc2d3d18b3fbe13c77806bc0 Mon Sep 17 00:00:00 2001 From: iximeow Date: Thu, 16 Jan 2020 23:53:37 -0800 Subject: compat with yaxpeax-arch changes, make microcorruption msp430 support optional --- src/lib.rs | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 408216e..74f814c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,8 +40,8 @@ pub enum Width { W, B } -impl Instruction { - pub fn blank() -> Instruction { +impl Default for Instruction { + fn default() -> Instruction { Instruction { opcode: Opcode::Invalid(0xffff), op_width: Width::W, @@ -144,16 +144,39 @@ impl yaxpeax_arch::Instruction for Instruction { fn well_defined(&self) -> bool { true } } -#[derive(Default, Debug)] -pub struct InstDecoder {} +#[derive(Debug)] +pub struct InstDecoder { + flags: u8 +} + +impl InstDecoder { + pub fn minimal() -> Self { + InstDecoder { + flags: 0 + } + } + + pub fn with_microcorruption(mut self) -> Self { + self.flags |= 1; + self + } + + pub fn microcorruption_quirks(&self) -> bool { + (self.flags & 1) != 0 + } +} + +impl Default for InstDecoder { + fn default() -> Self { + InstDecoder { + flags: 0xff + } + } +} impl Decoder for InstDecoder { type Error = DecodeError; - fn decode>(&self, bytes: T) -> Result { - let mut inst = Instruction::blank(); - self.decode_into(&mut inst, bytes).map(|_: ()| inst) - } fn decode_into>(&self, inst: &mut Instruction, bytes: T) -> Result<(), Self::Error> { let mut bytes_iter = bytes.into_iter(); let word: Vec = bytes_iter.by_ref().take(2).collect(); @@ -247,6 +270,10 @@ impl Decoder for InstDecoder { }, */ instrword if instrword < 0x2000 => { // microcorruption msp430 is non-standard and accepts invalid instructions.. + if !self.microcorruption_quirks() { + return Err(DecodeError::InvalidOpcode); + } + let (opcode_idx, operands) = ((instrword & 0x0380) >> 7, instrword & 0x7f); match opcode_idx { x if x < 6 => { -- cgit v1.1