From f2a27d8d9352425dbed59e85e04b40d12703e7a8 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 1 Mar 2025 11:32:20 -0800 Subject: update x86, arm, msp430 disassemblers to yaxpeax-arch 0.3-based versions --- Cargo.lock | 117 +++++++++++++++++++++++++++++++++++++++++++++++------------- Cargo.toml | 9 +++-- src/main.rs | 74 ++++++++++++++++++++++++++++++-------- 3 files changed, 158 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9945b4f..1518c50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "atty" @@ -31,10 +31,22 @@ version = "0.19.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55f93d0ef3363c364d5976646a38f04cf67cfe1d4c8d160cdea02cab2c116b33" dependencies = [ - "funty", - "radium", + "funty 1.1.0", + "radium 0.5.3", "tap", - "wyz", + "wyz 0.2.0", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty 2.0.0", + "radium 0.7.0", + "tap", + "wyz 0.5.1", ] [[package]] @@ -95,6 +107,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" [[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -245,6 +263,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" [[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] name = "serde" version = "1.0.151" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -366,12 +390,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" [[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] name = "yaxpeax-6502" version = "0.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e89d220a799f57094ad0a58c16b2c3b7730e8f1404665bee5f10e039e7c17c3" dependencies = [ - "yaxpeax-arch", + "yaxpeax-arch 0.2.7", ] [[package]] @@ -386,15 +419,26 @@ dependencies = [ ] [[package]] +name = "yaxpeax-arch" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36274fcc5403da2a7636ffda4d02eca12a1b2b8267b9d2e04447bd2ccfc72082" +dependencies = [ + "num-traits", + "serde", + "serde_derive", +] + +[[package]] name = "yaxpeax-arm" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dd4915314c4ff9cb079acd1ad25245f54b2e651238da929fb79971443ea7834" +checksum = "e1c6a2af41f88546a08df3bc77aadf7263884d6dffdac5b32dea7dc2df23f241" dependencies = [ - "bitvec", + "bitvec 1.0.1", "serde", "serde_derive", - "yaxpeax-arch", + "yaxpeax-arch 0.3.2", ] [[package]] @@ -403,7 +447,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94153e4e363dd4b0bea761ce9615647f2a29a9c3d46d3467c776969eb2b4e91c" dependencies = [ - "yaxpeax-arch", + "yaxpeax-arch 0.2.7", ] [[package]] @@ -415,7 +459,8 @@ dependencies = [ "itertools", "num-traits", "yaxpeax-6502", - "yaxpeax-arch", + "yaxpeax-arch 0.2.7", + "yaxpeax-arch 0.3.2", "yaxpeax-arm", "yaxpeax-avr", "yaxpeax-ia64", @@ -425,6 +470,8 @@ dependencies = [ "yaxpeax-msp430", "yaxpeax-pic17", "yaxpeax-pic18", + "yaxpeax-rx", + "yaxpeax-sm83", "yaxpeax-superh", "yaxpeax-x86", ] @@ -435,8 +482,8 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3ea0f2b5728fb7eb1861532cd755ff7dd993843778d548df70a4aca95f9914e" dependencies = [ - "bitvec", - "yaxpeax-arch", + "bitvec 0.19.6", + "yaxpeax-arch 0.2.7", ] [[package]] @@ -445,7 +492,7 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2cf556f365c2fa2104e4e9a36105d9a2f72085dfd7168c95abf4f0d7cdac0cff" dependencies = [ - "yaxpeax-arch", + "yaxpeax-arch 0.2.7", ] [[package]] @@ -457,7 +504,7 @@ dependencies = [ "num-traits", "serde", "serde_derive", - "yaxpeax-arch", + "yaxpeax-arch 0.2.7", ] [[package]] @@ -467,16 +514,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d83d243a75ff9312b78ef761596cf0bf3b625786176363d65e653a75042873a" dependencies = [ "num_enum", - "yaxpeax-arch", + "yaxpeax-arch 0.2.7", ] [[package]] name = "yaxpeax-msp430" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de2211ec03a726b4b2a3a3f63789e8fe8e41b1e7be2e7034df44e4148f6e8be" +checksum = "40c1711ed166c1082be771cf9beb6c24160b83691079704a8f59b6d9cb8bed36" dependencies = [ - "yaxpeax-arch", + "yaxpeax-arch 0.3.2", ] [[package]] @@ -485,7 +532,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15ca63b323712143e563e146af6a3df21fa3c75976985ee7b157470616c15c1e" dependencies = [ - "yaxpeax-arch", + "yaxpeax-arch 0.2.7", ] [[package]] @@ -494,7 +541,27 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f64bb0d36fc65721e5919e9febe316ae62cf0ba2510cddb01d1f182ddcc97f84" dependencies = [ - "yaxpeax-arch", + "yaxpeax-arch 0.2.7", +] + +[[package]] +name = "yaxpeax-rx" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a8d00ff8148f0092fd2ac4f08f2651c433187b11200bc1a880d2edb9a03914e" +dependencies = [ + "num-traits", + "yaxpeax-arch 0.2.7", +] + +[[package]] +name = "yaxpeax-sm83" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5175d9ee200f1a2b8773500c579608f89b898f4439dfa87b09b23d4143e8d2f0" +dependencies = [ + "num_enum", + "yaxpeax-arch 0.2.7", ] [[package]] @@ -504,16 +571,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5281091585bd676e16313291703e8724889d4076672fc7b4d0e5b1718c54e2c" dependencies = [ "bitflags", - "yaxpeax-arch", + "yaxpeax-arch 0.2.7", ] [[package]] name = "yaxpeax-x86" -version = "1.1.5" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "934a0186cc9f96af563264382d03946c95d8393e8e03f18cbbadd2efa8830b53" +checksum = "9a9a30b7dd533c7b1a73eaf7c4ea162a7a632a2bb29b9fff47d8f2cc8513a883" dependencies = [ "cfg-if", "num-traits", - "yaxpeax-arch", + "yaxpeax-arch 0.3.2", ] diff --git a/Cargo.toml b/Cargo.toml index f959be3..f22fb4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,16 +21,19 @@ itertools = "0.10.1" # common interfaces for all yaxpeax decoders yaxpeax-arch-02 = { package = "yaxpeax-arch", version = "0.2.4" , default-features = false, features = ["std"] } +yaxpeax-arch-03 = { package = "yaxpeax-arch", version = "0.3.1" , default-features = false, features = ["std"] } -yaxpeax-arm = { version = "0.2.3" } +yaxpeax-arm = { version = "0.3.0" } yaxpeax-avr = { version = "0.1.0" } yaxpeax-m16c = { version = "0.1.0" } yaxpeax-mips = { version = "0.1.0" } -yaxpeax-msp430 = { version = "0.1.0" } +yaxpeax-msp430 = { version = "0.2.0" } yaxpeax-lc87 = { version = "1.0.0" } +yaxpeax-sm83 = { version = "0.2.0" } +yaxpeax-rx = { version = "0.0.1" } yaxpeax-pic17 = { version = "0.1.0" } yaxpeax-pic18 = { version = "0.1.0" } -yaxpeax-x86 = { version = "1.1.5", default-features = false, features = ["fmt", "std"] } +yaxpeax-x86 = { version = "2.0.0", default-features = false, features = ["fmt", "std"] } yaxpeax-ia64 = { version = "0.2.1" } yaxpeax-superh = { version = "1.0.0" } yaxpeax-6502 = { version = "0.0.2", features = ["std"] } diff --git a/src/main.rs b/src/main.rs index 86315bc..a1ac7de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,16 +122,16 @@ fn main() { use Architecture::*; match args.architecture { - X86_64 => arch_02::decode_input_and_annotate::(&buf, &printer), - X86_32 => arch_02::decode_input_and_annotate::(&buf, &printer), - X86_16 => arch_02::decode_input_and_annotate::(&buf, &printer), + X86_64 => arch_03::decode_input_and_annotate::(&buf, &printer), + X86_32 => arch_03::decode_input_and_annotate::(&buf, &printer), + X86_16 => arch_03::decode_input_and_annotate::(&buf, &printer), IA64 => arch_02::decode_input::(&buf, &printer), AVR => arch_02::decode_input::(&buf, &printer), - ARMv7 => arch_02::decode_input::(&buf, &printer), - ARMv7Thumb => arch_02::decode_armv7_thumb(&buf, &printer), - ARMv8 => arch_02::decode_input::(&buf, &printer), + ARMv7 => arch_03::decode_input::(&buf, &printer), + ARMv7Thumb => arch_03::decode_armv7_thumb(&buf, &printer), + ARMv8 => arch_03::decode_input::(&buf, &printer), MIPS => arch_02::decode_input::(&buf, &printer), - MSP430 => arch_02::decode_input_and_annotate::(&buf, &printer), + MSP430 => arch_03::decode_input_and_annotate::(&buf, &printer), PIC17 => arch_02::decode_input::(&buf, &printer), PIC18 => arch_02::decode_input::(&buf, &printer), M16C => arch_02::decode_input::(&buf, &printer), @@ -228,14 +228,14 @@ struct InstDetails { // yaxpeax-arch, implemented by all decoders here, may be required at incompatible versions by // different decoders if/when a new version releases. implement the actual decode-and-print // behavior independent of yaxpeax-arch so decoders using different version can exist in parallel. -mod arch_02 { +mod arch_03 { use super::Printer; use num_traits::identities::Zero; use std::fmt; - use yaxpeax_arch_02::{ + use yaxpeax_arch_03::{ AddressBase, Arch, Decoder, Instruction, LengthedInstruction, Reader, U8Reader, }; - use yaxpeax_arch_02::annotation::{AnnotatingDecoder, FieldDescription, VecSink}; + use yaxpeax_arch_03::annotation::{AnnotatingDecoder, FieldDescription, VecSink}; use crate::{FieldRecord, ItemDescription}; @@ -270,8 +270,8 @@ mod arch_02 { A::Instruction: fmt::Display, for<'data> U8Reader<'data>: Reader, { - let mut addr = A::Address::zero(); - while let Some(rest) = buf.get(addr.to_linear()..).filter(|v| !v.is_empty()) { + let mut addr = 0usize; + while let Some(rest) = buf.get(addr..) { let mut reader = U8Reader::new(rest); let res = decoder.decode(&mut reader); let advance_addr = match &res { @@ -286,8 +286,8 @@ mod arch_02 { field_descriptions: None, } }); - printer.print_instr(rest, addr.to_linear(), generic_res); - addr += advance_addr; + printer.print_instr(rest, addr, generic_res); + addr += (A::Address::zero() + advance_addr).to_linear(); } } @@ -356,6 +356,52 @@ mod arch_02 { } } +mod arch_02 { + use super::Printer; + use num_traits::identities::Zero; + use std::fmt; + use yaxpeax_arch_02::{ + AddressBase, Arch, Decoder, Instruction, LengthedInstruction, Reader, U8Reader, + }; + + pub(crate) fn decode_input(buf: &[u8], printer: &Printer) + where + A::Instruction: fmt::Display, + for<'data> U8Reader<'data>: Reader, + { + decode_input_with_decoder::(A::Decoder::default(), buf, printer); + } + + pub(crate) fn decode_input_with_decoder( + decoder: A::Decoder, + buf: &[u8], + printer: &Printer, + ) where + A::Instruction: fmt::Display, + for<'data> U8Reader<'data>: Reader, + { + let mut addr = 0usize; + while let Some(rest) = buf.get(addr..) { + let mut reader = U8Reader::new(rest); + let res = decoder.decode(&mut reader); + let advance_addr = match &res { + Ok(inst) => inst.len(), + Err(_) => A::Instruction::min_size(), + }; + let generic_res = res.map(|inst| { + crate::InstDetails { + inst_len: A::Address::zero().wrapping_offset(inst.len()).to_linear(), + well_defined: inst.well_defined(), + inst, + field_descriptions: None, + } + }); + printer.print_instr(rest, addr, generic_res); + addr += (A::Address::zero() + advance_addr).to_linear(); + } + } +} + /// any architecture with an `AnnotatingDecoder` implementation will have annotations reported at /// positions of bits in the instruction. `yaxpeax-dis` requires some description of how to convert /// between a column and a bit for a given architecture. -- cgit v1.1