diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Cargo.lock | 417 | ||||
-rw-r--r-- | Cargo.toml | 26 | ||||
-rw-r--r-- | src/main.rs | 81 |
4 files changed, 525 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..31888f2 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,417 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "clap" +version = "2.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "derivative" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942ca430eef7a3806595a6737bc388bf51adb888d3fc0dd1b50f1c170167ee3a" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + +[[package]] +name = "hermit-abi" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e" + +[[package]] +name = "itoa" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" + +[[package]] +name = "libc" +version = "0.2.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" + +[[package]] +name = "num-traits" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_enum" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be601e38e20a6f3d01049d85801cb9b7a34a8da7a0da70df507bbde7735058c8" +dependencies = [ + "derivative", + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b59f30f6a043f2606adbd0addbf1eef6f2e28e8c4968918b63b7ff97ac0db2a7" +dependencies = [ + "proc-macro-crate", + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", +] + +[[package]] +name = "numtoa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" + +[[package]] +name = "proc-macro-crate" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e" +dependencies = [ + "toml", +] + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + +[[package]] +name = "proc-macro2" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0319972dcae462681daf4da1adeeaa066e3ebd29c69be96c6abb1259d2ee2bcc" +dependencies = [ + "unicode-xid 0.2.0", +] + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + +[[package]] +name = "quote" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +dependencies = [ + "proc-macro2 1.0.7", +] + +[[package]] +name = "redox_syscall" +version = "0.1.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" + +[[package]] +name = "redox_termios" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +dependencies = [ + "redox_syscall", +] + +[[package]] +name = "ryu" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" + +[[package]] +name = "serde" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" + +[[package]] +name = "serde_derive" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +dependencies = [ + "proc-macro2 1.0.7", + "quote 1.0.2", + "syn 1.0.13", +] + +[[package]] +name = "serde_json" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c575e0cc52bdd09b47f330f646cf59afc586e9c4e3ccd6fc1f625b8ea1dad7" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + +[[package]] +name = "syn" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4ff033220a41d1a57d8125eab57bf5263783dfdcc18688b1dacc6ce9651ef8" +dependencies = [ + "proc-macro2 1.0.7", + "quote 1.0.2", + "unicode-xid 0.2.0", +] + +[[package]] +name = "termion" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "818ef3700c2a7b447dca1a1dd28341fe635e6ee103c806c636bb9c929991b2cd" +dependencies = [ + "libc", + "numtoa", + "redox_syscall", + "redox_termios", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "toml" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" +dependencies = [ + "serde", +] + +[[package]] +name = "unicode-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" + +[[package]] +name = "vec_map" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" + +[[package]] +name = "winapi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "yaxpeax-arch" +version = "0.0.1" +dependencies = [ + "num-traits", + "serde", + "termion", +] + +[[package]] +name = "yaxpeax-arm" +version = "0.0.1" +dependencies = [ + "serde", + "serde_derive", + "yaxpeax-arch", +] + +[[package]] +name = "yaxpeax-dis" +version = "0.1.0" +dependencies = [ + "clap", + "hex", + "num-traits", + "yaxpeax-arch", + "yaxpeax-arm", + "yaxpeax-mips", + "yaxpeax-msp430-mc", + "yaxpeax-pic17", + "yaxpeax-pic18", + "yaxpeax-pic24", + "yaxpeax-x86", +] + +[[package]] +name = "yaxpeax-mips" +version = "0.0.1" +dependencies = [ + "num_enum", + "serde", + "serde_derive", + "termion", + "yaxpeax-arch", +] + +[[package]] +name = "yaxpeax-msp430-mc" +version = "0.0.1" +dependencies = [ + "serde", + "serde_derive", + "termion", + "yaxpeax-arch", +] + +[[package]] +name = "yaxpeax-pic17" +version = "0.0.1" +dependencies = [ + "serde", + "serde_derive", + "termion", + "yaxpeax-arch", +] + +[[package]] +name = "yaxpeax-pic18" +version = "0.0.1" +dependencies = [ + "serde", + "serde_derive", + "yaxpeax-arch", +] + +[[package]] +name = "yaxpeax-pic24" +version = "0.0.1" +dependencies = [ + "serde", + "serde_derive", + "yaxpeax-arch", +] + +[[package]] +name = "yaxpeax-x86" +version = "0.0.1" +dependencies = [ + "num-traits", + "serde", + "serde_derive", + "serde_json", + "termion", + "yaxpeax-arch", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3076334 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "yaxpeax-dis" +version = "0.1.0" +authors = ["iximeow <me@iximeow.net>"] +edition = "2018" +description = "disassembly tool using yaxpeax instruction decoders" + +[[bin]] +name = "yaxdis" +path = "src/main.rs" + +[dependencies] +clap = "2.33" +hex = "0.4.0" +num-traits = "0.2.10" + +# common interfaces for all yaxpeax decoders +yaxpeax-arch = { path = "../yaxpeax-arch" } + +yaxpeax-arm = { path = "../arch/arm" } +yaxpeax-mips = { path = "../arch/mips" } +yaxpeax-msp430-mc = { path = "../arch/msp430" } +yaxpeax-pic17 = { path = "../arch/pic17" } +yaxpeax-pic18 = { path = "../arch/pic18" } +yaxpeax-pic24 = { path = "../arch/pic24" } +yaxpeax-x86 = { path = "../arch/x86" } diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..3a9fef4 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,81 @@ +use yaxpeax_arch::{Address, Arch, Decoder, Instruction, LengthedInstruction}; + +use clap::{Arg, App}; +use num_traits::identities::Zero; + +use std::fmt; + +fn main() { + let matches = App::new("yaxpeax disassembler") + .version("0.0.1") + .author("iximeow <me@iximeow.net>") + .about("disassembly tool using yaxpeax decoders") + .arg(Arg::with_name("arch") + .short("a") + .long("architecture") + .takes_value(true) + .help("architecture to disassemble input as")) + .arg(Arg::with_name("file") + .short("f") + .long("file") + .takes_value(true) + .help("file of bytes to decode")) + .arg(Arg::with_name("verbose") + .short("v") + .long("verbose") + .help("increased detail when decoding instructions")) + .arg(Arg::with_name("data") + .index(1)) + .get_matches(); + + let arch_str = matches.value_of("arch").unwrap_or("x86_64"); + eprintln!("disassembling as {}", arch_str); +// let file = matches.value_of("file").unwrap(); + let buf: &str = matches.value_of("data").unwrap_or(""); + let verbose = matches.occurrences_of("verbose") > 0; + + match arch_str { + "x86_64" => decode_input::<yaxpeax_x86::x86_64>(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_mc::MSP430>(buf, verbose), + "pic17" => decode_input::<yaxpeax_pic17::PIC17>(buf, verbose), + "pic18" => decode_input::<yaxpeax_pic18::PIC18>(buf, verbose), +// "pic24" => decode_input::<yaxpeax_pic24::PIC24>(buf), + other => { + println!("unsupported architecture: {}", other); + } + } +} + +fn decode_input<A: Arch>(buf: &str, verbose: bool) where A::Instruction: fmt::Display { + let buf = match hex::decode(buf) { + Ok(buf) => buf, + Err(e) => { + eprintln!("Invalid input, {}. Expected a sequence of bytes as hex", e); + return; + } + }; + let decoder = A::Decoder::default(); + 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()..][..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); break; }, + } + if addr.to_linear() >= buf.len() { + break; + } + } +} |