mirror of
https://github.com/encounter/objdiff.git
synced 2025-12-19 18:05:35 +00:00
WIP objdiff 3.0 refactor
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user