bug fix bug fix bug fix WIP
This commit is contained in:
parent
b30e91b86a
commit
b17a84212f
5 changed files with 153 additions and 151 deletions
|
|
@ -35,12 +35,16 @@ impl CodeItem {
|
|||
pub fn sanity_check(&self) -> Result<()> {
|
||||
if self.tries.is_empty() && self.handlers.is_some() {
|
||||
return Err(Error::InconsistantStruct(
|
||||
"CodeItem cannot have a `handlers` value if `tries_size` is 0 (CodeItem.tries is empty)".into()
|
||||
"CodeItem cannot have a `handlers` value if `tries_size` \
|
||||
is 0 (CodeItem.tries is empty)"
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
if !self.tries.is_empty() && self.handlers.is_none() {
|
||||
return Err(Error::InconsistantStruct(
|
||||
"CodeItem must have a `handlers` value if `tries_size` is not 0 (CodeItem.tries not empty)".into()
|
||||
"CodeItem must have a `handlers` value if `tries_size` \
|
||||
is not 0 (CodeItem.tries not empty)"
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
let mut max_addr = 0;
|
||||
|
|
@ -48,7 +52,9 @@ impl CodeItem {
|
|||
let addr = item.start_addr;
|
||||
if addr < max_addr {
|
||||
return Err(Error::InconsistantStruct(
|
||||
"try_item in a code_item must be non overlapping and sorted from low to high address".into()
|
||||
"try_item in a code_item must be non overlapping and \
|
||||
sorted from low to high address"
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
max_addr = addr + (item.insn_count as u32);
|
||||
|
|
@ -121,8 +127,10 @@ impl CodeItem {
|
|||
}
|
||||
}
|
||||
if i < addresses.len() && addresses[i] < addr {
|
||||
println!("{addresses:x?}");
|
||||
return Err(Error::InconsistantStruct(format!(
|
||||
"Found an address in try block (0x{addr:x}) that does not align with an instruction"
|
||||
"Found an address in try block (0x{:x}) that does not align with an instruction",
|
||||
addresses[i]
|
||||
)));
|
||||
}
|
||||
|
||||
|
|
@ -170,11 +178,21 @@ impl Serializable for CodeItem {
|
|||
|
||||
let mut insns = vec![];
|
||||
let mut serialized_insns_size = 0;
|
||||
while serialized_insns_size != insns_size {
|
||||
let ins = Instruction::deserialize(input)?;
|
||||
serialized_insns_size += ins.size() as u32;
|
||||
while serialized_insns_size < insns_size {
|
||||
let ins = Instruction::deserialize(input).map_err(|err| {
|
||||
Error::DeserializationError(format!(
|
||||
"Failed to deserialize instruction at 0x{serialized_insns_size:x}: {err}"
|
||||
))
|
||||
})?;
|
||||
serialized_insns_size += ins.size() as u32 / 2;
|
||||
insns.push(ins);
|
||||
}
|
||||
if serialized_insns_size != insns_size {
|
||||
return Err(Error::DeserializationError(format!(
|
||||
"Failed to deserialize instructions, expected size of {insns_size} code \
|
||||
units (16 bits), found at least {serialized_insns_size}"
|
||||
)));
|
||||
}
|
||||
if tries_size != 0 && insns_size % 2 == 1 {
|
||||
let _ = u16::deserialize(input)?;
|
||||
}
|
||||
|
|
@ -265,7 +283,8 @@ impl EncodedCatchHandlerList {
|
|||
current_offset += handler.size();
|
||||
}
|
||||
Err(Error::InconsistantStruct(format!(
|
||||
"Offset 0x{offset:x} does not match with the begining of a EncodedCatchHandler in this EncodedCatchHandlerList"
|
||||
"Offset 0x{offset:x} does not match with the begining of a \
|
||||
EncodedCatchHandler in this EncodedCatchHandlerList"
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -389,8 +389,11 @@ impl Instruction {
|
|||
requires the first byte to be 0 found {v}"
|
||||
)));
|
||||
}
|
||||
/*
|
||||
let [a_l0, a_l1, a_h0, a_h1] = i32::deserialize(input)?.to_be_bytes();
|
||||
let a = i32::from_be_bytes([a_h0, a_h1, a_l0, a_l1]);
|
||||
*/
|
||||
let a = i32::deserialize(input)?;
|
||||
Ok(Self::Format30T { op, a })
|
||||
}
|
||||
|
||||
|
|
@ -412,24 +415,33 @@ impl Instruction {
|
|||
pub fn deserialize_31i(input: &mut dyn ReadSeek) -> Result<Self> {
|
||||
let op = u8::deserialize(input)?;
|
||||
let va = u8::deserialize(input)?;
|
||||
let b = i32::deserialize(input)?;
|
||||
/*
|
||||
let [b_l0, b_l1, b_h0, b_h1] = i32::deserialize(input)?.to_be_bytes();
|
||||
let b = i32::from_be_bytes([b_h0, b_h1, b_l0, b_l1]);
|
||||
*/
|
||||
Ok(Self::Format31I { va, op, b })
|
||||
}
|
||||
|
||||
pub fn deserialize_31t(input: &mut dyn ReadSeek) -> Result<Self> {
|
||||
let op = u8::deserialize(input)?;
|
||||
let va = u8::deserialize(input)?;
|
||||
let b = i32::deserialize(input)?;
|
||||
/*
|
||||
let [b_l0, b_l1, b_h0, b_h1] = i32::deserialize(input)?.to_be_bytes();
|
||||
let b = i32::from_be_bytes([b_h0, b_h1, b_l0, b_l1]);
|
||||
*/
|
||||
Ok(Self::Format31T { va, op, b })
|
||||
}
|
||||
|
||||
pub fn deserialize_31c(input: &mut dyn ReadSeek) -> Result<Self> {
|
||||
let op = u8::deserialize(input)?;
|
||||
let va = u8::deserialize(input)?;
|
||||
let b = u32::deserialize(input)?;
|
||||
/*
|
||||
let [b_l0, b_l1, b_h0, b_h1] = u32::deserialize(input)?.to_be_bytes();
|
||||
let b = u32::from_be_bytes([b_h0, b_h1, b_l0, b_l1]);
|
||||
*/
|
||||
Ok(Self::Format31C { va, op, b })
|
||||
}
|
||||
|
||||
|
|
@ -824,8 +836,11 @@ impl Serializable for Instruction {
|
|||
Self::Format30T { op, a } => {
|
||||
op.serialize(output)?;
|
||||
0u8.serialize(output)?;
|
||||
/*
|
||||
let [a_h0, a_h1, a_l0, a_l1] = a.to_be_bytes();
|
||||
u32::from_be_bytes([a_l0, a_l1, a_h0, a_h1]).serialize(output)
|
||||
*/
|
||||
a.serialize(output)
|
||||
}
|
||||
Self::Format32X { op, va, vb } => {
|
||||
op.serialize(output)?;
|
||||
|
|
@ -836,20 +851,29 @@ impl Serializable for Instruction {
|
|||
Self::Format31I { va, op, b } => {
|
||||
op.serialize(output)?;
|
||||
va.serialize(output)?;
|
||||
/*
|
||||
let [b_h0, b_h1, b_l0, b_l1] = b.to_be_bytes();
|
||||
u32::from_be_bytes([b_l0, b_l1, b_h0, b_h1]).serialize(output)
|
||||
*/
|
||||
b.serialize(output)
|
||||
}
|
||||
Self::Format31T { va, op, b } => {
|
||||
op.serialize(output)?;
|
||||
va.serialize(output)?;
|
||||
/*
|
||||
let [b_h0, b_h1, b_l0, b_l1] = b.to_be_bytes();
|
||||
u32::from_be_bytes([b_l0, b_l1, b_h0, b_h1]).serialize(output)
|
||||
*/
|
||||
b.serialize(output)
|
||||
}
|
||||
Self::Format31C { va, op, b } => {
|
||||
op.serialize(output)?;
|
||||
va.serialize(output)?;
|
||||
/*
|
||||
let [b_h0, b_h1, b_l0, b_l1] = b.to_be_bytes();
|
||||
u32::from_be_bytes([b_l0, b_l1, b_h0, b_h1]).serialize(output)
|
||||
*/
|
||||
b.serialize(output)
|
||||
}
|
||||
Self::Format35C {
|
||||
a,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue