Skip to content

Commit c35ebb1

Browse files
committed
fix link error
1 parent cbb1805 commit c35ebb1

7 files changed

Lines changed: 9 additions & 62 deletions

File tree

Cargo.lock

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

crates/fspy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ winapi = { workspace = true, features = [
5858
"handleapi",
5959
] }
6060
fspy_preload_windows = { workspace = true }
61+
fspy_detours_sys = { workspace = true }
6162

6263
[target.'cfg(target_os = "macos")'.dev-dependencies]
6364
tempfile = "3.19.1"

crates/fspy/src/windows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use fspy_shared::{
1515
windows::{PAYLOAD_ID, Payload},
1616
};
1717
use futures_util::FutureExt;
18-
use ms_detours::{DetourCopyPayloadToProcess, DetourUpdateProcessWithDll};
18+
use fspy_detours_sys::{DetourCopyPayloadToProcess, DetourUpdateProcessWithDll};
1919
use tokio::{
2020
io::AsyncReadExt,
2121
net::windows::named_pipe::{PipeMode, ServerOptions},

crates/fspy_detours_sys/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
fn main() {
2+
if std::env::var_os("CARGO_CFG_TARGET_OS").unwrap() != "windows" {
3+
return;
4+
}
25
println!("cargo:rerun-if-changed=detours/src");
36
// https://github.com/Berrysoft/detours/blob/c9bc2ad6e9cd8f5f7b74cfa65365d61ecc45203f/detours-sys/build.rs
47
cc::Build::new()

crates/fspy_detours_sys/src/generated_bindings.rs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,24 @@ pub type PF_DETOUR_IMPORT_FUNC_CALLBACK_EX = ::std::option::Option<
6767
pub type PDETOUR_BINARY = *mut ::std::os::raw::c_void;
6868
unsafe extern "system" {
6969
#[doc = " Transaction APIs."]
70-
#[link_name = "\u{1}_DetourTransactionBegin@0"]
7170
pub fn DetourTransactionBegin() -> LONG;
7271
}
7372
unsafe extern "system" {
74-
#[link_name = "\u{1}_DetourTransactionAbort@0"]
7573
pub fn DetourTransactionAbort() -> LONG;
7674
}
7775
unsafe extern "system" {
78-
#[link_name = "\u{1}_DetourTransactionCommit@0"]
7976
pub fn DetourTransactionCommit() -> LONG;
8077
}
8178
unsafe extern "system" {
82-
#[link_name = "\u{1}_DetourTransactionCommitEx@4"]
8379
pub fn DetourTransactionCommitEx(pppFailedPointer: *mut *mut PVOID) -> LONG;
8480
}
8581
unsafe extern "system" {
86-
#[link_name = "\u{1}_DetourUpdateThread@4"]
8782
pub fn DetourUpdateThread(hThread: HANDLE) -> LONG;
8883
}
8984
unsafe extern "system" {
90-
#[link_name = "\u{1}_DetourAttach@8"]
9185
pub fn DetourAttach(ppPointer: *mut PVOID, pDetour: PVOID) -> LONG;
9286
}
9387
unsafe extern "system" {
94-
#[link_name = "\u{1}_DetourAttachEx@20"]
9588
pub fn DetourAttachEx(
9689
ppPointer: *mut PVOID,
9790
pDetour: PVOID,
@@ -101,36 +94,28 @@ unsafe extern "system" {
10194
) -> LONG;
10295
}
10396
unsafe extern "system" {
104-
#[link_name = "\u{1}_DetourDetach@8"]
10597
pub fn DetourDetach(ppPointer: *mut PVOID, pDetour: PVOID) -> LONG;
10698
}
10799
unsafe extern "system" {
108-
#[link_name = "\u{1}_DetourSetIgnoreTooSmall@4"]
109100
pub fn DetourSetIgnoreTooSmall(fIgnore: BOOL) -> BOOL;
110101
}
111102
unsafe extern "system" {
112-
#[link_name = "\u{1}_DetourSetRetainRegions@4"]
113103
pub fn DetourSetRetainRegions(fRetain: BOOL) -> BOOL;
114104
}
115105
unsafe extern "system" {
116-
#[link_name = "\u{1}_DetourSetSystemRegionLowerBound@4"]
117106
pub fn DetourSetSystemRegionLowerBound(pSystemRegionLowerBound: PVOID) -> PVOID;
118107
}
119108
unsafe extern "system" {
120-
#[link_name = "\u{1}_DetourSetSystemRegionUpperBound@4"]
121109
pub fn DetourSetSystemRegionUpperBound(pSystemRegionUpperBound: PVOID) -> PVOID;
122110
}
123111
unsafe extern "system" {
124112
#[doc = " Code Functions."]
125-
#[link_name = "\u{1}_DetourFindFunction@8"]
126113
pub fn DetourFindFunction(pszModule: LPCSTR, pszFunction: LPCSTR) -> PVOID;
127114
}
128115
unsafe extern "system" {
129-
#[link_name = "\u{1}_DetourCodeFromPointer@8"]
130116
pub fn DetourCodeFromPointer(pPointer: PVOID, ppGlobals: *mut PVOID) -> PVOID;
131117
}
132118
unsafe extern "system" {
133-
#[link_name = "\u{1}_DetourCopyInstruction@20"]
134119
pub fn DetourCopyInstruction(
135120
pDst: PVOID,
136121
ppDstPool: *mut PVOID,
@@ -140,47 +125,38 @@ unsafe extern "system" {
140125
) -> PVOID;
141126
}
142127
unsafe extern "system" {
143-
#[link_name = "\u{1}_DetourSetCodeModule@8"]
144128
pub fn DetourSetCodeModule(hModule: HMODULE, fLimitReferencesToModule: BOOL) -> BOOL;
145129
}
146130
unsafe extern "system" {
147-
#[link_name = "\u{1}_DetourAllocateRegionWithinJumpBounds@8"]
148131
pub fn DetourAllocateRegionWithinJumpBounds(
149132
pbTarget: LPCVOID,
150133
pcbAllocatedSize: PDWORD,
151134
) -> PVOID;
152135
}
153136
unsafe extern "system" {
154-
#[link_name = "\u{1}_DetourIsFunctionImported@8"]
155137
pub fn DetourIsFunctionImported(pbCode: PBYTE, pbAddress: PBYTE) -> BOOL;
156138
}
157139
unsafe extern "system" {
158140
#[doc = " Loaded Binary Functions."]
159-
#[link_name = "\u{1}_DetourGetContainingModule@4"]
160141
pub fn DetourGetContainingModule(pvAddr: PVOID) -> HMODULE;
161142
}
162143
unsafe extern "system" {
163-
#[link_name = "\u{1}_DetourEnumerateModules@4"]
164144
pub fn DetourEnumerateModules(hModuleLast: HMODULE) -> HMODULE;
165145
}
166146
unsafe extern "system" {
167-
#[link_name = "\u{1}_DetourGetEntryPoint@4"]
168147
pub fn DetourGetEntryPoint(hModule: HMODULE) -> PVOID;
169148
}
170149
unsafe extern "system" {
171-
#[link_name = "\u{1}_DetourGetModuleSize@4"]
172150
pub fn DetourGetModuleSize(hModule: HMODULE) -> ULONG;
173151
}
174152
unsafe extern "system" {
175-
#[link_name = "\u{1}_DetourEnumerateExports@12"]
176153
pub fn DetourEnumerateExports(
177154
hModule: HMODULE,
178155
pContext: PVOID,
179156
pfExport: PF_DETOUR_ENUMERATE_EXPORT_CALLBACK,
180157
) -> BOOL;
181158
}
182159
unsafe extern "system" {
183-
#[link_name = "\u{1}_DetourEnumerateImports@16"]
184160
pub fn DetourEnumerateImports(
185161
hModule: HMODULE,
186162
pContext: PVOID,
@@ -189,7 +165,6 @@ unsafe extern "system" {
189165
) -> BOOL;
190166
}
191167
unsafe extern "system" {
192-
#[link_name = "\u{1}_DetourEnumerateImportsEx@16"]
193168
pub fn DetourEnumerateImportsEx(
194169
hModule: HMODULE,
195170
pContext: PVOID,
@@ -198,28 +173,22 @@ unsafe extern "system" {
198173
) -> BOOL;
199174
}
200175
unsafe extern "system" {
201-
#[link_name = "\u{1}_DetourFindPayload@12"]
202176
pub fn DetourFindPayload(hModule: HMODULE, rguid: *const GUID, pcbData: *mut DWORD) -> PVOID;
203177
}
204178
unsafe extern "system" {
205-
#[link_name = "\u{1}_DetourFindPayloadEx@8"]
206179
pub fn DetourFindPayloadEx(rguid: *const GUID, pcbData: *mut DWORD) -> PVOID;
207180
}
208181
unsafe extern "system" {
209-
#[link_name = "\u{1}_DetourGetSizeOfPayloads@4"]
210182
pub fn DetourGetSizeOfPayloads(hModule: HMODULE) -> DWORD;
211183
}
212184
unsafe extern "system" {
213-
#[link_name = "\u{1}_DetourFreePayload@4"]
214185
pub fn DetourFreePayload(pvData: PVOID) -> BOOL;
215186
}
216187
unsafe extern "system" {
217188
#[doc = " Persistent Binary Functions."]
218-
#[link_name = "\u{1}_DetourBinaryOpen@4"]
219189
pub fn DetourBinaryOpen(hFile: HANDLE) -> PDETOUR_BINARY;
220190
}
221191
unsafe extern "system" {
222-
#[link_name = "\u{1}_DetourBinaryEnumeratePayloads@16"]
223192
pub fn DetourBinaryEnumeratePayloads(
224193
pBinary: PDETOUR_BINARY,
225194
pGuid: *mut GUID,
@@ -228,15 +197,13 @@ unsafe extern "system" {
228197
) -> PVOID;
229198
}
230199
unsafe extern "system" {
231-
#[link_name = "\u{1}_DetourBinaryFindPayload@12"]
232200
pub fn DetourBinaryFindPayload(
233201
pBinary: PDETOUR_BINARY,
234202
rguid: *const GUID,
235203
pcbData: *mut DWORD,
236204
) -> PVOID;
237205
}
238206
unsafe extern "system" {
239-
#[link_name = "\u{1}_DetourBinarySetPayload@16"]
240207
pub fn DetourBinarySetPayload(
241208
pBinary: PDETOUR_BINARY,
242209
rguid: *const GUID,
@@ -245,19 +212,15 @@ unsafe extern "system" {
245212
) -> PVOID;
246213
}
247214
unsafe extern "system" {
248-
#[link_name = "\u{1}_DetourBinaryDeletePayload@8"]
249215
pub fn DetourBinaryDeletePayload(pBinary: PDETOUR_BINARY, rguid: *const GUID) -> BOOL;
250216
}
251217
unsafe extern "system" {
252-
#[link_name = "\u{1}_DetourBinaryPurgePayloads@4"]
253218
pub fn DetourBinaryPurgePayloads(pBinary: PDETOUR_BINARY) -> BOOL;
254219
}
255220
unsafe extern "system" {
256-
#[link_name = "\u{1}_DetourBinaryResetImports@4"]
257221
pub fn DetourBinaryResetImports(pBinary: PDETOUR_BINARY) -> BOOL;
258222
}
259223
unsafe extern "system" {
260-
#[link_name = "\u{1}_DetourBinaryEditImports@24"]
261224
pub fn DetourBinaryEditImports(
262225
pBinary: PDETOUR_BINARY,
263226
pContext: PVOID,
@@ -268,16 +231,13 @@ unsafe extern "system" {
268231
) -> BOOL;
269232
}
270233
unsafe extern "system" {
271-
#[link_name = "\u{1}_DetourBinaryWrite@8"]
272234
pub fn DetourBinaryWrite(pBinary: PDETOUR_BINARY, hFile: HANDLE) -> BOOL;
273235
}
274236
unsafe extern "system" {
275-
#[link_name = "\u{1}_DetourBinaryClose@4"]
276237
pub fn DetourBinaryClose(pBinary: PDETOUR_BINARY) -> BOOL;
277238
}
278239
unsafe extern "system" {
279240
#[doc = " Create Process & Load Dll."]
280-
#[link_name = "\u{1}_DetourFindRemotePayload@12"]
281241
pub fn DetourFindRemotePayload(
282242
hProcess: HANDLE,
283243
rguid: *const GUID,
@@ -313,7 +273,6 @@ pub type PDETOUR_CREATE_PROCESS_ROUTINEW = ::std::option::Option<
313273
) -> BOOL,
314274
>;
315275
unsafe extern "system" {
316-
#[link_name = "\u{1}_DetourCreateProcessWithDllA@48"]
317276
pub fn DetourCreateProcessWithDllA(
318277
lpApplicationName: LPCSTR,
319278
lpCommandLine: LPSTR,
@@ -330,7 +289,6 @@ unsafe extern "system" {
330289
) -> BOOL;
331290
}
332291
unsafe extern "system" {
333-
#[link_name = "\u{1}_DetourCreateProcessWithDllW@48"]
334292
pub fn DetourCreateProcessWithDllW(
335293
lpApplicationName: LPCWSTR,
336294
lpCommandLine: LPWSTR,
@@ -347,7 +305,6 @@ unsafe extern "system" {
347305
) -> BOOL;
348306
}
349307
unsafe extern "system" {
350-
#[link_name = "\u{1}_DetourCreateProcessWithDllExA@48"]
351308
pub fn DetourCreateProcessWithDllExA(
352309
lpApplicationName: LPCSTR,
353310
lpCommandLine: LPSTR,
@@ -364,7 +321,6 @@ unsafe extern "system" {
364321
) -> BOOL;
365322
}
366323
unsafe extern "system" {
367-
#[link_name = "\u{1}_DetourCreateProcessWithDllExW@48"]
368324
pub fn DetourCreateProcessWithDllExW(
369325
lpApplicationName: LPCWSTR,
370326
lpCommandLine: LPWSTR,
@@ -381,7 +337,6 @@ unsafe extern "system" {
381337
) -> BOOL;
382338
}
383339
unsafe extern "system" {
384-
#[link_name = "\u{1}_DetourCreateProcessWithDllsA@52"]
385340
pub fn DetourCreateProcessWithDllsA(
386341
lpApplicationName: LPCSTR,
387342
lpCommandLine: LPSTR,
@@ -399,7 +354,6 @@ unsafe extern "system" {
399354
) -> BOOL;
400355
}
401356
unsafe extern "system" {
402-
#[link_name = "\u{1}_DetourCreateProcessWithDllsW@52"]
403357
pub fn DetourCreateProcessWithDllsW(
404358
lpApplicationName: LPCWSTR,
405359
lpCommandLine: LPWSTR,
@@ -417,23 +371,20 @@ unsafe extern "system" {
417371
) -> BOOL;
418372
}
419373
unsafe extern "system" {
420-
#[link_name = "\u{1}_DetourProcessViaHelperA@12"]
421374
pub fn DetourProcessViaHelperA(
422375
dwTargetPid: DWORD,
423376
lpDllName: LPCSTR,
424377
pfCreateProcessA: PDETOUR_CREATE_PROCESS_ROUTINEA,
425378
) -> BOOL;
426379
}
427380
unsafe extern "system" {
428-
#[link_name = "\u{1}_DetourProcessViaHelperW@12"]
429381
pub fn DetourProcessViaHelperW(
430382
dwTargetPid: DWORD,
431383
lpDllName: LPCSTR,
432384
pfCreateProcessW: PDETOUR_CREATE_PROCESS_ROUTINEW,
433385
) -> BOOL;
434386
}
435387
unsafe extern "system" {
436-
#[link_name = "\u{1}_DetourProcessViaHelperDllsA@16"]
437388
pub fn DetourProcessViaHelperDllsA(
438389
dwTargetPid: DWORD,
439390
nDlls: DWORD,
@@ -442,7 +393,6 @@ unsafe extern "system" {
442393
) -> BOOL;
443394
}
444395
unsafe extern "system" {
445-
#[link_name = "\u{1}_DetourProcessViaHelperDllsW@16"]
446396
pub fn DetourProcessViaHelperDllsW(
447397
dwTargetPid: DWORD,
448398
nDlls: DWORD,
@@ -451,12 +401,10 @@ unsafe extern "system" {
451401
) -> BOOL;
452402
}
453403
unsafe extern "system" {
454-
#[link_name = "\u{1}_DetourUpdateProcessWithDll@12"]
455404
pub fn DetourUpdateProcessWithDll(hProcess: HANDLE, rlpDlls: *mut LPCSTR, nDlls: DWORD)
456405
-> BOOL;
457406
}
458407
unsafe extern "system" {
459-
#[link_name = "\u{1}_DetourUpdateProcessWithDllEx@20"]
460408
pub fn DetourUpdateProcessWithDllEx(
461409
hProcess: HANDLE,
462410
hImage: HMODULE,
@@ -466,7 +414,6 @@ unsafe extern "system" {
466414
) -> BOOL;
467415
}
468416
unsafe extern "system" {
469-
#[link_name = "\u{1}_DetourCopyPayloadToProcess@16"]
470417
pub fn DetourCopyPayloadToProcess(
471418
hProcess: HANDLE,
472419
rguid: *const GUID,
@@ -475,7 +422,6 @@ unsafe extern "system" {
475422
) -> BOOL;
476423
}
477424
unsafe extern "system" {
478-
#[link_name = "\u{1}_DetourCopyPayloadToProcessEx@16"]
479425
pub fn DetourCopyPayloadToProcessEx(
480426
hProcess: HANDLE,
481427
rguid: *const GUID,
@@ -484,18 +430,14 @@ unsafe extern "system" {
484430
) -> PVOID;
485431
}
486432
unsafe extern "system" {
487-
#[link_name = "\u{1}_DetourRestoreAfterWith@0"]
488433
pub fn DetourRestoreAfterWith() -> BOOL;
489434
}
490435
unsafe extern "system" {
491-
#[link_name = "\u{1}_DetourRestoreAfterWithEx@8"]
492436
pub fn DetourRestoreAfterWithEx(pvData: PVOID, cbData: DWORD) -> BOOL;
493437
}
494438
unsafe extern "system" {
495-
#[link_name = "\u{1}_DetourIsHelperProcess@0"]
496439
pub fn DetourIsHelperProcess() -> BOOL;
497440
}
498441
unsafe extern "system" {
499-
#[link_name = "\u{1}_DetourFinishHelperProcess@16"]
500442
pub fn DetourFinishHelperProcess(arg1: HWND, arg2: HINSTANCE, arg3: LPSTR, arg4: INT);
501443
}

crates/fspy_detours_sys/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#[allow(non_camel_case_types, non_snake_case)]
1+
#![cfg(windows)]
22

3+
#[allow(non_camel_case_types, non_snake_case)]
34
mod generated_bindings;
45

56
pub use generated_bindings::*;

crates/fspy_detours_sys/tests/bindings.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use std::{env, fs};
44

55
#[test]
66
fn detours_bindings() {
7-
// https://github.com/0xC9C3/rust-ms-detours/blob/0abc7b11c038afbc2f976de88d44e5691f43bd9a/build.rs#L78
87
let bindings = bindgen::Builder::default()
9-
.clang_args(["-Idetours/src", "-DWIN32_LEAN_AND_MEAN", "-target", "i686-pc-windows-msvc"])
8+
.clang_args(["-Idetours/src", "-DWIN32_LEAN_AND_MEAN"])
109
.header_contents("wrapper.h", "#include <windows.h>\n#include <detours.h>\n")
1110
.allowlist_function("Detour.*")
1211
.blocklist_type("LP.*")

0 commit comments

Comments
 (0)