Reputation: 2527
I want to find the full path for libraries used in a given .NET application.
These are both, referenced assemblies (obtained as AssemblyName
s) and P/Invoke/DllImport
ed functions (obtained as just the dll name).
So basically I'm searching for the content of these two methods, where executablePath
is the path of that third party .NET application which can be completely different from my program.
static string ResolveAssemblyPath(AssemblyName name, string executablePath)
{
// ...
}
static string ResolveDllPath(string name, string executablePath)
{
// ...
}
It's important that these found libraries do not execute any code in the process of determining their full path! (DllMain
, module initializers, ...)
Is that even possible in every case? It's not an option to guess wrong.
Upvotes: 3
Views: 349
Reputation: 2754
It's possible but you need to replicate the search order of the windows loader, which differs for native and managed modules, and even windows versions. I've seen it posted in different levels of details in various blogs, though I have none of them at hand. It also seems to be documented in the MSDN, so see if that works for you.
Anyways if it's not an option to guess wrong you got a problem because any future windows version can extend or modify the search order, so you won't be upwards-compatible to future windows versions.
Also there are rules to redirect the windows loader, eg. through the manifest or the registry, which you would also have to replicate if you want exact coverage.
Upvotes: 1