MCPcopy Create free account
hub / github.com/audiorouterdev/audio-router / DllMain

Function DllMain

bootstrapper/main.cpp:76–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74bool is_patched;
75
76BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
77{
78 if(fdwReason == DLL_PROCESS_ATTACH)
79 {
80 is_patched = false;
81
82 if(GetModuleHandle(L"Audio Router.exe") != NULL)
83 return FALSE;
84
85 hheap = HeapCreate(0, 0, 0);
86 patch_ntcreateuserprocess = (ntcreateuserprocess_patcher_t*)
87 HeapAlloc(hheap, 0, sizeof(ntcreateuserprocess_patcher_t));
88 new (patch_ntcreateuserprocess) ntcreateuserprocess_patcher_t(ntcreateuserprocess_patch);
89
90 if(!try_init_bootstrapper(patch_ntcreateuserprocess))
91 return FALSE;
92 }
93 else if(fdwReason == DLL_THREAD_ATTACH)
94 {
95 // restore patch if it was reverted when audio router was closed
96 // (only if audio router is present again)
97 CHandle hfile(OpenMutexW(SYNCHRONIZE, FALSE, L"Local\\audio-router-mutex"));
98 if(hfile && !is_patched)
99 try_init_bootstrapper(patch_ntcreateuserprocess);
100 else if(!hfile && is_patched)
101 {
102 patch_ntcreateuserprocess->lock();
103 patch_ntcreateuserprocess->revert();
104 is_patched = false;
105 patch_ntcreateuserprocess->unlock();
106 }
107 }
108 else if(fdwReason == DLL_PROCESS_DETACH)
109 {
110 // TODO: remove
111 patch_ntcreateuserprocess->lock();
112 patch_ntcreateuserprocess->revert();
113 is_patched = false;
114 patch_ntcreateuserprocess->unlock();
115 }
116
117 return TRUE;
118}
119
120NTSTATUS NTAPI ntcreateuserprocess_patch(
121 PHANDLE ProcessHandle,

Callers

nothing calls this directly

Calls 4

try_init_bootstrapperFunction · 0.85
lockMethod · 0.80
revertMethod · 0.80
unlockMethod · 0.80

Tested by

no test coverage detected