2

Closed

RemoteHooking.PrepareInjection FileNotFound error

description

We have a special situation in which we run .NET Framework inside a Win32 Delphi application.

In this situation, the following line of PrepareInjection throws a FileNotFound exception
           if ((UserAsm = Assembly.ReflectionOnlyLoad(InRemoteInfo.UserLibraryName)) == null && (UserAsm = Assembly.ReflectionOnlyLoadFrom(InRemoteInfo.UserLibrary)) == null)
                throw new DllNotFoundException("The given assembly could not be found.");
In fact it is the Assembly.ReflectionOnlyLoad(InRemoteInfo.UserLibraryName) that fails. If in debug I am executing the second part of the if and then letting the code goes on it will succesfully complete the injection.

This happens when the Assembly that is being tried to load by its fullname is not in the standard series of path that .NET loads from.
Closed Mar 21, 2015 at 6:17 AM by spazzarama
Fixed in changeset r75627

comments

spazzarama wrote Jun 18, 2014 at 8:29 AM

Hi, just to clarify is the first Assembly.ReflectionOnlyLoad throwing the FileNotFound exception?

Do you have a simple reproduction project you could attach?

etommVizubi wrote Jun 18, 2014 at 5:35 PM

Yes that's the first one just.

I don't have an example, because in our project we relocated some libraries in a subfolder and the one that we are trying to load is being loaded into the project manually with Assembly.Load. This plays fine with the rest of the code, but as per documentation Assembly.ReflectionOnlyLoad throws a FileNotFoundException if it can't find the assembly in the standard loading paths.

My correction is this:
            // Attempt to load the library by its FullName and if that fails, by its original library filename
            try
            {
                UserAsm = Assembly.ReflectionOnlyLoad(InRemoteInfo.UserLibraryName);
            }
            catch (FileNotFoundException)
            {
                if (File.Exists(InRemoteInfo.UserLibrary))
                    UserAsm = null;
                else
                    throw;
            }

            if (UserAsm  == null && (UserAsm = Assembly.ReflectionOnlyLoadFrom(InRemoteInfo.UserLibrary)) == null)
                throw new DllNotFoundException("The given assembly could not be found.");

wrote Jun 24, 2014 at 10:22 AM

wrote Mar 21, 2015 at 6:17 AM

Fixed on changeset 75627

wrote Mar 21, 2015 at 6:17 AM