Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DLL Redirection on Windows 7

I am trying to perform DLL redirection on a Windows 7 x64 machine. I have a 3rd party application say App.exe which is located in %PROGRAMFILES%\SomeApp\App.exe. App.exe is a native unmanaged Windows application and depends on an unmanaged native DLL, say foo.dll which is present within C:\Windows\System32

Now I have my own version of foo.dll which I want App.exe to load instead of the one present within C:\Windows\System32.

Here is what I tried and works well on XP:

  1. Create a manifest file App.exe.manifest
  2. Copy my version of foo.dll within %PROGRAMFILES%\SomeApp. This is the same directory where App.exe resides.
  3. Within the manifest file, specify the DLL dependencies (especially related to MS VC runtime) and also include <file name="foo.dll">
  4. Launch the application.

However, this does not work on Windows 7.

I googled around and my research led me to this MSDN discussion. Here the answer talks about creating assemblies and also providing configuration files (e.g. App.exe.config). MSDN does not talk about this. Hence my first question:

Is it mandatory to have our unmanaged DLL wrapped into an assembly as mentioned in the above link and is it also mandated to have an application config file for DLL redirection to take place?

In addition I referred to some of the application manifests present within the WinSxS folder in Windows 7 and found some manifest files containing the <file> element entry as below:

<file hash="6bd4c0b867d2ec23a03fc1b290abc62a7d7d0908" 
      hashalg="SHA1" 
      name="aspnet_regiis.exe" 
      destinationPath="$(runtime.windows)\Microsoft.NET\Framework64\v2.0.50727\" 
      sourceName="aspnet_regiis.exe" 
      sourcePath="Win\Microsoft.NET\Framework\URTInstallPath\" 
      importPath="$(build.nttree)\netfx\Win\Microsoft.NET\Framework\URTInstallPath\">

Hence my second question:

What do the attributes destinationPath, sourceName, sourcePath and importPath stand for? These are not documented within the Assembly Manifest or Application Manifest MSDN documentation.

And my third question (implied by the first and second):

What is the correct <file> tag entry that must be specified within the App.exe.manifest so that my version of foo.dll is picked up?

Any other pointers to achieve DLL redirection on Windows 7 are welcome.

like image 964
Prahalad Deshpande Avatar asked Nov 12 '22 18:11

Prahalad Deshpande


1 Answers

Try to avoid DLL redirection if at all possible. Put all your DLLs int the same folder as the EXE. This can only not be avoided for the MSVC DLLs themselves. Installing the redist as a dependency in your installer normally fixes these.

like image 68
Joshua Avatar answered Nov 15 '22 06:11

Joshua