MCPcopy Create free account
hub / github.com/TranslucentTB/TranslucentTB / InjectExplorerHook

Function InjectExplorerHook

ExplorerHooks/api.cpp:18–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18HHOOK InjectExplorerHook(HWND window) noexcept
19{
20 DWORD pid = 0;
21 const DWORD tid = GetWindowThreadProcessId(window, &pid);
22
23 wil::unique_process_handle proc(OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pid));
24 if (!proc) [[unlikely]]
25 {
26 return nullptr;
27 }
28
29 if (!DetourFindRemotePayload(proc.get(), EXPLORER_PAYLOAD, nullptr))
30 {
31 proc.reset(OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, false, pid));
32 if (!proc) [[unlikely]]
33 {
34 return nullptr;
35 }
36
37 static constexpr uint32_t content = 0xDEADBEEF;
38 if (!DetourCopyPayloadToProcess(proc.get(), EXPLORER_PAYLOAD, &content, sizeof(content))) [[unlikely]]
39 {
40 return nullptr;
41 }
42 }
43
44 return SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, wil::GetModuleInstanceHandle(), tid);
45}

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected