diff --git a/Cargo.toml b/Cargo.toml index 81d3dde..cff3f11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "re0box" -version = "0.4.0" +version = "0.4.1" authors = ["descawed "] edition = "2021" description = "An item box mod for Resident Evil 0" @@ -20,7 +20,7 @@ panic = "abort" [dependencies] anyhow = "1.0" -binrw = "0.12" +binrw = "0.13" configparser = "3.0" log = "0.4" simplelog = "0.12" diff --git a/src/error.rs b/src/error.rs index b4f2934..d2be101 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,7 +8,7 @@ use std::{cmp, mem}; use anyhow::Result; use simplelog::{Config, LevelFilter, WriteLogger}; use windows::core::PWSTR; -use windows::Win32::Foundation::{HMODULE, MAX_PATH}; +use windows::Win32::Foundation::{DBG_PRINTEXCEPTION_C, DBG_PRINTEXCEPTION_WIDE_C, HMODULE, MAX_PATH, NTSTATUS}; use windows::Win32::System::Diagnostics::Debug::{ AddVectoredExceptionHandler, RemoveVectoredExceptionHandler, CONTEXT_CONTROL_X86, CONTEXT_DEBUG_REGISTERS_X86, CONTEXT_FLOATING_POINT_X86, CONTEXT_INTEGER_X86, @@ -24,6 +24,10 @@ use windows::Win32::System::ProcessStatus::{ }; use windows::Win32::System::Threading::GetCurrentProcess; +const IGNORED_EXCEPTIONS: [NTSTATUS; 2] = [ + DBG_PRINTEXCEPTION_C, + DBG_PRINTEXCEPTION_WIDE_C, +]; const STACK_DUMP_WORDS_PER_LINE: usize = 4; const STACK_DUMP_LINES: usize = 6; const READABLE_PROTECT: [PAGE_PROTECTION_FLAGS; 4] = [ @@ -36,18 +40,27 @@ const MAX_MODULES: usize = 1000; unsafe extern "system" fn exception_handler(exc_info: *mut EXCEPTION_POINTERS) -> i32 { if let Some(exc_info) = exc_info.as_ref() { + let mut had_notable_exception = false; + // exception details let mut record_ptr = exc_info.ExceptionRecord; while let Some(record) = record_ptr.as_ref() { - log::error!( - "Unhandled exception {:08X} at {:08X}. Parameters: {:?}", - record.ExceptionCode.0, - record.ExceptionAddress as usize, - &record.ExceptionInformation[..record.NumberParameters as usize] - ); + if !IGNORED_EXCEPTIONS.contains(&record.ExceptionCode) { + had_notable_exception = true; + log::error!( + "Unhandled exception {:08X} at {:08X}. Parameters: {:?}", + record.ExceptionCode.0, + record.ExceptionAddress as usize, + &record.ExceptionInformation[..record.NumberParameters as usize] + ); + } record_ptr = record.ExceptionRecord; } + if !had_notable_exception { + return ExceptionContinueSearch.0; + } + // registers let mut sp = None; if let Some(context) = exc_info.ContextRecord.as_ref() {