From 07feb52bbc141071cd8826401ccf4ce8d26699e8 Mon Sep 17 00:00:00 2001 From: KishouYusa Date: Sun, 5 Jul 2026 22:52:51 +0700 Subject: [PATCH] Fixing clippy errors --- src/api/windows/helper.rs | 19 ++---- src/api/windows/winapi32/advapi32.rs | 4 +- src/api/windows/winapi32/crypt32.rs | 4 +- src/api/windows/winapi32/dnsapi.rs | 4 +- src/api/windows/winapi32/iphlpapi.rs | 34 +++++------ .../winapi32/kernel32/get_thread_context.rs | 2 +- .../winapi32/kernel32/load_resource.rs | 2 +- .../winapi32/kernel32/lock_resource.rs | 2 +- src/api/windows/winapi32/kernel32/mod.rs | 4 +- src/api/windows/winapi32/kernel32/resolver.rs | 9 ++- .../winapi32/kernel32/set_thread_context.rs | 2 +- .../winapi32/kernel32/sizeof_resource.rs | 2 +- src/api/windows/winapi32/kernelbase.rs | 4 +- src/api/windows/winapi32/libgcc.rs | 4 +- src/api/windows/winapi32/mscoree.rs | 4 +- src/api/windows/winapi32/msvcrt.rs | 4 +- src/api/windows/winapi32/ntdll.rs | 4 +- src/api/windows/winapi32/ntdll/loader.rs | 2 +- src/api/windows/winapi32/ntdll/misc.rs | 2 +- src/api/windows/winapi32/ntoskrnl.rs | 4 +- src/api/windows/winapi32/oleaut32.rs | 4 +- src/api/windows/winapi32/shell32.rs | 4 +- src/api/windows/winapi32/shlwapi.rs | 4 +- src/api/windows/winapi32/urlmon.rs | 4 +- src/api/windows/winapi32/user32.rs | 4 +- src/api/windows/winapi32/wincrt.rs | 4 +- src/api/windows/winapi32/wininet/mod.rs | 4 +- src/api/windows/winapi32/wininet/request.rs | 4 +- src/api/windows/winapi32/ws2_32.rs | 6 +- src/api/windows/winapi64/advapi32.rs | 4 +- src/api/windows/winapi64/comctl32.rs | 4 +- src/api/windows/winapi64/comctl64.rs | 34 +++++------ src/api/windows/winapi64/dnsapi.rs | 34 +++++------ src/api/windows/winapi64/gdi32.rs | 4 +- .../winapi64/kernel32/create_file_a.rs | 4 +- .../winapi64/kernel32/create_file_w.rs | 4 +- .../winapi64/kernel32/get_locale_info_a.rs | 2 +- .../winapi64/kernel32/get_locale_info_w.rs | 4 +- .../kernel32/get_system_firmware_table.rs | 2 +- .../winapi64/kernel32/get_thread_context.rs | 2 +- .../winapi64/kernel32/heap_re_alloc.rs | 4 +- .../winapi64/kernel32/load_resource.rs | 2 +- .../windows/winapi64/kernel32/local_free.rs | 2 +- .../winapi64/kernel32/lock_resource.rs | 2 +- src/api/windows/winapi64/kernel32/mod.rs | 4 +- .../kernel32/multi_byte_to_wide_char.rs | 4 +- .../windows/winapi64/kernel32/read_file.rs | 10 ++-- src/api/windows/winapi64/kernel32/resolver.rs | 4 +- .../winapi64/kernel32/sizeof_resource.rs | 2 +- .../kernel32/wide_char_to_multi_byte.rs | 7 +-- src/api/windows/winapi64/kernelbase.rs | 2 +- src/api/windows/winapi64/msvcrt.rs | 4 +- src/api/windows/winapi64/ntdll.rs | 6 +- src/api/windows/winapi64/ntdll/loader.rs | 2 +- src/api/windows/winapi64/ntdll/memory.rs | 2 +- src/api/windows/winapi64/ntdll/misc.rs | 2 +- src/api/windows/winapi64/ole32.rs | 4 +- src/api/windows/winapi64/oleaut32.rs | 4 +- src/api/windows/winapi64/shell32.rs | 4 +- src/api/windows/winapi64/shlwapi.rs | 4 +- src/api/windows/winapi64/urlmon.rs | 4 +- src/api/windows/winapi64/user32.rs | 4 +- src/api/windows/winapi64/uxtheme.rs | 4 +- src/api/windows/winapi64/wincrt.rs | 4 +- src/api/windows/winapi64/winhttp.rs | 34 +++++------ src/api/windows/winapi64/wininet.rs | 6 +- src/api/windows/winapi64/ws2_32.rs | 4 +- src/arch/aarch64/regs.rs | 6 ++ src/arch/x86/flags.rs | 36 +++++------ src/arch/x86/fpu.rs | 60 ++++++++++--------- src/arch/x86/fpu/f80.rs | 10 +++- src/arch/x86/fpu/fpu_stack.rs | 10 +++- src/arch/x86/regs.rs | 20 +++---- src/config.rs | 2 +- src/debug/console.rs | 4 +- src/debug/definitions.rs | 4 +- src/debug/script.rs | 8 +-- src/debug/tracing.rs | 2 +- src/emu/disassemble/mod.rs | 6 ++ src/emu/emu_context.rs | 4 +- src/emu/execution/mod.rs | 10 ++-- src/emu/initialization.rs | 15 +++-- src/emu/instruction_pointer.rs | 23 ++++--- src/emu/loaders/elf.rs | 2 +- src/emu/loaders/macho.rs | 6 +- src/emu/maps.rs | 9 +-- src/emu/memory.rs | 13 ++-- src/emu/object_handle/file_handle.rs | 22 +++---- src/emu/object_handle/mod.rs | 6 ++ src/emu/object_handle/windows_path.rs | 9 ++- src/emu/operands.rs | 18 +++--- src/emu/stack.rs | 8 +-- src/emu/trace.rs | 16 ++--- src/emu/winver.rs | 2 +- src/engine/aarch64/helpers.rs | 2 +- src/engine/instructions/bound.rs | 2 +- src/engine/instructions/call.rs | 10 ++-- src/engine/instructions/fcom.rs | 5 +- src/engine/instructions/fdiv.rs | 5 +- src/engine/instructions/fmul.rs | 5 +- src/engine/instructions/fsubr.rs | 2 +- src/engine/instructions/int3.rs | 2 +- src/engine/instructions/jmp.rs | 4 +- src/engine/instructions/pcmpistri.rs | 2 +- src/engine/instructions/pcmpistrm.rs | 2 +- src/engine/instructions/pusha.rs | 16 ++--- src/engine/instructions/ret.rs | 4 +- src/engine/instructions/shlx.rs | 2 +- src/engine/instructions/shrx.rs | 2 +- src/exception/handlers.rs | 8 +-- src/exception/types.rs | 28 ++++----- src/loaders/macho/macho64.rs | 8 +-- src/maps/heap_allocation.rs | 2 +- src/maps/inspection.rs | 4 +- src/maps/mem64.rs | 17 ++---- src/maps/mod.rs | 19 +++--- src/maps/search.rs | 2 +- src/maps/tlb.rs | 6 ++ src/serialization/maps.rs | 8 +-- src/serialization/minidump/writer.rs | 10 ++-- src/syscall/linux/syscall64/memory.rs | 2 +- src/syscall/linux/syscall64/misc.rs | 1 - src/syscall/windows/syscall64/alpc.rs | 2 +- src/syscall/windows/syscall64/memory.rs | 41 ++++--------- src/syscall/windows/syscall64/mod.rs | 10 ++-- src/syscall/windows/syscall64/process.rs | 15 ++--- src/syscall/windows/syscall64/system.rs | 5 +- src/threading/global_locks.rs | 6 ++ src/threading/scheduler.rs | 5 +- src/windows/constants.rs | 2 +- src/windows/peb/peb32.rs | 2 +- src/windows/peb/peb64/ldr.rs | 2 +- .../act_ctx_section_keyed_data32.rs | 6 ++ .../act_ctx_section_keyed_data64.rs | 6 ++ .../structures/image_resource_data_entry32.rs | 6 ++ .../structures/image_resource_data_entry64.rs | 6 ++ .../structures/image_resource_directory.rs | 6 ++ .../image_resource_directory_entry.rs | 6 ++ src/windows/structures/system_info64.rs | 2 +- src/windows/structures/system_time.rs | 8 +-- src/windows/structures/vs_versioninfo.rs | 6 ++ 141 files changed, 519 insertions(+), 521 deletions(-) diff --git a/src/api/windows/helper.rs b/src/api/windows/helper.rs index 3ce0e311..2cb27f59 100644 --- a/src/api/windows/helper.rs +++ b/src/api/windows/helper.rs @@ -65,7 +65,7 @@ pub fn handler_create(uri: &str) -> u64 { // Start at 3 so allocated file descriptors never collide with the standard // streams (0=stdin, 1=stdout, 2=stderr) on the Linux syscall path; harmless // for Windows handles, which carry no special meaning at 1/2. - let new_id: u64 = if handles.len() == 0 { + let new_id: u64 = if handles.is_empty() { 3 } else { let last_id = handles[handles.len() - 1].id; @@ -97,18 +97,12 @@ pub fn handler_print() { pub fn handler_exist(hndl: u64) -> bool { let handles = HANDLERS.lock().unwrap(); - match handles.iter().position(|h| h.id == hndl) { - Some(_) => true, - None => false, - } + handles.iter().position(|h| h.id == hndl).is_some() } pub fn handler_put_bytes(hndl: u64, data: &[u8]) { let mut handles = HANDLERS.lock().unwrap(); - match handles.iter().position(|h| h.id == hndl) { - Some(idx) => handles[idx].data = data.to_vec(), - None => (), - } + if let Some(idx) = handles.iter().position(|h| h.id == hndl) { handles[idx].data = data.to_vec() } } pub fn handler_get_uri(hndl: u64) -> String { @@ -127,7 +121,7 @@ pub fn handler_find_by_uri(uri: &str) -> Option { pub fn socket_create() -> u64 { let mut sockets = SOCKETS.lock().unwrap(); - let new_socket: u64 = if sockets.len() == 0 { + let new_socket: u64 = if sockets.is_empty() { sockets.push(0); // stdin sockets.push(1); // stdout sockets.push(2); // stderr @@ -153,10 +147,7 @@ pub fn socket_close(sock: u64) -> bool { pub fn socket_exist(sock: u64) -> bool { let sockets = SOCKETS.lock().unwrap(); - match sockets.iter().position(|s| *s == sock) { - Some(_) => true, - None => false, - } + sockets.iter().position(|s| *s == sock).is_some() } pub fn advance_tick(emu: &mut emu::Emu, millis: u64) { diff --git a/src/api/windows/winapi32/advapi32.rs b/src/api/windows/winapi32/advapi32.rs index 8fdd3ca3..53c53d83 100644 --- a/src/api/windows/winapi32/advapi32.rs +++ b/src/api/windows/winapi32/advapi32.rs @@ -28,10 +28,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "CryptDeriveKey" => CryptDeriveKey(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/crypt32.rs b/src/api/windows/winapi32/crypt32.rs index 85334cd1..edd3905f 100644 --- a/src/api/windows/winapi32/crypt32.rs +++ b/src/api/windows/winapi32/crypt32.rs @@ -16,10 +16,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "CryptStringToBinaryA" => CryptStringToBinaryA(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/dnsapi.rs b/src/api/windows/winapi32/dnsapi.rs index ff55e3e9..5b8fcd15 100644 --- a/src/api/windows/winapi32/dnsapi.rs +++ b/src/api/windows/winapi32/dnsapi.rs @@ -14,10 +14,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "DnsQueryW" => DnsQuery_W(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/iphlpapi.rs b/src/api/windows/winapi32/iphlpapi.rs index 56dbd9a2..be468398 100644 --- a/src/api/windows/winapi32/iphlpapi.rs +++ b/src/api/windows/winapi32/iphlpapi.rs @@ -5,25 +5,23 @@ use crate::winapi::winapi32::kernel32; pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { let api = kernel32::guess_api_name(emu, addr); let api = api.split("!").last().unwrap_or(&api); - match api { - _ => { - if emu.cfg.skip_unimplemented == false { - if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { - serialization::Serialization::dump( - &emu, - emu.cfg.dump_filename.as_ref().unwrap(), - ); - } - - unimplemented!("atemmpt to call unimplemented API 0x{:x} {}", addr, api); + { + if !emu.cfg.skip_unimplemented { + if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { + serialization::Serialization::dump( + emu, + emu.cfg.dump_filename.as_ref().unwrap(), + ); } - log::warn!( - "calling unimplemented API 0x{:x} {} at 0x{:x}", - addr, - api, - emu.regs().rip - ); - return api.to_ascii_lowercase(); + + unimplemented!("atemmpt to call unimplemented API 0x{:x} {}", addr, api); } + log::warn!( + "calling unimplemented API 0x{:x} {} at 0x{:x}", + addr, + api, + emu.regs().rip + ); + api.to_ascii_lowercase() } } diff --git a/src/api/windows/winapi32/kernel32/get_thread_context.rs b/src/api/windows/winapi32/kernel32/get_thread_context.rs index 90e011dd..647d18ac 100644 --- a/src/api/windows/winapi32/kernel32/get_thread_context.rs +++ b/src/api/windows/winapi32/kernel32/get_thread_context.rs @@ -11,7 +11,7 @@ pub fn GetThreadContext(emu: &mut emu::Emu) { .read_dword(emu.regs().get_esp() + 4) .expect("kernel32!GetThreadContext cannot read the ctx"); - let ctx = context32::Context32::new(&emu.regs()); + let ctx = context32::Context32::new(emu.regs()); ctx.save(ctx_ptr, &mut emu.maps); log_red!(emu, "kernel32!GetThreadContext"); diff --git a/src/api/windows/winapi32/kernel32/load_resource.rs b/src/api/windows/winapi32/kernel32/load_resource.rs index 44bbd9f2..6194969c 100644 --- a/src/api/windows/winapi32/kernel32/load_resource.rs +++ b/src/api/windows/winapi32/kernel32/load_resource.rs @@ -2,7 +2,7 @@ use crate::emu; pub fn LoadResource(emu: &mut emu::Emu) { let hModule = emu.regs().rcx; - let hResInfo = emu.regs().rdx as u64; + let hResInfo = emu.regs().rdx; log_red!( emu, diff --git a/src/api/windows/winapi32/kernel32/lock_resource.rs b/src/api/windows/winapi32/kernel32/lock_resource.rs index e3e2d4e4..85eaad6a 100644 --- a/src/api/windows/winapi32/kernel32/lock_resource.rs +++ b/src/api/windows/winapi32/kernel32/lock_resource.rs @@ -8,7 +8,7 @@ pub fn LockResource(emu: &mut emu::Emu) { if helper::handler_exist(hResData) { let uri = helper::handler_get_uri(hResData); - let ptr = uri.split("_").next().unwrap().parse::().unwrap() + emu.base as u64; + let ptr = uri.split("_").next().unwrap().parse::().unwrap() + emu.base; log_red!( emu, diff --git a/src/api/windows/winapi32/kernel32/mod.rs b/src/api/windows/winapi32/kernel32/mod.rs index bd3f0401..42dc14fe 100644 --- a/src/api/windows/winapi32/kernel32/mod.rs +++ b/src/api/windows/winapi32/kernel32/mod.rs @@ -795,10 +795,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "ZombifyActCtxWorker" => ZombifyActCtxWorker(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/kernel32/resolver.rs b/src/api/windows/winapi32/kernel32/resolver.rs index af1a3f7d..e8c5cd9e 100644 --- a/src/api/windows/winapi32/kernel32/resolver.rs +++ b/src/api/windows/winapi32/kernel32/resolver.rs @@ -18,8 +18,8 @@ pub fn dump_module_iat(emu: &mut emu::Emu, module: &str) { log::trace!( "0x{:x} {}!{}", ordinal.func_va, - &flink.mod_name, - &ordinal.func_name + flink.mod_name, + ordinal.func_name ); } } @@ -44,8 +44,8 @@ pub fn resolve_api_name_in_module(emu: &mut emu::Emu, module: &str, name: &str) let first_ptr = flink.get_ptr(); loop { - if flink.mod_name.to_lowercase().contains(&module_lc) { - if flink.export_table_rva > 0 { + if flink.mod_name.to_lowercase().contains(&module_lc) + && flink.export_table_rva > 0 { for i in 0..flink.num_of_funcs { if flink.pe_hdr == 0 { continue; @@ -57,7 +57,6 @@ pub fn resolve_api_name_in_module(emu: &mut emu::Emu, module: &str, name: &str) } } } - } flink.next(emu); if flink.get_ptr() == first_ptr { diff --git a/src/api/windows/winapi32/kernel32/set_thread_context.rs b/src/api/windows/winapi32/kernel32/set_thread_context.rs index 649ef7bc..4b35b3f9 100644 --- a/src/api/windows/winapi32/kernel32/set_thread_context.rs +++ b/src/api/windows/winapi32/kernel32/set_thread_context.rs @@ -19,7 +19,7 @@ pub fn SetThreadContext(emu: &mut emu::Emu) { let opt = con.cmd(); if opt == "y" || opt == "yes" { - let mut ctx = context32::Context32::new(&emu.regs()); + let mut ctx = context32::Context32::new(emu.regs()); ctx.load(ctx_ptr, &mut emu.maps); ctx.sync(emu.regs_mut()); } diff --git a/src/api/windows/winapi32/kernel32/sizeof_resource.rs b/src/api/windows/winapi32/kernel32/sizeof_resource.rs index fbafeebc..3ea4b33c 100644 --- a/src/api/windows/winapi32/kernel32/sizeof_resource.rs +++ b/src/api/windows/winapi32/kernel32/sizeof_resource.rs @@ -3,7 +3,7 @@ use crate::winapi::helper; pub fn SizeofResource(emu: &mut emu::Emu) { let hModule = emu.regs().rcx; - let hResInfo = emu.regs().rdx as u64; + let hResInfo = emu.regs().rdx; emu.stack_pop32(false); emu.stack_pop32(false); diff --git a/src/api/windows/winapi32/kernelbase.rs b/src/api/windows/winapi32/kernelbase.rs index 3fcd5d8a..a839411f 100644 --- a/src/api/windows/winapi32/kernelbase.rs +++ b/src/api/windows/winapi32/kernelbase.rs @@ -23,10 +23,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "LocalAlloc" => LocalAlloc(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/libgcc.rs b/src/api/windows/winapi32/libgcc.rs index 24db4c1c..0ae54bdb 100644 --- a/src/api/windows/winapi32/libgcc.rs +++ b/src/api/windows/winapi32/libgcc.rs @@ -13,10 +13,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "__deregister_frame_info" => __deregister_frame_info(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/mscoree.rs b/src/api/windows/winapi32/mscoree.rs index 9d5e9000..35e8b3ff 100644 --- a/src/api/windows/winapi32/mscoree.rs +++ b/src/api/windows/winapi32/mscoree.rs @@ -9,10 +9,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "_CorExeMain" => _CorExeMain(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/msvcrt.rs b/src/api/windows/winapi32/msvcrt.rs index ecb9baad..e5452fbc 100644 --- a/src/api/windows/winapi32/msvcrt.rs +++ b/src/api/windows/winapi32/msvcrt.rs @@ -31,10 +31,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "_errno" => _errno(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/ntdll.rs b/src/api/windows/winapi32/ntdll.rs index 2ebb2a94..ce0e8477 100644 --- a/src/api/windows/winapi32/ntdll.rs +++ b/src/api/windows/winapi32/ntdll.rs @@ -24,9 +24,9 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { return String::new(); } - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { - serialization::Serialization::dump(&emu, emu.cfg.dump_filename.as_ref().unwrap()); + serialization::Serialization::dump(emu, emu.cfg.dump_filename.as_ref().unwrap()); } unimplemented!("atemmpt to call unimplemented API 0x{:x} {}", addr, api); diff --git a/src/api/windows/winapi32/ntdll/loader.rs b/src/api/windows/winapi32/ntdll/loader.rs index 7dd46e7a..4249dadb 100644 --- a/src/api/windows/winapi32/ntdll/loader.rs +++ b/src/api/windows/winapi32/ntdll/loader.rs @@ -29,7 +29,7 @@ fn LdrLoadDll(emu: &mut emu::Emu) { emu.maps.write_dword(libaddr_ptr, base as u32); } - emu.regs_mut().rax = constants::STATUS_SUCCESS as u64; + emu.regs_mut().rax = constants::STATUS_SUCCESS; } fn LdrLoadDll_gul(emu: &mut emu::Emu) { diff --git a/src/api/windows/winapi32/ntdll/misc.rs b/src/api/windows/winapi32/ntdll/misc.rs index 9b3175f4..5b302892 100644 --- a/src/api/windows/winapi32/ntdll/misc.rs +++ b/src/api/windows/winapi32/ntdll/misc.rs @@ -35,7 +35,7 @@ fn NtGetContextThread(emu: &mut emu::Emu) { log_red!(emu, "ntdll_NtGetContextThread ctx"); - let ctx = Context32::new(&emu.regs()); + let ctx = Context32::new(emu.regs()); ctx.save(ctx_ptr2 as u32, &mut emu.maps); emu.regs_mut().rax = 0; diff --git a/src/api/windows/winapi32/ntoskrnl.rs b/src/api/windows/winapi32/ntoskrnl.rs index 9f5a5a7e..fdcc0807 100644 --- a/src/api/windows/winapi32/ntoskrnl.rs +++ b/src/api/windows/winapi32/ntoskrnl.rs @@ -11,10 +11,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { match api { "RtlInitUnicodeString" => RtlInitUnicodeString(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/oleaut32.rs b/src/api/windows/winapi32/oleaut32.rs index bae1c3f9..33197485 100644 --- a/src/api/windows/winapi32/oleaut32.rs +++ b/src/api/windows/winapi32/oleaut32.rs @@ -12,10 +12,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "SysFreeString" => SysFreeString(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/shell32.rs b/src/api/windows/winapi32/shell32.rs index 79dc3dd8..b2d8a1bd 100644 --- a/src/api/windows/winapi32/shell32.rs +++ b/src/api/windows/winapi32/shell32.rs @@ -9,10 +9,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "ShellExecuteA" => ShellExecuteA(emu), "ShellExecuteW" => ShellExecuteW(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/shlwapi.rs b/src/api/windows/winapi32/shlwapi.rs index 051d95dc..4ef20f6c 100644 --- a/src/api/windows/winapi32/shlwapi.rs +++ b/src/api/windows/winapi32/shlwapi.rs @@ -11,10 +11,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "PathFileExistsA" => PathFileExistsA(emu), "PathFileExistsW" => PathFileExistsW(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/urlmon.rs b/src/api/windows/winapi32/urlmon.rs index 7242adc1..803aabc0 100644 --- a/src/api/windows/winapi32/urlmon.rs +++ b/src/api/windows/winapi32/urlmon.rs @@ -9,10 +9,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "URLDownloadToFileA" => URLDownloadToFileA(emu), "URLDownloadToFileW" => URLDownloadToFileW(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/user32.rs b/src/api/windows/winapi32/user32.rs index ce535b5e..5542a7b8 100644 --- a/src/api/windows/winapi32/user32.rs +++ b/src/api/windows/winapi32/user32.rs @@ -15,10 +15,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "CharLowerW" => CharLowerW(emu), "wsprintfA" => wsprintfA(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/wincrt.rs b/src/api/windows/winapi32/wincrt.rs index e9205081..14020bec 100644 --- a/src/api/windows/winapi32/wincrt.rs +++ b/src/api/windows/winapi32/wincrt.rs @@ -11,10 +11,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "_set_invalid_parameter_handler" => set_invalid_parameter_handler(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/wininet/mod.rs b/src/api/windows/winapi32/wininet/mod.rs index e221a53a..f7efdff5 100644 --- a/src/api/windows/winapi32/wininet/mod.rs +++ b/src/api/windows/winapi32/wininet/mod.rs @@ -28,10 +28,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { "InternetCrackUrlA" => url::internet_crack_url_a(emu), "InternetCrackUrlW" => url::internet_crack_url_w(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi32/wininet/request.rs b/src/api/windows/winapi32/wininet/request.rs index 67519d62..0de0338c 100644 --- a/src/api/windows/winapi32/wininet/request.rs +++ b/src/api/windows/winapi32/wininet/request.rs @@ -40,7 +40,7 @@ pub(super) fn http_open_request_a(emu: &mut emu::Emu) { log::trace!("\tinvalid handle."); } - if flags & constants::INTERNET_FLAG_SECURE == 1 { + if flags & constants::INTERNET_FLAG_SECURE != 0 { log::trace!("\tssl communication."); } @@ -84,7 +84,7 @@ pub(super) fn http_open_request_w(emu: &mut emu::Emu) { log::trace!("\tinvalid handle."); } - if flags & constants::INTERNET_FLAG_SECURE == 1 { + if flags & constants::INTERNET_FLAG_SECURE != 0 { log::trace!("\tssl communication."); } diff --git a/src/api/windows/winapi32/ws2_32.rs b/src/api/windows/winapi32/ws2_32.rs index 082da052..ebedef2e 100644 --- a/src/api/windows/winapi32/ws2_32.rs +++ b/src/api/windows/winapi32/ws2_32.rs @@ -37,10 +37,10 @@ pub fn gateway(addr: u32, emu: &mut emu::Emu) -> String { 0x7748cc3f => WsaConnect(emu), */ _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } @@ -180,7 +180,7 @@ fn getaddrinfo(emu: &mut emu::Emu) { }, ); // ai_protocol (IPPROTO_TCP) emu.maps - .write_qword(addrinfo_addr + 16, sockaddr_in_size as u64); // ai_addrlen + .write_qword(addrinfo_addr + 16, sockaddr_in_size); // ai_addrlen emu.maps.write_qword(addrinfo_addr + 24, canonname_addr); // ai_canonname emu.maps.write_qword(addrinfo_addr + 32, sockaddr_addr); // ai_addr diff --git a/src/api/windows/winapi64/advapi32.rs b/src/api/windows/winapi64/advapi32.rs index b46d1d14..0c4b9c71 100644 --- a/src/api/windows/winapi64/advapi32.rs +++ b/src/api/windows/winapi64/advapi32.rs @@ -17,10 +17,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { "GetUserNameW" => GetUserNameW(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/comctl32.rs b/src/api/windows/winapi64/comctl32.rs index d0e335f1..926e5324 100644 --- a/src/api/windows/winapi64/comctl32.rs +++ b/src/api/windows/winapi64/comctl32.rs @@ -9,10 +9,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { "InitCommonControls" => InitCommonControls(emu), "InitCommonControlsEx" => InitCommonControlsEx(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/comctl64.rs b/src/api/windows/winapi64/comctl64.rs index ea61101b..47604a34 100644 --- a/src/api/windows/winapi64/comctl64.rs +++ b/src/api/windows/winapi64/comctl64.rs @@ -6,26 +6,24 @@ use crate::winapi::winapi64::kernel32; pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { let api = kernel32::guess_api_name(emu, addr); let api = api.split("!").last().unwrap_or(&api); - match api { - _ => { - if emu.cfg.skip_unimplemented == false { - if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { - serialization::Serialization::dump( - &emu, - emu.cfg.dump_filename.as_ref().unwrap(), - ); - } - - unimplemented!("atemmpt to call unimplemented API 0x{:x} {}", addr, api); + { + if !emu.cfg.skip_unimplemented { + if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { + serialization::Serialization::dump( + emu, + emu.cfg.dump_filename.as_ref().unwrap(), + ); } - log::warn!( - "calling unimplemented API 0x{:x} {} at 0x{:x}", - addr, - api, - emu.regs().rip - ); - return api.to_ascii_lowercase(); + + unimplemented!("atemmpt to call unimplemented API 0x{:x} {}", addr, api); } + log::warn!( + "calling unimplemented API 0x{:x} {} at 0x{:x}", + addr, + api, + emu.regs().rip + ); + api.to_ascii_lowercase() } //String::new() diff --git a/src/api/windows/winapi64/dnsapi.rs b/src/api/windows/winapi64/dnsapi.rs index 0c1d0839..96d57ed9 100644 --- a/src/api/windows/winapi64/dnsapi.rs +++ b/src/api/windows/winapi64/dnsapi.rs @@ -5,25 +5,23 @@ use crate::winapi::winapi64; pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { let api = winapi64::kernel32::guess_api_name(emu, addr); let api = api.split("!").last().unwrap_or(&api); - match api { - _ => { - if emu.cfg.skip_unimplemented == false { - if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { - serialization::Serialization::dump( - &emu, - emu.cfg.dump_filename.as_ref().unwrap(), - ); - } - - unimplemented!("atemmpt to call unimplemented API 0x{:x} {}", addr, api); + { + if !emu.cfg.skip_unimplemented { + if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { + serialization::Serialization::dump( + emu, + emu.cfg.dump_filename.as_ref().unwrap(), + ); } - log::warn!( - "calling unimplemented API 0x{:x} {} at 0x{:x}", - addr, - api, - emu.regs().rip - ); - return api.to_ascii_lowercase(); + + unimplemented!("atemmpt to call unimplemented API 0x{:x} {}", addr, api); } + log::warn!( + "calling unimplemented API 0x{:x} {} at 0x{:x}", + addr, + api, + emu.regs().rip + ); + api.to_ascii_lowercase() } } diff --git a/src/api/windows/winapi64/gdi32.rs b/src/api/windows/winapi64/gdi32.rs index d955333f..c05f7d27 100644 --- a/src/api/windows/winapi64/gdi32.rs +++ b/src/api/windows/winapi64/gdi32.rs @@ -9,10 +9,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { "CreateFontIndirectA" => CreateFontIndirectA(emu), "GetDeviceCaps" => GetDeviceCaps(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/kernel32/create_file_a.rs b/src/api/windows/winapi64/kernel32/create_file_a.rs index 04f2f0d3..eea6b52f 100644 --- a/src/api/windows/winapi64/kernel32/create_file_a.rs +++ b/src/api/windows/winapi64/kernel32/create_file_a.rs @@ -4,10 +4,10 @@ use crate::emu::object_handle::file_handle::{FILE_SYSTEM, INVALID_HANDLE_VALUE}; use log::error; pub fn CreateFileA(emu: &mut emu::Emu) { - let lp_file_name = emu.regs().rcx as u64; + let lp_file_name = emu.regs().rcx; let dw_desired_access = emu.regs().rdx as u32; let dw_share_mode = emu.regs().r8 as u32; - let lp_security_attributes = emu.regs().r9 as u64; + let lp_security_attributes = emu.regs().r9; let dw_creation_disposition = emu.maps .read_qword(emu.regs().rsp + 0x20) diff --git a/src/api/windows/winapi64/kernel32/create_file_w.rs b/src/api/windows/winapi64/kernel32/create_file_w.rs index f00c8928..9be8c1a9 100644 --- a/src/api/windows/winapi64/kernel32/create_file_w.rs +++ b/src/api/windows/winapi64/kernel32/create_file_w.rs @@ -4,10 +4,10 @@ use crate::emu::object_handle::file_handle::{FILE_SYSTEM, INVALID_HANDLE_VALUE}; use log::error; pub fn CreateFileW(emu: &mut emu::Emu) { - let lp_file_name_wide = emu.regs().rcx as u64; + let lp_file_name_wide = emu.regs().rcx; let dw_desired_access = emu.regs().rdx as u32; let dw_share_mode = emu.regs().r8 as u32; - let lp_security_attributes = emu.regs().r9 as u64; // LPSECURITY_ATTRIBUTES + let lp_security_attributes = emu.regs().r9; // LPSECURITY_ATTRIBUTES let dw_creation_disposition = emu.maps .read_qword(emu.regs().rsp + 0x20) diff --git a/src/api/windows/winapi64/kernel32/get_locale_info_a.rs b/src/api/windows/winapi64/kernel32/get_locale_info_a.rs index 49990e2a..0676681e 100644 --- a/src/api/windows/winapi64/kernel32/get_locale_info_a.rs +++ b/src/api/windows/winapi64/kernel32/get_locale_info_a.rs @@ -32,7 +32,7 @@ pub fn GetLocaleInfoA(emu: &mut emu::Emu) { } // Write result directly to provided buffer - emu.maps.write_string(lp_lc_data as u64, &result); + emu.maps.write_string(lp_lc_data as u64, result); emu.regs_mut().rax = result.len() as u64; // Return length without null terminator clear_last_error(emu); } diff --git a/src/api/windows/winapi64/kernel32/get_locale_info_w.rs b/src/api/windows/winapi64/kernel32/get_locale_info_w.rs index 0ac02108..18fc508a 100644 --- a/src/api/windows/winapi64/kernel32/get_locale_info_w.rs +++ b/src/api/windows/winapi64/kernel32/get_locale_info_w.rs @@ -103,8 +103,8 @@ const LOCALE_IFIRSTWEEKOFYEAR: u64 = 0x100D; // First week of year - MADE UP VAL const LOCALE_RETURN_NUMBER: u64 = 0x20000000; pub fn GetLocaleInfoW(emu: &mut emu::Emu) { - let locale = emu.regs().rcx as u64; - let lctype = emu.regs().rdx as u64; + let locale = emu.regs().rcx; + let lctype = emu.regs().rdx; let lp_lc_data = emu.regs().r8 as usize; let cch_data = emu.regs().r9 as usize; diff --git a/src/api/windows/winapi64/kernel32/get_system_firmware_table.rs b/src/api/windows/winapi64/kernel32/get_system_firmware_table.rs index b1032f5d..7617ebb5 100644 --- a/src/api/windows/winapi64/kernel32/get_system_firmware_table.rs +++ b/src/api/windows/winapi64/kernel32/get_system_firmware_table.rs @@ -35,7 +35,7 @@ pub fn GetSystemFirmwareTable(emu: &mut emu::Emu) { // TODO: Return actual bytes written/required, or 0 on error if buffer_size == 0 { - emu.regs_mut().rax = 1 * 1024 * 1024; // 1MB + emu.regs_mut().rax = 1024 * 1024; // 1MB } else { emu.regs_mut().rax = 0; // Return 0 (error) for now } diff --git a/src/api/windows/winapi64/kernel32/get_thread_context.rs b/src/api/windows/winapi64/kernel32/get_thread_context.rs index ccfefea5..add4a35f 100644 --- a/src/api/windows/winapi64/kernel32/get_thread_context.rs +++ b/src/api/windows/winapi64/kernel32/get_thread_context.rs @@ -5,7 +5,7 @@ pub fn GetThreadContext(emu: &mut emu::Emu) { let hndl = emu.regs().rcx; let ctx_ptr = emu.regs().rdx; - let ctx = context64::Context64::new(&emu.regs()); + let ctx = context64::Context64::new(emu.regs()); ctx.save(ctx_ptr, &mut emu.maps); log_red!(emu, "kernel32!GetThreadContext"); diff --git a/src/api/windows/winapi64/kernel32/heap_re_alloc.rs b/src/api/windows/winapi64/kernel32/heap_re_alloc.rs index 5f154c1a..718388df 100644 --- a/src/api/windows/winapi64/kernel32/heap_re_alloc.rs +++ b/src/api/windows/winapi64/kernel32/heap_re_alloc.rs @@ -26,12 +26,12 @@ pub fn HeapReAlloc(emu: &mut emu::Emu) { match emu.maps.alloc(new_size) { Some(new_addr) => { // Create new memory map for the allocated space - if let Err(_) = emu.maps.create_map( + if emu.maps.create_map( format!("alloc_{:x}", new_addr).as_str(), new_addr, new_size, Permission::READ_WRITE, - ) { + ).is_err() { emu.regs_mut().rax = 0; return; } diff --git a/src/api/windows/winapi64/kernel32/load_resource.rs b/src/api/windows/winapi64/kernel32/load_resource.rs index 61b4f970..1f578cc1 100644 --- a/src/api/windows/winapi64/kernel32/load_resource.rs +++ b/src/api/windows/winapi64/kernel32/load_resource.rs @@ -2,7 +2,7 @@ use crate::emu; pub fn LoadResource(emu: &mut emu::Emu) { let hModule = emu.regs().rcx; - let hResInfo = emu.regs().rdx as u64; + let hResInfo = emu.regs().rdx; log_red!( emu, diff --git a/src/api/windows/winapi64/kernel32/local_free.rs b/src/api/windows/winapi64/kernel32/local_free.rs index 27d36a68..cb3b723f 100644 --- a/src/api/windows/winapi64/kernel32/local_free.rs +++ b/src/api/windows/winapi64/kernel32/local_free.rs @@ -6,6 +6,6 @@ pub fn LocalFree(emu: &mut emu::Emu) { log_red!(emu, "kernel32!LocalFree flags: {:x}", addr); let heap_management = emu.heap_mut(); - let base = heap_management.free(addr); + heap_management.free(addr); emu.regs_mut().rax = 0; } diff --git a/src/api/windows/winapi64/kernel32/lock_resource.rs b/src/api/windows/winapi64/kernel32/lock_resource.rs index 930bb738..60c1bc08 100644 --- a/src/api/windows/winapi64/kernel32/lock_resource.rs +++ b/src/api/windows/winapi64/kernel32/lock_resource.rs @@ -6,7 +6,7 @@ pub fn LockResource(emu: &mut emu::Emu) { if helper::handler_exist(hResData) { let uri = helper::handler_get_uri(hResData); - let ptr = uri.split("_").next().unwrap().parse::().unwrap() + emu.base as u64; + let ptr = uri.split("_").next().unwrap().parse::().unwrap() + emu.base; log_red!( emu, diff --git a/src/api/windows/winapi64/kernel32/mod.rs b/src/api/windows/winapi64/kernel32/mod.rs index df95e94a..1abe0a33 100644 --- a/src/api/windows/winapi64/kernel32/mod.rs +++ b/src/api/windows/winapi64/kernel32/mod.rs @@ -228,10 +228,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { "WriteProcessMemory" => WriteProcessMemory(emu), "DeviceIoControl" => api_DeviceIoControl(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/kernel32/multi_byte_to_wide_char.rs b/src/api/windows/winapi64/kernel32/multi_byte_to_wide_char.rs index d825d39a..3832cb65 100644 --- a/src/api/windows/winapi64/kernel32/multi_byte_to_wide_char.rs +++ b/src/api/windows/winapi64/kernel32/multi_byte_to_wide_char.rs @@ -31,7 +31,7 @@ pub fn MultiByteToWideChar(emu: &mut emu::Emu) { } // validation 3: size too big - if cch_wide_char < 0 || cch_wide_char > 1_000_000 { + if !(0..=1_000_000).contains(&cch_wide_char) { log::warn!( "[ALERT] MultiByteToWideChar: cch_wide_char = {} exceeds 1_000_000", cch_wide_char, @@ -39,7 +39,7 @@ pub fn MultiByteToWideChar(emu: &mut emu::Emu) { } // validation 4: if cb_multi_byte is negative or too big - if cb_multi_byte < 0 || cb_multi_byte > 10_000_000 { + if !(0..=10_000_000).contains(&cb_multi_byte) { log::warn!( "[ALERT] MultiByteToWideChar: cb_multi_byte = {} is suspicious", cb_multi_byte diff --git a/src/api/windows/winapi64/kernel32/read_file.rs b/src/api/windows/winapi64/kernel32/read_file.rs index 16538075..1c129c14 100644 --- a/src/api/windows/winapi64/kernel32/read_file.rs +++ b/src/api/windows/winapi64/kernel32/read_file.rs @@ -101,8 +101,8 @@ pub fn ReadFile(emu: &mut emu::Emu) { bytes ); // Write the data back to the emulator's memory - if bytes > 0 { - if !emu.maps.write_bytes(lp_buffer, &buffer) { + if bytes > 0 + && !emu.maps.write_bytes(lp_buffer, &buffer) { log_red!( emu, "** {} kernel32!ReadFile ERROR: Failed to write data to buffer at 0x{:x}", @@ -113,7 +113,6 @@ pub fn ReadFile(emu: &mut emu::Emu) { emu.regs_mut().rax = 0; // FALSE return; } - } bytes } Err(e) => { @@ -144,8 +143,8 @@ pub fn ReadFile(emu: &mut emu::Emu) { }; // Write the number of bytes read to the output parameter - if lp_number_of_bytes_read != 0 { - if !emu + if lp_number_of_bytes_read != 0 + && !emu .maps .write_dword(lp_number_of_bytes_read, bytes_read as u32) { @@ -159,7 +158,6 @@ pub fn ReadFile(emu: &mut emu::Emu) { emu.regs_mut().rax = 0; // FALSE return; } - } // Success! emu.last_error = 0; // NO_ERROR diff --git a/src/api/windows/winapi64/kernel32/resolver.rs b/src/api/windows/winapi64/kernel32/resolver.rs index 206e684f..80efeaaf 100644 --- a/src/api/windows/winapi64/kernel32/resolver.rs +++ b/src/api/windows/winapi64/kernel32/resolver.rs @@ -18,8 +18,8 @@ pub fn dump_module_iat(emu: &mut emu::Emu, module: &str) { log::trace!( "0x{:x} {}!{}", ordinal.func_va, - &flink.mod_name, - &ordinal.func_name + flink.mod_name, + ordinal.func_name ); } } diff --git a/src/api/windows/winapi64/kernel32/sizeof_resource.rs b/src/api/windows/winapi64/kernel32/sizeof_resource.rs index c51f7f26..1f1d0699 100644 --- a/src/api/windows/winapi64/kernel32/sizeof_resource.rs +++ b/src/api/windows/winapi64/kernel32/sizeof_resource.rs @@ -3,7 +3,7 @@ use crate::winapi::helper; pub fn SizeofResource(emu: &mut emu::Emu) { let hModule = emu.regs().rcx; - let hResInfo = emu.regs().rdx as u64; + let hResInfo = emu.regs().rdx; if helper::handler_exist(hResInfo) { let uri = helper::handler_get_uri(hResInfo); diff --git a/src/api/windows/winapi64/kernel32/wide_char_to_multi_byte.rs b/src/api/windows/winapi64/kernel32/wide_char_to_multi_byte.rs index 14a6b152..6cd951c3 100644 --- a/src/api/windows/winapi64/kernel32/wide_char_to_multi_byte.rs +++ b/src/api/windows/winapi64/kernel32/wide_char_to_multi_byte.rs @@ -2,7 +2,7 @@ use crate::winapi::winapi64::kernel32::{LAST_ERROR, clear_last_error}; use crate::{emu, windows::constants}; pub fn WideCharToMultiByte(emu: &mut emu::Emu) { - let code_page = emu.regs().rcx as u64; + let code_page = emu.regs().rcx; let dw_flags = emu.regs().rdx as usize; let lp_wide_char_str = emu.regs().r8 as usize; let cch_wide_char = emu.regs().r9 as isize; @@ -48,8 +48,8 @@ pub fn WideCharToMultiByte(emu: &mut emu::Emu) { } // 2. Handle special code pages - if code_page == constants::CP_UTF7 || code_page == constants::CP_UTF8 { - if lp_default_char != 0 || lp_used_default_char != 0 { + if (code_page == constants::CP_UTF7 || code_page == constants::CP_UTF8) + && (lp_default_char != 0 || lp_used_default_char != 0) { // Set last error to ERROR_INVALID_PARAMETER log::warn!("{} kernel32!WideCharToMultiByte invalid parameter", emu.pos); let mut err = LAST_ERROR.lock().unwrap(); @@ -57,7 +57,6 @@ pub fn WideCharToMultiByte(emu: &mut emu::Emu) { emu.regs_mut().rax = 0; return; } - } // 3. Read input string and get its length let s = emu.maps.read_wide_string(lp_wide_char_str as u64); diff --git a/src/api/windows/winapi64/kernelbase.rs b/src/api/windows/winapi64/kernelbase.rs index 8c1ea4a3..095b47e2 100644 --- a/src/api/windows/winapi64/kernelbase.rs +++ b/src/api/windows/winapi64/kernelbase.rs @@ -386,7 +386,7 @@ fn SetUnhandledExceptionFilter(emu: &mut emu::Emu) { emu.colors.nc ); - emu.set_uef(ptr1 as u64); + emu.set_uef(ptr1); emu.regs_mut().rax = 0; } diff --git a/src/api/windows/winapi64/msvcrt.rs b/src/api/windows/winapi64/msvcrt.rs index 1e6892eb..955a7c8c 100644 --- a/src/api/windows/winapi64/msvcrt.rs +++ b/src/api/windows/winapi64/msvcrt.rs @@ -16,10 +16,10 @@ pub fn gateway_by_name(api: &str, emu: &mut emu::Emu) -> String { "malloc" => malloc(emu), "_errno" => _errno(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/ntdll.rs b/src/api/windows/winapi64/ntdll.rs index 5038d26a..30c1d011 100644 --- a/src/api/windows/winapi64/ntdll.rs +++ b/src/api/windows/winapi64/ntdll.rs @@ -24,9 +24,9 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { return String::new(); } - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { - serialization::Serialization::dump(&emu, emu.cfg.dump_filename.as_ref().unwrap()); + serialization::Serialization::dump(emu, emu.cfg.dump_filename.as_ref().unwrap()); } unimplemented!("atemmpt to call unimplemented API 0x{:x} {}", addr, api); @@ -37,5 +37,5 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { api, emu.regs().rip ); - return api.to_ascii_lowercase(); + api.to_ascii_lowercase() } diff --git a/src/api/windows/winapi64/ntdll/loader.rs b/src/api/windows/winapi64/ntdll/loader.rs index 3ce80cbe..cfa7316a 100644 --- a/src/api/windows/winapi64/ntdll/loader.rs +++ b/src/api/windows/winapi64/ntdll/loader.rs @@ -42,7 +42,7 @@ fn LdrGetDllHandleEx(emu: &mut emu::Emu) { log_red!(emu, "ntdll!LdrGetDllHandleEx {}", dll_name); let result = emu.maps.memcpy(path_ptr, dll_name_ptr, dll_name.len()); - if result == false { + if !result { panic!("LdrGetDllHandleEx failed to copy"); } diff --git a/src/api/windows/winapi64/ntdll/memory.rs b/src/api/windows/winapi64/ntdll/memory.rs index c5e603bb..40a416ae 100644 --- a/src/api/windows/winapi64/ntdll/memory.rs +++ b/src/api/windows/winapi64/ntdll/memory.rs @@ -177,7 +177,7 @@ fn RtlCopyMemory(emu: &mut emu::Emu) { let src = emu.regs().rdx; let sz = emu.regs().r8 as usize; let result = ntdll::memcpy(emu, dst, src, sz); - if result == false { + if !result { panic!("RtlCopyMemory failed to copy"); } log_red!( diff --git a/src/api/windows/winapi64/ntdll/misc.rs b/src/api/windows/winapi64/ntdll/misc.rs index f81d09ef..200ab540 100644 --- a/src/api/windows/winapi64/ntdll/misc.rs +++ b/src/api/windows/winapi64/ntdll/misc.rs @@ -39,7 +39,7 @@ fn NtGetContextThread(emu: &mut emu::Emu) { log_red!(emu, "ntdll_NtGetContextThread ctx:"); - let ctx = Context64::new(&emu.regs()); + let ctx = Context64::new(emu.regs()); ctx.save(ctx_ptr2, &mut emu.maps); emu.regs_mut().rax = 0; diff --git a/src/api/windows/winapi64/ole32.rs b/src/api/windows/winapi64/ole32.rs index 8f66be47..b91ef8a0 100644 --- a/src/api/windows/winapi64/ole32.rs +++ b/src/api/windows/winapi64/ole32.rs @@ -9,10 +9,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { match api { "OleInitialize" => OleInitialize(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/oleaut32.rs b/src/api/windows/winapi64/oleaut32.rs index 33004244..05de19ed 100644 --- a/src/api/windows/winapi64/oleaut32.rs +++ b/src/api/windows/winapi64/oleaut32.rs @@ -15,10 +15,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { "VariantClear" => VariantClear(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/shell32.rs b/src/api/windows/winapi64/shell32.rs index 574cbe00..e4a9f304 100644 --- a/src/api/windows/winapi64/shell32.rs +++ b/src/api/windows/winapi64/shell32.rs @@ -11,10 +11,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { "ShellExecuteA" => ShellExecuteA(emu), "ShellExecuteW" => ShellExecuteW(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/shlwapi.rs b/src/api/windows/winapi64/shlwapi.rs index 2178d111..8cf92684 100644 --- a/src/api/windows/winapi64/shlwapi.rs +++ b/src/api/windows/winapi64/shlwapi.rs @@ -14,10 +14,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { "PathFileExistsW" => PathFileExistsW(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/urlmon.rs b/src/api/windows/winapi64/urlmon.rs index d8ce830d..ffa6eba4 100644 --- a/src/api/windows/winapi64/urlmon.rs +++ b/src/api/windows/winapi64/urlmon.rs @@ -9,10 +9,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { "URLDownloadToFileA" => URLDownloadToFileA(emu), "URLDownloadToFileW" => URLDownloadToFileW(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/user32.rs b/src/api/windows/winapi64/user32.rs index 3c0f1e13..9e366b77 100644 --- a/src/api/windows/winapi64/user32.rs +++ b/src/api/windows/winapi64/user32.rs @@ -17,10 +17,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { "GetDC" => GetDC(emu), "ReleaseDC" => ReleaseDC(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/uxtheme.rs b/src/api/windows/winapi64/uxtheme.rs index dfc36861..b22affad 100644 --- a/src/api/windows/winapi64/uxtheme.rs +++ b/src/api/windows/winapi64/uxtheme.rs @@ -10,10 +10,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { "IsThemeActive" => IsThemeActive(emu), "GetThemeAppProperties" => GetThemeAppProperties(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/wincrt.rs b/src/api/windows/winapi64/wincrt.rs index 1fbb4721..90f3c613 100644 --- a/src/api/windows/winapi64/wincrt.rs +++ b/src/api/windows/winapi64/wincrt.rs @@ -37,10 +37,10 @@ pub fn gateway_by_name(api: &str, emu: &mut emu::Emu) -> String { "abort" => abort(emu), "signal" => signal(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } diff --git a/src/api/windows/winapi64/winhttp.rs b/src/api/windows/winapi64/winhttp.rs index 0c1d0839..96d57ed9 100644 --- a/src/api/windows/winapi64/winhttp.rs +++ b/src/api/windows/winapi64/winhttp.rs @@ -5,25 +5,23 @@ use crate::winapi::winapi64; pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { let api = winapi64::kernel32::guess_api_name(emu, addr); let api = api.split("!").last().unwrap_or(&api); - match api { - _ => { - if emu.cfg.skip_unimplemented == false { - if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { - serialization::Serialization::dump( - &emu, - emu.cfg.dump_filename.as_ref().unwrap(), - ); - } - - unimplemented!("atemmpt to call unimplemented API 0x{:x} {}", addr, api); + { + if !emu.cfg.skip_unimplemented { + if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { + serialization::Serialization::dump( + emu, + emu.cfg.dump_filename.as_ref().unwrap(), + ); } - log::warn!( - "calling unimplemented API 0x{:x} {} at 0x{:x}", - addr, - api, - emu.regs().rip - ); - return api.to_ascii_lowercase(); + + unimplemented!("atemmpt to call unimplemented API 0x{:x} {}", addr, api); } + log::warn!( + "calling unimplemented API 0x{:x} {} at 0x{:x}", + addr, + api, + emu.regs().rip + ); + api.to_ascii_lowercase() } } diff --git a/src/api/windows/winapi64/wininet.rs b/src/api/windows/winapi64/wininet.rs index 4e3f7af0..8daa3bb4 100644 --- a/src/api/windows/winapi64/wininet.rs +++ b/src/api/windows/winapi64/wininet.rs @@ -27,10 +27,10 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { "InternetReadFileExW" => InternetReadFileExW(emu), "InternetErrorDlg" => InternetErrorDlg(emu), _ => { - if emu.cfg.skip_unimplemented == false { + if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } @@ -315,7 +315,7 @@ fn HttpOpenRequestA(emu: &mut emu::Emu) { log::trace!("\tinvalid handle."); } - if flags & constants::INTERNET_FLAG_SECURE == 1 { + if flags & constants::INTERNET_FLAG_SECURE != 0 { log::trace!("\tssl communication."); } diff --git a/src/api/windows/winapi64/ws2_32.rs b/src/api/windows/winapi64/ws2_32.rs index 7a123e7b..e7bb6205 100644 --- a/src/api/windows/winapi64/ws2_32.rs +++ b/src/api/windows/winapi64/ws2_32.rs @@ -43,7 +43,7 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String { if !emu.cfg.skip_unimplemented { if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } @@ -171,7 +171,7 @@ fn getaddrinfo(emu: &mut emu::Emu) { }, ); // ai_protocol (IPPROTO_TCP) emu.maps - .write_qword(addrinfo_addr + 16, sockaddr_in_size as u64); // ai_addrlen + .write_qword(addrinfo_addr + 16, sockaddr_in_size); // ai_addrlen emu.maps.write_qword(addrinfo_addr + 24, canonname_addr); // ai_canonname emu.maps.write_qword(addrinfo_addr + 32, sockaddr_addr); // ai_addr diff --git a/src/arch/aarch64/regs.rs b/src/arch/aarch64/regs.rs index d1e241d9..a0b5d526 100644 --- a/src/arch/aarch64/regs.rs +++ b/src/arch/aarch64/regs.rs @@ -146,6 +146,12 @@ pub struct RegsAarch64 { pub v: [u128; 32], } +impl Default for RegsAarch64 { + fn default() -> Self { + Self::new() + } +} + impl RegsAarch64 { pub fn new() -> Self { Self { diff --git a/src/arch/x86/flags.rs b/src/arch/x86/flags.rs index f10fe933..40272864 100644 --- a/src/arch/x86/flags.rs +++ b/src/arch/x86/flags.rs @@ -473,7 +473,7 @@ impl Flags { if flags.f_of { fs.push_str("OF "); } - fs.push_str("]"); + fs.push(']'); log::trace!("\t{} flags: 0x{:x} {}", pos, flags.dump(), fs); } @@ -1249,7 +1249,7 @@ impl Flags { return value0 & 0xff; } - let result = ((value0 << count) & 0xff) as u64; + let result = (value0 << count) & 0xff ; self.f_cf = if count <= 8 { ((value0 >> (8 - count)) & 0x1) == 0x1 @@ -1273,7 +1273,7 @@ impl Flags { return value0 & 0xffff; } - let result = ((value0 << count) & 0xffff) as u64; + let result = (value0 << count) & 0xffff ; self.f_cf = if count <= 16 { ((value0 >> (16 - count)) & 0x1) == 0x1 @@ -1297,7 +1297,7 @@ impl Flags { return value0 & 0xffff_ffff; } - let result = ((value0 << count) & 0xffff_ffff) as u64; + let result = (value0 << count) & 0xffff_ffff ; self.f_cf = if count <= 32 { ((value0 >> (32 - count)) & 0x1) == 0x1 @@ -1345,7 +1345,7 @@ impl Flags { } let count = value1 & 0x3f; - let result = (value0 << count) & 0xffffffffffffffff; + let result = value0 << count ; self.f_cf = ((value0 >> (64 - count)) & 0x1) == 0x1; self.f_of = (self.f_cf as u64 ^ (result >> 63)) == 0x1; self.calc_flags(result, 64); @@ -1393,7 +1393,7 @@ impl Flags { // TODO: update shl1 the same as shl2 pub fn shl1p64(&mut self, value: u64) -> u64 { - let result = (value << 1) & 0xffffffffffffffff; + let result = value << 1 ; self.f_cf = ((value >> 63) & 0x1) == 0x1; self.f_of = (self.f_cf as u64 ^ (result >> 63)) == 0x1; self.calc_flags(result, 64); @@ -1430,7 +1430,7 @@ impl Flags { return value0 & 0xff; } - let result = ((value0 >> count) & 0xff) as u64; + let result = (value0 >> count) & 0xff ; self.f_cf = if count <= 8 { ((value0 >> (count - 1)) & 0x1) == 1 @@ -1454,7 +1454,7 @@ impl Flags { return value0 & 0xffff; } - let result = ((value0 >> count) & 0xffff) as u64; + let result = (value0 >> count) & 0xffff ; self.f_cf = if count <= 16 { ((value0 >> (count - 1)) & 0x1) == 1 @@ -1478,7 +1478,7 @@ impl Flags { return value0 & 0xffff_ffff; } - let result = ((value0 >> count) & 0xffff_ffff) as u64; + let result = (value0 >> count) & 0xffff_ffff ; self.f_cf = if count <= 32 { ((value0 >> (count - 1)) & 0x1) == 1 @@ -1526,7 +1526,7 @@ impl Flags { } let count = value1 & 0x3f; - let result = (value0 >> count) & 0xffffffffffffffff; + let result = value0 >> count ; self.f_cf = ((value0 >> (count - 1)) & 0x1) == 0x1; self.f_of = (((result << 1) ^ result) >> 63 & 0x1) == 0x1; self.calc_flags(result, 64); @@ -1573,7 +1573,7 @@ impl Flags { } pub fn shr1p64(&mut self, value: u64) -> u64 { - let result = (value >> 1) & 0xffffffffffffffff; + let result = value >> 1 ; self.f_cf = (value & 0x1) == 0x1; self.f_of = (((result << 1) ^ result) >> 63) == 0x1; self.calc_flags(result, 64); @@ -1656,8 +1656,8 @@ impl Flags { self.f_of = false; } - let res = (uresult & 0xffff) as u64; - res + + (uresult & 0xffff) as u64 } pub fn imul8p2(&mut self, value0: u64, value1: u64) -> u64 { @@ -1672,8 +1672,8 @@ impl Flags { self.f_of = false; } - let res = (uresult & 0xff) as u64; - res + + (uresult & 0xff) as u64 } pub fn rcr_of_and_cf(&mut self, value0: u64, value1: u64, sz: u32) { @@ -1754,7 +1754,7 @@ impl Flags { let msb = (res >> 63) & 1; self.f_of = self.f_cf ^ (msb != 0); } - return res as u64; + res as u64 } else { let pow = (1u64 << sz) - 1; let extended = ((value0 & pow) << 1) | (self.f_cf as u64); @@ -1766,7 +1766,7 @@ impl Flags { let msb = (res >> (sz - 1)) & 1; self.f_of = self.f_cf ^ (msb != 0); } - return res; + res } } @@ -1852,7 +1852,7 @@ impl Flags { // CF = least significant bit of the result after the rotate self.f_cf = if count != 0 { - ((res >> 0) & 0x1) == 1 + (res & 0x1) == 1 } else { self.f_cf // unchanged }; diff --git a/src/arch/x86/fpu.rs b/src/arch/x86/fpu.rs index b189cb93..098c4615 100644 --- a/src/arch/x86/fpu.rs +++ b/src/arch/x86/fpu.rs @@ -21,6 +21,12 @@ pub struct FPUState { pub reserved2: [u8; 224], // Reserved } +impl Default for FPUState { + fn default() -> Self { + Self::new() + } +} + impl FPUState { pub fn new() -> Self { Self { @@ -261,11 +267,11 @@ impl FPU { } pub fn set_st(&mut self, i: usize, value: f64) { - self.st.get_mut(i).map(|st| st.set_f64(value)); + if let Some(st) = self.st.get_mut(i) { st.set_f64(value) } } pub fn set_st_u80(&mut self, i: usize, value: u128) { - self.st.get_mut(i).map(|st| st.set(value)); + if let Some(st) = self.st.get_mut(i) { st.set(value) } } // only use from test.rs @@ -289,11 +295,11 @@ impl FPU { } pub fn get_st_u80(&mut self, i: usize) -> u128 { - return self.st.get(i).get(); + self.st.get(i).get() } pub fn get_st(&mut self, i: usize) -> f64 { - return self.st.get(i).get_f64(); + self.st.get(i).get_f64() } pub fn xchg_st(&mut self, i: usize) { @@ -302,38 +308,38 @@ impl FPU { } pub fn clear_st(&mut self, i: usize) { - self.st.get_mut(i).map(|st| st.set(0)); + if let Some(st) = self.st.get_mut(i) { st.set(0) } } pub fn neg_st(&mut self, i: usize) { - self.st.get_mut(i).map(|st| st.neg()); + if let Some(st) = self.st.get_mut(i) { st.neg() } } pub fn move_to_st0(&mut self, i: usize) { let v = self.st.get(i).get(); - self.st.get_mut(0).map(|st| st.set(v)); + if let Some(st) = self.st.get_mut(0) { st.set(v) } } pub fn add_to_st0(&mut self, i: usize) { let v = self.st.get(i); - self.st.get_mut(0).map(|st| st.add(v)); + if let Some(st) = self.st.get_mut(0) { st.add(v) } } pub fn add(&mut self, i: usize, j: usize) { let v = self.st.get(j); - self.st.get_mut(i).map(|st| st.add(v)); + if let Some(st) = self.st.get_mut(i) { st.add(v) } } pub fn sub(&mut self, i: usize, j: usize) { let v = self.st.get(j); - self.st.get_mut(i).map(|st| st.sub(v)); + if let Some(st) = self.st.get_mut(i) { st.sub(v) } } pub fn subr(&mut self, i: usize, j: usize) { - let a = self.st.get(i).clone(); - let mut b = self.st.get(j).clone(); + let a = self.st.get(i); + let mut b = self.st.get(j); b.sub(a); - self.st.get_mut(i).map(|st| st.set(b.get())); + if let Some(st) = self.st.get_mut(i) { st.set(b.get()) } } pub fn push_f64(&mut self, value: f64) { @@ -357,30 +363,30 @@ impl FPU { } pub fn pop2(&mut self) -> u128 { - let v = match self.st.pop() { + + match self.st.pop() { Some(f80val) => f80val.get(), None => 0, - }; - v + } } pub fn pop_f64(&mut self) -> f64 { - let v = match self.st.pop() { + + match self.st.pop() { Some(f80val) => f80val.get_f64(), None => 0.0, - }; - v + } } pub fn fyl2x(&mut self) { let v = self.st.get(1).get_f64() * self.st.get(0).get_f64().log2(); - self.st.get_mut(1).map(|st| st.set_f64(v)); + if let Some(st) = self.st.get_mut(1) { st.set_f64(v) } self.st.pop(); } pub fn fyl2xp1(&mut self) { let v = self.st.get(1).get_f64() * (self.st.get(0).get_f64().log2() + 1.0); - self.st.get_mut(1).map(|st| st.set_f64(v)); + if let Some(st) = self.st.get_mut(1) { st.set_f64(v) } self.st.pop(); } @@ -431,13 +437,13 @@ impl FPU { pub fn set_streg_f80(&mut self, reg: Register, value: u128) { //println!("{:?} {}", reg, value); let idx = self.reg_to_idx(reg); - self.st.get_mut(idx).map(|st| st.set(value)); + if let Some(st) = self.st.get_mut(idx) { st.set(value) } } pub fn set_streg(&mut self, reg: Register, value: f64) { //println!("{:?} {}", reg, value); let idx = self.reg_to_idx(reg); - self.st.get_mut(idx).map(|st| st.set_f64(value)); + if let Some(st) = self.st.get_mut(idx) { st.set_f64(value) } } pub fn frexp(&self, value: f64) -> (f64, i32) { @@ -484,10 +490,10 @@ impl FPU { state.rdp = self.operand_ptr; state.mxcsr = self.mxcsr; state.mxcsr_mask = self.mxcsr; - state.st = self.st.clone(); + state.st = self.st; //state.st = self.convert_st(self.st.clone()); - state.xmm = self.xmm.clone(); - return state; + state.xmm = self.xmm; + state } pub fn fxrstor(&mut self, state: FPUState) { @@ -502,7 +508,7 @@ impl FPU { // Convert the packed 128-bit ST registers back to f64 values for i in 0..8 { - self.st.get_mut(i).map(|st| st.fix()); + if let Some(st) = self.st.get_mut(i) { st.fix() } } self.xmm = state.xmm; diff --git a/src/arch/x86/fpu/f80.rs b/src/arch/x86/fpu/f80.rs index b32da749..5a9a91f3 100644 --- a/src/arch/x86/fpu/f80.rs +++ b/src/arch/x86/fpu/f80.rs @@ -26,6 +26,12 @@ pub struct F80 { pub st: u128, } +impl Default for F80 { + fn default() -> Self { + Self::new() + } +} + impl F80 { pub fn new() -> Self { F80 { st: 0 } @@ -93,7 +99,7 @@ impl F80 { } pub fn fix(&mut self) { - self.st = self.st & FPU_80_BITS_MAX; + self.st &= FPU_80_BITS_MAX; } pub fn is_negative(&self) -> bool { @@ -157,7 +163,7 @@ impl F80 { } fn get_mantissa_with_integer_bit(&self) -> u64 { - let mantissa = (self.st & MANTISSA_MASK_NOINT) >> 0; + let mantissa = self.st & MANTISSA_MASK_NOINT ; let int_bit = ((self.st & INT_BIT_MASK) >> 63) as u64; (mantissa as u64) | (int_bit << 63) } diff --git a/src/arch/x86/fpu/fpu_stack.rs b/src/arch/x86/fpu/fpu_stack.rs index 580ee11f..d4e05394 100644 --- a/src/arch/x86/fpu/fpu_stack.rs +++ b/src/arch/x86/fpu/fpu_stack.rs @@ -11,6 +11,12 @@ pub struct FPUStack { invalid_flag: u8, } +impl Default for FPUStack { + fn default() -> Self { + Self::new() + } +} + impl FPUStack { pub fn new() -> Self { Self { @@ -93,7 +99,7 @@ impl FPUStack { if self.depth == 0 { return None; } - let val = self.regs[self.top as usize].clone(); + let val = self.regs[self.top as usize]; self.top = (self.top.wrapping_add(1)) & 7; self.depth -= 1; //println!("depth decremented to {}", self.depth); @@ -102,7 +108,7 @@ impl FPUStack { // only for tests.rs, this acces directly to index, it's not using self.top pub fn peek(&self, n: usize) -> F80 { - self.regs[n].clone() + self.regs[n] } pub fn get(&mut self, n: usize) -> F80 { diff --git a/src/arch/x86/regs.rs b/src/arch/x86/regs.rs index 917aa95a..e57a9a7f 100644 --- a/src/arch/x86/regs.rs +++ b/src/arch/x86/regs.rs @@ -902,7 +902,8 @@ impl Regs64 { } pub fn get_xmm_reg(&self, reg: Register) -> u128 { - let value = match reg { + + match reg { Register::XMM0 => self.xmm0, Register::XMM1 => self.xmm1, Register::XMM2 => self.xmm2, @@ -929,8 +930,7 @@ impl Regs64 { Register::MM7 => self.mm7, _ => unimplemented!("SSE XMM register: {:?} ", reg), - }; - value + } } pub fn set_xmm_reg(&mut self, reg: Register, value: u128) { @@ -1072,7 +1072,8 @@ impl Regs64 { } pub fn get_ymm_reg(&self, reg: Register) -> U256 { - let value = match reg { + + match reg { Register::YMM0 => self.ymm0, Register::YMM1 => self.ymm1, Register::YMM2 => self.ymm2, @@ -1091,8 +1092,7 @@ impl Regs64 { Register::YMM15 => self.ymm15, _ => unimplemented!("SSE YMM register: {:?} ", reg), - }; - value + } } pub fn set_ymm_reg(&mut self, reg: Register, value: U256) { @@ -1142,7 +1142,9 @@ impl Regs64 { } pub fn get_reg(&self, reg: Register) -> u64 { - let value = match reg { + + + match reg { // 64bits Register::RAX => self.rax, Register::RBX => self.rbx, @@ -1250,9 +1252,7 @@ impl Regs64 { Register::CR5 => 0, _ => unimplemented!("unimplemented register {:?}", reg), - }; - - value + } } pub fn set_reg(&mut self, reg: Register, value: u64) { diff --git a/src/config.rs b/src/config.rs index 63839749..23426c3b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -203,7 +203,7 @@ impl Config { if !path.ends_with('/') { path.push('/'); } - path.push_str(&filename); + path.push_str(filename); path } } diff --git a/src/debug/console.rs b/src/debug/console.rs index 5a287c81..99b2afe1 100644 --- a/src/debug/console.rs +++ b/src/debug/console.rs @@ -1032,7 +1032,7 @@ impl Console { "dump" => { if emu.cfg.dump_filename.is_some() { serialization::Serialization::dump( - &emu, + emu, emu.cfg.dump_filename.as_ref().unwrap(), ); } @@ -1126,7 +1126,7 @@ impl Console { } else if cmd.starts_with("m ") { let parts: Vec<&str> = cmd.split_whitespace().collect(); if parts.len() >= 2 { - emu.maps.print_maps_keyword(&parts[1]); + emu.maps.print_maps_keyword(parts[1]); } } else if cmd.starts_with("r2 ") { let parts: Vec<&str> = cmd.split_whitespace().collect(); diff --git a/src/debug/definitions.rs b/src/debug/definitions.rs index 6d11a6ec..e5ff3be1 100644 --- a/src/debug/definitions.rs +++ b/src/debug/definitions.rs @@ -42,9 +42,9 @@ where { let s: String = serde::Deserialize::deserialize(deserializer)?; if s.starts_with("0x") { - u64::from_str_radix(&s[2..], 16).map_err(|e| serde::de::Error::custom(e)) + u64::from_str_radix(&s[2..], 16).map_err(serde::de::Error::custom) } else { - s.parse::().map_err(|e| serde::de::Error::custom(e)) + s.parse::().map_err(serde::de::Error::custom) } } diff --git a/src/debug/script.rs b/src/debug/script.rs index ffa25e4d..afdfd520 100644 --- a/src/debug/script.rs +++ b/src/debug/script.rs @@ -486,7 +486,7 @@ impl Script { }; emu.maps .create_map(args[1], addr, sz, Permission::READ_WRITE_EXECUTE); - log::trace!("allocated {} at 0x{:x} sz: {}", &args[1], addr, sz); + log::trace!("allocated {} at 0x{:x} sz: {}", args[1], addr, sz); self.result = addr; } "mca" => { @@ -505,7 +505,7 @@ impl Script { }; emu.maps .create_map(args[1], addr, sz, Permission::READ_WRITE_EXECUTE); - log::trace!("allocated {} at 0x{:x} sz: {}", &args[1], addr, sz); + log::trace!("allocated {} at 0x{:x} sz: {}", args[1], addr, sz); } "ml" => { // ml @@ -653,7 +653,7 @@ impl Script { } }; - if sz <= 0 { + if sz == 0 { log::trace!("error in line {}, bad size", i); return; } @@ -796,7 +796,7 @@ impl Script { .collect::>() .join(" "); - if emu.maps.search_spaced_bytes(&bytes, args[1]).len() == 0 { + if emu.maps.search_spaced_bytes(&bytes, args[1]).is_empty() { log::trace!("bytes not found."); } } diff --git a/src/debug/tracing.rs b/src/debug/tracing.rs index 6bf264ad..9ef1fad5 100644 --- a/src/debug/tracing.rs +++ b/src/debug/tracing.rs @@ -186,7 +186,7 @@ pub fn trace_instruction(emu: &Emu, instruction_count: u64) { let now = Instant::now(); let should_log = LAST_IPS_LOG .with(|l| l.get()) - .map_or(true, |last| now.duration_since(last).as_secs() >= 1); + .is_none_or(|last| now.duration_since(last).as_secs() >= 1); if should_log { log::info!( "⚡ IPS: {:.2} ({} instructions in {:.2}s)", diff --git a/src/emu/disassemble/mod.rs b/src/emu/disassemble/mod.rs index 9bd4c0a1..1b7b2035 100644 --- a/src/emu/disassemble/mod.rs +++ b/src/emu/disassemble/mod.rs @@ -61,6 +61,12 @@ pub struct InstructionCache { current_decode_idx: usize, } +impl Default for InstructionCache { + fn default() -> Self { + Self::new() + } +} + impl InstructionCache { pub fn new() -> Self { InstructionCache { diff --git a/src/emu/emu_context.rs b/src/emu/emu_context.rs index c3d08fdd..dcffdf0d 100644 --- a/src/emu/emu_context.rs +++ b/src/emu/emu_context.rs @@ -20,7 +20,7 @@ fn format_decoded(decoded: &DecodedInstruction) -> String { } thread_local! { - static CURRENT_EMU: RefCell> = RefCell::new(None); + static CURRENT_EMU: RefCell> = const { RefCell::new(None) }; } pub fn with_current_emu(f: F) -> Option @@ -40,7 +40,7 @@ where // (e.g. the run loop). That is the fragile part of this global- // pointer pattern — see the module note in the issue. It is only // used for read-only logging of emulator state. - .and_then(|ptr| unsafe { ptr.as_ref().map(|emu| f(emu)) }) + .and_then(|ptr| unsafe { ptr.as_ref().map(f) }) }) } diff --git a/src/emu/execution/mod.rs b/src/emu/execution/mod.rs index cb9cfe3d..193fa890 100644 --- a/src/emu/execution/mod.rs +++ b/src/emu/execution/mod.rs @@ -778,7 +778,7 @@ impl Emu { self.max_pos = Some(end_pos); let r = self.run(None); self.max_pos = None; - return r; + r } /// Start or continue emulation. @@ -1284,8 +1284,8 @@ impl Emu { for i in 0..16u64 { let addr = self.regs().rsp.wrapping_add(i * 8); if let Some(v) = self.maps.read_qword(addr) { - if (v >= 0x180000000 && v < 0x180400000) - || (v >= 0x7ff000000000 && v < 0x7ff800000000) + if (0x180000000..0x180400000).contains(&v) + || (0x7ff000000000..0x7ff800000000).contains(&v) { let m = self.maps.get_addr_name(v).unwrap_or("?"); log::trace!(" rsp+0x{:x}: 0x{:x} ({})", i * 8, v, m); @@ -1582,8 +1582,8 @@ impl Emu { for i in 0..8u64 { let a = self.regs().rsp.wrapping_add(i * 8); if let Some(v) = self.maps.read_qword(a) { - if (v >= 0x180000000 && v < 0x180400000) - || (v >= 0x7ff000000000 && v < 0x7ff800000000) + if (0x180000000..0x180400000).contains(&v) + || (0x7ff000000000..0x7ff800000000).contains(&v) { log::trace!(" ret[+0x{:x}] = 0x{:x}", i * 8, v); } diff --git a/src/emu/initialization.rs b/src/emu/initialization.rs index d2d7ffa8..14def3cd 100644 --- a/src/emu/initialization.rs +++ b/src/emu/initialization.rs @@ -402,7 +402,7 @@ impl Emu { } // loading banzai on 32bits - if self.cfg.arch.is_64bits() == false { + if !self.cfg.arch.is_64bits() { let mut rdr = ReaderBuilder::new() .from_path(format!("{}/banzai.csv", self.cfg.maps_folder)) .expect("banzai.csv not found on maps folder, please download last mwemu maps"); @@ -451,8 +451,8 @@ impl Emu { self.maps.is_64bits = self.cfg.arch.is_64bits(); // Ensure thread context matches the target architecture - if self.cfg.arch.is_aarch64() { - if matches!( + if self.cfg.arch.is_aarch64() + && matches!( self.threads[self.current_thread_id].arch, crate::threading::context::ArchThreadState::X86 { .. } ) { @@ -460,7 +460,6 @@ impl Emu { self.threads[self.current_thread_id] = crate::threading::context::ThreadContext::new(id, self.cfg.arch); } - } // Ensure arch_state matches the target architecture if self.cfg.arch.is_aarch64() && matches!(self.arch_state, super::ArchState::X86 { .. }) { @@ -1196,7 +1195,7 @@ impl Emu { for dll in &base { self.ensure_maps_dll(dll); // fetch from the symbol server if missing let filepath = self.cfg.get_maps_folder(dll); - log::debug!("mapping base lib64: {}", &filepath); + log::debug!("mapping base lib64: {}", filepath); assert!( std::path::Path::new(&filepath).exists(), "required base DLL not found: {} (maps_folder={})", @@ -1231,7 +1230,7 @@ impl Emu { for dll in dependencies { self.ensure_maps_dll(&dll); // fetch from the symbol server if missing let filepath = self.cfg.get_maps_folder(&dll); - log::debug!("mapping depenency {}", &filepath); + log::debug!("mapping depenency {}", filepath); assert!( std::path::Path::new(&filepath).exists(), "required dependency DLL not found: {} (maps_folder={})", @@ -1250,13 +1249,13 @@ impl Emu { // Stage 3: dynamic linking base + deps for dll in &metadata { - log::debug!("dynamic linking {}", &dll.name); + log::debug!("dynamic linking {}", dll.name); peb64::dynamic_link_module(dll.base, dll.pe64.get_pe_off(), &dll.name, self); } // Stage 3: IAT binding for base + deps (relocs already applied in `map_dll_pe64`). for dll in metadata.iter_mut() { - log::debug!("iat binding {}", &dll.name); + log::debug!("iat binding {}", dll.name); dll.pe64.iat_binding(&dll.raw, self, dll.base); dll.pe64.delay_load_binding(&dll.raw, self, dll.base); } diff --git a/src/emu/instruction_pointer.rs b/src/emu/instruction_pointer.rs index 4d984b4f..c7c91070 100644 --- a/src/emu/instruction_pointer.rs +++ b/src/emu/instruction_pointer.rs @@ -145,15 +145,15 @@ impl Emu { if !self.ld_bootstrap { let symbol = self.resolve_unix_x64_symbol(addr); if symbol == "__libc_start_main" { - let section_name = name; - return self.intercept_unix_x64_api_call(addr, §ion_name.to_string()); + let section_name = name.to_string(); + return self.intercept_unix_x64_api_call(addr, §ion_name); } } self.regs_mut().rip = addr; return true; } else if self.os.is_linux() || self.os.is_macos() { - let section_name = name; - return self.intercept_unix_x64_api_call(addr, §ion_name.to_string()); + let section_name = name.to_string(); + return self.intercept_unix_x64_api_call(addr, §ion_name); } else { if self.cfg.verbose >= 2 && !self.cfg.emulate_winapi { log::trace!("/!\\ changing RIP to {} ", name); @@ -167,11 +167,10 @@ impl Emu { // surface. if self.cfg.emulate_winapi { let api_name = winapi64::kernel32::guess_api_name(self, addr); - if !api_name.is_empty() { - if self.cfg.verbose >= 1 { + if !api_name.is_empty() + && self.cfg.verbose >= 1 { log_red!(self, "emulating {}", api_name); } - } self.regs_mut().rip = addr; return true; } @@ -262,11 +261,10 @@ impl Emu { // emulate winapi mode if self.cfg.emulate_winapi { let api_name = winapi64::kernel32::guess_api_name(self, addr); - if !api_name.is_empty() { - if self.cfg.verbose >= 1 { + if !api_name.is_empty() + && self.cfg.verbose >= 1 { log_red!(self, "emulating {}", api_name); } - } self.regs_aarch64_mut().pc = addr; return true; } @@ -369,11 +367,10 @@ impl Emu { // winapi emulation case if self.cfg.emulate_winapi { let api_name = winapi32::kernel32::guess_api_name(self, addr as u32); - if !api_name.is_empty() { - if self.cfg.verbose >= 1 { + if !api_name.is_empty() + && self.cfg.verbose >= 1 { log_red!(self, "emulating {}", api_name); } - } self.regs_mut().set_eip(addr); return true; } diff --git a/src/emu/loaders/elf.rs b/src/emu/loaders/elf.rs index c12dd603..820b3035 100644 --- a/src/emu/loaders/elf.rs +++ b/src/emu/loaders/elf.rs @@ -254,7 +254,7 @@ impl Emu { let mut cache: HashMap = HashMap::new(); // Save emulator state so the load phase stays transparent. - let saved_regs = self.regs().clone(); + let saved_regs = *self.regs(); let saved_pos = self.pos; for (patch_addr, resolver) in irelative { diff --git a/src/emu/loaders/macho.rs b/src/emu/loaders/macho.rs index b4210f6e..770ed66e 100644 --- a/src/emu/loaders/macho.rs +++ b/src/emu/loaders/macho.rs @@ -99,10 +99,8 @@ impl Emu { let mem = self .maps .create_map(&map_name, seg_addr, seg.vmsize, perm) - .expect(&format!( - "cannot create map for dylib segment '{}'", - map_name - )); + .unwrap_or_else(|_| panic!("cannot create map for dylib segment '{}'", + map_name)); if !seg.data.is_empty() { mem.force_write_bytes(seg_addr, &seg.data); diff --git a/src/emu/maps.rs b/src/emu/maps.rs index 551e4e80..65f3bbba 100644 --- a/src/emu/maps.rs +++ b/src/emu/maps.rs @@ -117,7 +117,7 @@ impl Emu { if file.name().ends_with('/') { // Create directory - fs::create_dir_all(&outpath)?; + fs::create_dir_all(outpath)?; } else { // Create parent directories if they don't exist if let Some(p) = outpath.parent() { @@ -127,7 +127,7 @@ impl Emu { } // Extract file - let mut outfile = fs::File::create(&outpath)?; + let mut outfile = fs::File::create(outpath)?; io::copy(&mut file, &mut outfile)?; } } @@ -139,10 +139,7 @@ impl Emu { /// Get the base address of the code, if code map doesn't exist yet will return None. pub fn get_base_addr(&self) -> Option { //TODO: fix this, now there is no code map. - let map = match self.maps.get_map_by_name("code") { - Some(m) => m, - None => return None, - }; + let map = self.maps.get_map_by_name("code")?; Some(map.get_base()) } diff --git a/src/emu/memory.rs b/src/emu/memory.rs index 73d5b4b9..a2116017 100644 --- a/src/emu/memory.rs +++ b/src/emu/memory.rs @@ -183,10 +183,7 @@ impl Emu { 64 => match self.maps.read_qword(addr) { Some(v) => { if self.cfg.trace_mem { - let name = match self.maps.get_addr_name(addr) { - Some(n) => n, - None => "not mapped", - }; + let name = self.maps.get_addr_name(addr).unwrap_or("not mapped"); let memory_operation = MemoryOperation { pos: self.pos, rip: self.pc(), @@ -218,7 +215,7 @@ impl Emu { let name = self .maps .get_addr_name(addr) - .unwrap_or_else(|| "not mapped"); + .unwrap_or("not mapped"); let memory_operation = MemoryOperation { pos: self.pos, rip: self.pc(), @@ -250,7 +247,7 @@ impl Emu { let name = self .maps .get_addr_name(addr) - .unwrap_or_else(|| "not mapped"); + .unwrap_or("not mapped"); let memory_operation = MemoryOperation { pos: self.pos, rip: self.pc(), @@ -282,7 +279,7 @@ impl Emu { let name = self .maps .get_addr_name(addr) - .unwrap_or_else(|| "not mapped"); + .unwrap_or("not mapped"); let memory_operation = MemoryOperation { pos: self.pos, rip: self.pc(), @@ -330,7 +327,7 @@ impl Emu { panic!("writting in non mapped memory"); }*/ - let name = self.maps.get_addr_name(addr).unwrap_or_else(|| "error"); + let name = self.maps.get_addr_name(addr).unwrap_or("error"); if name == "code" { if self.cfg.verbose >= 1 { diff --git a/src/emu/object_handle/file_handle.rs b/src/emu/object_handle/file_handle.rs index 925e40ac..be8d1f48 100644 --- a/src/emu/object_handle/file_handle.rs +++ b/src/emu/object_handle/file_handle.rs @@ -100,7 +100,7 @@ pub fn init_file_system>(file_root: Option

) -> io::Result<()> // Relative to executable directory let exe_dir = env::current_exe()? .parent() - .ok_or_else(|| io::Error::new(ErrorKind::Other, "Failed to get exe directory"))? + .ok_or_else(|| io::Error::other("Failed to get exe directory"))? .to_path_buf(); exe_dir.join(path) } @@ -108,7 +108,7 @@ pub fn init_file_system>(file_root: Option

) -> io::Result<()> // Default: "file_root" folder next to executable let exe_dir = env::current_exe()? .parent() - .ok_or_else(|| io::Error::new(ErrorKind::Other, "Failed to get exe directory"))? + .ok_or_else(|| io::Error::other("Failed to get exe directory"))? .to_path_buf(); exe_dir.join("file_root") }; @@ -129,7 +129,7 @@ pub fn init_file_system>(file_root: Option

) -> io::Result<()> FILE_SYSTEM .set(fs) - .map_err(|_| io::Error::new(ErrorKind::Other, "FileSystem already initialized")) + .map_err(|_| io::Error::other("FileSystem already initialized")) } // Represents the state and metadata associated with a Windows file handle @@ -242,11 +242,7 @@ impl FileHandle { let bytes_read = f.read(buffer)?; self.file_position += bytes_read as u64; // Update EOF flag if necessary - if self.file_position >= self.file_size && bytes_read == 0 { - self.is_eof = true; - } else { - self.is_eof = false; - } + self.is_eof = self.file_position >= self.file_size && bytes_read == 0; Ok(bytes_read) } else { Err(io::Error::new( @@ -566,7 +562,7 @@ impl FileSystem { if abs_path.starts_with(&abs_base) { let remainder = abs_path .strip_prefix(&abs_base) - .map_err(|_| io::Error::new(ErrorKind::Other, "Failed to strip prefix")) + .map_err(|_| io::Error::other("Failed to strip prefix")) .unwrap(); Some(PathBuf::from(remainder)) } else { @@ -581,6 +577,12 @@ pub struct FileSystemBuilder { initial_mappings: Vec<(WindowsPath, PathBuf)>, } +impl Default for FileSystemBuilder { + fn default() -> Self { + Self::new() + } +} + impl FileSystemBuilder { pub fn new() -> Self { Self { @@ -610,7 +612,7 @@ impl FileSystemBuilder { println!("Failed to initialize filesystem with err: {}", err); println!( "Please check the file location: {}", - &root.to_str().unwrap() + root.to_str().unwrap() ); return Err(err); } diff --git a/src/emu/object_handle/mod.rs b/src/emu/object_handle/mod.rs index 8cea1161..7cf310f8 100644 --- a/src/emu/object_handle/mod.rs +++ b/src/emu/object_handle/mod.rs @@ -24,6 +24,12 @@ pub struct HandleManagement { handle_types: Slab, } +impl Default for HandleManagement { + fn default() -> Self { + Self::new() + } +} + impl HandleManagement { pub fn new() -> Self { Self { diff --git a/src/emu/object_handle/windows_path.rs b/src/emu/object_handle/windows_path.rs index e88afef1..b12491ad 100644 --- a/src/emu/object_handle/windows_path.rs +++ b/src/emu/object_handle/windows_path.rs @@ -69,7 +69,7 @@ impl WindowsPath { } // Parse folders - while let Some(c) = chars.next() { + for c in chars { if c == '\\' || c == '/' { if !current_folder.is_empty() { path.folders.push_back(current_folder.to_ascii_lowercase()); @@ -115,8 +115,7 @@ impl WindowsPath { self.to_string().encode_utf16().collect() } - /// Returns the path as a string - pub fn to_string(&self) -> String { + fn as_windows_string(&self) -> String { let mut path = String::new(); if let Some(drive) = self.drive { @@ -149,7 +148,7 @@ impl WindowsPath { if self.is_relative() { self.to_string() } else { - format!("{}{}", UNC_PREFIX, self.to_string()) + format!("{}{}", UNC_PREFIX, self) } } @@ -270,7 +269,7 @@ impl Default for WindowsPath { impl std::fmt::Display for WindowsPath { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.to_string()) + write!(f, "{}", self.as_windows_string()) } } diff --git a/src/emu/operands.rs b/src/emu/operands.rs index 690e0ebd..20a654af 100644 --- a/src/emu/operands.rs +++ b/src/emu/operands.rs @@ -293,7 +293,9 @@ impl Emu { } 0x58 => { // Get or create static TLS array (for __declspec(thread) variables) - let static_tls = match self.maps.get_mem2("static_tls_array") { + + + match self.maps.get_mem2("static_tls_array") { Some(mem) => mem.get_base(), None => { // This should be sized based on the number of modules with .tls sections @@ -307,9 +309,7 @@ impl Emu { tls_array } - }; - - static_tls + } } _ => { // Fall back to reading from actual TEB memory so that real ntdll code @@ -409,7 +409,7 @@ impl Emu { let name = self .maps .get_addr_name(mem_addr) - .unwrap_or_else(|| "not mapped"); + .unwrap_or("not mapped"); let memory_operation = MemoryOperation { pos: self.pos, rip: self.regs().rip, @@ -699,7 +699,7 @@ impl Emu { let should_flush = self .maps .get_mem_by_addr(mem_addr) - .map_or(false, |mem1| mem1.can_execute()); + .is_some_and(|mem1| mem1.can_execute()); if should_flush { let idx = self.x86_instruction_cache_ref().get_index_of(mem_addr, 0); self.x86_instruction_cache().flush_cache_line(idx); @@ -852,7 +852,7 @@ impl Emu { let name = self .maps .get_addr_name(mem_addr) - .unwrap_or_else(|| "not mapped"); + .unwrap_or("not mapped"); let memory_operation = MemoryOperation { pos: self.pos, rip: self.regs().rip, @@ -1038,9 +1038,9 @@ impl Emu { } let bytes = self.maps.read_bytes_array::<32>(mem_addr); - let value = regs64::U256::from_little_endian(&bytes); + - value + regs64::U256::from_little_endian(&bytes) } else { regs64::U256::from(mem_addr) } diff --git a/src/emu/stack.rs b/src/emu/stack.rs index 8f136c7b..70366676 100644 --- a/src/emu/stack.rs +++ b/src/emu/stack.rs @@ -13,7 +13,7 @@ impl Emu { let name = self .maps .get_addr_name(self.regs().get_esp()) - .unwrap_or_else(|| "not mapped"); + .unwrap_or("not mapped"); let memory_operation = MemoryOperation { pos: self.pos, rip: self.regs().rip, @@ -90,7 +90,7 @@ impl Emu { if self.cfg.trace_mem { let pc = self.pc(); - let name = self.maps.get_addr_name(sp).unwrap_or_else(|| "not mapped"); + let name = self.maps.get_addr_name(sp).unwrap_or("not mapped"); let memory_operation = MemoryOperation { pos: self.pos, rip: pc, @@ -191,7 +191,7 @@ impl Emu { let name = self .maps .get_addr_name(self.regs().get_esp()) - .unwrap_or_else(|| "not mapped"); + .unwrap_or("not mapped"); let read_operation = MemoryOperation { pos: self.pos, rip: self.regs().rip, @@ -262,7 +262,7 @@ impl Emu { if self.cfg.trace_mem { let pc = self.pc(); - let name = self.maps.get_addr_name(sp).unwrap_or_else(|| "not mapped"); + let name = self.maps.get_addr_name(sp).unwrap_or("not mapped"); let read_operation = MemoryOperation { pos: self.pos, rip: pc, diff --git a/src/emu/trace.rs b/src/emu/trace.rs index 93c32f7f..cbed8f66 100644 --- a/src/emu/trace.rs +++ b/src/emu/trace.rs @@ -26,11 +26,8 @@ impl Emu { pub fn capture_pre_op(&mut self) { if self.cfg.arch.is_aarch64() { let regs = *self.regs_aarch64(); - match &mut self.threads[self.current_thread_id].arch { - crate::threading::context::ArchThreadState::AArch64 { pre_op_regs, .. } => { - *pre_op_regs = regs - } - _ => {} + if let crate::threading::context::ArchThreadState::AArch64 { pre_op_regs, .. } = &mut self.threads[self.current_thread_id].arch { + *pre_op_regs = regs } } else { self.set_pre_op_regs(*self.regs()); @@ -43,11 +40,8 @@ impl Emu { pub fn capture_post_op(&mut self) { if self.cfg.arch.is_aarch64() { let regs = *self.regs_aarch64(); - match &mut self.threads[self.current_thread_id].arch { - crate::threading::context::ArchThreadState::AArch64 { post_op_regs, .. } => { - *post_op_regs = regs - } - _ => {} + if let crate::threading::context::ArchThreadState::AArch64 { post_op_regs, .. } = &mut self.threads[self.current_thread_id].arch { + *post_op_regs = regs } } else { self.set_post_op_regs(*self.regs()); @@ -301,7 +295,7 @@ impl Emu { ); } else { let w = self.maps.read_wide_string_nocrash(self.cfg.string_addr); - if w.len() == 0 { + if w.is_empty() { return; } if w.len() < 80 { diff --git a/src/emu/winver.rs b/src/emu/winver.rs index df88b75e..2e3263b7 100644 --- a/src/emu/winver.rs +++ b/src/emu/winver.rs @@ -176,7 +176,7 @@ fn winbindex_key(basename: &str, build: &str, machine_type: u64) -> Result().ok()) .unwrap_or(0); - if fallback.map_or(true, |(u, _, _)| ubr > u) { + if fallback.is_none_or(|(u, _, _)| ubr > u) { fallback = Some((ubr, ts, vsize)); } } diff --git a/src/engine/aarch64/helpers.rs b/src/engine/aarch64/helpers.rs index ca1f06cd..a28fd638 100644 --- a/src/engine/aarch64/helpers.rs +++ b/src/engine/aarch64/helpers.rs @@ -112,7 +112,7 @@ pub fn resolve_mem_addr(emu: &Emu, op: &Operand) -> (u64, Option<(usize, u64)>) let base = regs.get_x_or_sp(*base_reg as usize); let mut index = regs.get_x(*index_reg as usize); if !is_64(index_size) { - index = index & 0xffffffff; + index &= 0xffffffff; } index = apply_shift(index, *shift_style, *shift_amt as u32); (base.wrapping_add(index), None) diff --git a/src/engine/instructions/bound.rs b/src/engine/instructions/bound.rs index 882bfcf3..4cffa6be 100644 --- a/src/engine/instructions/bound.rs +++ b/src/engine/instructions/bound.rs @@ -29,7 +29,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste lower_upper_bound ); log::trace!("Bound unimplemented"); - return false; + false // https://www.felixcloutier.com/x86/bound //true } diff --git a/src/engine/instructions/call.rs b/src/engine/instructions/call.rs index 1f77744e..ad05aaf4 100644 --- a/src/engine/instructions/call.rs +++ b/src/engine/instructions/call.rs @@ -42,12 +42,12 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste ); } - if emu.regs_mut().rip == addr - 5 { - if emu.cfg.verbose >= 1 { + if emu.regs_mut().rip == addr - 5 + && emu.cfg.verbose >= 1 { log::trace!("call next instruction, prolly call/pop"); } //emu.stack_lvl[emu.stack_lvl_idx] -= 1; - } /*else { + /*else { emu.stack_lvl.push(0); emu.stack_lvl_idx += 1; }*/ @@ -76,12 +76,12 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste if !emu.stack_push64(emu.regs().rip + instruction_sz as u64) { return false; } - return emu.set_rip(addr, false); + emu.set_rip(addr, false) } else { if !emu.stack_push32(emu.regs().get_eip() as u32 + instruction_sz as u32) { return false; } - return emu.set_eip(addr, false); + emu.set_eip(addr, false) } //true } diff --git a/src/engine/instructions/fcom.rs b/src/engine/instructions/fcom.rs index fb704d9a..62018a3e 100644 --- a/src/engine/instructions/fcom.rs +++ b/src/engine/instructions/fcom.rs @@ -9,10 +9,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste ); let st0 = emu.fpu_mut().get_st(0); - let value1 = match emu.get_operand_value(ins, 1, false) { - Some(v1) => v1, - None => 0, - }; + let value1 = emu.get_operand_value(ins, 1, false).unwrap_or_default(); let st4 = emu.fpu_mut().get_st(value1 as usize); diff --git a/src/engine/instructions/fdiv.rs b/src/engine/instructions/fdiv.rs index c36ebb67..b8392729 100644 --- a/src/engine/instructions/fdiv.rs +++ b/src/engine/instructions/fdiv.rs @@ -9,10 +9,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste ); let st0 = emu.fpu_mut().get_st(0); - let value1 = match emu.get_operand_value(ins, 1, false) { - Some(v1) => v1, - None => 0, - }; + let value1 = emu.get_operand_value(ins, 1, false).unwrap_or_default(); let stn = emu.fpu_mut().get_st(value1 as usize); emu.fpu_mut().set_st(0, st0 / stn); diff --git a/src/engine/instructions/fmul.rs b/src/engine/instructions/fmul.rs index 0ab05188..8aa84387 100644 --- a/src/engine/instructions/fmul.rs +++ b/src/engine/instructions/fmul.rs @@ -9,10 +9,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste ); let st0 = emu.fpu_mut().get_st(0); - let value1 = match emu.get_operand_value(ins, 1, false) { - Some(v1) => v1, - None => 0, - }; + let value1 = emu.get_operand_value(ins, 1, false).unwrap_or_default(); let stn = emu.fpu_mut().get_st(value1 as usize); emu.fpu_mut().set_st(0, st0 * stn); diff --git a/src/engine/instructions/fsubr.rs b/src/engine/instructions/fsubr.rs index f34fcab9..e07e4c9f 100644 --- a/src/engine/instructions/fsubr.rs +++ b/src/engine/instructions/fsubr.rs @@ -10,7 +10,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste let value0 = emu.get_operand_value(ins, 0, false).unwrap_or(0) as usize; let value1 = emu.get_operand_value(ins, 1, false).unwrap_or(0) as usize; - emu.fpu_mut().subr(value0 as usize, value1 as usize); + emu.fpu_mut().subr(value0, value1); emu.sync_fpu_ip(); true } diff --git a/src/engine/instructions/int3.rs b/src/engine/instructions/int3.rs index 878726fc..cd303347 100644 --- a/src/engine/instructions/int3.rs +++ b/src/engine/instructions/int3.rs @@ -14,5 +14,5 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste if emu.seh() == 0 && emu.veh() == 0 && emu.uef() == 0 { emu.stop(); } - return true; + true } diff --git a/src/engine/instructions/jmp.rs b/src/engine/instructions/jmp.rs index d68bdab0..8ad4e957 100644 --- a/src/engine/instructions/jmp.rs +++ b/src/engine/instructions/jmp.rs @@ -18,9 +18,9 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste }; if emu.cfg.is_x64() { - return emu.set_rip(addr, false); + emu.set_rip(addr, false) } else { - return emu.set_eip(addr, false); + emu.set_eip(addr, false) } //true } diff --git a/src/engine/instructions/pcmpistri.rs b/src/engine/instructions/pcmpistri.rs index 9e9a8f5e..d93ccc6a 100644 --- a/src/engine/instructions/pcmpistri.rs +++ b/src/engine/instructions/pcmpistri.rs @@ -15,7 +15,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, _instruction_sz: usize, _rep_st Some(v) => v, None => return false, }; - let imm = ins.immediate8() as u8; + let imm = ins.immediate8(); let is_word = imm & 1 != 0; let is_signed = imm & 2 != 0; diff --git a/src/engine/instructions/pcmpistrm.rs b/src/engine/instructions/pcmpistrm.rs index 6ab5daf6..8e1f36a7 100644 --- a/src/engine/instructions/pcmpistrm.rs +++ b/src/engine/instructions/pcmpistrm.rs @@ -15,7 +15,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, _instruction_sz: usize, _rep_st Some(v) => v, None => return false, }; - let imm = ins.immediate8() as u8; + let imm = ins.immediate8(); let is_word = imm & 1 != 0; let is_signed = imm & 2 != 0; diff --git a/src/engine/instructions/pusha.rs b/src/engine/instructions/pusha.rs index 8c966158..4ec47381 100644 --- a/src/engine/instructions/pusha.rs +++ b/src/engine/instructions/pusha.rs @@ -13,7 +13,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste emu.regs_mut().sub_sp(); if !emu .maps - .write_word(emu.regs().get_sp() as u64, emu.regs().get_ax() as u16) + .write_word(emu.regs().get_sp(), emu.regs().get_ax() as u16) { return false; } @@ -21,7 +21,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste emu.regs_mut().sub_sp(); if !emu .maps - .write_word(emu.regs().get_sp() as u64, emu.regs().get_cx() as u16) + .write_word(emu.regs().get_sp(), emu.regs().get_cx() as u16) { return false; } @@ -29,7 +29,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste emu.regs_mut().sub_sp(); if !emu .maps - .write_word(emu.regs().get_sp() as u64, emu.regs().get_dx() as u16) + .write_word(emu.regs().get_sp(), emu.regs().get_dx() as u16) { return false; } @@ -37,20 +37,20 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste emu.regs_mut().sub_sp(); if !emu .maps - .write_word(emu.regs().get_sp() as u64, emu.regs().get_bx() as u16) + .write_word(emu.regs().get_sp(), emu.regs().get_bx() as u16) { return false; } emu.regs_mut().sub_sp(); - if !emu.maps.write_word(emu.regs().get_sp() as u64, tmp_sp) { + if !emu.maps.write_word(emu.regs().get_sp(), tmp_sp) { return false; } emu.regs_mut().sub_sp(); if !emu .maps - .write_word(emu.regs().get_sp() as u64, emu.regs().get_bp() as u16) + .write_word(emu.regs().get_sp(), emu.regs().get_bp() as u16) { return false; } @@ -58,7 +58,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste emu.regs_mut().sub_sp(); if !emu .maps - .write_word(emu.regs().get_sp() as u64, emu.regs().get_si() as u16) + .write_word(emu.regs().get_sp(), emu.regs().get_si() as u16) { return false; } @@ -66,7 +66,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste emu.regs_mut().sub_sp(); if !emu .maps - .write_word(emu.regs().get_sp() as u64, emu.regs().get_di() as u16) + .write_word(emu.regs().get_sp(), emu.regs().get_di() as u16) { return false; } diff --git a/src/engine/instructions/ret.rs b/src/engine/instructions/ret.rs index 59792eb5..d60d9cc7 100644 --- a/src/engine/instructions/ret.rs +++ b/src/engine/instructions/ret.rs @@ -99,9 +99,9 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste } if emu.cfg.is_x64() { - return emu.set_rip(ret_addr, false); + emu.set_rip(ret_addr, false) } else { - return emu.set_eip(ret_addr, false); + emu.set_eip(ret_addr, false) } //true } diff --git a/src/engine/instructions/shlx.rs b/src/engine/instructions/shlx.rs index 9ba6c70b..45ce26fb 100644 --- a/src/engine/instructions/shlx.rs +++ b/src/engine/instructions/shlx.rs @@ -14,7 +14,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, _instruction_sz: usize, _rep_st let shift = cnt & (sz - 1); let result = match sz { 64 => src << shift, - 32 => ((src as u32) << shift) as u32 as u64, + 32 => ((src as u32) << shift) as u64, _ => return false, }; emu.set_operand_value(ins, 0, result); diff --git a/src/engine/instructions/shrx.rs b/src/engine/instructions/shrx.rs index 3d71f20c..ecb15e3d 100644 --- a/src/engine/instructions/shrx.rs +++ b/src/engine/instructions/shrx.rs @@ -14,7 +14,7 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, _instruction_sz: usize, _rep_st let shift = cnt & (sz - 1); let result = match sz { 64 => src >> shift, - 32 => ((src as u32) >> shift) as u32 as u64, + 32 => ((src as u32) >> shift) as u64, _ => return false, }; emu.set_operand_value(ins, 0, result); diff --git a/src/exception/handlers.rs b/src/exception/handlers.rs index c1ee2b95..3963bc53 100644 --- a/src/exception/handlers.rs +++ b/src/exception/handlers.rs @@ -81,7 +81,7 @@ pub fn enter32(emu: &mut emu::Emu, ex_type: types::ExceptionType, handler_kind: emu.maps .write_dword(emu.eh_ctx(), types::exception_type_code(ex_type)); // STATUS_BREAKPOINT - let ctx = Context32::new(&emu.regs()); + let ctx = Context32::new(emu.regs()); ctx.save(emu.eh_ctx() as u32, &mut emu.maps); } @@ -91,7 +91,7 @@ pub fn exit32(emu: &mut emu::Emu) { let ex_code = emu.maps.read_dword(ctx_ptr).unwrap_or(0); let handler_kind = emu.maps.read_dword(ctx_ptr.saturating_sub(8)).unwrap_or(0); - let mut ctx = Context32::new(&emu.regs()); + let mut ctx = Context32::new(emu.regs()); ctx.load(emu.eh_ctx() as u32, &mut emu.maps); ctx.sync(emu.regs_mut()); emu.set_eh_ctx(0); @@ -127,7 +127,7 @@ pub fn enter64(emu: &mut emu::Emu, ex_type: types::ExceptionType, handler_kind: // so exit64 can retrieve it from `eh_ctx()` (offset +0). emu.maps .write_dword(emu.eh_ctx(), types::exception_type_code(ex_type)); - let ctx = Context64::new(&emu.regs()); + let ctx = Context64::new(emu.regs()); ctx.save(emu.eh_ctx(), &mut emu.maps); } @@ -137,7 +137,7 @@ pub fn exit64(emu: &mut emu::Emu) { let ex_code = emu.maps.read_dword(ctx_ptr).unwrap_or(0); let handler_kind = emu.maps.read_dword(ctx_ptr.saturating_sub(16)).unwrap_or(0); - let mut ctx = Context64::new(&emu.regs()); + let mut ctx = Context64::new(emu.regs()); ctx.load(emu.eh_ctx(), &mut emu.maps); ctx.sync(emu.regs_mut()); emu.set_eh_ctx(0); diff --git a/src/exception/types.rs b/src/exception/types.rs index 1beaba82..dc55fa78 100644 --- a/src/exception/types.rs +++ b/src/exception/types.rs @@ -19,7 +19,7 @@ pub enum ExceptionType { impl PartialEq for ExceptionType { fn eq(&self, other: &Self) -> bool { - return *self as u32 == *other as u32; + *self as u32 == *other as u32 } } @@ -47,21 +47,21 @@ impl std::fmt::Display for ExceptionType { pub fn exception_type_code(ex_type: ExceptionType) -> u32 { match ex_type { - ExceptionType::Int3 => return constants::STATUS_BREAKPOINT, - ExceptionType::Div0 => return constants::STATUS_INTEGER_DIVIDE_BY_ZERO, - ExceptionType::SignChangeOnDivision => return constants::STATUS_INTEGER_OVERFLOW, - ExceptionType::PopfCannotReadStack => return constants::STATUS_POPF_CANNOT_READ_STACK, - ExceptionType::WritingWord => return constants::STATUS_WRITING_WORD, - ExceptionType::SettingRipToNonMappedAddr => return constants::STATUS_READING_RIP, - ExceptionType::QWordDereferencing => return constants::STATUS_QWORD_DEREFERENCING, - ExceptionType::DWordDereferencing => return constants::STATUS_DWORD_DEREFERENCING, - ExceptionType::WordDereferencing => return constants::STATUS_WORD_DEREFERENCING, - ExceptionType::ByteDereferencing => return constants::STATUS_BYTE_DEREFERENCING, + ExceptionType::Int3 => constants::STATUS_BREAKPOINT, + ExceptionType::Div0 => constants::STATUS_INTEGER_DIVIDE_BY_ZERO, + ExceptionType::SignChangeOnDivision => constants::STATUS_INTEGER_OVERFLOW, + ExceptionType::PopfCannotReadStack => constants::STATUS_POPF_CANNOT_READ_STACK, + ExceptionType::WritingWord => constants::STATUS_WRITING_WORD, + ExceptionType::SettingRipToNonMappedAddr => constants::STATUS_READING_RIP, + ExceptionType::QWordDereferencing => constants::STATUS_QWORD_DEREFERENCING, + ExceptionType::DWordDereferencing => constants::STATUS_DWORD_DEREFERENCING, + ExceptionType::WordDereferencing => constants::STATUS_WORD_DEREFERENCING, + ExceptionType::ByteDereferencing => constants::STATUS_BYTE_DEREFERENCING, ExceptionType::BadAddressDereferencing => { - return constants::STATUS_BAD_ADDRESS_DEREFERENCING; + constants::STATUS_BAD_ADDRESS_DEREFERENCING } - ExceptionType::SettingXmmOperand => return constants::STATUS_SETTING_XMM_OPERAND, - ExceptionType::ReadingXmmOperand => return constants::STATUS_READING_XMM_OPERAND, + ExceptionType::SettingXmmOperand => constants::STATUS_SETTING_XMM_OPERAND, + ExceptionType::ReadingXmmOperand => constants::STATUS_READING_XMM_OPERAND, } } diff --git a/src/loaders/macho/macho64.rs b/src/loaders/macho/macho64.rs index a661c9c3..3c924d4a 100644 --- a/src/loaders/macho/macho64.rs +++ b/src/loaders/macho/macho64.rs @@ -235,10 +235,8 @@ impl Macho64 { let mem = maps .create_map(&seg.name, seg.vmaddr, seg.vmsize, perm) - .expect(&format!( - "cannot create map for segment '{}' at 0x{:x}", - seg.name, seg.vmaddr - )); + .unwrap_or_else(|_| panic!("cannot create map for segment '{}' at 0x{:x}", + seg.name, seg.vmaddr)); if !seg.data.is_empty() { mem.force_write_bytes(seg.vmaddr, &seg.data); @@ -343,7 +341,7 @@ impl Macho64 { let starts_offset = u32::from_le_bytes(data[4..8].try_into().unwrap()) as usize; let imports_offset = u32::from_le_bytes(data[8..12].try_into().unwrap()) as usize; let symbols_offset = u32::from_le_bytes(data[12..16].try_into().unwrap()) as usize; - let imports_count = u32::from_le_bytes(data[16..20].try_into().unwrap()) as u32; + let imports_count = u32::from_le_bytes(data[16..20].try_into().unwrap()); let imports_format = u32::from_le_bytes(data[20..24].try_into().unwrap()); // Parse import table diff --git a/src/maps/heap_allocation.rs b/src/maps/heap_allocation.rs index b6bb7f16..6aba2e47 100644 --- a/src/maps/heap_allocation.rs +++ b/src/maps/heap_allocation.rs @@ -107,7 +107,7 @@ impl O1Heap { let hashes: HashMap> = HashMap::default(); let mut heap = Self { - base: base, + base, bins: vec![None; NUM_BINS_MAX], hashes, nonempty_bin_mask: 0, diff --git a/src/maps/inspection.rs b/src/maps/inspection.rs index 4b4d19eb..b6eb4dfd 100644 --- a/src/maps/inspection.rs +++ b/src/maps/inspection.rs @@ -98,7 +98,7 @@ impl Maps { None => break, }; - let name = self.get_addr_name(value).unwrap_or_else(|| ""); + let name = self.get_addr_name(value).unwrap_or(""); log::trace!( "0x{:x}: 0x{:x} ({}) '{}'", @@ -122,7 +122,7 @@ impl Maps { if !self.is_64bits { // only in 32bits make sense derreference dwords in memory - let name = self.get_addr_name(value.into()).unwrap_or_else(|| ""); + let name = self.get_addr_name(value.into()).unwrap_or(""); let mut s = "".to_string(); if !name.is_empty() { diff --git a/src/maps/mem64.rs b/src/maps/mem64.rs index 5ec23cd0..eafb3517 100644 --- a/src/maps/mem64.rs +++ b/src/maps/mem64.rs @@ -272,11 +272,7 @@ impl Mem64 { #[inline] pub fn inside(&self, addr: u64) -> bool { - if addr >= self.base_addr && addr < self.bottom_addr { - true - } else { - false - } + addr >= self.base_addr && addr < self.bottom_addr } #[inline(always)] @@ -714,7 +710,7 @@ impl Mem64 { wide_string.push(0); } let wide_string_byte_slice: &[u8] = cast_slice(&wide_string); - self.write_bytes(addr, &wide_string_byte_slice); + self.write_bytes(addr, wide_string_byte_slice); if cfg!(feature = "log_mem_write") { emu_context::with_current_emu(|emu| { @@ -894,10 +890,10 @@ impl Mem64 { match String::from_utf16(&s) { Ok(s) => { - return s; + s } Err(_) => { - return "".to_string(); + "".to_string() } } } @@ -1056,10 +1052,7 @@ impl Mem64 { let blob = self.mem.get(0..).unwrap(); - let res = match f.write_all(blob) { - Ok(_) => true, - Err(_) => false, - }; + let res = f.write_all(blob).is_ok(); f.sync_all().unwrap(); diff --git a/src/maps/mod.rs b/src/maps/mod.rs index 481152f1..bca665f9 100644 --- a/src/maps/mod.rs +++ b/src/maps/mod.rs @@ -250,11 +250,11 @@ impl Maps { } pub fn read_f64(&self, addr: u64) -> Option { - self.read_qword(addr).map(|v| f64::from_bits(v)) + self.read_qword(addr).map(f64::from_bits) } pub fn read_f32(&self, addr: u64) -> Option { - self.read_dword(addr).map(|v| f32::from_bits(v)) + self.read_dword(addr).map(f32::from_bits) } pub fn write_f64(&mut self, addr: u64, value: f64) -> bool { @@ -407,11 +407,10 @@ impl Maps { let mem_key = entry.get_mem(); match self.mem_slab.get(mem_key) { - Some(mem) => { - if mem.inside(addr) { - return Some(&mem); // Clone the &Mem64 + Some(mem) + if mem.inside(addr) => { + return Some(mem); // Clone the &Mem64 } - } _ => (), // TLB miss now search in maps }; @@ -518,7 +517,7 @@ impl Maps { /// Iterates maps named `*.pe`, reads the PE optional-header `SizeOfImage`, /// and checks whether `addr` falls within `[base, base+size_of_image)`. pub fn find_pe_image_info(&self, addr: u64) -> Option<(u64, u64)> { - for (name, _) in self.name_map.iter() { + for name in self.name_map.keys() { if !name.ends_with(".pe") { continue; } @@ -630,7 +629,7 @@ impl Maps { let id = self .name_map .get(name) - .expect(format!("map name {} not found", name).as_str()); + .unwrap_or_else(|| panic!("map name {} not found", name)); let mem = self.mem_slab.get_mut(*id).unwrap(); mem.clear(); self.maps.remove(&mem.get_base()); @@ -722,7 +721,7 @@ impl Maps { } // Here we assume that we go from the bottom to the most - for (_, mem_key) in self.maps.iter() { + for mem_key in self.maps.values() { let mem = self.mem_slab.get(*mem_key).unwrap(); let base = mem.get_base(); @@ -781,7 +780,7 @@ impl Maps { if mem.get_name().to_string().starts_with("alloc_") { let mut ppath = path.clone(); ppath.push('/'); - ppath.push_str(&mem.get_name()); + ppath.push_str(mem.get_name()); ppath.push_str(".bin"); mem.save(mem.get_base(), mem.size(), ppath); } diff --git a/src/maps/search.rs b/src/maps/search.rs index 7a09f58c..3b8585f5 100644 --- a/src/maps/search.rs +++ b/src/maps/search.rs @@ -189,7 +189,7 @@ impl Maps { continue; } - let results = match self.search_string(&kw, &mem.get_name()) { + let results = match self.search_string(&kw, mem.get_name()) { Some(v) => v, None => { continue; diff --git a/src/maps/tlb.rs b/src/maps/tlb.rs index 861841cf..fddd3fd2 100644 --- a/src/maps/tlb.rs +++ b/src/maps/tlb.rs @@ -50,6 +50,12 @@ pub struct TLB { entry: [TLBEntry; TLB_SIZE], } +impl Default for TLB { + fn default() -> Self { + Self::new() + } +} + impl TLB { pub fn new() -> Self { Self { diff --git a/src/serialization/maps.rs b/src/serialization/maps.rs index 84d9ccca..ed25b296 100644 --- a/src/serialization/maps.rs +++ b/src/serialization/maps.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::maps::Maps; #[derive(Serialize, Deserialize)] +#[derive(Default)] pub struct SerializableMaps { maps: Maps, } @@ -25,13 +26,6 @@ impl From for Maps { } } -impl Default for SerializableMaps { - fn default() -> Self { - Self { - maps: Default::default(), - } - } -} impl SerializableMaps { pub fn new(maps: Maps) -> Self { diff --git a/src/serialization/minidump/writer.rs b/src/serialization/minidump/writer.rs index 5c361cec..cae34c06 100644 --- a/src/serialization/minidump/writer.rs +++ b/src/serialization/minidump/writer.rs @@ -200,17 +200,15 @@ fn display_name_for_module(emu: &Emu, prefix: &str) -> String { .and_then(|stem| stem.to_str()) .map(|stem| stem.to_ascii_lowercase()); - if main_stem.as_deref() == Some(prefix_lc.as_str()) { - if !emu.filename.is_empty() { + if main_stem.as_deref() == Some(prefix_lc.as_str()) + && !emu.filename.is_empty() { return emu.filename.clone(); } - } - if exe_name_stem.as_deref() == Some(prefix_lc.as_str()) { - if !emu.cfg.exe_name.is_empty() { + if exe_name_stem.as_deref() == Some(prefix_lc.as_str()) + && !emu.cfg.exe_name.is_empty() { return emu.cfg.exe_name.clone(); } - } if !emu.cfg.maps_folder.is_empty() { let dll_path = Path::new(&emu.cfg.maps_folder).join(format!("{prefix}.dll")); diff --git a/src/syscall/linux/syscall64/memory.rs b/src/syscall/linux/syscall64/memory.rs index 3b478874..fdb06320 100644 --- a/src/syscall/linux/syscall64/memory.rs +++ b/src/syscall/linux/syscall64/memory.rs @@ -33,7 +33,7 @@ pub(super) fn handle_syscall64_brk(emu: &mut emu::Emu) { .create_map("heap", HEAP_START, HEAP_MAX, Permission::READ_WRITE); } } - if requested >= HEAP_START && requested <= HEAP_START + HEAP_MAX { + if (HEAP_START..=HEAP_START + HEAP_MAX).contains(&requested) { emu.heap_addr = requested; // move the program break } emu.regs_mut().rax = emu.heap_addr; diff --git a/src/syscall/linux/syscall64/misc.rs b/src/syscall/linux/syscall64/misc.rs index 223ee321..dd27711a 100644 --- a/src/syscall/linux/syscall64/misc.rs +++ b/src/syscall/linux/syscall64/misc.rs @@ -131,7 +131,6 @@ fn dispatch_legacy_syscall64(emu: &mut emu::Emu) { constants::NR64_EXIT | constants::NR64_EXIT_GROUP => { super::proc::handle_syscall64_exit(emu); - return; } constants::NR64_FORK => super::proc::handle_syscall64_fork(emu), diff --git a/src/syscall/windows/syscall64/alpc.rs b/src/syscall/windows/syscall64/alpc.rs index d8d27ab7..c0fced98 100644 --- a/src/syscall/windows/syscall64/alpc.rs +++ b/src/syscall/windows/syscall64/alpc.rs @@ -255,7 +255,7 @@ pub fn nt_alpc_send_wait_receive_port(emu: &mut Emu) { let _ = emu.maps.write_byte(recv_msg_ptr + off, 0); } // Write PORT_MESSAGE header: DataLength, TotalLength, then Type=LPC_REPLY at +0x04. - let _ = emu.maps.write_word(recv_msg_ptr + 0x00, send_data_len); + let _ = emu.maps.write_word(recv_msg_ptr, send_data_len); let _ = emu.maps.write_word( recv_msg_ptr + 0x02, PORT_MESSAGE_SIZE as u16 + send_data_len, diff --git a/src/syscall/windows/syscall64/memory.rs b/src/syscall/windows/syscall64/memory.rs index 97e859e2..1f26e19e 100644 --- a/src/syscall/windows/syscall64/memory.rs +++ b/src/syscall/windows/syscall64/memory.rs @@ -130,7 +130,7 @@ pub fn ntdll_heap_list_walk_fixup(emu: &mut Emu, ins: &Instruction, rip: u64) { } let rsi = emu.regs().rsi; - if rsi < ALLOC64_MIN || rsi >= ALLOC64_MAX { + if !(ALLOC64_MIN..ALLOC64_MAX).contains(&rsi) { return; } if !emu.maps.is_mapped(rsi) || !emu.maps.is_mapped(rsi + 8) { @@ -287,15 +287,14 @@ pub fn nt_query_virtual_memory(emu: &mut Emu) { mem_info.save(memory_information, &mut emu.maps); - if return_length_ptr != 0 { - if !emu + if return_length_ptr != 0 + && !emu .maps .write_qword(return_length_ptr, MemoryBasicInformation64::SIZE) { emu.regs_mut().rax = STATUS_INVALID_PARAMETER; return; } - } emu.regs_mut().rax = STATUS_SUCCESS; } @@ -443,7 +442,7 @@ fn alloc_64k_aligned(emu: &mut Emu, size: u64) -> Option { let aligned = (probe + GRAN - 1) & !(GRAN - 1); // Validate the aligned range is still free (the probe gave us [probe, probe+size+GRAN-1) // — sliding to `aligned` keeps us inside that window). - if aligned + size <= probe + size + GRAN - 1 && !emu.maps.overlaps(aligned, size) { + if aligned + size < probe + size + GRAN && !emu.maps.overlaps(aligned, size) { Some(aligned) } else { // Fallback: scan for a free 64K-aligned region directly. @@ -691,7 +690,7 @@ pub fn nt_free_virtual_memory(emu: &mut Emu) { // ntdll may call MEM_RELEASE on a range already torn down by a prior successful free or // on an address our single-map model treats as unmapped; real kernel often accepts the // no-op. - if emu.cfg.emulate_winapi && base >= ALLOC64_MIN && base < ALLOC64_MAX { + if emu.cfg.emulate_winapi && (ALLOC64_MIN..ALLOC64_MAX).contains(&base) { // Windows writes back the page-aligned freed base (not zero) so callers can // inspect what was released. Do not zero *BaseAddress. emu.regs_mut().rax = STATUS_SUCCESS; @@ -790,7 +789,7 @@ pub fn nt_protect_virtual_memory(emu: &mut Emu) { }; if old_protect_ptr != 0 { - let _ = emu.maps.write_dword(old_protect_ptr as u64, old_protect); + let _ = emu.maps.write_dword(old_protect_ptr, old_protect); } if let Some(mem) = emu.maps.get_mem_by_addr_mut(base) { @@ -920,7 +919,7 @@ pub fn nt_unmap_view_of_section(emu: &mut Emu) { let map_name = emu .maps .get_addr_name(base) - .unwrap_or_else(|| "") + .unwrap_or("") .to_string(); log_orange!( emu, @@ -1158,30 +1157,10 @@ pub fn nt_open_section(emu: &mut Emu) { // here causes ntdll to fall through to disk lookup, which also fails, and // terminate the process with STATUS_DLL_NOT_FOUND. // - // First few of these are API-set entries that redirect to kernelbase in - // real Windows — fall back to a kernelbase section handle so the loader - // accepts the dependency. After a small budget, switch to NOT_FOUND: an - // unbounded fake fallback causes ntdll to re-init those phantom modules - // (TLS callbacks, DllMain) in a tight loop and exhaust the stack. + // The former kernelbase fallback is disabled: an unbounded fake fallback + // causes ntdll to re-init phantom modules (TLS callbacks, DllMain) in a + // tight loop and exhaust the stack. if is_known_dll_dir && dll_name.is_none() { - const FALLBACK_BUDGET: usize = 0; - if emu - .section_handles - .values() - .filter(|n| *n == "kernelbase.dll") - .count() - < FALLBACK_BUDGET - { - let h = crate::syscall::windows::syscall64::sync::next_handle(); - let _ = emu.maps.write_qword(handle_out, h); - log::trace!( - "NtOpenSection: empty-name KnownDll → handle 0x{:x} -> kernelbase.dll (api-set fallback)", - h - ); - emu.section_handles.insert(h, "kernelbase.dll".to_string()); - emu.regs_mut().rax = STATUS_SUCCESS; - return; - } emu.regs_mut().rax = STATUS_OBJECT_NAME_NOT_FOUND; return; } diff --git a/src/syscall/windows/syscall64/mod.rs b/src/syscall/windows/syscall64/mod.rs index 7a495d6a..7f56603b 100644 --- a/src/syscall/windows/syscall64/mod.rs +++ b/src/syscall/windows/syscall64/mod.rs @@ -331,7 +331,7 @@ pub fn gateway(emu: &mut Emu) { ); // Extract the filename (last path segment) from the NT path. let basename = nt_name - .rsplit(|c| c == '\\' || c == '/') + .rsplit(['\\', '/']) .next() .unwrap_or("") .to_lowercase(); @@ -344,7 +344,7 @@ pub fn gateway(emu: &mut Emu) { // recent value is good enough for any single emulation. const FAKE_FILETIME: u64 = 0x01DA_0000_0000_0000; // ~2023 const FILE_ATTRIBUTE_NORMAL: u32 = 0x80; - let _ = emu.maps.write_qword(file_info_ptr + 0x00, FAKE_FILETIME); + let _ = emu.maps.write_qword(file_info_ptr, FAKE_FILETIME); let _ = emu.maps.write_qword(file_info_ptr + 0x08, FAKE_FILETIME); let _ = emu.maps.write_qword(file_info_ptr + 0x10, FAKE_FILETIME); let _ = emu.maps.write_qword(file_info_ptr + 0x18, FAKE_FILETIME); @@ -528,7 +528,7 @@ pub fn gateway(emu: &mut Emu) { for off in 0..NEED as u64 { let _ = emu.maps.write_byte(sysinfo + off, 0); } - let _ = emu.maps.write_dword(sysinfo + 0x00, 4); // Relationship = RelationGroup + let _ = emu.maps.write_dword(sysinfo, 4); // Relationship = RelationGroup let _ = emu.maps.write_dword(sysinfo + 0x04, NEED); // Size let _ = emu.maps.write_word(sysinfo + 0x08, 1); // MaximumGroupCount let _ = emu.maps.write_word(sysinfo + 0x0a, 1); // ActiveGroupCount @@ -586,7 +586,7 @@ pub fn gateway(emu: &mut Emu) { emu, obj_attr, ); let basename = nt_name - .rsplit(|c| c == '\\' || c == '/') + .rsplit(['\\', '/']) .next() .unwrap_or("") .to_lowercase(); @@ -638,7 +638,7 @@ pub fn gateway(emu: &mut Emu) { emu, obj_attr, ); let basename = nt_name - .rsplit(|c| c == '\\' || c == '/') + .rsplit(['\\', '/']) .next() .unwrap_or("") .to_lowercase(); diff --git a/src/syscall/windows/syscall64/process.rs b/src/syscall/windows/syscall64/process.rs index 9571ed16..d07f6ad2 100644 --- a/src/syscall/windows/syscall64/process.rs +++ b/src/syscall/windows/syscall64/process.rs @@ -103,15 +103,14 @@ pub fn nt_query_information_process(emu: &mut Emu) { }; process_info.save(process_information, &mut emu.maps); - if return_length_ptr != 0 { - if !emu + if return_length_ptr != 0 + && !emu .maps .write_qword(return_length_ptr, ProcessBasicInformation64::size()) { emu.regs_mut().rax = STATUS_INVALID_PARAMETER; return; } - } emu.regs_mut().rax = STATUS_SUCCESS; return; @@ -135,12 +134,11 @@ pub fn nt_query_information_process(emu: &mut Emu) { emu.regs_mut().rax = STATUS_INVALID_PARAMETER; return; } - if return_length_ptr != 0 { - if !emu.maps.write_dword(return_length_ptr, 4) { + if return_length_ptr != 0 + && !emu.maps.write_dword(return_length_ptr, 4) { emu.regs_mut().rax = STATUS_INVALID_PARAMETER; return; } - } emu.regs_mut().rax = STATUS_SUCCESS; return; } @@ -158,12 +156,11 @@ pub fn nt_query_information_process(emu: &mut Emu) { emu.regs_mut().rax = STATUS_INVALID_PARAMETER; return; } - if return_length_ptr != 0 { - if !emu.maps.write_qword(return_length_ptr, 8) { + if return_length_ptr != 0 + && !emu.maps.write_qword(return_length_ptr, 8) { emu.regs_mut().rax = STATUS_INVALID_PARAMETER; return; } - } emu.regs_mut().rax = STATUS_SUCCESS; return; } diff --git a/src/syscall/windows/syscall64/system.rs b/src/syscall/windows/syscall64/system.rs index 64ba45ab..8c72694c 100644 --- a/src/syscall/windows/syscall64/system.rs +++ b/src/syscall/windows/syscall64/system.rs @@ -83,13 +83,12 @@ pub fn nt_query_system_information(emu: &mut Emu) { return; } - if len > 0 && info != 0 { - if !emu.maps.is_mapped(info) || !emu.maps.is_mapped(info + u64::from(len).saturating_sub(1)) + if len > 0 && info != 0 + && (!emu.maps.is_mapped(info) || !emu.maps.is_mapped(info + u64::from(len).saturating_sub(1))) { emu.regs_mut().rax = STATUS_ACCESS_VIOLATION; return; } - } match class { // Both return the same x64 `SYSTEM_BASIC_INFORMATION`; the emulation diff --git a/src/threading/global_locks.rs b/src/threading/global_locks.rs index a971f796..fce73814 100644 --- a/src/threading/global_locks.rs +++ b/src/threading/global_locks.rs @@ -6,6 +6,12 @@ pub struct GlobalLocks { pub crit_map: HashMap, // key = pointer to CRITICAL_SECTION } +impl Default for GlobalLocks { + fn default() -> Self { + Self::new() + } +} + impl GlobalLocks { pub fn new() -> Self { Self { diff --git a/src/threading/scheduler.rs b/src/threading/scheduler.rs index ede58a54..00bea73e 100644 --- a/src/threading/scheduler.rs +++ b/src/threading/scheduler.rs @@ -176,11 +176,10 @@ impl ThreadScheduler { /// Uses the arch-dispatched decode_and_execute() and advance_pc() on Emu. pub fn execute_thread_instruction(emu: &mut Emu, thread_id: usize) -> bool { // Switch to target thread if needed - if emu.current_thread_id != thread_id { - if !Self::switch_to_thread(emu, thread_id) { + if emu.current_thread_id != thread_id + && !Self::switch_to_thread(emu, thread_id) { return false; } - } let pc = emu.pc(); diff --git a/src/windows/constants.rs b/src/windows/constants.rs index 0056fcca..26efe338 100644 --- a/src/windows/constants.rs +++ b/src/windows/constants.rs @@ -378,7 +378,7 @@ pub fn get_crypto_key_len(value: u32) -> usize { } } -//// WINDOWS KERNEL //// +/// WINDOWS KERNEL //// /// `_MEMORY_INFORMATION_CLASS` for `NtQueryVirtualMemory` (see Windows SDK). pub const MEMORY_INFORMATION_CLASS_MEMORY_BASIC_INFORMATION: u64 = 0; diff --git a/src/windows/peb/peb32.rs b/src/windows/peb/peb32.rs index 90339f9e..10ba3630 100644 --- a/src/windows/peb/peb32.rs +++ b/src/windows/peb/peb32.rs @@ -253,7 +253,7 @@ impl Flink { self.func_name_tbl = self.func_name_tbl_rva + self.mod_base; } - return true; + true } pub fn get_function_ordinal(&self, emu: &mut emu::Emu, function_id: u64) -> OrdinalTable { diff --git a/src/windows/peb/peb64/ldr.rs b/src/windows/peb/peb64/ldr.rs index 9955fab4..92c84a8e 100644 --- a/src/windows/peb/peb64/ldr.rs +++ b/src/windows/peb/peb64/ldr.rs @@ -759,7 +759,7 @@ pub fn rebuild_ldr_lists(emu: &mut emu::Emu) { .cfg .filename .split('/') - .last() + .next_back() .unwrap_or("") .split('.') .next() diff --git a/src/windows/structures/act_ctx_section_keyed_data32.rs b/src/windows/structures/act_ctx_section_keyed_data32.rs index 2c6ac043..4e9a0a48 100644 --- a/src/windows/structures/act_ctx_section_keyed_data32.rs +++ b/src/windows/structures/act_ctx_section_keyed_data32.rs @@ -15,6 +15,12 @@ pub struct ActCtxSectionKeyedData32 { pub assembly_metadata: [u8; 64], } +impl Default for ActCtxSectionKeyedData32 { + fn default() -> Self { + Self::new() + } +} + impl ActCtxSectionKeyedData32 { pub fn new() -> ActCtxSectionKeyedData32 { ActCtxSectionKeyedData32 { diff --git a/src/windows/structures/act_ctx_section_keyed_data64.rs b/src/windows/structures/act_ctx_section_keyed_data64.rs index 1272ba73..61ea0643 100644 --- a/src/windows/structures/act_ctx_section_keyed_data64.rs +++ b/src/windows/structures/act_ctx_section_keyed_data64.rs @@ -15,6 +15,12 @@ pub struct ActCtxSectionKeyedData64 { pub assembly_metadata: [u8; 64], } +impl Default for ActCtxSectionKeyedData64 { + fn default() -> Self { + Self::new() + } +} + impl ActCtxSectionKeyedData64 { pub fn new() -> ActCtxSectionKeyedData64 { ActCtxSectionKeyedData64 { diff --git a/src/windows/structures/image_resource_data_entry32.rs b/src/windows/structures/image_resource_data_entry32.rs index 8e921835..053adbc6 100644 --- a/src/windows/structures/image_resource_data_entry32.rs +++ b/src/windows/structures/image_resource_data_entry32.rs @@ -5,6 +5,12 @@ pub struct ImageResourceDataEntry32 { pub reserved: u32, } +impl Default for ImageResourceDataEntry32 { + fn default() -> Self { + Self::new() + } +} + impl ImageResourceDataEntry32 { pub fn new() -> ImageResourceDataEntry32 { ImageResourceDataEntry32 { diff --git a/src/windows/structures/image_resource_data_entry64.rs b/src/windows/structures/image_resource_data_entry64.rs index 025d41bd..da0b552b 100644 --- a/src/windows/structures/image_resource_data_entry64.rs +++ b/src/windows/structures/image_resource_data_entry64.rs @@ -5,6 +5,12 @@ pub struct ImageResourceDataEntry64 { pub reserved: u64, } +impl Default for ImageResourceDataEntry64 { + fn default() -> Self { + Self::new() + } +} + impl ImageResourceDataEntry64 { pub fn new() -> ImageResourceDataEntry64 { ImageResourceDataEntry64 { diff --git a/src/windows/structures/image_resource_directory.rs b/src/windows/structures/image_resource_directory.rs index 82a82fe1..21cfe95a 100644 --- a/src/windows/structures/image_resource_directory.rs +++ b/src/windows/structures/image_resource_directory.rs @@ -7,6 +7,12 @@ pub struct ImageResourceDirectory { pub number_of_id_entries: u16, } +impl Default for ImageResourceDirectory { + fn default() -> Self { + Self::new() + } +} + impl ImageResourceDirectory { pub fn new() -> ImageResourceDirectory { ImageResourceDirectory { diff --git a/src/windows/structures/image_resource_directory_entry.rs b/src/windows/structures/image_resource_directory_entry.rs index bfee2014..ca1f85fa 100644 --- a/src/windows/structures/image_resource_directory_entry.rs +++ b/src/windows/structures/image_resource_directory_entry.rs @@ -4,6 +4,12 @@ pub struct ImageResourceDirectoryEntry { pub data_or_directory: u32, } +impl Default for ImageResourceDirectoryEntry { + fn default() -> Self { + Self::new() + } +} + impl ImageResourceDirectoryEntry { pub fn new() -> ImageResourceDirectoryEntry { ImageResourceDirectoryEntry { diff --git a/src/windows/structures/system_info64.rs b/src/windows/structures/system_info64.rs index 352c35ec..a3bae466 100644 --- a/src/windows/structures/system_info64.rs +++ b/src/windows/structures/system_info64.rs @@ -42,7 +42,7 @@ impl SystemInfo64 { pub fn save(&mut self, addr: u64, maps: &mut Maps) { // First union/struct (4 bytes total) - maps.write_word(addr + 0, self.processor_architecture as u16); + maps.write_word(addr, self.processor_architecture as u16); maps.write_word(addr + 2, self.reserved); // Rest of the structure diff --git a/src/windows/structures/system_time.rs b/src/windows/structures/system_time.rs index 41a96ce1..6f10a40f 100644 --- a/src/windows/structures/system_time.rs +++ b/src/windows/structures/system_time.rs @@ -17,7 +17,9 @@ pub struct SystemTime { impl SystemTime { pub fn now() -> SystemTime { let now = Utc::now(); - let systime = SystemTime { + + + SystemTime { year: now.year() as u16, month: now.month() as u16, day_of_week: now.weekday() as u16, @@ -26,9 +28,7 @@ impl SystemTime { minute: now.minute() as u16, second: now.second() as u16, millis: now.timestamp_millis() as u16, - }; - - systime + } } pub fn save(&self, addr: u64, maps: &mut Maps) { diff --git a/src/windows/structures/vs_versioninfo.rs b/src/windows/structures/vs_versioninfo.rs index efc1061f..d04f5662 100644 --- a/src/windows/structures/vs_versioninfo.rs +++ b/src/windows/structures/vs_versioninfo.rs @@ -15,6 +15,12 @@ pub struct VS_VERSIONINFO { pub children: u16, } +impl Default for VS_VERSIONINFO { + fn default() -> Self { + Self::new() + } +} + impl VS_VERSIONINFO { pub fn new() -> Self { let mut sz_key = [0u16; 16];