chore: replace all panic's with proper error propagation

This commit is contained in:
2025-05-25 15:45:09 +09:00
parent 73b1a99cbd
commit 74e936ab76
4 changed files with 278 additions and 243 deletions

View File

@@ -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()?,
})
}
}