diff options
author | iximeow <me@iximeow.net> | 2025-04-13 19:40:49 -0700 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2025-04-13 19:40:49 -0700 |
commit | 513c666d352c1bbff44c58b27edd46dcea54a73e (patch) | |
tree | 0ae70f543844eaaedcd3c303636dab3f6eee8739 | |
parent | 5a1731a2584222cf3e2d66685f96f8dc43cd3542 (diff) |
actually commit the fuzz target and a bit of test binary
-rw-r--r-- | fuzz/Cargo.lock | 149 | ||||
-rw-r--r-- | fuzz/fuzz_targets/no-panic.rs | 18 | ||||
-rw-r--r-- | tests/from_docs.rs | 123 |
3 files changed, 290 insertions, 0 deletions
diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock new file mode 100644 index 0000000..8de7bec --- /dev/null +++ b/fuzz/Cargo.lock @@ -0,0 +1,149 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "jobserver", + "libc", +] + +[[package]] +name = "jobserver" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" +dependencies = [ + "libc", +] + +[[package]] +name = "libc" +version = "0.2.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" + +[[package]] +name = "libfuzzer-sys" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a96cfd5557eb82f2b83fed4955246c988d331975a002961b07c81584d107e7f7" +dependencies = [ + "arbitrary", + "cc", + "once_cell", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[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-hexagon" +version = "0.0.1" +dependencies = [ + "num-traits", + "yaxpeax-arch", +] + +[[package]] +name = "yaxpeax-hexagon-fuzz" +version = "0.0.0" +dependencies = [ + "libfuzzer-sys", + "yaxpeax-arch", + "yaxpeax-hexagon", +] diff --git a/fuzz/fuzz_targets/no-panic.rs b/fuzz/fuzz_targets/no-panic.rs new file mode 100644 index 0000000..d2653dd --- /dev/null +++ b/fuzz/fuzz_targets/no-panic.rs @@ -0,0 +1,18 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; + +use yaxpeax_arch::Decoder; + +use std::fmt::Write; + +fuzz_target!(|data: &[u8]| { + let decoder = yaxpeax_hexagon::InstDecoder::default(); + + let mut hexagon_inst = yaxpeax_hexagon::InstructionPacket::default(); + + let mut words = yaxpeax_arch::U8Reader::new(data); + + // whatever the output, we should be able to format the instruction that was decoded into + let _ = decoder.decode_into(&mut hexagon_inst, &mut words); + write!(&mut String::new(), "{}", hexagon_inst).expect("formatting does not panic either"); +}); diff --git a/tests/from_docs.rs b/tests/from_docs.rs new file mode 100644 index 0000000..44db80a --- /dev/null +++ b/tests/from_docs.rs @@ -0,0 +1,123 @@ +use yaxpeax_arch::AddressBase; +use yaxpeax_arch::Decoder; +use yaxpeax_arch::LengthedInstruction; + +// for "lazy" reasons i've found fairly few known-correct disassemblies to compare against + +/* +fn test_display(bytes: &[u8], text: &str) { + let decoder = yaxpeax_hexagon::InstDecoder::default(); + let inst = decoder.decode(&mut yaxpeax_arch::U8Reader::new(bytes)).expect("decode succeeds"); + let rendered = format!("{}", inst); + assert_eq!(rendered, text); +} +*/ + +#[test] +fn misc_bytes() { + const BYTES: &'static [u8] = &[ + 0x0e, 0xc0, 0x00, 0x58, 0x00, 0xc0, 0x00, 0x58, 0x00, 0xc0, 0x00, 0x58, + 0x00, 0xc0, 0x00, 0x58, 0x00, 0xc0, 0x00, 0x58, 0x00, 0xc0, 0x00, 0x58, + 0x00, 0xc0, 0x00, 0x58, 0x02, 0xc7, 0x00, 0x58, 0x00, 0xc0, 0x00, 0x78, + 0x06, 0xc0, 0x00, 0x67, 0x00, 0xc0, 0x92, 0x6e, 0x00, 0xc3, 0xc0, 0x8c, + 0x00, 0xc5, 0xc0, 0x8c, 0x12, 0xc0, 0x00, 0x67, 0x00, 0xc0, 0x00, 0xa2, + 0x00, 0xd0, 0xc0, 0x56, 0x66, 0xc0, 0x00, 0x58, 0x00, 0x00, 0x00, 0x00, + 0x0f, 0x40, 0x92, 0x6e, 0x04, 0x40, 0xe1, 0x0f, 0x0e, 0xc0, 0x00, 0x78, + 0x02, 0x40, 0x00, 0x00, 0x01, 0x56, 0x49, 0x6a, 0x25, 0x4c, 0x0e, 0x8c, + 0x8f, 0xff, 0x2f, 0x76, 0x7f, 0x4e, 0x01, 0xef, 0x24, 0x4c, 0x01, 0x8c, + 0x34, 0xdf, 0x04, 0x20, 0x02, 0xc0, 0x85, 0x6c, 0x03, 0xc0, 0x84, 0x6c, + 0x0a, 0xc0, 0x42, 0x6c, 0x27, 0x5d, 0xcb, 0x8c, 0x0c, 0x60, 0x42, 0x73, + 0xf0, 0x7f, 0x63, 0x75, 0x01, 0xc3, 0x02, 0xf2, 0x07, 0x54, 0x04, 0x8f, + 0x06, 0x40, 0xca, 0x8c, 0x03, 0x40, 0x2c, 0x74, 0x03, 0xc0, 0x0c, 0x74, + 0x08, 0xc0, 0x43, 0x6c, 0x26, 0x57, 0x04, 0x8f, 0x0e, 0x5f, 0xae, 0x74, + 0x8e, 0x5d, 0x2e, 0x74, 0x12, 0xc1, 0x20, 0x5c, 0x00, 0xc2, 0x06, 0x6c, + 0x02, 0xc0, 0xc0, 0x57, 0x07, 0x54, 0x09, 0x8f, 0x8e, 0x54, 0x29, 0x8f, + 0x8d, 0xc1, 0x0e, 0xb0, 0x00, 0xc3, 0x06, 0x6c, 0x02, 0xc0, 0xc0, 0x57, + 0x12, 0x40, 0x0f, 0x67, 0x2f, 0xc1, 0xc0, 0x8c, 0x02, 0xc0, 0xc0, 0x57, + 0x00, 0xd0, 0xc0, 0x56, 0x02, 0xc0, 0xc0, 0x57, 0x12, 0xc0, 0x0f, 0x67, + 0x02, 0xc0, 0xc0, 0x57, 0x00, 0xc0, 0x8e, 0x52, 0x00, 0xc2, 0x0a, 0x6c, + 0x02, 0xc0, 0xc0, 0x57, 0x00, 0xc0, 0x8d, 0x52, 0x00, 0xc3, 0x08, 0x6c, + 0x02, 0xc0, 0xc0, 0x57, 0x12, 0xc0, 0x00, 0x67, 0x02, 0xc0, 0xc0, 0x57, + 0x00, 0xc0, 0x9f, 0x52, 0x02, 0xc0, 0xc0, 0x57, 0x00, 0xc0, 0x92, 0x6e, + 0x02, 0x40, 0x00, 0x7c, 0x00, 0xc8, 0x80, 0x76, 0x12, 0xc0, 0x00, 0x67, + 0x1e, 0xc0, 0x02, 0x6d, 0x02, 0xc0, 0xc0, 0x57, 0x00, 0xc0, 0x22, 0x63, + 0x02, 0xc0, 0x22, 0x63, 0x04, 0xc0, 0x02, 0x6d, 0x1c, 0xc0, 0x02, 0x67, + 0x07, 0xc0, 0x02, 0x67, 0x08, 0xc0, 0x22, 0x62, 0x15, 0xc0, 0x02, 0x67, + 0xc0, 0x7f, 0xff, 0x0f, 0x00, 0x40, 0x00, 0x78, 0x00, 0x40, 0xe1, 0x0f, + 0x1a, 0xc0, 0x00, 0x78, 0x18, 0x40, 0x09, 0x6a, 0xc0, 0x71, 0xe1, 0x0f, + 0x1b, 0x40, 0x00, 0x78, 0x1a, 0xc0, 0x1a, 0xf1, 0x18, 0xc0, 0x18, 0xf1, + 0x19, 0xd8, 0x3a, 0xf3, 0x04, 0x40, 0x00, 0x00, 0x11, 0xc0, 0x00, 0x78, + 0x00, 0x40, 0x00, 0x00, 0xf1, 0xc1, 0x91, 0x76, 0x19, 0xc0, 0x11, 0x67, + 0x07, 0x40, 0x00, 0x00, 0xf1, 0xc7, 0x00, 0x78, 0x17, 0xc0, 0x11, 0x67, + 0x3a, 0x4f, 0x00, 0x5a, 0x20, 0xea, 0x19, 0x73, 0xa8, 0x46, 0xe1, 0x0f, + 0x20, 0xc0, 0x99, 0xa1, 0x5e, 0x4f, 0x00, 0x5a, 0x02, 0x40, 0x00, 0x00, + 0x60, 0xe6, 0x19, 0x73, 0x1a, 0x46, 0x00, 0x5a, 0xa8, 0x46, 0xe1, 0x0f, + 0x1c, 0xc0, 0x99, 0xa1, 0x26, 0x4f, 0x00, 0x5a, 0x02, 0x40, 0x00, 0x00, + 0x80, 0xe1, 0x19, 0x73, 0xa7, 0x46, 0xe1, 0x0f, 0x34, 0xc0, 0x99, 0xa1, + 0xa7, 0x46, 0xe1, 0x0f, 0x80, 0xc3, 0x99, 0x91, 0x40, 0x40, 0x00, 0x75, + 0x01, 0xc0, 0x00, 0x75, 0xe2, 0xc0, 0x01, 0x5c, 0x00, 0xc0, 0x20, 0xa8, + 0x00, 0xc0, 0x40, 0xa8, 0xdc, 0xc1, 0x21, 0x5c, 0x0c, 0x4f, 0x00, 0x5a, + 0x02, 0x40, 0x00, 0x00, 0x80, 0xe5, 0x19, 0x73, 0xa7, 0x46, 0xe1, 0x0f, + 0x30, 0xc0, 0x99, 0xa1, 0x0c, 0x42, 0xe1, 0x0f, 0x17, 0x42, 0x19, 0xb0, + 0xa7, 0x46, 0xe1, 0x0f, 0x80, 0xc4, 0x99, 0x91, 0x0a, 0x40, 0x80, 0x11, + 0x01, 0xc0, 0x97, 0x91, 0x00, 0x40, 0x01, 0x75, 0x00, 0xc0, 0x97, 0x42, + 0x04, 0xc0, 0x00, 0x58, 0x00, 0xdb, 0x97, 0xa1, 0x0c, 0xc0, 0x9d, 0x6e, + 0xec, 0x4e, 0x00, 0x5a, 0xa0, 0xee, 0x19, 0x73, 0x04, 0x40, 0x60, 0x70, + 0xa7, 0x46, 0xe1, 0x0f, 0x38, 0xc0, 0x99, 0xa1, 0xe2, 0x4e, 0x00, 0x5a, + 0x02, 0x40, 0x00, 0x00, 0xa0, 0xe0, 0x19, 0x73, 0x26, 0x60, 0x00, 0x10, + 0x05, 0xc0, 0x60, 0x70, 0x04, 0x4f, 0x00, 0x5a, 0x03, 0x40, 0x00, 0x00, + 0xa0, 0xe0, 0x19, 0x73, 0x06, 0xd9, 0x00, 0xf3, 0xfc, 0x4e, 0x00, 0x5a, + 0x03, 0x40, 0x00, 0x00, 0x60, 0xe0, 0x19, 0x73, 0x07, 0xd9, 0x00, 0xf3, + 0xe5, 0x7f, 0xe5, 0xbf, 0x28, 0x40, 0x86, 0x9b, 0x29, 0xc0, 0x87, 0x9b, + 0x00, 0x4c, 0x09, 0xf2, 0x08, 0x48, 0x00, 0x5c, 0x04, 0xe0, 0x08, 0x74, + 0xf4, 0xe0, 0x75, 0x12, 0xa7, 0x46, 0xe1, 0x0f, 0x38, 0xc4, 0x99, 0xa1, + 0xb6, 0x4e, 0x00, 0x5a, 0xc0, 0xee, 0x19, 0x73, 0x04, 0x40, 0x60, 0x70, + 0xa7, 0x46, 0xe1, 0x0f, 0x3c, 0xc0, 0x99, 0xa1, 0xac, 0x4e, 0x00, 0x5a, + 0x02, 0x40, 0x00, 0x00, 0xc0, 0xe0, 0x19, 0x73, 0x26, 0x60, 0x00, 0x10, + 0x05, 0xc0, 0x60, 0x70, 0xce, 0x4e, 0x00, 0x5a, 0x03, 0x40, 0x00, 0x00, + 0xc0, 0xe0, 0x19, 0x73, 0x06, 0xd9, 0x00, 0xf3, 0xc6, 0x4e, 0x00, 0x5a, + 0x03, 0x40, 0x00, 0x00, 0x80, 0xe0, 0x19, 0x73, 0x07, 0xd9, 0x00, 0xf3, + 0xe5, 0x7f, 0xe5, 0xbf, 0x28, 0x40, 0x86, 0x9b, 0x29, 0xc0, 0x87, 0x9b, + 0x00, 0x4c, 0x09, 0xf2, 0x08, 0x48, 0x00, 0x5c, 0x04, 0xe0, 0x08, 0x74, + 0xf4, 0xe0, 0x75, 0x12, 0xa7, 0x46, 0xe1, 0x0f, 0x3c, 0xc4, 0x99, 0xa1, + 0x80, 0x4e, 0x00, 0x5a, 0x40, 0xee, 0x19, 0x73, 0x04, 0x40, 0x60, 0x70, + 0xa8, 0x46, 0xe1, 0x0f, 0x00, 0xc0, 0x99, 0xa1, 0x76, 0x4e, 0x00, 0x5a, + 0x02, 0x40, 0x00, 0x00, 0x80, 0xe0, 0x19, 0x73, 0x26, 0x60, 0x00, 0x10, + 0x05, 0xc0, 0x60, 0x70, 0x98, 0x4e, 0x00, 0x5a, 0x03, 0x40, 0x00, 0x00, + 0x00, 0xe0, 0x19, 0x73, 0x06, 0xd9, 0x00, 0xf3, 0x90, 0x4e, 0x00, 0x5a, + 0x03, 0x40, 0x00, 0x00, 0x40, 0xe0, 0x19, 0x73, 0x07, 0xd9, 0x00, 0xf3, + 0xe5, 0x7f, 0xe5, 0xbf, 0x28, 0x40, 0x86, 0x9b, 0x29, 0xc0, 0x87, 0x9b, + 0x00, 0x4c, 0x09, 0xf2, 0x08, 0x48, 0x00, 0x5c, 0x04, 0xe0, 0x08, 0x74, + 0xf4, 0xe0, 0x75, 0x12, 0xa8, 0x46, 0xe1, 0x0f, 0x00, 0xc4, 0x99, 0xa1, + 0x4a, 0x4e, 0x00, 0x5a, 0x20, 0xee, 0x19, 0x73, 0x04, 0x40, 0x60, 0x70, + 0xa8, 0x46, 0xe1, 0x0f, 0x04, 0xc0, 0x99, 0xa1, 0x40, 0x4e, 0x00, 0x5a, + 0x02, 0x40, 0x00, 0x00, 0x60, 0xe0, 0x19, 0x73, 0x26, 0x60, 0x00, 0x10, + 0x05, 0xc0, 0x60, 0x70, 0x62, 0x4e, 0x00, 0x5a, 0x02, 0x40, 0x00, 0x00, + 0xe0, 0xe7, 0x19, 0x73, 0x06, 0xd9, 0x00, 0xf3, 0x5a, 0x4e, 0x00, 0x5a, + 0x03, 0x40, 0x00, 0x00, 0x20, 0xe0, 0x19, 0x73, 0x07, 0xd9, 0x00, 0xf3, + 0xe5, 0x7f, 0xe5, 0xbf, 0x28, 0x40, 0x86, 0x9b, 0x29, 0xc0, 0x87, 0x9b, + 0x00, 0x4c, 0x09, 0xf2, 0x08, 0x48, 0x00, 0x5c, 0x04, 0xe0, 0x08, 0x74, + 0xf4, 0xe0, 0x75, 0x12, 0xa8, 0x46, 0xe1, 0x0f, 0x04, 0xc4, 0x99, 0xa1, + 0xa7, 0x46, 0xe1, 0x0f, 0x00, 0xc7, 0x99, 0x91, 0x3c, 0xc0, 0x00, 0x67, + 0xa8, 0x46, 0xe1, 0x0f, 0x80, 0xc0, 0x99, 0x91, 0x20, 0xd5, 0xc0, 0x8c, + 0x3f, 0xc0, 0x00, 0x67, 0xa8, 0x46, 0xe1, 0x0f, 0x00, 0xc0, 0x99, 0x91, + 0x3e, 0xc0, 0x00, 0x67 + ]; + + let mut offs = 0; + let decoder = yaxpeax_hexagon::InstDecoder::default(); + while offs < BYTES.len() { + let inst = decoder.decode(&mut yaxpeax_arch::U8Reader::new(&BYTES[offs..])); + match inst { + Ok(inst) => { + println!("{:04x}: {}", offs, inst); + offs += inst.len().to_const().to_linear(); + }, + Err(e) => { + println!("{:04x}: {}", offs, e); + println!("{:04x}: {:#x?}", offs, &BYTES[offs..][..4]); + offs += 4; + } + } + } +} |