dont unwrap

This commit is contained in:
Janis 2023-04-15 00:19:01 +02:00
parent e9363700df
commit 856e5e6f38

View file

@ -22,6 +22,8 @@ use winapi::{
},
};
use crate::error::ImageHelpError;
pub mod error {
use std::ffi::NulError;
@ -39,6 +41,8 @@ pub mod error {
pub enum ImageHelpError {
#[error("Module could not be found")]
ModuleNotFound,
#[error("inline null byte found")]
InlineNullByte,
}
impl Error {
@ -107,7 +111,8 @@ impl ImageHelp {
) -> Result<*const u8, error::Error> {
let process_handle = self.process_handle.read().unwrap();
let module_name_w = widestring::U16CString::from_str(module_name).expect("unexpected null");
let module_name_w = widestring::U16CString::from_str(module_name)
.map_err(|_| ImageHelpError::InlineNullByte)?;
let module_handle = unsafe {
let handle = LoadLibraryW(module_name_w.as_ptr());
@ -161,8 +166,8 @@ impl ImageHelp {
unsafe { std::mem::MaybeUninit::<dbghelp::SYMBOL_INFOW>::zeroed().assume_init() };
sym_info.SizeOfStruct = std::mem::size_of::<dbghelp::SYMBOL_INFOW>() as ULONG;
let symbol_name_utf16 =
widestring::U16CString::from_str(function_name).expect("unexpected null char");
let symbol_name_utf16 = widestring::U16CString::from_str(function_name)
.map_err(|_| ImageHelpError::InlineNullByte)?;
sym_info.MaxNameLen = 255;
log::debug!("SymFromNameW..");
@ -172,6 +177,8 @@ impl ImageHelp {
!= 0
})?;
log::debug!("asdf");
Ok(sym_info.Address as *const u8)
};