style(hook): clippy -D warnings clean on default + fifa17 features

Modernize manual nul-terminated byte strings to C-string literals (c"...")
at all Win32 GetModuleHandleA/GetProcAddress/getaddrinfo call sites (byte-identical),
drop two redundant SOL_SOCKET-as-i32 casts, remove a needless return in the fifa17
install path, and add a # Safety section to DllMain. Scope the FIFA-23-path
dead-code/unused-import lints (unused only under the fifa17 feature, stripped by the
linker) with a documented crate-level cfg_attr allow. Cross-verified: both the
default and fifa17 builds now pass clippy -D warnings and compile; probe and
capture_baseline still build.
This commit is contained in:
funman300
2026-08-15 19:31:21 +00:00
parent 0d3f33cede
commit d1a71bd5a1
9 changed files with 30 additions and 15 deletions
+3 -3
View File
@@ -191,7 +191,7 @@ pub unsafe extern "system" fn hooked_connect(s: usize, name: *const u8, namelen:
let mut len: i32 = 4; let mut len: i32 = 4;
getsockopt( getsockopt(
s, s,
SOL_SOCKET as i32, SOL_SOCKET,
SO_TYPE, SO_TYPE,
&mut ty as *mut i32 as *mut u8, &mut ty as *mut i32 as *mut u8,
&mut len, &mut len,
@@ -265,11 +265,11 @@ pub unsafe extern "system" fn hooked_wsa_connect(
pub unsafe fn install_inline_connect_hook() -> bool { pub unsafe fn install_inline_connect_hook() -> bool {
use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress}; use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};
let ws2 = GetModuleHandleA(b"ws2_32.dll\0".as_ptr()); let ws2 = GetModuleHandleA(c"ws2_32.dll".as_ptr().cast());
if ws2.is_null() { if ws2.is_null() {
return false; return false;
} }
let connect_fn = match GetProcAddress(ws2, b"connect\0".as_ptr()) { let connect_fn = match GetProcAddress(ws2, c"connect".as_ptr().cast()) {
Some(f) => f as *mut u8, Some(f) => f as *mut u8,
None => return false, None => return false,
}; };
+2 -2
View File
@@ -152,11 +152,11 @@ pub unsafe extern "system" fn hooked_wsaioctl(
pub unsafe fn install_wsaioctl_hook() -> bool { pub unsafe fn install_wsaioctl_hook() -> bool {
use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress}; use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};
let ws2 = GetModuleHandleA(b"ws2_32.dll\0".as_ptr()); let ws2 = GetModuleHandleA(c"ws2_32.dll".as_ptr().cast());
if ws2.is_null() { if ws2.is_null() {
return false; return false;
} }
let fn_ptr = match GetProcAddress(ws2, b"WSAIoctl\0".as_ptr()) { let fn_ptr = match GetProcAddress(ws2, c"WSAIoctl".as_ptr().cast()) {
Some(f) => f as *mut u8, Some(f) => f as *mut u8,
None => return false, None => return false,
}; };
+1 -1
View File
@@ -71,7 +71,7 @@ pub unsafe extern "system" fn hooked_getaddrinfo(
let redirect = REDIRECT_IP let redirect = REDIRECT_IP
.get() .get()
.map(|v| v.as_ptr()) .map(|v| v.as_ptr())
.unwrap_or(b"127.0.0.1\0".as_ptr()); .unwrap_or(c"127.0.0.1".as_ptr().cast());
let real = REAL.get().copied().unwrap_or(sys_getaddrinfo); let real = REAL.get().copied().unwrap_or(sys_getaddrinfo);
return real(redirect, service_name, hints, result); return real(redirect, service_name, hints, result);
} }
+16 -1
View File
@@ -1,3 +1,12 @@
// The `fifa17` feature compiles this shared crate but activates only the FIFA-17
// injection path (fifa17.rs + sbc_*): install_hooks() routes to fifa17::install()
// and the FIFA-23 hook modules are reached solely via install_hooks_fifa23(), which
// is itself `#[cfg(not(feature = "fifa17"))]`. Those modules are therefore compiled
// but unused under `fifa17` (the linker strips them from the cdylib). Scope the
// resulting dead-code/unused-import lints to that feature so both builds stay
// `-D warnings` clean without dropping code the default (FIFA-23) build needs.
#![cfg_attr(feature = "fifa17", allow(dead_code, unused_imports))]
mod config; mod config;
mod connect_hook; mod connect_hook;
mod connectex_hook; mod connectex_hook;
@@ -54,6 +63,13 @@ pub(crate) fn flush_log() {
} }
} }
/// # Safety
///
/// This is the DLL entry point invoked by the Windows loader; it MUST NOT be
/// called manually. `module` must be the valid `HMODULE` the loader passes for
/// this DLL. On `DLL_PROCESS_ATTACH` it installs process-wide inline detours
/// (raw memory patching), so it must run exactly once, on the loader thread,
/// before any hooked API is used.
#[no_mangle] #[no_mangle]
pub unsafe extern "system" fn DllMain(module: HMODULE, reason: u32, _: *mut ()) -> BOOL { pub unsafe extern "system" fn DllMain(module: HMODULE, reason: u32, _: *mut ()) -> BOOL {
if reason == DLL_PROCESS_ATTACH { if reason == DLL_PROCESS_ATTACH {
@@ -73,7 +89,6 @@ unsafe fn install_hooks(module: HMODULE) {
{ {
let _ = module; let _ = module;
fifa17::install(); fifa17::install();
return;
} }
#[cfg(not(feature = "fifa17"))] #[cfg(not(feature = "fifa17"))]
install_hooks_fifa23(module) install_hooks_fifa23(module)
+2 -2
View File
@@ -313,12 +313,12 @@ unsafe fn read_u16(ptr: usize) -> Option<u16> {
/// Resolve CardsDLL's runtime base, or 0. Tries the exact loaded name; the ToolHelp /// Resolve CardsDLL's runtime base, or 0. Tries the exact loaded name; the ToolHelp
/// fallback (name-contains "CardsDLL") lives in the spec — add it if EA ever renames. /// fallback (name-contains "CardsDLL") lives in the spec — add it if EA ever renames.
unsafe fn resolve_cards_base() -> usize { unsafe fn resolve_cards_base() -> usize {
let h = GetModuleHandleA(b"CardsDLL_Win64_retail.dll\0".as_ptr()); let h = GetModuleHandleA(c"CardsDLL_Win64_retail.dll".as_ptr().cast());
if !h.is_null() { if !h.is_null() {
return h as usize; return h as usize;
} }
// Also try the short form some tooling reports. // Also try the short form some tooling reports.
let h2 = GetModuleHandleA(b"CardsDLL.dll\0".as_ptr()); let h2 = GetModuleHandleA(c"CardsDLL.dll".as_ptr().cast());
if !h2.is_null() { if !h2.is_null() {
return h2 as usize; return h2 as usize;
} }
+1 -1
View File
@@ -367,7 +367,7 @@ unsafe fn worker() {
} }
let mut base = 0usize; let mut base = 0usize;
for _ in 0..600u32 { for _ in 0..600u32 {
base = GetModuleHandleA(b"CardsDLL_Win64_retail.dll\0".as_ptr()) as usize; base = GetModuleHandleA(c"CardsDLL_Win64_retail.dll".as_ptr().cast()) as usize;
if base != 0 { if base != 0 {
break; break;
} }
+3 -3
View File
@@ -839,7 +839,7 @@ unsafe fn worker() {
let _pending = CodeInstallerPending; let _pending = CodeInstallerPending;
let mut base = 0usize; let mut base = 0usize;
for _ in 0..600u32 { for _ in 0..600u32 {
base = GetModuleHandleA(b"CardsDLL_Win64_retail.dll\0".as_ptr()) as usize; base = GetModuleHandleA(c"CardsDLL_Win64_retail.dll".as_ptr().cast()) as usize;
if base != 0 { if base != 0 {
break; break;
} }
@@ -926,7 +926,7 @@ unsafe fn notifier_worker() {
let _pending = CodeInstallerPending; let _pending = CodeInstallerPending;
let mut base = 0usize; let mut base = 0usize;
for _ in 0..600u32 { for _ in 0..600u32 {
base = GetModuleHandleA(b"CardsDLL_Win64_retail.dll\0".as_ptr()) as usize; base = GetModuleHandleA(c"CardsDLL_Win64_retail.dll".as_ptr().cast()) as usize;
if base != 0 { if base != 0 {
break; break;
} }
@@ -1029,7 +1029,7 @@ unsafe fn controller_register_worker() {
let _pending = CodeInstallerPending; let _pending = CodeInstallerPending;
let mut base = 0usize; let mut base = 0usize;
for _ in 0..600u32 { for _ in 0..600u32 {
base = GetModuleHandleA(b"CardsDLL_Win64_retail.dll\0".as_ptr()) as usize; base = GetModuleHandleA(c"CardsDLL_Win64_retail.dll".as_ptr().cast()) as usize;
if base != 0 { if base != 0 {
break; break;
} }
+1 -1
View File
@@ -67,7 +67,7 @@ fn patch_module(module: isize, scan_bytes: usize) -> bool {
/// Patch ProtoSSL cert-verify in EAWebKit.dll (call when EAWebKit is loaded). /// Patch ProtoSSL cert-verify in EAWebKit.dll (call when EAWebKit is loaded).
pub unsafe fn patch_eawebkit_cert_verify() -> bool { pub unsafe fn patch_eawebkit_cert_verify() -> bool {
let module = GetModuleHandleA(b"EAWebKit.dll\0".as_ptr()) as isize; let module = GetModuleHandleA(c"EAWebKit.dll".as_ptr().cast()) as isize;
// EAWebKit.dll is ~22 MB // EAWebKit.dll is ~22 MB
patch_module(module, 24 * 1024 * 1024) patch_module(module, 24 * 1024 * 1024)
} }
+1 -1
View File
@@ -152,7 +152,7 @@ pub unsafe fn note_connect(api: &str, name: *const u8, namelen: i32, s: usize) {
let mut len: i32 = 4; let mut len: i32 = 4;
getsockopt( getsockopt(
s, s,
SOL_SOCKET as i32, SOL_SOCKET,
SO_TYPE, SO_TYPE,
&mut ty as *mut i32 as *mut u8, &mut ty as *mut i32 as *mut u8,
&mut len, &mut len,