Пример #1
0
 private static bool hasIcons(string exeFilename)
 {
     // Console.WriteLine($"Checking for icons in {exeFilename}");
     using PortableExecutableImage exeFile = PortableExecutableImage.FromFile(exeFilename);
     try {
         ResourceCollection?resourceCollection = ResourceCollection.Get(exeFile);
         return(resourceCollection?.Any(type => type.Id == ResourceType.GroupIcon) ?? false);
     } catch (TargetInvocationException) {
         Console.WriteLine($"Failed to parse icon resources in {exeFilename}");
         return(false);
     }
 }
Пример #2
0
        static void CheckPE(Regex module, Regex function, string filename)
        {
            bool found = false;

            try
            {
                PortableExecutableImage image          = PortableExecutableImage.FromFile(filename);
                DelayedImports          delayedImports = DelayedImports.Get(image);
                if (delayedImports != null)
                {
                    foreach (DelayedImportLibrary import in delayedImports)
                    {
                        found = CheckImport(module, function, import);
                        if (found)
                        {
                            break;
                        }
                    }
                }
                // If not in delayed imports, try explicit ones
                if (!found)
                {
                    Imports imports = Imports.Get(image);
                    if (imports != null)
                    {
                        foreach (ImportLibrary import in imports)
                        {
                            found = CheckImport(module, function, import);
                            if (found)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            // If there's a bad DOS header or its not a valid PE, just ignore it
            catch (Workshell.PE.PortableExecutableImageException) { }

            if (found)
            {
                Console.WriteLine(filename);
            }
        }