Craft Anything: understand how any software works, and craft your own.
Rust
An A32 doubleword load or store into r15 decodes as invalid instead of stopping the ARM analysis (#204)
GGWAfa7f1a114e4e
diff --git a/crates/disasm/src/decode.rs b/crates/disasm/src/decode.rsindex 1c1e4212..de134a60 100644--- a/crates/disasm/src/decode.rs+++ b/crates/disasm/src/decode.rs@@ -842,6 +842,14 @@ fn decode_a32(mode: Mode, bytes: &[u8], addr: u64, fmt: bool) -> Option<Insn> {use yaxpeax_arm::armv7::{ConditionCode as C, InstDecoder, Opcode, Operand};let dec = if mode == Mode::T32 { InstDecoder::default_thumb() } else { InstDecoder::default() };let window = bytes.get(..bytes.len().min(4))?;+ if mode == Mode::A32 {+ let word = u32::from_le_bytes(window.try_into().ok()?);+ // A32 extra load/store: L=0 and SH=10/11 select LDRD/STRD.+ // Rt=15 would make yaxpeax construct the nonexistent second register r16.+ if word & 0x0e10_00d0 == 0x0000_00d0 && (word >> 12) & 0xf == 15 {+ return None;+ }+ }let mut reader = U8Reader::new(window);let inst = dec.decode(&mut reader).ok()?;let len = u8::try_from(inst.len().to_const()).ok().filter(|l| *l > 0)?;@@ -1150,6 +1158,33 @@ mod tests {assert_eq!(c.value("x0"), Some(0x2010));}+ #[test]+ fn a32_doubleword_rt15_is_invalid() {+ assert!(decode(Mode::A32, &[0xf3, 0xfe, 0xc7, 0xc0], 0, true).is_none());+ for word in [0xe1c0_f0d0u32, 0xe1c0_f0f0, 0xe180_f0d1, 0xe180_f0f1] {+ assert!(decode(Mode::A32, &word.to_le_bytes(), 0, true).is_none());+ }+ }++ #[test]+ fn a32_doubleword_other_registers_still_decode() {+ // LDRD/STRD immediate and register forms, including valid Rt=2.+ for base in [0xe1c0_00d0u32, 0xe1c0_00f0, 0xe180_00d1, 0xe180_00f1] {+ for rt in 0..15 {+ let word = base | (rt << 12);+ assert!(decode(Mode::A32, &word.to_le_bytes(), 0, true).is_some());+ }+ }+ }++ #[test]+ fn a32_single_register_loads_and_stores_still_decode() {+ // Ordinary LDR/STR, plus extra halfword/signed loads with Rt=15.+ for word in [0xe590_2000u32, 0xe580_2000, 0xe1d0_f0b0, 0xe1d0_f0d0, 0xe1d0_f0f0] {+ assert!(decode(Mode::A32, &word.to_le_bytes(), 0, true).is_some());+ }+ }+#[test]fn junk_never_panics() {for seed in 0..64u64 {diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 09345d8d..3dcf3f2b 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -154,9 +154,9 @@ Owner: open · Status: done (branch chore/r0.5-cleanups)- [x] The Agent console keeps its size: its history and prompt box came out 17 points taller thanthe bottom panel, which grew by that every frame until its maximum and then cut off the topof the Agent / Jobs / Log tabs (`chat::conversation`)-- [ ] `yaxpeax-arm` 0.5.0 panics ("register number out of range") on an A32 `STRD`/`LDRD` with- Rt = 15 (e.g. the word `0xc0c7fef3`), so one such word fails the whole analysis of a 32-bit- ARM program; decode it as invalid instead+- [x] `yaxpeax-arm` 0.5.0 panicked ("register number out of range") on an A32 `STRD`/`LDRD` with+ Rt = 15 (e.g. the word `0xc0c7fef3`), so one such word failed the whole analysis of a 32-bit+ ARM program; the word now decodes as invalid- [x] Unchecked `o + 4`/`o + 8` on section and program header offsets in `formats/src/dart.rs`(`Elf::parse`): a header table near `usize::MAX` panicked in debug builds (in release thewrapped reads were thrown away, since the entry's first field was already out of range); an