WIP objdiff 3.0 refactor

This commit is contained in:
2025-02-20 17:48:00 -07:00
parent 6d3c63ccd8
commit f3c157ff06
79 changed files with 14886 additions and 6820 deletions

View File

@@ -1,7 +1,7 @@
use alloc::format;
use core::fmt;
use anyhow::Result;
use anyhow::{ensure, Result};
use num_traits::PrimInt;
use object::{Endian, Object};
@@ -27,17 +27,15 @@ impl<N: PrimInt> fmt::UpperHex for ReallySigned<N> {
}
pub fn read_u32(obj_file: &object::File, reader: &mut &[u8]) -> Result<u32> {
if reader.len() < 4 {
return Err(anyhow::anyhow!("Not enough bytes to read u32"));
}
ensure!(reader.len() >= 4, "Not enough bytes to read u32");
let value = u32::from_ne_bytes(reader[..4].try_into()?);
*reader = &reader[4..];
Ok(obj_file.endianness().read_u32(value))
}
pub fn read_u16(obj_file: &object::File, reader: &mut &[u8]) -> Result<u16> {
if reader.len() < 2 {
return Err(anyhow::anyhow!("Not enough bytes to read u16"));
}
ensure!(reader.len() >= 2, "Not enough bytes to read u16");
let value = u16::from_ne_bytes(reader[..2].try_into()?);
*reader = &reader[2..];
Ok(obj_file.endianness().read_u16(value))
}