aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2021-07-21 00:19:36 -0700
committeriximeow <me@iximeow.net>2021-07-21 00:38:12 -0700
commit754f28d76c6c0def07561337969699accb843423 (patch)
tree2ae3ce6e7a71d41b061c6e75affc4c238ea91756
parent12ee099cad10cf93948239bb4b44966d60ffc8af (diff)
update decoders to yaxpeax_arch 0.2 versions, add lc87 and x86_16
-rw-r--r--CHANGELOG15
-rw-r--r--Cargo.lock85
-rw-r--r--Cargo.toml26
-rw-r--r--src/main.rs175
4 files changed, 201 insertions, 100 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 50e51e1..b7419e5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,19 @@
-## 0.2.2
+## 0.2.5
+
+* update yaxpeax-x86 to 1.0, bringing in avx512 support and x86_32, x86_16 decoding
+* add yaxpeax-lc87
+* update all other decoders to yaxpeax-arch 0.2.*, if conforming implementations are available
+
+## 0.2.4
+
+* add cr1901's yaxpeax-6502, thank you!
+
+## 0.2.3
* add наб's yaxpeax-superh. thank you!!
+
+## 0.2.2
+
* bump yaxpeax-x86 to 0.1.5, and -ia64 to 0.1.3
## 0.2.1
diff --git a/Cargo.lock b/Cargo.lock
index 779efbe..ffa3718 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -436,7 +436,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d53afe49cd799784eeefe7108efd48852ea83673d55d98389a563532f05c5ea3"
dependencies = [
"take_mut",
- "yaxpeax-arch",
+ "yaxpeax-arch 0.0.5",
]
[[package]]
@@ -452,38 +452,52 @@ dependencies = [
]
[[package]]
+name = "yaxpeax-arch"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b0c90868b68ae34284714134e827062757881ab642e5746ecdcd567ffd582ff7"
+dependencies = [
+ "crossterm",
+ "num-traits",
+ "serde",
+ "serde_derive",
+]
+
+[[package]]
name = "yaxpeax-arm"
-version = "0.0.7"
+version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dda1e95c1c611f9348b9fe6a482f0abed62bda5bc75e05932668194a3b7bb3f5"
+checksum = "bfde0eac22b9044b4d1f07b9fba1e81114ddb529912035a56b64c5524d411966"
dependencies = [
"bitvec",
"serde",
"serde_derive",
- "yaxpeax-arch",
+ "yaxpeax-arch 0.2.5",
]
[[package]]
name = "yaxpeax-avr"
-version = "0.0.3"
+version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b8373ea37d880943258d4f5123cba4029514b95c386b7c0dd085cd3537b1c632"
+checksum = "94153e4e363dd4b0bea761ce9615647f2a29a9c3d46d3467c776969eb2b4e91c"
dependencies = [
- "yaxpeax-arch",
+ "yaxpeax-arch 0.2.5",
]
[[package]]
name = "yaxpeax-dis"
-version = "0.2.4"
+version = "0.2.5"
dependencies = [
"clap",
"hex",
"num-traits",
"yaxpeax-6502",
- "yaxpeax-arch",
+ "yaxpeax-arch 0.0.5",
+ "yaxpeax-arch 0.2.5",
"yaxpeax-arm",
"yaxpeax-avr",
"yaxpeax-ia64",
+ "yaxpeax-lc87",
"yaxpeax-m16c",
"yaxpeax-mips",
"yaxpeax-msp430",
@@ -495,61 +509,70 @@ dependencies = [
[[package]]
name = "yaxpeax-ia64"
-version = "0.1.4"
+version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "222f39266a267206a47b08e01b26a782c8080b933223d112e7932c453f869a45"
+checksum = "d3ea0f2b5728fb7eb1861532cd755ff7dd993843778d548df70a4aca95f9914e"
dependencies = [
"bitvec",
- "yaxpeax-arch",
+ "yaxpeax-arch 0.2.5",
+]
+
+[[package]]
+name = "yaxpeax-lc87"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2cf556f365c2fa2104e4e9a36105d9a2f72085dfd7168c95abf4f0d7cdac0cff"
+dependencies = [
+ "yaxpeax-arch 0.2.5",
]
[[package]]
name = "yaxpeax-m16c"
-version = "0.0.4"
+version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1809e45640571ec956d594589ccbc4de2929db609494224fb793dad7735c9233"
+checksum = "fe75dc0cf3df3eb4193e2b9bc002cf12b64a4963bd33c30998331d875789be7b"
dependencies = [
"num-traits",
"serde",
"serde_derive",
- "yaxpeax-arch",
+ "yaxpeax-arch 0.2.5",
]
[[package]]
name = "yaxpeax-mips"
-version = "0.0.4"
+version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "825d4301049003b56b420798f3819c4ff46e0927dc50c1c5f69c5b2f02e2ff8d"
+checksum = "8d83d243a75ff9312b78ef761596cf0bf3b625786176363d65e653a75042873a"
dependencies = [
"num_enum",
- "yaxpeax-arch",
+ "yaxpeax-arch 0.2.5",
]
[[package]]
name = "yaxpeax-msp430"
-version = "0.0.6"
+version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1f5ea01451a1766614d88911c648ec3b98db377af51402ded1c6e03cafbbd906"
+checksum = "63962bd68624664aa3a3391785f95388001e9d6107cdf8557e962153e4a854c5"
dependencies = [
- "yaxpeax-arch",
+ "yaxpeax-arch 0.2.5",
]
[[package]]
name = "yaxpeax-pic17"
-version = "0.0.4"
+version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "744a545b8aa7e370587188e890a1e07c094b52f3b1da21ff0812602a4bd4b75c"
+checksum = "cb717c23e96ce83de1569c512ab5508a6e39a194a73662e618608f0f1c41ada4"
dependencies = [
- "yaxpeax-arch",
+ "yaxpeax-arch 0.2.5",
]
[[package]]
name = "yaxpeax-pic18"
-version = "0.0.4"
+version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "16a979e0519c5de64aadf1bc1484ecf3bef80f2cf15670f2743d57b0506d8562"
+checksum = "cf1fb0d482f0f7d23394e31e50bce78d8320760c790d86e324c1a1e49710097a"
dependencies = [
- "yaxpeax-arch",
+ "yaxpeax-arch 0.2.5",
]
[[package]]
@@ -558,17 +581,17 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c04d16d2b60e7961ace2b8624c12295e86babb3b8a6615a4238bbb823ba0936e"
dependencies = [
- "yaxpeax-arch",
+ "yaxpeax-arch 0.0.5",
]
[[package]]
name = "yaxpeax-x86"
-version = "0.2.1"
+version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "429b69c99d9da2e4858adf192ba788607d84e50b008a3d607ac326fdc7746cf8"
+checksum = "a5a648df71c546b9d2a665fcffff2204caf24f39cb7f5b6952811cc2a869feac"
dependencies = [
"num-traits",
"serde",
"serde_derive",
- "yaxpeax-arch",
+ "yaxpeax-arch 0.2.5",
]
diff --git a/Cargo.toml b/Cargo.toml
index 525623d..c9897e3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "yaxpeax-dis"
-version = "0.2.4"
+version = "0.2.5"
authors = ["iximeow <me@iximeow.net>"]
license = "0BSD"
edition = "2018"
@@ -19,16 +19,18 @@ hex = "0.4.0"
num-traits = "0.2.10"
# common interfaces for all yaxpeax decoders
-yaxpeax-arch = { version = "0.0.5" }
+yaxpeax-arch-02 = { package = "yaxpeax-arch", version = "0.2.4" }
+yaxpeax-arch-01 = { package = "yaxpeax-arch", version = "0.0.5" }
-yaxpeax-arm = { version = "0.0.7" }
-yaxpeax-avr = { version = "0.0.3" }
-yaxpeax-m16c = { version = "0.0.4" }
-yaxpeax-mips = { version = "0.0.4" }
-yaxpeax-msp430 = { version = "0.0.6" }
-yaxpeax-pic17 = { version = "0.0.4" }
-yaxpeax-pic18 = { version = "0.0.4" }
-yaxpeax-x86 = { version = "0.2.0" }
-yaxpeax-ia64 = { version = "0.1.4" }
-yaxpeax-superh = { version = "0.1.1" }
+yaxpeax-arm = { version = "0.1.1" }
+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-lc87 = { version = "1.0.0" }
+yaxpeax-pic17 = { version = "0.1.0" }
+yaxpeax-pic18 = { version = "0.1.0" }
+yaxpeax-x86 = { version = "1.0.3" }
+yaxpeax-ia64 = { version = "0.2.1" }
+yaxpeax-superh = { version = "0.1.0" }
yaxpeax-6502 = { version = "0.0.1" }
diff --git a/src/main.rs b/src/main.rs
index f577a42..0c6a5fc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,5 @@
-use yaxpeax_arch::{AddressBase, Arch, Decoder, Instruction, LengthedInstruction};
-
use clap::*;
-use num_traits::identities::Zero;
-use std::fmt;
use std::fs::File;
use std::io::Read;
use std::collections::BTreeSet;
@@ -17,17 +13,19 @@ fn main() {
.long("--architecture")
.takes_value(true)
.validator(|a| {
- if ["x86_64", "x86:32", "ia64", "armv7", "armv8", "avr", "mips", "msp430",
- "pic17", "pic18", "m16c", "6502"].contains(&&a[..]) ||
+ if ["x86_64", "x86_32", "x86_16",
+ "x86:64", "x86:32", "x86:16",
+ "ia64", "armv7", "armv8", "avr", "mips", "msp430",
+ "pic17", "pic18", "m16c", "6502", "lc87"].contains(&&a[..]) ||
(["sh", "sh2", "sh3", "sh4", "j2"].contains(
&&a[0..a.find(|c| c == '+' || c == '-').unwrap_or(a.len())]) &&
a.split(|c| c == '+' || c == '-').skip(1).all(
|f| ["be", "mmu", "fpu", "f64", "j2"].contains(&f))) {
Ok(())
} else {
- Err("possible values: x86_64, x86:32, ia64, armv7, armv8, avr, mips, \
- msp430, pic17, pic18, m16c, 6502, \
- {sh{,2,3,4},j2}[[+-]{be,mmu,fpu,f64,j2}]*"
+ Err("possible values: x86_64, x86_32, x86_16, x86:64, x86:32, x86:16, \
+ ia64, armv7, armv8, avr, mips, msp430, pic17, pic18, \
+ m16c, 6502, lc87, {sh{,2,3,4},j2}[[+-]{be,mmu,fpu,f64,j2}]*"
.to_string())
}
})
@@ -84,23 +82,28 @@ fn main() {
let verbose = matches.occurrences_of("verbose") > 0;
match arch_str {
- "x86_64" => decode_input::<yaxpeax_x86::long_mode::Arch>(&buf, verbose),
- "x86:32" => decode_input::<yaxpeax_x86::protected_mode::Arch>(&buf, verbose),
- "ia64" => decode_input::<yaxpeax_ia64::IA64>(&buf, verbose),
- "avr" => decode_input::<yaxpeax_avr::AVR>(&buf, verbose),
- "armv7" => decode_input::<yaxpeax_arm::armv7::ARMv7>(&buf, verbose),
- "armv8" => decode_input::<yaxpeax_arm::armv8::a64::ARMv8>(&buf, verbose),
- "mips" => decode_input::<yaxpeax_mips::MIPS>(&buf, verbose),
- "msp430" => decode_input::<yaxpeax_msp430::MSP430>(&buf, verbose),
- "pic17" => decode_input::<yaxpeax_pic17::PIC17>(&buf, verbose),
- "pic18" => decode_input::<yaxpeax_pic18::PIC18>(&buf, verbose),
- "m16c" => decode_input::<yaxpeax_m16c::M16C>(&buf, verbose),
- "6502" => decode_input::<yaxpeax_6502::N6502>(&buf, verbose),
+ "x86_64" |
+ "x86:64" => crate::current_arch::decode_input::<yaxpeax_x86::long_mode::Arch>(&buf, verbose),
+ "x86_32" |
+ "x86:32" => crate::current_arch::decode_input::<yaxpeax_x86::protected_mode::Arch>(&buf, verbose),
+ "x86_16" |
+ "x86:16" => crate::current_arch::decode_input::<yaxpeax_x86::real_mode::Arch>(&buf, verbose),
+ "ia64" => crate::current_arch::decode_input::<yaxpeax_ia64::IA64>(&buf, verbose),
+ "avr" => crate::current_arch::decode_input::<yaxpeax_avr::AVR>(&buf, verbose),
+ "armv7" => crate::current_arch::decode_input::<yaxpeax_arm::armv7::ARMv7>(&buf, verbose),
+ "armv8" => crate::current_arch::decode_input::<yaxpeax_arm::armv8::a64::ARMv8>(&buf, verbose),
+ "mips" => crate::current_arch::decode_input::<yaxpeax_mips::MIPS>(&buf, verbose),
+ "msp430" => crate::current_arch::decode_input::<yaxpeax_msp430::MSP430>(&buf, verbose),
+ "pic17" => crate::current_arch::decode_input::<yaxpeax_pic17::PIC17>(&buf, verbose),
+ "pic18" => crate::current_arch::decode_input::<yaxpeax_pic18::PIC18>(&buf, verbose),
+ "m16c" => crate::current_arch::decode_input::<yaxpeax_m16c::M16C>(&buf, verbose),
+ "6502" => crate::legacy_arch::decode_input::<yaxpeax_6502::N6502>(&buf, verbose),
+ "lc87" => crate::current_arch::decode_input::<yaxpeax_lc87::LC87>(&buf, verbose),
// "pic24" => decode_input::<yaxpeax_pic24::PIC24>(buf),
other => {
let seg_idx = arch_str.find(|c| c == '+' || c == '-').unwrap_or(arch_str.len());
let wps = |base| with_parsed_superh(base, &arch_str[seg_idx..],
- |decoder| decode_input_with_decoder::<yaxpeax_superh::SuperH>(decoder, &buf, verbose));
+ |decoder| crate::legacy_arch::decode_input_with_decoder::<yaxpeax_superh::SuperH>(decoder, &buf, verbose));
match &arch_str[0..seg_idx] {
"sh" => wps(yaxpeax_superh::SuperHDecoder::SH1),
"sh2" => wps(yaxpeax_superh::SuperHDecoder::SH2),
@@ -150,46 +153,106 @@ fn with_parsed_superh<F: FnOnce(yaxpeax_superh::SuperHDecoder)>(
})
}
-fn decode_input<A: Arch>(buf: &[u8], verbose: bool)
-where
- A::Instruction: fmt::Display,
-{
- decode_input_with_decoder::<A>(A::Decoder::default(), buf, verbose);
-}
+// yaxpeax-arch, implemented by all decoders here, is required at incompatible versions by
+// different decoders. implement the actual decode-and-print behavior on both versions of
+// yaxpeax-arch while older decoders are still being updated.
+mod current_arch {
+ use yaxpeax_arch_02::{AddressBase, Arch, Decoder, Instruction, LengthedInstruction, Reader, U8Reader};
+ use std::fmt;
+ use num_traits::identities::Zero;
-fn decode_input_with_decoder<A: Arch>(decoder: A::Decoder, buf: &[u8], verbose: bool)
-where
- A::Instruction: fmt::Display,
-{
- let start = A::Address::zero();
- let mut addr = start;
- loop {
- match decoder.decode(buf[addr.to_linear()..].iter().cloned()) {
- Ok(inst) => {
- println!(
- "{:#010x}: {:14}: {}",
- addr.to_linear(),
- hex::encode(
- &buf[addr.to_linear()..]
- [..A::Address::zero().wrapping_offset(inst.len()).to_linear()]
- ),
- inst
- );
- if verbose {
- println!(" {:?}", inst);
- if !inst.well_defined() {
- println!(" not well-defined");
+ pub(crate) fn decode_input<A: Arch>(buf: &[u8], verbose: bool)
+ where
+ A::Instruction: fmt::Display, for<'data> U8Reader<'data>: Reader<A::Address, A::Word>,
+ {
+ decode_input_with_decoder::<A>(A::Decoder::default(), buf, verbose);
+ }
+
+ pub(crate) fn decode_input_with_decoder<A: Arch>(decoder: A::Decoder, buf: &[u8], verbose: bool)
+ where
+ A::Instruction: fmt::Display, for<'data> U8Reader<'data>: Reader<A::Address, A::Word>,
+ {
+ let start = A::Address::zero();
+ let mut addr = start;
+ loop {
+ let mut reader = U8Reader::new(&buf[addr.to_linear()..]);
+ match decoder.decode(&mut reader) {
+ Ok(inst) => {
+ println!(
+ "{:#010x}: {:14}: {}",
+ addr.to_linear(),
+ hex::encode(
+ &buf[addr.to_linear()..]
+ [..A::Address::zero().wrapping_offset(inst.len()).to_linear()]
+ ),
+ inst
+ );
+ if verbose {
+ println!(" {:?}", inst);
+ if !inst.well_defined() {
+ println!(" not well-defined");
+ }
}
+ addr += inst.len();
+ }
+ Err(e) => {
+ println!("{:#010x}: {}", addr.to_linear(), e);
+ addr += A::Instruction::min_size();
}
- addr += inst.len();
}
- Err(e) => {
- println!("{:#010x}: {}", addr.to_linear(), e);
- addr += A::Instruction::min_size();
+ if addr.to_linear() >= buf.len() {
+ break;
}
}
- if addr.to_linear() >= buf.len() {
- break;
+ }
+}
+
+mod legacy_arch {
+ use yaxpeax_arch_01::{AddressBase, Arch, Decoder, Instruction, LengthedInstruction};
+ use std::fmt;
+ use num_traits::identities::Zero;
+
+ pub(crate) fn decode_input<A: Arch>(buf: &[u8], verbose: bool)
+ where
+ A::Instruction: fmt::Display,
+ {
+ decode_input_with_decoder::<A>(A::Decoder::default(), buf, verbose);
+ }
+
+ pub(crate) fn decode_input_with_decoder<A: Arch>(decoder: A::Decoder, buf: &[u8], verbose: bool)
+ where
+ A::Instruction: fmt::Display,
+ {
+ let start = A::Address::zero();
+ let mut addr = start;
+ loop {
+ match decoder.decode(buf[addr.to_linear()..].iter().cloned()) {
+ Ok(inst) => {
+ println!(
+ "{:#010x}: {:14}: {}",
+ addr.to_linear(),
+ hex::encode(
+ &buf[addr.to_linear()..]
+ [..A::Address::zero().wrapping_offset(inst.len()).to_linear()]
+ ),
+ inst
+ );
+ if verbose {
+ println!(" {:?}", inst);
+ if !inst.well_defined() {
+ println!(" not well-defined");
+ }
+ }
+ addr += inst.len();
+ }
+ Err(e) => {
+ println!("{:#010x}: {}", addr.to_linear(), e);
+ addr += A::Instruction::min_size();
+ }
+ }
+ if addr.to_linear() >= buf.len() {
+ break;
+ }
}
}
}