chore: fix clippy warnings, use windows-sys for Win32 types
Browse files- Replace manual Win32 type aliases and extern declarations in
openwa-launcher with windows-sys imports (HANDLE, BOOL, STARTUPINFOA,
CreateProcessA, VirtualAllocEx, etc.)
- Replace manual HANDLE/DWORD in openwa-dll file_isolation with
windows-sys types
- Fix b"...\0" → c"..." literal style (manual_c_str_literals)
- Fix len_zero, let_and_return, redundant_pattern_matching warnings
- Suppress intentional clippy warnings on CRT FILE alias
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Cargo.lock +1 -0
- crates/openwa-core/src/audio/music.rs +1 -1
- crates/openwa-core/src/display/dd_display.rs +8 -7
- crates/openwa-core/src/display/line_draw.rs +2 -4
- crates/openwa-core/src/field_format.rs +3 -3
- crates/openwa-debug-cli/src/main.rs +8 -12
- crates/openwa-dll/src/replacements/bitgrid.rs +1 -0
- crates/openwa-dll/src/replacements/config.rs +2 -2
- crates/openwa-dll/src/replacements/file_isolation.rs +14 -13
- crates/openwa-dll/src/replacements/headless.rs +7 -5
- crates/openwa-dll/src/replacements/replay.rs +1 -1
- crates/openwa-dll/src/replacements/sprite.rs +1 -1
- crates/openwa-launcher/Cargo.toml +10 -0
- crates/openwa-launcher/src/inject.rs +15 -61
- crates/openwa-launcher/src/main.rs +14 -84
Cargo.lock
CHANGED
|
@@ -1563,6 +1563,7 @@ name = "openwa-launcher"
|
|
| 1563 |
version = "0.1.0"
|
| 1564 |
dependencies = [
|
| 1565 |
"openwa-config",
|
|
|
|
| 1566 |
]
|
| 1567 |
|
| 1568 |
[[package]]
|
|
|
|
| 1563 |
version = "0.1.0"
|
| 1564 |
dependencies = [
|
| 1565 |
"openwa-config",
|
| 1566 |
+
"windows-sys 0.59.0",
|
| 1567 |
]
|
| 1568 |
|
| 1569 |
[[package]]
|
crates/openwa-core/src/audio/music.rs
CHANGED
|
@@ -865,7 +865,7 @@ impl Music {
|
|
| 865 |
///
|
| 866 |
/// Maps the track ID to a WAV filename, builds the full path, and starts streaming.
|
| 867 |
pub unsafe fn play_track(this: *mut Music, track_id: u32, do_loop: bool) {
|
| 868 |
-
if
|
| 869 |
return;
|
| 870 |
}
|
| 871 |
|
|
|
|
| 865 |
///
|
| 866 |
/// Maps the track ID to a WAV filename, builds the full path, and starts streaming.
|
| 867 |
pub unsafe fn play_track(this: *mut Music, track_id: u32, do_loop: bool) {
|
| 868 |
+
if !(1..=13).contains(&track_id) {
|
| 869 |
return;
|
| 870 |
}
|
| 871 |
|
crates/openwa-core/src/display/dd_display.rs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
use crate::fixed::Fixed;
|
| 2 |
|
| 3 |
/// DDDisplay — display/rendering subsystem.
|
|
@@ -163,7 +164,7 @@ pub struct DDDisplayVtable {
|
|
| 163 |
this: *mut DDDisplay,
|
| 164 |
x: Fixed,
|
| 165 |
y: Fixed,
|
| 166 |
-
sprite: *mut
|
| 167 |
src_x: i32,
|
| 168 |
src_y: i32,
|
| 169 |
src_w: i32,
|
|
@@ -771,9 +772,9 @@ pub unsafe extern "thiscall" fn draw_polyline(
|
|
| 771 |
return;
|
| 772 |
}
|
| 773 |
|
| 774 |
-
let mut verts = [
|
| 775 |
-
for i in
|
| 776 |
-
|
| 777 |
Fixed::from_raw(*points.add(i * 2)) + cam_x,
|
| 778 |
Fixed::from_raw(*points.add(i * 2 + 1)) + cam_y,
|
| 779 |
);
|
|
@@ -871,7 +872,7 @@ pub unsafe fn draw_scaled_sprite(
|
|
| 871 |
this: *mut DDDisplay,
|
| 872 |
x: Fixed,
|
| 873 |
y: Fixed,
|
| 874 |
-
sprite: *mut
|
| 875 |
src_x: i32,
|
| 876 |
src_y: i32,
|
| 877 |
src_w: i32,
|
|
@@ -953,12 +954,12 @@ pub unsafe fn draw_scaled_sprite(
|
|
| 953 |
pub enum DrawScaledSpriteResult {
|
| 954 |
/// Blit should be performed with these parameters.
|
| 955 |
Blit {
|
| 956 |
-
layer: *mut
|
| 957 |
dst_x: i32,
|
| 958 |
dst_y: i32,
|
| 959 |
width: i32,
|
| 960 |
height: i32,
|
| 961 |
-
sprite: *mut
|
| 962 |
src_x: i32,
|
| 963 |
src_y: i32,
|
| 964 |
color_table: *const u8,
|
|
|
|
| 1 |
+
use crate::display::line_draw::Vertex;
|
| 2 |
use crate::fixed::Fixed;
|
| 3 |
|
| 4 |
/// DDDisplay — display/rendering subsystem.
|
|
|
|
| 164 |
this: *mut DDDisplay,
|
| 165 |
x: Fixed,
|
| 166 |
y: Fixed,
|
| 167 |
+
sprite: *mut DisplayBitGrid,
|
| 168 |
src_x: i32,
|
| 169 |
src_y: i32,
|
| 170 |
src_w: i32,
|
|
|
|
| 772 |
return;
|
| 773 |
}
|
| 774 |
|
| 775 |
+
let mut verts = [Vertex::new(Fixed::ZERO, Fixed::ZERO); 256];
|
| 776 |
+
for (i, vert) in verts.iter_mut().enumerate().take(n) {
|
| 777 |
+
*vert = Vertex::new(
|
| 778 |
Fixed::from_raw(*points.add(i * 2)) + cam_x,
|
| 779 |
Fixed::from_raw(*points.add(i * 2 + 1)) + cam_y,
|
| 780 |
);
|
|
|
|
| 872 |
this: *mut DDDisplay,
|
| 873 |
x: Fixed,
|
| 874 |
y: Fixed,
|
| 875 |
+
sprite: *mut DisplayBitGrid,
|
| 876 |
src_x: i32,
|
| 877 |
src_y: i32,
|
| 878 |
src_w: i32,
|
|
|
|
| 954 |
pub enum DrawScaledSpriteResult {
|
| 955 |
/// Blit should be performed with these parameters.
|
| 956 |
Blit {
|
| 957 |
+
layer: *mut DisplayBitGrid,
|
| 958 |
dst_x: i32,
|
| 959 |
dst_y: i32,
|
| 960 |
width: i32,
|
| 961 |
height: i32,
|
| 962 |
+
sprite: *mut DisplayBitGrid,
|
| 963 |
src_x: i32,
|
| 964 |
src_y: i32,
|
| 965 |
color_table: *const u8,
|
crates/openwa-core/src/display/line_draw.rs
CHANGED
|
@@ -682,7 +682,7 @@ fn clip_polygon(
|
|
| 682 |
}
|
| 683 |
|
| 684 |
// Clip against bottom Y
|
| 685 |
-
|
| 686 |
&buf_a[..count],
|
| 687 |
out,
|
| 688 |
|y| y <= cb,
|
|
@@ -690,9 +690,7 @@ fn clip_polygon(
|
|
| 690 |
|v| v.x,
|
| 691 |
|y, x| Vertex { x, y },
|
| 692 |
cb,
|
| 693 |
-
)
|
| 694 |
-
|
| 695 |
-
count
|
| 696 |
}
|
| 697 |
|
| 698 |
/// Maximum scanline height for the span table.
|
|
|
|
| 682 |
}
|
| 683 |
|
| 684 |
// Clip against bottom Y
|
| 685 |
+
clip_polygon_edge(
|
| 686 |
&buf_a[..count],
|
| 687 |
out,
|
| 688 |
|y| y <= cb,
|
|
|
|
| 690 |
|v| v.x,
|
| 691 |
|y, x| Vertex { x, y },
|
| 692 |
cb,
|
| 693 |
+
)
|
|
|
|
|
|
|
| 694 |
}
|
| 695 |
|
| 696 |
/// Maximum scanline height for the span table.
|
crates/openwa-core/src/field_format.rs
CHANGED
|
@@ -59,10 +59,10 @@ pub fn format_field(
|
|
| 59 |
|
| 60 |
// Built-in defaults
|
| 61 |
match field.kind {
|
| 62 |
-
ValueKind::U8 if data.
|
| 63 |
write!(w, "{}", data[0])
|
| 64 |
}
|
| 65 |
-
ValueKind::I8 if data.
|
| 66 |
write!(w, "{}", data[0] as i8)
|
| 67 |
}
|
| 68 |
ValueKind::U16 if data.len() >= 2 => {
|
|
@@ -85,7 +85,7 @@ pub fn format_field(
|
|
| 85 |
let v = i32::from_le_bytes([data[0], data[1], data[2], data[3]]);
|
| 86 |
write!(w, "{}", v)
|
| 87 |
}
|
| 88 |
-
ValueKind::Bool if data.
|
| 89 |
0 => write!(w, "false"),
|
| 90 |
1 => write!(w, "true"),
|
| 91 |
v => write!(w, "??(0x{:02X})", v),
|
|
|
|
| 59 |
|
| 60 |
// Built-in defaults
|
| 61 |
match field.kind {
|
| 62 |
+
ValueKind::U8 if !data.is_empty() => {
|
| 63 |
write!(w, "{}", data[0])
|
| 64 |
}
|
| 65 |
+
ValueKind::I8 if !data.is_empty() => {
|
| 66 |
write!(w, "{}", data[0] as i8)
|
| 67 |
}
|
| 68 |
ValueKind::U16 if data.len() >= 2 => {
|
|
|
|
| 85 |
let v = i32::from_le_bytes([data[0], data[1], data[2], data[3]]);
|
| 86 |
write!(w, "{}", v)
|
| 87 |
}
|
| 88 |
+
ValueKind::Bool if !data.is_empty() => match data[0] {
|
| 89 |
0 => write!(w, "false"),
|
| 90 |
1 => write!(w, "true"),
|
| 91 |
v => write!(w, "??(0x{:02X})", v),
|
crates/openwa-debug-cli/src/main.rs
CHANGED
|
@@ -404,15 +404,14 @@ fn resolve_offset(s: &str, class: &Option<String>, port: u16) -> u32 {
|
|
| 404 |
|
| 405 |
// Try as field name
|
| 406 |
if let Some(cls) = class {
|
| 407 |
-
|
| 408 |
port,
|
| 409 |
&Request::ResolveField {
|
| 410 |
class_name: cls.clone(),
|
| 411 |
field_name: s.to_string(),
|
| 412 |
},
|
| 413 |
) {
|
| 414 |
-
|
| 415 |
-
_ => {}
|
| 416 |
}
|
| 417 |
}
|
| 418 |
|
|
@@ -473,7 +472,7 @@ fn resolve_address_expr(s: &str, port: u16) -> AddressExpr {
|
|
| 473 |
let (s, absolute) = if let Some(rest) = s.strip_prefix("abs:") {
|
| 474 |
(rest, true)
|
| 475 |
} else {
|
| 476 |
-
(s
|
| 477 |
};
|
| 478 |
|
| 479 |
// Split on "->" for chain syntax
|
|
@@ -539,7 +538,7 @@ fn resolve_base(s: &str, absolute: bool, port: u16) -> (u32, bool, Option<String
|
|
| 539 |
|
| 540 |
// If it looks like hex (starts with digit or 0x), parse directly
|
| 541 |
if looks_like_hex(base_str) {
|
| 542 |
-
let extra = offset_str.map(
|
| 543 |
return (parse_hex(base_str).wrapping_add(extra), absolute, None);
|
| 544 |
}
|
| 545 |
|
|
@@ -560,7 +559,7 @@ fn resolve_base(s: &str, absolute: bool, port: u16) -> (u32, bool, Option<String
|
|
| 560 |
}
|
| 561 |
_ => {
|
| 562 |
// Fall back to hex parse (will error if not valid hex)
|
| 563 |
-
let extra = offset_str.map(
|
| 564 |
(parse_hex(base_str).wrapping_add(extra), absolute, None)
|
| 565 |
}
|
| 566 |
}
|
|
@@ -580,17 +579,14 @@ fn resolve_chain_segment_typed(s: &str, current_class: &Option<String>, port: u1
|
|
| 580 |
|
| 581 |
// Try resolving as a field name if we know the current class
|
| 582 |
if let Some(class) = current_class {
|
| 583 |
-
|
| 584 |
port,
|
| 585 |
&Request::ResolveField {
|
| 586 |
class_name: class.clone(),
|
| 587 |
field_name: base_str.to_string(),
|
| 588 |
},
|
| 589 |
) {
|
| 590 |
-
|
| 591 |
-
return ChainSegment::FieldOffset(f.offset.wrapping_add(extra));
|
| 592 |
-
}
|
| 593 |
-
_ => {}
|
| 594 |
}
|
| 595 |
}
|
| 596 |
|
|
@@ -602,7 +598,7 @@ fn resolve_chain_segment_typed(s: &str, current_class: &Option<String>, port: u1
|
|
| 602 |
fn looks_like_hex(s: &str) -> bool {
|
| 603 |
s.starts_with("0x")
|
| 604 |
|| s.starts_with("0X")
|
| 605 |
-
|| s.chars().next().
|
| 606 |
}
|
| 607 |
|
| 608 |
fn print_usage() {
|
|
|
|
| 404 |
|
| 405 |
// Try as field name
|
| 406 |
if let Some(cls) = class {
|
| 407 |
+
if let Ok(Response::FieldResult(f)) = send_request(
|
| 408 |
port,
|
| 409 |
&Request::ResolveField {
|
| 410 |
class_name: cls.clone(),
|
| 411 |
field_name: s.to_string(),
|
| 412 |
},
|
| 413 |
) {
|
| 414 |
+
return f.offset;
|
|
|
|
| 415 |
}
|
| 416 |
}
|
| 417 |
|
|
|
|
| 472 |
let (s, absolute) = if let Some(rest) = s.strip_prefix("abs:") {
|
| 473 |
(rest, true)
|
| 474 |
} else {
|
| 475 |
+
(s, false)
|
| 476 |
};
|
| 477 |
|
| 478 |
// Split on "->" for chain syntax
|
|
|
|
| 538 |
|
| 539 |
// If it looks like hex (starts with digit or 0x), parse directly
|
| 540 |
if looks_like_hex(base_str) {
|
| 541 |
+
let extra = offset_str.map(parse_u32).unwrap_or(0);
|
| 542 |
return (parse_hex(base_str).wrapping_add(extra), absolute, None);
|
| 543 |
}
|
| 544 |
|
|
|
|
| 559 |
}
|
| 560 |
_ => {
|
| 561 |
// Fall back to hex parse (will error if not valid hex)
|
| 562 |
+
let extra = offset_str.map(parse_u32).unwrap_or(0);
|
| 563 |
(parse_hex(base_str).wrapping_add(extra), absolute, None)
|
| 564 |
}
|
| 565 |
}
|
|
|
|
| 579 |
|
| 580 |
// Try resolving as a field name if we know the current class
|
| 581 |
if let Some(class) = current_class {
|
| 582 |
+
if let Ok(Response::FieldResult(f)) = send_request(
|
| 583 |
port,
|
| 584 |
&Request::ResolveField {
|
| 585 |
class_name: class.clone(),
|
| 586 |
field_name: base_str.to_string(),
|
| 587 |
},
|
| 588 |
) {
|
| 589 |
+
return ChainSegment::FieldOffset(f.offset.wrapping_add(extra));
|
|
|
|
|
|
|
|
|
|
| 590 |
}
|
| 591 |
}
|
| 592 |
|
|
|
|
| 598 |
fn looks_like_hex(s: &str) -> bool {
|
| 599 |
s.starts_with("0x")
|
| 600 |
|| s.starts_with("0X")
|
| 601 |
+
|| s.chars().next().is_some_and(|c| c.is_ascii_digit())
|
| 602 |
}
|
| 603 |
|
| 604 |
fn print_usage() {
|
crates/openwa-dll/src/replacements/bitgrid.rs
CHANGED
|
@@ -357,6 +357,7 @@ pub unsafe fn capture_blit_snapshots() {
|
|
| 357 |
let dst_size = ((*dst).row_stride * dh) as usize;
|
| 358 |
|
| 359 |
// Test cases: (name_suffix, dst_x, dst_y, width, height, src_x, src_y, flags, bg_fill)
|
|
|
|
| 360 |
let test_cases: &[(&str, i32, i32, i32, i32, i32, i32, u32, u8)] = &[
|
| 361 |
// Basic orientations (blend mode 0 = direct copy)
|
| 362 |
("identity", 16, 16, sw, sh, 0, 0, 0x0000_0000, 0),
|
|
|
|
| 357 |
let dst_size = ((*dst).row_stride * dh) as usize;
|
| 358 |
|
| 359 |
// Test cases: (name_suffix, dst_x, dst_y, width, height, src_x, src_y, flags, bg_fill)
|
| 360 |
+
#[allow(clippy::type_complexity)]
|
| 361 |
let test_cases: &[(&str, i32, i32, i32, i32, i32, i32, u32, u8)] = &[
|
| 362 |
// Basic orientations (blend mode 0 = direct copy)
|
| 363 |
("identity", 16, 16, sw, sh, 0, 0, 0x0000_0000, 0),
|
crates/openwa-dll/src/replacements/config.rs
CHANGED
|
@@ -57,7 +57,7 @@ unsafe extern "stdcall" fn hook_theme_load(dest: u32) {
|
|
| 57 |
/// stdcall(buffer: *const u8, size: u32)
|
| 58 |
unsafe extern "stdcall" fn hook_theme_save(buffer: u32, size: u32) {
|
| 59 |
let data = core::slice::from_raw_parts(buffer as *const u8, size as usize);
|
| 60 |
-
if
|
| 61 |
show_error_message("ERROR: Could Not create CURRENT.THM File");
|
| 62 |
}
|
| 63 |
}
|
|
@@ -124,7 +124,7 @@ unsafe extern "stdcall" fn hook_registry_clean_all(struct_ptr: u32) {
|
|
| 124 |
extern "system" {
|
| 125 |
fn WriteProfileSectionA(app_name: *const u8, string: *const u8) -> i32;
|
| 126 |
}
|
| 127 |
-
WriteProfileSectionA(
|
| 128 |
|
| 129 |
*((struct_ptr as usize + CLEAN_ALL_FLAG_OFFSET) as *mut u8) = 0;
|
| 130 |
|
|
|
|
| 57 |
/// stdcall(buffer: *const u8, size: u32)
|
| 58 |
unsafe extern "stdcall" fn hook_theme_save(buffer: u32, size: u32) {
|
| 59 |
let data = core::slice::from_raw_parts(buffer as *const u8, size as usize);
|
| 60 |
+
if std::fs::write(THEME_PATH, data).is_err() {
|
| 61 |
show_error_message("ERROR: Could Not create CURRENT.THM File");
|
| 62 |
}
|
| 63 |
}
|
|
|
|
| 124 |
extern "system" {
|
| 125 |
fn WriteProfileSectionA(app_name: *const u8, string: *const u8) -> i32;
|
| 126 |
}
|
| 127 |
+
WriteProfileSectionA(c"NetSettings".as_ptr().cast(), c"".as_ptr().cast());
|
| 128 |
|
| 129 |
*((struct_ptr as usize + CLEAN_ALL_FLAG_OFFSET) as *mut u8) = 0;
|
| 130 |
|
crates/openwa-dll/src/replacements/file_isolation.rs
CHANGED
|
@@ -16,17 +16,17 @@ use core::sync::atomic::{AtomicU32, Ordering};
|
|
| 16 |
use std::ffi::CStr;
|
| 17 |
use std::sync::OnceLock;
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
type LpSecurityAttributes = *mut c_void;
|
| 22 |
|
| 23 |
type CreateFileAFn = unsafe extern "system" fn(
|
| 24 |
lpFileName: *const u8,
|
| 25 |
-
dwDesiredAccess:
|
| 26 |
-
dwShareMode:
|
| 27 |
lpSecurityAttributes: LpSecurityAttributes,
|
| 28 |
-
dwCreationDisposition:
|
| 29 |
-
dwFlagsAndAttributes:
|
| 30 |
hTemplateFile: HANDLE,
|
| 31 |
) -> HANDLE;
|
| 32 |
|
|
@@ -101,11 +101,11 @@ fn redirect_path(path: &str) -> Option<String> {
|
|
| 101 |
|
| 102 |
unsafe extern "system" fn hook_create_file_a(
|
| 103 |
lp_file_name: *const u8,
|
| 104 |
-
desired_access:
|
| 105 |
-
share_mode:
|
| 106 |
security_attributes: LpSecurityAttributes,
|
| 107 |
-
creation_disposition:
|
| 108 |
-
flags_and_attributes:
|
| 109 |
template_file: HANDLE,
|
| 110 |
) -> HANDLE {
|
| 111 |
let orig: CreateFileAFn = core::mem::transmute(ORIG_CREATE_FILE_A.load(Ordering::Relaxed));
|
|
@@ -147,15 +147,16 @@ pub fn install() -> Result<(), String> {
|
|
| 147 |
}
|
| 148 |
|
| 149 |
unsafe {
|
| 150 |
-
let module =
|
| 151 |
-
|
|
|
|
| 152 |
if module.is_null() {
|
| 153 |
return Err("kernel32.dll not loaded".to_string());
|
| 154 |
}
|
| 155 |
|
| 156 |
let proc = windows_sys::Win32::System::LibraryLoader::GetProcAddress(
|
| 157 |
module,
|
| 158 |
-
|
| 159 |
);
|
| 160 |
let addr = proc.ok_or("CreateFileA not found in kernel32.dll")?;
|
| 161 |
let target = addr as *mut c_void;
|
|
|
|
| 16 |
use std::ffi::CStr;
|
| 17 |
use std::sync::OnceLock;
|
| 18 |
|
| 19 |
+
use windows_sys::Win32::Foundation::HANDLE;
|
| 20 |
+
|
| 21 |
type LpSecurityAttributes = *mut c_void;
|
| 22 |
|
| 23 |
type CreateFileAFn = unsafe extern "system" fn(
|
| 24 |
lpFileName: *const u8,
|
| 25 |
+
dwDesiredAccess: u32,
|
| 26 |
+
dwShareMode: u32,
|
| 27 |
lpSecurityAttributes: LpSecurityAttributes,
|
| 28 |
+
dwCreationDisposition: u32,
|
| 29 |
+
dwFlagsAndAttributes: u32,
|
| 30 |
hTemplateFile: HANDLE,
|
| 31 |
) -> HANDLE;
|
| 32 |
|
|
|
|
| 101 |
|
| 102 |
unsafe extern "system" fn hook_create_file_a(
|
| 103 |
lp_file_name: *const u8,
|
| 104 |
+
desired_access: u32,
|
| 105 |
+
share_mode: u32,
|
| 106 |
security_attributes: LpSecurityAttributes,
|
| 107 |
+
creation_disposition: u32,
|
| 108 |
+
flags_and_attributes: u32,
|
| 109 |
template_file: HANDLE,
|
| 110 |
) -> HANDLE {
|
| 111 |
let orig: CreateFileAFn = core::mem::transmute(ORIG_CREATE_FILE_A.load(Ordering::Relaxed));
|
|
|
|
| 147 |
}
|
| 148 |
|
| 149 |
unsafe {
|
| 150 |
+
let module = windows_sys::Win32::System::LibraryLoader::GetModuleHandleA(
|
| 151 |
+
c"kernel32.dll".as_ptr().cast(),
|
| 152 |
+
);
|
| 153 |
if module.is_null() {
|
| 154 |
return Err("kernel32.dll not loaded".to_string());
|
| 155 |
}
|
| 156 |
|
| 157 |
let proc = windows_sys::Win32::System::LibraryLoader::GetProcAddress(
|
| 158 |
module,
|
| 159 |
+
c"CreateFileA".as_ptr().cast(),
|
| 160 |
);
|
| 161 |
let addr = proc.ok_or("CreateFileA not found in kernel32.dll")?;
|
| 162 |
let target = addr as *mut c_void;
|
crates/openwa-dll/src/replacements/headless.rs
CHANGED
|
@@ -78,8 +78,9 @@ pub fn install() -> Result<(), String> {
|
|
| 78 |
let _ = log_line("[Headless] Suppressing all message boxes");
|
| 79 |
|
| 80 |
unsafe {
|
| 81 |
-
let module =
|
| 82 |
-
|
|
|
|
| 83 |
if module.is_null() {
|
| 84 |
return Err("user32.dll not loaded".to_string());
|
| 85 |
}
|
|
@@ -116,12 +117,13 @@ pub fn install() -> Result<(), String> {
|
|
| 116 |
// semaphore per-PID. Without this, concurrent WA.exe instances detect
|
| 117 |
// each other and skip initialization or show warnings.
|
| 118 |
unsafe {
|
| 119 |
-
let k32 =
|
| 120 |
-
|
|
|
|
| 121 |
if !k32.is_null() {
|
| 122 |
let proc = windows_sys::Win32::System::LibraryLoader::GetProcAddress(
|
| 123 |
k32,
|
| 124 |
-
|
| 125 |
);
|
| 126 |
if let Some(addr) = proc {
|
| 127 |
let target = addr as *mut core::ffi::c_void;
|
|
|
|
| 78 |
let _ = log_line("[Headless] Suppressing all message boxes");
|
| 79 |
|
| 80 |
unsafe {
|
| 81 |
+
let module = windows_sys::Win32::System::LibraryLoader::GetModuleHandleA(
|
| 82 |
+
c"user32.dll".as_ptr().cast(),
|
| 83 |
+
);
|
| 84 |
if module.is_null() {
|
| 85 |
return Err("user32.dll not loaded".to_string());
|
| 86 |
}
|
|
|
|
| 117 |
// semaphore per-PID. Without this, concurrent WA.exe instances detect
|
| 118 |
// each other and skip initialization or show warnings.
|
| 119 |
unsafe {
|
| 120 |
+
let k32 = windows_sys::Win32::System::LibraryLoader::GetModuleHandleA(
|
| 121 |
+
c"kernel32.dll".as_ptr().cast(),
|
| 122 |
+
);
|
| 123 |
if !k32.is_null() {
|
| 124 |
let proc = windows_sys::Win32::System::LibraryLoader::GetProcAddress(
|
| 125 |
k32,
|
| 126 |
+
c"CreateSemaphoreA".as_ptr().cast(),
|
| 127 |
);
|
| 128 |
if let Some(addr) = proc {
|
| 129 |
let target = addr as *mut core::ffi::c_void;
|
crates/openwa-dll/src/replacements/replay.rs
CHANGED
|
@@ -37,7 +37,7 @@ fn playback_thm_path() -> String {
|
|
| 37 |
// WA's CRT FILE* can't be used with Rust's std::fs::File directly, but we can
|
| 38 |
// extract the Win32 HANDLE via _fileno + _get_osfhandle and wrap it.
|
| 39 |
|
| 40 |
-
#[allow(non_camel_case_types)]
|
| 41 |
type FILE = c_void;
|
| 42 |
|
| 43 |
/// Convert a WA CRT FILE* to a borrowed Rust File (ManuallyDrop — we don't own it).
|
|
|
|
| 37 |
// WA's CRT FILE* can't be used with Rust's std::fs::File directly, but we can
|
| 38 |
// extract the Win32 HANDLE via _fileno + _get_osfhandle and wrap it.
|
| 39 |
|
| 40 |
+
#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
|
| 41 |
type FILE = c_void;
|
| 42 |
|
| 43 |
/// Convert a WA CRT FILE* to a borrowed Rust File (ManuallyDrop — we don't own it).
|
crates/openwa-dll/src/replacements/sprite.rs
CHANGED
|
@@ -152,7 +152,7 @@ unsafe extern "cdecl" fn process_sprite_impl(
|
|
| 152 |
if !has_secondary {
|
| 153 |
// Remap every bitmap byte: pixel = lookup_table[pixel]
|
| 154 |
let bitmap_byte_count_raw = (data_size as usize + 4).saturating_sub(hdr.bitmap_offset);
|
| 155 |
-
let dword_count =
|
| 156 |
let remap_byte_count = dword_count * 4;
|
| 157 |
|
| 158 |
for i in 0..remap_byte_count {
|
|
|
|
| 152 |
if !has_secondary {
|
| 153 |
// Remap every bitmap byte: pixel = lookup_table[pixel]
|
| 154 |
let bitmap_byte_count_raw = (data_size as usize + 4).saturating_sub(hdr.bitmap_offset);
|
| 155 |
+
let dword_count = bitmap_byte_count_raw.div_ceil(4);
|
| 156 |
let remap_byte_count = dword_count * 4;
|
| 157 |
|
| 158 |
for i in 0..remap_byte_count {
|
crates/openwa-launcher/Cargo.toml
CHANGED
|
@@ -10,3 +10,13 @@ path = "src/main.rs"
|
|
| 10 |
|
| 11 |
[dependencies]
|
| 12 |
openwa-config = { path = "../openwa-config" }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
[dependencies]
|
| 12 |
openwa-config = { path = "../openwa-config" }
|
| 13 |
+
|
| 14 |
+
[target.'cfg(target_os = "windows")'.dependencies]
|
| 15 |
+
windows-sys = { version = "0.59", features = [
|
| 16 |
+
"Win32_Foundation",
|
| 17 |
+
"Win32_Security",
|
| 18 |
+
"Win32_System_Diagnostics_Debug",
|
| 19 |
+
"Win32_System_LibraryLoader",
|
| 20 |
+
"Win32_System_Memory",
|
| 21 |
+
"Win32_System_Threading",
|
| 22 |
+
] }
|
crates/openwa-launcher/src/inject.rs
CHANGED
|
@@ -2,62 +2,13 @@ use std::ffi::CString;
|
|
| 2 |
use std::mem;
|
| 3 |
use std::ptr;
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
#[allow(non_camel_case_types)]
|
| 13 |
-
type SIZE_T = usize;
|
| 14 |
-
#[allow(non_camel_case_types)]
|
| 15 |
-
type DWORD = u32;
|
| 16 |
-
#[allow(non_camel_case_types)]
|
| 17 |
-
type BOOL = i32;
|
| 18 |
-
type FARPROC = unsafe extern "system" fn() -> isize;
|
| 19 |
-
|
| 20 |
-
extern "system" {
|
| 21 |
-
fn VirtualAllocEx(
|
| 22 |
-
hProcess: HANDLE,
|
| 23 |
-
lpAddress: LPVOID,
|
| 24 |
-
dwSize: SIZE_T,
|
| 25 |
-
flAllocationType: DWORD,
|
| 26 |
-
flProtect: DWORD,
|
| 27 |
-
) -> LPVOID;
|
| 28 |
-
fn VirtualFreeEx(
|
| 29 |
-
hProcess: HANDLE,
|
| 30 |
-
lpAddress: LPVOID,
|
| 31 |
-
dwSize: SIZE_T,
|
| 32 |
-
dwFreeType: DWORD,
|
| 33 |
-
) -> BOOL;
|
| 34 |
-
fn WriteProcessMemory(
|
| 35 |
-
hProcess: HANDLE,
|
| 36 |
-
lpBaseAddress: LPVOID,
|
| 37 |
-
lpBuffer: LPCVOID,
|
| 38 |
-
nSize: SIZE_T,
|
| 39 |
-
lpNumberOfBytesWritten: *mut SIZE_T,
|
| 40 |
-
) -> BOOL;
|
| 41 |
-
fn GetModuleHandleA(lpModuleName: *const u8) -> HANDLE;
|
| 42 |
-
fn GetProcAddress(hModule: HANDLE, lpProcName: *const u8) -> Option<FARPROC>;
|
| 43 |
-
fn CreateRemoteThread(
|
| 44 |
-
hProcess: HANDLE,
|
| 45 |
-
lpThreadAttributes: LPVOID,
|
| 46 |
-
dwStackSize: SIZE_T,
|
| 47 |
-
lpStartAddress: unsafe extern "system" fn(LPVOID) -> DWORD,
|
| 48 |
-
lpParameter: LPVOID,
|
| 49 |
-
dwCreationFlags: DWORD,
|
| 50 |
-
lpThreadId: *mut DWORD,
|
| 51 |
-
) -> HANDLE;
|
| 52 |
-
fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD;
|
| 53 |
-
fn CloseHandle(hObject: HANDLE) -> BOOL;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
const MEM_COMMIT: DWORD = 0x1000;
|
| 57 |
-
const MEM_RESERVE: DWORD = 0x2000;
|
| 58 |
-
const MEM_RELEASE: DWORD = 0x8000;
|
| 59 |
-
const PAGE_READWRITE: DWORD = 0x04;
|
| 60 |
-
const INFINITE: DWORD = 0xFFFF_FFFF;
|
| 61 |
|
| 62 |
/// Inject `dll_path` into `process` by creating a remote thread that calls `LoadLibraryA`.
|
| 63 |
///
|
|
@@ -70,7 +21,7 @@ pub unsafe fn inject_dll(process: HANDLE, dll_path: &str) -> Result<(), String>
|
|
| 70 |
// Allocate memory in the target process for the DLL path string.
|
| 71 |
let remote_buf = VirtualAllocEx(
|
| 72 |
process,
|
| 73 |
-
ptr::
|
| 74 |
path_bytes.len(),
|
| 75 |
MEM_COMMIT | MEM_RESERVE,
|
| 76 |
PAGE_READWRITE,
|
|
@@ -94,12 +45,12 @@ pub unsafe fn inject_dll(process: HANDLE, dll_path: &str) -> Result<(), String>
|
|
| 94 |
|
| 95 |
// LoadLibraryA lives at the same address in every process (kernel32 is always mapped
|
| 96 |
// at the same base across all processes on the same OS session due to ASLR sharing).
|
| 97 |
-
let k32 = GetModuleHandleA(
|
| 98 |
if k32.is_null() {
|
| 99 |
VirtualFreeEx(process, remote_buf, 0, MEM_RELEASE);
|
| 100 |
return Err("GetModuleHandleA(kernel32) failed".to_string());
|
| 101 |
}
|
| 102 |
-
let load_library = GetProcAddress(k32,
|
| 103 |
let Some(load_library) = load_library else {
|
| 104 |
VirtualFreeEx(process, remote_buf, 0, MEM_RELEASE);
|
| 105 |
return Err("GetProcAddress(LoadLibraryA) failed".to_string());
|
|
@@ -109,9 +60,12 @@ pub unsafe fn inject_dll(process: HANDLE, dll_path: &str) -> Result<(), String>
|
|
| 109 |
// This triggers DllMain(DLL_PROCESS_ATTACH) which installs all our hooks.
|
| 110 |
let thread = CreateRemoteThread(
|
| 111 |
process,
|
| 112 |
-
ptr::
|
| 113 |
0,
|
| 114 |
-
mem::transmute
|
|
|
|
|
|
|
|
|
|
| 115 |
remote_buf,
|
| 116 |
0,
|
| 117 |
ptr::null_mut(),
|
|
|
|
| 2 |
use std::mem;
|
| 3 |
use std::ptr;
|
| 4 |
|
| 5 |
+
use windows_sys::Win32::Foundation::{CloseHandle, HANDLE};
|
| 6 |
+
use windows_sys::Win32::System::Diagnostics::Debug::WriteProcessMemory;
|
| 7 |
+
use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};
|
| 8 |
+
use windows_sys::Win32::System::Memory::{
|
| 9 |
+
VirtualAllocEx, VirtualFreeEx, MEM_COMMIT, MEM_RELEASE, MEM_RESERVE, PAGE_READWRITE,
|
| 10 |
+
};
|
| 11 |
+
use windows_sys::Win32::System::Threading::{CreateRemoteThread, WaitForSingleObject, INFINITE};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
/// Inject `dll_path` into `process` by creating a remote thread that calls `LoadLibraryA`.
|
| 14 |
///
|
|
|
|
| 21 |
// Allocate memory in the target process for the DLL path string.
|
| 22 |
let remote_buf = VirtualAllocEx(
|
| 23 |
process,
|
| 24 |
+
ptr::null(),
|
| 25 |
path_bytes.len(),
|
| 26 |
MEM_COMMIT | MEM_RESERVE,
|
| 27 |
PAGE_READWRITE,
|
|
|
|
| 45 |
|
| 46 |
// LoadLibraryA lives at the same address in every process (kernel32 is always mapped
|
| 47 |
// at the same base across all processes on the same OS session due to ASLR sharing).
|
| 48 |
+
let k32 = GetModuleHandleA(c"kernel32.dll".as_ptr().cast());
|
| 49 |
if k32.is_null() {
|
| 50 |
VirtualFreeEx(process, remote_buf, 0, MEM_RELEASE);
|
| 51 |
return Err("GetModuleHandleA(kernel32) failed".to_string());
|
| 52 |
}
|
| 53 |
+
let load_library = GetProcAddress(k32, c"LoadLibraryA".as_ptr().cast());
|
| 54 |
let Some(load_library) = load_library else {
|
| 55 |
VirtualFreeEx(process, remote_buf, 0, MEM_RELEASE);
|
| 56 |
return Err("GetProcAddress(LoadLibraryA) failed".to_string());
|
|
|
|
| 60 |
// This triggers DllMain(DLL_PROCESS_ATTACH) which installs all our hooks.
|
| 61 |
let thread = CreateRemoteThread(
|
| 62 |
process,
|
| 63 |
+
ptr::null(),
|
| 64 |
0,
|
| 65 |
+
Some(mem::transmute::<
|
| 66 |
+
unsafe extern "system" fn() -> isize,
|
| 67 |
+
unsafe extern "system" fn(*mut core::ffi::c_void) -> u32,
|
| 68 |
+
>(load_library)),
|
| 69 |
remote_buf,
|
| 70 |
0,
|
| 71 |
ptr::null_mut(),
|
crates/openwa-launcher/src/main.rs
CHANGED
|
@@ -5,86 +5,16 @@ use std::mem;
|
|
| 5 |
use std::path::{Path, PathBuf};
|
| 6 |
use std::ptr;
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
#[allow(non_camel_case_types)]
|
| 16 |
-
type BOOL = i32;
|
| 17 |
-
#[allow(non_camel_case_types)]
|
| 18 |
-
type LPVOID = *mut core::ffi::c_void;
|
| 19 |
-
#[allow(non_camel_case_types)]
|
| 20 |
-
type LPDWORD = *mut u32;
|
| 21 |
-
|
| 22 |
-
#[repr(C)]
|
| 23 |
-
#[allow(non_snake_case)]
|
| 24 |
-
struct STARTUPINFOA {
|
| 25 |
-
cb: DWORD,
|
| 26 |
-
lpReserved: *mut u8,
|
| 27 |
-
lpDesktop: *mut u8,
|
| 28 |
-
lpTitle: *mut u8,
|
| 29 |
-
dwX: DWORD,
|
| 30 |
-
dwY: DWORD,
|
| 31 |
-
dwXSize: DWORD,
|
| 32 |
-
dwYSize: DWORD,
|
| 33 |
-
dwXCountChars: DWORD,
|
| 34 |
-
dwYCountChars: DWORD,
|
| 35 |
-
dwFillAttribute: DWORD,
|
| 36 |
-
dwFlags: DWORD,
|
| 37 |
-
wShowWindow: u16,
|
| 38 |
-
cbReserved2: u16,
|
| 39 |
-
lpReserved2: *mut u8,
|
| 40 |
-
hStdInput: HANDLE,
|
| 41 |
-
hStdOutput: HANDLE,
|
| 42 |
-
hStdError: HANDLE,
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
#[repr(C)]
|
| 46 |
-
#[allow(non_snake_case)]
|
| 47 |
-
struct PROCESS_INFORMATION {
|
| 48 |
-
hProcess: HANDLE,
|
| 49 |
-
hThread: HANDLE,
|
| 50 |
-
dwProcessId: DWORD,
|
| 51 |
-
dwThreadId: DWORD,
|
| 52 |
-
}
|
| 53 |
|
| 54 |
-
const CREATE_SUSPENDED: DWORD = 0x0000_0004;
|
| 55 |
-
const CREATE_NO_WINDOW: DWORD = 0x0800_0000;
|
| 56 |
-
const STARTF_USESHOWWINDOW: DWORD = 0x0000_0001;
|
| 57 |
const SW_HIDE: u16 = 0;
|
| 58 |
const SW_SHOWMINIMIZED: u16 = 2;
|
| 59 |
-
const INFINITE: DWORD = 0xFFFF_FFFF;
|
| 60 |
-
|
| 61 |
-
#[link(name = "kernel32")]
|
| 62 |
-
extern "system" {
|
| 63 |
-
fn CreateProcessA(
|
| 64 |
-
lpApplicationName: *const u8,
|
| 65 |
-
lpCommandLine: *mut u8,
|
| 66 |
-
lpProcessAttributes: LPVOID,
|
| 67 |
-
lpThreadAttributes: LPVOID,
|
| 68 |
-
bInheritHandles: BOOL,
|
| 69 |
-
dwCreationFlags: DWORD,
|
| 70 |
-
lpEnvironment: LPVOID,
|
| 71 |
-
lpCurrentDirectory: *const u8,
|
| 72 |
-
lpStartupInfo: *const STARTUPINFOA,
|
| 73 |
-
lpProcessInformation: *mut PROCESS_INFORMATION,
|
| 74 |
-
) -> BOOL;
|
| 75 |
-
fn ResumeThread(hThread: HANDLE) -> DWORD;
|
| 76 |
-
fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD;
|
| 77 |
-
fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL;
|
| 78 |
-
fn TerminateProcess(hProcess: HANDLE, uExitCode: u32) -> BOOL;
|
| 79 |
-
fn CloseHandle(hObject: HANDLE) -> BOOL;
|
| 80 |
-
fn GetModuleFileNameA(hModule: HMODULE, lpFilename: *mut u8, nSize: DWORD) -> DWORD;
|
| 81 |
-
fn CreateEventA(
|
| 82 |
-
lpEventAttributes: LPVOID,
|
| 83 |
-
bManualReset: BOOL,
|
| 84 |
-
bInitialState: BOOL,
|
| 85 |
-
lpName: *const u8,
|
| 86 |
-
) -> HANDLE;
|
| 87 |
-
}
|
| 88 |
|
| 89 |
fn main() {
|
| 90 |
if let Err(e) = run() {
|
|
@@ -171,7 +101,7 @@ unsafe fn launch(
|
|
| 171 |
let headless = std::env::var("OPENWA_HEADLESS").is_ok();
|
| 172 |
|
| 173 |
let mut si: STARTUPINFOA = mem::zeroed();
|
| 174 |
-
si.cb = mem::size_of::<STARTUPINFOA>() as
|
| 175 |
if headless {
|
| 176 |
si.dwFlags |= STARTF_USESHOWWINDOW;
|
| 177 |
si.wShowWindow = SW_HIDE;
|
|
@@ -185,11 +115,11 @@ unsafe fn launch(
|
|
| 185 |
let ok = CreateProcessA(
|
| 186 |
exe_cstr.as_ptr().cast(),
|
| 187 |
cmdline_buf.as_mut_ptr(),
|
| 188 |
-
ptr::
|
| 189 |
-
ptr::
|
| 190 |
0, // bInheritHandles = FALSE
|
| 191 |
CREATE_SUSPENDED | if headless { CREATE_NO_WINDOW } else { 0 },
|
| 192 |
-
ptr::
|
| 193 |
wd_cstr.as_ptr().cast(),
|
| 194 |
&si,
|
| 195 |
&mut pi,
|
|
@@ -216,7 +146,7 @@ unsafe fn launch(
|
|
| 216 |
// possible for a suspended process. So we rely on the DLL reading the
|
| 217 |
// event name from a fixed pattern: OpenWA_HooksReady_{its_own_pid}.
|
| 218 |
// The DLL can call GetCurrentProcessId() to reconstruct the same name.
|
| 219 |
-
let event = CreateEventA(ptr::
|
| 220 |
// event may be null if CreateEventA fails — we'll fall through gracefully.
|
| 221 |
|
| 222 |
if let Err(e) = inject::inject_dll(pi.hProcess, dll_str) {
|
|
@@ -247,7 +177,7 @@ unsafe fn launch(
|
|
| 247 |
|
| 248 |
// Wait for WA.exe to exit, then propagate its exit code.
|
| 249 |
WaitForSingleObject(pi.hProcess, INFINITE);
|
| 250 |
-
let mut exit_code:
|
| 251 |
GetExitCodeProcess(pi.hProcess, &mut exit_code);
|
| 252 |
CloseHandle(pi.hProcess);
|
| 253 |
|
|
@@ -260,7 +190,7 @@ unsafe fn launch(
|
|
| 260 |
|
| 261 |
fn launcher_dir() -> Result<PathBuf, String> {
|
| 262 |
let mut buf = vec![0u8; 32768];
|
| 263 |
-
let len = unsafe { GetModuleFileNameA(
|
| 264 |
if len == 0 {
|
| 265 |
return Err("GetModuleFileNameA failed".to_string());
|
| 266 |
}
|
|
|
|
| 5 |
use std::path::{Path, PathBuf};
|
| 6 |
use std::ptr;
|
| 7 |
|
| 8 |
+
use windows_sys::Win32::Foundation::{CloseHandle, HMODULE};
|
| 9 |
+
use windows_sys::Win32::System::LibraryLoader::GetModuleFileNameA;
|
| 10 |
+
use windows_sys::Win32::System::Threading::{
|
| 11 |
+
CreateEventA, CreateProcessA, GetExitCodeProcess, ResumeThread, TerminateProcess,
|
| 12 |
+
WaitForSingleObject, CREATE_NO_WINDOW, CREATE_SUSPENDED, INFINITE, PROCESS_INFORMATION,
|
| 13 |
+
STARTF_USESHOWWINDOW, STARTUPINFOA,
|
| 14 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
const SW_HIDE: u16 = 0;
|
| 17 |
const SW_SHOWMINIMIZED: u16 = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
fn main() {
|
| 20 |
if let Err(e) = run() {
|
|
|
|
| 101 |
let headless = std::env::var("OPENWA_HEADLESS").is_ok();
|
| 102 |
|
| 103 |
let mut si: STARTUPINFOA = mem::zeroed();
|
| 104 |
+
si.cb = mem::size_of::<STARTUPINFOA>() as u32;
|
| 105 |
if headless {
|
| 106 |
si.dwFlags |= STARTF_USESHOWWINDOW;
|
| 107 |
si.wShowWindow = SW_HIDE;
|
|
|
|
| 115 |
let ok = CreateProcessA(
|
| 116 |
exe_cstr.as_ptr().cast(),
|
| 117 |
cmdline_buf.as_mut_ptr(),
|
| 118 |
+
ptr::null(),
|
| 119 |
+
ptr::null(),
|
| 120 |
0, // bInheritHandles = FALSE
|
| 121 |
CREATE_SUSPENDED | if headless { CREATE_NO_WINDOW } else { 0 },
|
| 122 |
+
ptr::null(), // inherit environment
|
| 123 |
wd_cstr.as_ptr().cast(),
|
| 124 |
&si,
|
| 125 |
&mut pi,
|
|
|
|
| 146 |
// possible for a suspended process. So we rely on the DLL reading the
|
| 147 |
// event name from a fixed pattern: OpenWA_HooksReady_{its_own_pid}.
|
| 148 |
// The DLL can call GetCurrentProcessId() to reconstruct the same name.
|
| 149 |
+
let event = CreateEventA(ptr::null(), 1, 0, event_name.as_ptr());
|
| 150 |
// event may be null if CreateEventA fails — we'll fall through gracefully.
|
| 151 |
|
| 152 |
if let Err(e) = inject::inject_dll(pi.hProcess, dll_str) {
|
|
|
|
| 177 |
|
| 178 |
// Wait for WA.exe to exit, then propagate its exit code.
|
| 179 |
WaitForSingleObject(pi.hProcess, INFINITE);
|
| 180 |
+
let mut exit_code: u32 = 0;
|
| 181 |
GetExitCodeProcess(pi.hProcess, &mut exit_code);
|
| 182 |
CloseHandle(pi.hProcess);
|
| 183 |
|
|
|
|
| 190 |
|
| 191 |
fn launcher_dir() -> Result<PathBuf, String> {
|
| 192 |
let mut buf = vec![0u8; 32768];
|
| 193 |
+
let len = unsafe { GetModuleFileNameA(HMODULE::default(), buf.as_mut_ptr(), buf.len() as u32) };
|
| 194 |
if len == 0 {
|
| 195 |
return Err("GetModuleFileNameA failed".to_string());
|
| 196 |
}
|