chore: replace all panic's with proper error propagation
This commit is contained in:
@@ -141,27 +141,31 @@ pub struct Pointer {
|
||||
|
||||
impl Pointer {
|
||||
pub fn new(disasm: &mut Disassembler) -> Result<Self, DisasmError> {
|
||||
log::debug!(
|
||||
"Seeking 4 bytes ahead of current text offset... ({} + 4)",
|
||||
disasm.offset
|
||||
);
|
||||
let byte0 = disasm
|
||||
.text
|
||||
.get(disasm.offset)
|
||||
.ok_or(DisasmError::IndexOutOfBounds(disasm.offset))?;
|
||||
.ok_or(DisasmError::ReadBeyondTextSection(disasm.clone()))?;
|
||||
let byte1 = disasm
|
||||
.text
|
||||
.get(disasm.offset + 1)
|
||||
.ok_or(DisasmError::IndexOutOfBounds(disasm.offset + 1))?;
|
||||
.ok_or(DisasmError::ReadBeyondTextSection(disasm.clone()))?;
|
||||
let byte2 = disasm
|
||||
.text
|
||||
.get(disasm.offset + 2)
|
||||
.ok_or(DisasmError::IndexOutOfBounds(disasm.offset + 2))?;
|
||||
.ok_or(DisasmError::ReadBeyondTextSection(disasm.clone()))?;
|
||||
let byte3 = disasm
|
||||
.text
|
||||
.get(disasm.offset + 3)
|
||||
.ok_or(DisasmError::IndexOutOfBounds(disasm.offset + 3))?;
|
||||
.ok_or(DisasmError::ReadBeyondTextSection(disasm.clone()))?;
|
||||
|
||||
Ok(Pointer {
|
||||
raw: DWord::from_le_bytes([*byte0, *byte1, *byte2, *byte3]),
|
||||
segment: disasm.parse_word(),
|
||||
offset: disasm.parse_word(),
|
||||
segment: disasm.parse_word()?,
|
||||
offset: disasm.parse_word()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user