示例#1
0
        static Tuple <List <string>, List <string> > SearchNativeDll(List <string> dllname, List <string> searchpath, MachineType mt)
        {
            bool          found       = false;
            List <string> dllrpath    = new List <string>();
            List <string> dllnotfound = new List <string>();

            foreach (string dll in dllname)
            {
                found = false;
                foreach (string path in searchpath)
                {
                    string rpath = Path.Combine(path, dll);
                    if (File.Exists(rpath))
                    {
                        PEModel pemd = new PEModel();
                        pemd.LoadPE(rpath);
                        if (pemd.Arch == mt)
                        {
                            found = true;
                            dllrpath.Add(rpath);
                            break;
                        }
                    }
                }
                if (!found)
                {
                    dllnotfound.Add(dll);
                }
            }
            return(new Tuple <List <string>, List <string> >(dllrpath, dllnotfound));
        }
示例#2
0
        static void CopyDll(string inputpe, List <string> searchdir, string target = "", bool overwrite = false)
        {
            PEModel model = new PEModel();

            model.LoadPE(inputpe);
            if (model.IsManaged == CompilationMode.Invalid)
            {
                Console.WriteLine("The input file is not a valid PE file");
            }
            else
            {
                List <string> dependlist = new List <string>();
                if (model.IsManaged == CompilationMode.Native)
                {
                    NativeDepend nd = new NativeDepend();
                    nd.Init(inputpe);
                    List <string> dllneedcpy = nd.FindMissingDll();
                    Tuple <List <string>, List <string> > findresult = SearchNativeDllRecur(dllneedcpy, searchdir, model.Arch);
                    if (findresult.Item2.Count() > 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("The following dependencies cannot be found");
                    }
                    foreach (string dllmiss in findresult.Item2)
                    {
                        Console.WriteLine("{0}", dllmiss);
                    }
                    Console.ForegroundColor = ConsoleColor.White;
                    foreach (string dllfound in findresult.Item1)
                    {
                        Console.WriteLine("Found:\t{0} in {1}", Path.GetFileName(dllfound), dllfound);
                    }
                    Console.WriteLine("Copying files to {0}", Path.GetDirectoryName(inputpe));
                    DllCopy copy = new DllCopy
                    {
                        TargetDir = (target == "") ? Path.GetDirectoryName(inputpe) : target
                    };
                    foreach (string dllfound in findresult.Item1)
                    {
                        Console.WriteLine("Copying\t{0} to {1}", Path.GetFileName(dllfound), copy.TargetDir);
                        copy.CopyDll(Path.GetFileName(dllfound), Path.GetDirectoryName(dllfound), overwrite);
                    }
                }
            }
        }