Force x64 file redirection for a 32-bit application

Silently redirecting 64-bit system files to 32-bit equivalents can be disabled and returned using Wow64DisableWow64FsRedirection and Wow64RevertWow64FsRedirection. We use this for certain checks of file identification in our application.

The problem is that when performing some of these tasks, we can call the framework or the Windows API, which subsequently calls another API in a DLL that is not yet loaded. If redirection is enabled at this time, the wrong version of the dll may be loaded, which will result in an error XXX is not a valid Win32 application .

I have identified some of the API calls in question and what I would like to do is redirect the redirect to the time of this call, and then bring it back - exactly the opposite of the provided Win32 APIs. Unfortunately, these calls do not provide any WOW64 compatibility flag, as some of the registry methods do.

The obvious alternative is to use Wow64EnableWow64FsRedirection, pass TRUE to Wow64FsEanbledRedirection. However, there are many warnings about using this method and a note that it is not compatible with the combined Disable / Revert methods that replaced it.

Is there a safe way to force redirection to call Win32?

The docs indicate that redirection is a thread, so I considered creating a new thread for a specific call with the appropriate locks and expectations, but I was hoping for a simpler solution.

+4
source share
3 answers

So, I finally set off on a new flow route, which turned out to be easier than expected. The docs state that redirection is a specific stream, so a new stream will always have a redirection.

 var t = new Thread(() => SafeNativeMethods.LoadLibraryExW("NTMARTA.DLL", IntPtr.Zero, 0) ); t.Start(); t.Join(); 
0
source

blow in the dark. Could you enable the redirection, call all the API methods that you need, but ignore the results. This will load all the relevant DLLs. Then turn off the redirection and retry the method calls using the results this time?

0
source

Why not use SHGetKnownFolderPath or SHGetFolderPath and look at FOLDERID_SystemX86 / CSIDL_SYSTEMX86 to get the base path for loading the DLL? This should provide you with the correct folder, independent of file system redirection.

-1
source

Source: https://habr.com/ru/post/1307402/


All Articles