Skip to content

Commit 8cabf1d

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

File tree

9 files changed

+49
-16
lines changed

9 files changed

+49
-16
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

crates/libmwemu/src/winapi/winapi32/ws2_32.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ fn getaddrinfo(emu: &mut emu::Emu) {
8282
.expect("ws2_32!getaddrinfo cannot read result_ptr_ptr");
8383

8484
let node_name = if node_name_ptr != 0 {
85-
emu.maps.read_string(node_name_ptr)
85+
emu.maps.read_string(node_name_ptr as u64)
8686
} else {
8787
"NULL".to_string()
8888
};
8989

9090
let service_name = if service_name_ptr != 0 {
91-
emu.maps.read_string(service_name_ptr)
91+
emu.maps.read_string(service_name_ptr as u64)
9292
} else {
9393
"NULL".to_string()
9494
};
@@ -102,10 +102,10 @@ fn getaddrinfo(emu: &mut emu::Emu) {
102102
let mut hints_protocol = 0;
103103

104104
if hints_ptr != 0 {
105-
hints_flags = emu.maps.read_dword(hints_ptr).unwrap_or(0) as i32;
106-
hints_family = emu.maps.read_dword(hints_ptr + 4).unwrap_or(0) as i32;
107-
hints_socktype = emu.maps.read_dword(hints_ptr + 8).unwrap_or(0) as i32;
108-
hints_protocol = emu.maps.read_dword(hints_ptr + 12).unwrap_or(0) as i32;
105+
hints_flags = emu.maps.read_dword(hints_ptr as u64).unwrap_or(0) as i32;
106+
hints_family = emu.maps.read_dword((hints_ptr + 4) as u64).unwrap_or(0) as i32;
107+
hints_socktype = emu.maps.read_dword((hints_ptr + 8) as u64).unwrap_or(0) as i32;
108+
hints_protocol = emu.maps.read_dword((hints_ptr + 12) as u64).unwrap_or(0) as i32;
109109
}
110110

111111
// Create a dummy ADDRINFO structure
@@ -167,7 +167,7 @@ fn getaddrinfo(emu: &mut emu::Emu) {
167167
emu.maps.write_qword(addrinfo_addr + 40, 0);
168168

169169
// Store the result pointer in the ppResult parameter
170-
emu.maps.write_qword(result_ptr_ptr, addrinfo_addr);
170+
emu.maps.write_qword(result_ptr_ptr as u64, addrinfo_addr);
171171

172172
log::info!("\tcreated dummy ADDRINFO for {}:{} at 0x{:x}", node_name, service_name, addrinfo_addr);
173173
log::info!("\tsockaddr at 0x{:x}, canonname at 0x{:x}", sockaddr_addr, canonname_addr);
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::sync::Mutex;
33

44
use crate::constants;
55
use crate::emu;
6+
use crate::emu::Emu;
67
use crate::peb::peb64;
78
use crate::serialization;
89

@@ -178,6 +179,7 @@ pub mod win_exec;
178179
pub mod write_console_w;
179180
pub mod write_file;
180181
pub mod write_process_memory;
182+
pub mod device_io_control;
181183
mod local_free;
182184

183185
// Re-export all functions
@@ -354,7 +356,8 @@ pub use write_console_w::WriteConsoleW;
354356
pub use write_file::WriteFile;
355357
pub use write_process_memory::WriteProcessMemory;
356358
pub use local_free::LocalFree;
357-
use crate::emu::Emu;
359+
pub use device_io_control::api_DeviceIoControl;
360+
358361
// a in RCX, b in RDX, c in R8, d in R9, then e pushed on stack
359362

360363
pub fn clear_last_error(emu: &mut emu::Emu) {
@@ -540,6 +543,7 @@ pub fn gateway(addr: u64, emu: &mut emu::Emu) -> String {
540543
"WriteConsoleW" => WriteConsoleW(emu),
541544
"WriteFile" => WriteFile(emu),
542545
"WriteProcessMemory" => WriteProcessMemory(emu),
546+
"DeviceIoControl" => api_DeviceIoControl(emu),
543547
_ => {
544548
if emu.cfg.skip_unimplemented == false {
545549
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)