Skip to content

Commit

Permalink
Ignore debug print exceptions (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
descawed authored Nov 12, 2023
1 parent d06cf99 commit 4ede245
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "re0box"
version = "0.4.0"
version = "0.4.1"
authors = ["descawed <[email protected]>"]
edition = "2021"
description = "An item box mod for Resident Evil 0"
Expand All @@ -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"
Expand Down
27 changes: 20 additions & 7 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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] = [
Expand All @@ -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() {
Expand Down

0 comments on commit 4ede245

Please sign in to comment.