Skip to content

Commit 7b49539

Browse files
committed
Add support for 32-bit processes
1 parent 28052cb commit 7b49539

File tree

5 files changed

+57
-34
lines changed

5 files changed

+57
-34
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ jobs:
1111
uses: actions/checkout@v4
1212

1313
- name: Build Project
14-
run: cargo build --release
14+
run: |
15+
cargo build --release
16+
cargo build --release -p payload --target i686-pc-windows-msvc
17+
18+
- name: Copy 32-bit binaries
19+
shell: powershell
20+
run: Copy-Item -Path .\target\i686-pc-windows-msvc\release\utils.dll -Destination .\target\release\utils32.dll
1521

1622
- name: Generate zip bundle
1723
run: 7z a -tzip Invisiwind.zip .\hide.ahk .\target\release\*.dll .\target\release\*.exe

injector/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2024"
66
[dependencies]
77
clap = { version = "4.5.43", features = ["derive"] }
88
crossbeam-channel = "0.5.15"
9-
dll-syringe = { version = "0.17.0", features = ["rpc-raw"] }
9+
dll-syringe = { version = "0.17.0", features = ["into-x86-from-x64", "rpc-raw"] }
1010
eframe = { version = "0.32.0", features = ["wgpu"] }
1111
egui_extras = "0.32.0"
1212
image = { version = "0.25.6", default-features = false, features = ["ico"]}

injector/src/cli.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ pub fn start() {
9090

9191
processes.into_iter().for_each(|(pid, process)| {
9292
if let Some(hwnds) = windows.remove(&pid) {
93-
native::Injector::set_window_props(process, &hwnds, cli.hide_args.hide, None);
93+
let result =
94+
native::Injector::set_window_props(process, &hwnds, cli.hide_args.hide, None);
95+
if let Err(err) = result {
96+
print_error(format!("Error: {:?}", err));
97+
}
9498
} else {
9599
print_error(format!(
96100
"Cannot find any top level windows for pid {:?}",

injector/src/gui.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ impl Gui {
104104
}
105105
InjectorWorkerEvent::PerformOp(pid, hwnd, hide_window, hide_from_taskbar) => {
106106
println!("performing on op on {:?}", hwnd);
107-
native::Injector::set_window_props_with_pid(
107+
if let Err(error) = native::Injector::set_window_props_with_pid(
108108
pid,
109109
hwnd,
110110
hide_window,
111111
hide_from_taskbar,
112-
);
112+
) {
113+
println!("Failed: {:?}", error);
114+
}
113115
}
114116
}
115117
}

injector/src/native.rs

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use dll_syringe::{
22
Syringe,
3-
process::OwnedProcess,
3+
process::{BorrowedProcessModule, OwnedProcess, Process},
44
rpc::{RawRpcFunctionPtr, RemoteRawProcedure},
55
};
6-
use std::env;
6+
use std::error;
7+
use std::{env, path::PathBuf};
78
use windows::{
89
Win32::{
910
Foundation::{HWND, LPARAM, TRUE, WPARAM},
@@ -185,62 +186,72 @@ pub fn get_top_level_windows() -> Vec<WindowInfo> {
185186
pub struct Injector {}
186187

187188
impl Injector {
188-
pub fn inject_and_get_remote_proc<F>(
189-
syringe: &Syringe,
190-
proc_name: &str,
191-
) -> RemoteRawProcedure<F>
192-
where
193-
F: RawRpcFunctionPtr,
194-
{
195-
let mut dll_path = env::current_exe().unwrap();
189+
fn get_dll_path(process: &OwnedProcess) -> Result<PathBuf, Box<dyn error::Error>> {
190+
let mut dll_path = env::current_exe()?;
196191
dll_path.pop();
197-
dll_path.push("utils.dll");
198192

199-
let injected_payload = syringe.find_or_inject(dll_path).unwrap();
193+
if cfg!(debug_assertions) && process.runs_under_wow64()? {
194+
dll_path.push("../i686-pc-windows-msvc/debug/utils.dll");
195+
} else if process.is_x86()? {
196+
dll_path.push("utils32.dll");
197+
} else {
198+
dll_path.push("utils.dll");
199+
}
200+
201+
Ok(dll_path)
202+
}
200203

201-
return unsafe { syringe.get_raw_procedure::<F>(injected_payload, proc_name) }
202-
.unwrap()
203-
.unwrap();
204+
pub fn get_remote_proc<F: RawRpcFunctionPtr>(
205+
syringe: &Syringe,
206+
module: BorrowedProcessModule<'_>,
207+
proc_name: &str,
208+
) -> Result<RemoteRawProcedure<F>, Box<dyn error::Error>> {
209+
match unsafe { syringe.get_raw_procedure::<F>(module, proc_name) }? {
210+
Some(remote_proc) => Ok(remote_proc),
211+
None => Err(format!("Failed to find procedure {}", proc_name).into()),
212+
}
204213
}
205214

206215
pub fn set_window_props(
207216
target_process: OwnedProcess,
208217
hwnds: &[u32],
209218
hide: bool,
210219
hide_from_taskbar: Option<bool>,
211-
) {
220+
) -> Result<(), Box<dyn error::Error>> {
221+
let dll_path = Self::get_dll_path(&target_process)?;
212222
let syringe = Syringe::for_process(target_process);
223+
let module = syringe.find_or_inject(dll_path)?;
213224

214-
let remote_proc = Self::inject_and_get_remote_proc::<extern "system" fn(HWND, bool) -> bool>(
225+
let remote_proc = Self::get_remote_proc::<extern "system" fn(u32, bool) -> bool>(
215226
&syringe,
227+
module,
216228
"SetWindowVisibility",
217-
);
229+
)?;
218230

219-
let remote_proc2 = Self::inject_and_get_remote_proc::<extern "system" fn(HWND, bool) -> bool>(
231+
let remote_proc2 = Self::get_remote_proc::<extern "system" fn(u32, bool) -> bool>(
220232
&syringe,
233+
module,
221234
"HideFromTaskbar",
222-
);
235+
)?;
223236

224237
for hwnd in hwnds {
225-
remote_proc
226-
.call(HWND(hwnd.clone() as *mut _), hide)
227-
.unwrap();
238+
remote_proc.call(*hwnd, hide).unwrap();
228239

229240
if let Some(hide_from_taskbar) = hide_from_taskbar {
230-
remote_proc2
231-
.call(HWND(hwnd.clone() as *mut _), hide_from_taskbar)
232-
.unwrap();
241+
remote_proc2.call(*hwnd, hide_from_taskbar).unwrap();
233242
}
234243
}
244+
Ok(())
235245
}
236246

237247
pub fn set_window_props_with_pid(
238248
pid: u32,
239249
hwnd: u32,
240250
hide: bool,
241251
hide_from_taskbar: Option<bool>,
242-
) {
243-
let target_process = OwnedProcess::from_pid(pid).unwrap();
244-
Self::set_window_props(target_process, &[hwnd], hide, hide_from_taskbar);
252+
) -> Result<(), Box<dyn error::Error>> {
253+
let target_process = OwnedProcess::from_pid(pid)?;
254+
Self::set_window_props(target_process, &[hwnd], hide, hide_from_taskbar)?;
255+
Ok(())
245256
}
246257
}

0 commit comments

Comments
 (0)