Skip to content

Commit 364625b

Browse files
committed
Merge remote-tracking branch 'acheron2302/main'
2 parents 499eead + f68520b commit 364625b

File tree

8 files changed

+41
-9
lines changed

8 files changed

+41
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/libmwemu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libmwemu"
3-
version = "0.22.1"
3+
version = "0.22.2"
44
edition = "2018"
55
authors = ["sha0coder"]
66
license = "MIT"

crates/libmwemu/src/constants.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ pub const ERROR_BUFFER_OVERFLOW: u64 = 0x6f;
4343
pub const ERROR_INVALID_PARAMETER: u64 = 0x57;
4444
pub const ERROR_INSUFFICIENT_BUFFER: u64 = 0x7a;
4545

46+
47+
pub const HRESULT_E_INVALID_ARG: u64 = 0x80070057;
48+
/*
49+
* HRESULT STRUCTURE:
50+
* 0x8 -> severity: error
51+
* 0x007 -> facility: FACILITY_WIN32
52+
* 0x0057 -> ERROR_INVALID_PARAMETER
53+
*/
54+
4655
pub const CP_UTF7: u64 = 65000;
4756
pub const CP_UTF8: u64 = 65001;
4857

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use crate::emu;
2+
use crate::constants;
3+
4+
pub fn api_DeviceIoControl(emu: &mut emu::Emu) {
5+
let hDevice = emu.regs().rcx;
6+
let dwIoControlCode = emu.regs().rdx;
7+
let lpInBuffer = emu.regs().r8;
8+
let lpOutBuffer = emu.regs().r9;
9+
let rsp = emu.regs().rsp;
10+
let nOutBufferSize = emu.maps.read_qword(rsp + 0x20).expect("DeviceIoControl arg6 stack error.");
11+
let lpBytesReturned = emu.maps.read_qword(rsp + 0x28).expect("DeviceIoControl arg7 stack error.");
12+
13+
log_red!(emu, "kernel32!DeviceIoControl hDev: 0x{:x} code: 0x{:x} buff: 0x{:x}", hDevice, dwIoControlCode, lpInBuffer);
14+
15+
emu.regs_mut().rax = constants::TRUE;
16+
}

crates/libmwemu/src/winapi/winapi64/kernel32/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ pub mod win_exec;
178178
pub mod write_console_w;
179179
pub mod write_file;
180180
pub mod write_process_memory;
181+
pub mod device_io_control;
181182
mod local_free;
182183

183184
// Re-export all functions
@@ -354,7 +355,8 @@ pub use write_console_w::WriteConsoleW;
354355
pub use write_file::WriteFile;
355356
pub use write_process_memory::WriteProcessMemory;
356357
pub use local_free::LocalFree;
357-
use crate::emu::Emu;
358+
pub use device_io_control::api_DeviceIoControl;
359+
358360
// a in RCX, b in RDX, c in R8, d in R9, then e pushed on stack
359361

360362
pub fn clear_last_error(emu: &mut emu::Emu) {
@@ -540,6 +542,7 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String {
540542
"WriteConsoleW" => WriteConsoleW(emu),
541543
"WriteFile" => WriteFile(emu),
542544
"WriteProcessMemory" => WriteProcessMemory(emu),
545+
"DeviceIoControl" => api_DeviceIoControl(emu),
543546
_ => {
544547
if emu.cfg.skip_unimplemented == false {
545548
if emu.cfg.dump_on_exit && emu.cfg.dump_filename.is_some() {

crates/libmwemu/src/winapi/winapi64/ntdll.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::console::Console;
77
use crate::constants;
88
use crate::context::context64::Context64;
99
use crate::emu;
10-
use crate::emu::Emu;
1110
use crate::maps::mem64::Permission;
1211
use crate::serialization;
1312
use crate::structures;
@@ -1025,10 +1024,8 @@ fn NtReadFile(emu: &mut emu::Emu) {
10251024

10261025
emu.maps.memset(buff, 0x90, len);
10271026

1028-
// TODO: fix path duplication!!!!
1029-
if filename == "\\??\\c:\\cwd\\c:\\cwd\\version.dll" {
1030-
let local_path = "/tmp/version2.dll";
1031-
let mut file = File::open(local_path).unwrap();
1027+
if filename == "\\??\\c:\\cwd" {
1028+
let mut file = File::open(&emu.filename).unwrap();
10321029
file.seek(SeekFrom::Start(file_offset));
10331030
let mut file_buffer = vec![0u8; len];
10341031
let bytes_read = file.read(&mut file_buffer).unwrap();
@@ -1052,6 +1049,8 @@ fn NtReadFile(emu: &mut emu::Emu) {
10521049
panic!("TODO: read {}", filename);
10531050
}
10541051

1052+
1053+
10551054
emu.regs_mut().rax = constants::STATUS_SUCCESS;
10561055
}
10571056

crates/libmwemu/src/winapi/winapi64/oleaut32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ fn VariantClear(emu: &mut emu::Emu) {
298298
// Basic validation
299299
if pvarg == 0 || !emu.maps.is_mapped(pvarg) {
300300
log_red!(emu, "VariantClear: Invalid pvarg pointer");
301-
emu.regs_mut().rax = 0x80070057; // E_INVALIDARG
301+
emu.regs_mut().rax = constants::HRESULT_E_INVALID_ARG;
302302
return;
303303
}
304304

crates/mwemu/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ fn main() {
135135
.arg(clap_arg!("call", "", "call", "enable call tracer"))
136136
.arg(clap_arg!("cmd", "", "cmd", "launch a console command", "COMMAND"))
137137
.arg(clap_arg!("entropy", "", "entropy", "display changes in the entropy"))
138+
.arg(clap_arg!("multithread", "", "multithread", "enable multithread emulation"))
138139
.get_matches();
139140

140141
if !matches.is_present("filename") {
@@ -340,6 +341,10 @@ fn main() {
340341
emu.fpu_mut().mxcsr = value as u32;
341342
}
342343

344+
if matches.is_present("multithread") {
345+
emu.cfg.enable_threading = true;
346+
}
347+
343348
// endpoint
344349
if matches.is_present("endpoint") {
345350
//TODO: emu::endpoint::warning();

0 commit comments

Comments
 (0)