Esempio n. 1
0
 private bool TryReadAssembly(string file, out LWin32 assembly)
 {
     assembly = null;
     try
     {
         assembly = LWin32.LoadFile(file);
         _assemblyCache.Add(file, assembly);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 2
0
        //  /// <summary>
        //  /// Gets the address of the library reference in the portable executable file.
        //  /// </summary>
        //  public uint Address
        //  {
        //      get { return rawDescriptor.; }
        //  }

        /// <summary>
        /// Resolves the asembly by checking the directory of the assembly, the system directories and the current directory.
        /// </summary>
        /// <param name="parentAssembly">The parent assembly to search from. You can fill in a null value, but it can influent the result.</param>
        /// <param name="disableWOW64Redirection">Disables WOW64 layer redirections to get access 64 bit directories. Default value is true.</param>
        /// <returns></returns>
        public LWin32 Resolve(LWin32 parentAssembly, bool disableWOW64Redirection = true)
        {
            LWin32 assembly;

            if (disableWOW64Redirection)
            {
                ASMGlobals.Wow64EnableWow64FsRedirection(false);
            }
            try
            {
                string actualpath = "";
                if (parentAssembly != null)
                {
                    string path = parentAssembly._path.Substring(0, parentAssembly._path.LastIndexOf("\\"));
                    if (File.Exists(path + "\\" + LibraryName))
                    {
                        actualpath = path + "\\" + LibraryName;
                        goto things;
                    }
                }
                if (parentAssembly._ntHeader.OptionalHeader.Is32Bit)
                {
                    if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86) + "\\" + LibraryName))
                    {
                        actualpath = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86) + "\\" + LibraryName;
                    }
                }
                else if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\" + LibraryName))
                {
                    actualpath = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\" + LibraryName;
                }


                if (actualpath == "" & File.Exists(Environment.CurrentDirectory + "\\" + LibraryName))
                {
                    actualpath = Environment.CurrentDirectory + "\\" + LibraryName;
                }

things:
                if (actualpath == "")
                {
                    throw new ResolveException(new FileNotFoundException("The target application can not be found."));
                }


                try
                {
                    assembly = LWin32.LoadFile(actualpath);
                }
                catch (Exception ex)
                {
                    throw new ResolveException(ex);
                }
            }
            catch
            {
                if (disableWOW64Redirection)
                {
                    ASMGlobals.Wow64EnableWow64FsRedirection(true);
                }
                throw;
            }
            finally
            {
                if (disableWOW64Redirection)
                {
                    ASMGlobals.Wow64EnableWow64FsRedirection(true);
                }
            }
            return(assembly);
        }