@@ -276,8 +276,8 @@ class RerouteW
276276 }
277277 else
278278 {
279- if (m_PathCreated)
280- addDirectoryMapping (context, fs::path (m_RealPath).parent_path (), fs::path (m_FileName).parent_path ());
279+ // if (m_PathCreated)
280+ // addDirectoryMapping(context, fs::path(m_RealPath).parent_path(), fs::path(m_FileName).parent_path());
281281
282282 spdlog::get (" hooks" )->info (" mapping file in vfs: {}, {}" ,
283283 ush::string_cast<std::string>(m_RealPath, ush::CodePage::UTF8 ),
@@ -291,6 +291,9 @@ class RerouteW
291291
292292 void removeMapping (const usvfs::HookContext::ConstPtr &readContext, bool directory = false )
293293 {
294+ bool addToDelete = false ;
295+ bool dontAddToDelete = false ;
296+
294297 // We need to track deleted files even if they were not rerouted (i.e. files deleted from the real folder which there is
295298 // a virtualized mapped folder on top of it). Since we don't want to add, *every* file which is deleted we check this:
296299 if (!directory) {
@@ -305,7 +308,7 @@ class RerouteW
305308 found = true ;
306309 }
307310 if (found)
308- k32DeleteTracker. insert (m_RealPath, m_FileName) ;
311+ addToDelete = true ;
309312 }
310313
311314 if (wasRerouted ()) {
@@ -324,6 +327,7 @@ class RerouteW
324327 parent = fs::path (parent).parent_path ().wstring ();
325328 if (k32FakeDirTracker.contains (parent))
326329 {
330+ dontAddToDelete = true ;
327331 if (RemoveDirectoryW (parent.c_str ())) {
328332 k32FakeDirTracker.erase (parent);
329333 spdlog::get (" usvfs" )->info (" removed empty fake directory: {}" , string_cast<std::string>(parent));
@@ -339,6 +343,9 @@ class RerouteW
339343 }
340344 }
341345 }
346+ if (addToDelete && !dontAddToDelete) {
347+ k32DeleteTracker.insert (m_RealPath, m_FileName);
348+ }
342349 }
343350
344351 static bool createFakePath (fs::path path, LPSECURITY_ATTRIBUTES securityAttributes)
@@ -807,20 +814,49 @@ BOOL WINAPI usvfs::hook_CreateProcessInternalW(
807814 newToken);
808815 POST_REALCALL
809816
817+ BOOL blacklisted = FALSE ;
818+ if (applicationReroute.fileName ()) {
819+ auto context = READ_CONTEXT ();
820+ if (context->executableBlacklisted (applicationReroute.fileName ())) {
821+ spdlog::get (" hooks" )->info (
822+ " not injecting {} as application is blacklisted" ,
823+ ush::string_cast<std::string>(
824+ applicationReroute.fileName (),
825+ ush::CodePage::UTF8
826+ )
827+ );
828+ blacklisted = TRUE ;
829+ }
830+ } else if (cmdReroute.fileName ()) {
831+ auto context = READ_CONTEXT ();
832+ if (context->executableBlacklisted (cmdReroute.fileName ())) {
833+ spdlog::get (" hooks" )->info (
834+ " not injecting {} as command line is blacklisted" ,
835+ ush::string_cast<std::string>(
836+ cmdReroute.fileName (),
837+ ush::CodePage::UTF8
838+ )
839+ );
840+ blacklisted = TRUE ;
841+ }
842+ }
843+
810844 if (res)
811845 {
812- try {
813- injectProcess (dllPath, callParameters, *lpProcessInformation);
814- } catch (const std::exception &e) {
815- spdlog::get (" hooks" )
816- ->error (" failed to inject into {0}: {1}" ,
817- lpApplicationName != nullptr
818- ? log::wrap (applicationReroute.fileName ())
819- : log::wrap (static_cast <LPCWSTR >(lpCommandLine)),
820- e.what ());
846+ if (!blacklisted) {
847+ try {
848+ injectProcess (dllPath, callParameters, *lpProcessInformation);
849+ } catch (const std::exception &e) {
850+ spdlog::get (" hooks" )
851+ ->error (" failed to inject into {0}: {1}" ,
852+ lpApplicationName != nullptr
853+ ? log::wrap (applicationReroute.fileName ())
854+ : log::wrap (static_cast <LPCWSTR >(lpCommandLine)),
855+ e.what ());
856+ }
821857 }
822858
823- // resume unless process is suposed to start suspended
859+ // resume unless process is supposed to start suspended
824860 if (!susp && (ResumeThread (lpProcessInformation->hThread ) == (DWORD )-1 )) {
825861 spdlog::get (" hooks" )->error (" failed to inject into spawned process" );
826862 res = FALSE ;
@@ -830,9 +866,10 @@ BOOL WINAPI usvfs::hook_CreateProcessInternalW(
830866 LOG_CALL ()
831867 .PARAM (lpApplicationName)
832868 .PARAM (applicationReroute.fileName ())
833- .PARAM (cmdline )
869+ .PARAM (cmdReroute. fileName () )
834870 .PARAM (res)
835- .PARAM (callContext.lastError ());
871+ .PARAM (callContext.lastError ())
872+ .PARAM (cmdline);
836873 HOOK_END
837874
838875 return res;
@@ -2048,7 +2085,6 @@ HANDLE WINAPI usvfs::hook_FindFirstFileExW(LPCWSTR lpFileName, FINDEX_INFO_LEVEL
20482085
20492086 bool usedRewrite = false ;
20502087
2051-
20522088 if (boost::algorithm::icontains (lpFileName, tempPathStr)) {
20532089 PRE_REALCALL
20542090 // Force the mutEXHook to match NtQueryDirectoryFile so it calls the non hooked NtQueryDirectoryFile.
0 commit comments