public DllContext(string filePath, bool runHash = true) { DLLPath = filePath; if (!File.Exists(DLLPath)) { Console.WriteLine($"{DLLPath}: File does not exist"); return; } FileName = Path.GetFileName(filePath); // Compute and store the file hash if (runHash) { using (var cryptoProvider = new SHA1CryptoServiceProvider()) { SHA1Hash = BitConverter.ToString(cryptoProvider.ComputeHash(File.ReadAllBytes(filePath))).Replace("-", ""); } } // Get the module's exports DllExports = UnmanagedUtility.GetExports(DLLPath); if (DllExports.Count == 0) { Console.WriteLine($"{DLLPath}: No exports, possibly an invalid DLL"); return; } // Try to load the library into our process space dllHandle = UnmanagedUtility.LoadLibrary(filePath); if (dllHandle == IntPtr.Zero) { Console.WriteLine($"{DLLPath}: LoadLibrary failed"); return; } // Try to load addresses of all known exports dllAddressMappings = new Dictionary <string, IntPtr>(); foreach (string knownExport in ExportDefinition.KnownExportedFunctions) { if (DllExports.Contains(knownExport)) { dllAddressMappings.Add(knownExport, UnmanagedUtility.GetProcAddress(dllHandle, knownExport)); } else { dllAddressMappings.Add(knownExport, IntPtr.Zero); } } // Set capabilities KeyGenerationCapability = DllExports.Contains("GenerateKeyEx") || DllExports.Contains("GenerateKeyExOpt"); ModeSpecified = DllExports.Contains("GetKeyLength") && DllExports.Contains("GetSeedLength") && DllExports.Contains("GetConfiguredAccessTypes"); // Store additional metadata FileDescription = FileVersionInfo.GetVersionInfo(DLLPath).FileDescription; LoadAdditionalDataFromDllCalls(); }
public static void DumpExportsToConsole(string modulePath) { List <string> exports = UnmanagedUtility.GetExports(modulePath); Console.WriteLine($"Retrieving exports for {modulePath}"); foreach (string s in exports) { Console.WriteLine($"{modulePath}: {s}"); } Console.WriteLine($"End of {modulePath} exports."); }
/* * Diagnostics function to enumerate all DLLs and get unique exported functions so that the signatures can be built * * This is what I have so far: * * GenerateKeyExOpt * GetECUName * GetConfiguredAccessTypes * GetSeedLength * GetKeyLength * GenerateKeyEx * * GetComment * * VectorCompressInit * VectorCompress * VectorCompressExit */ public static void DumpUniqueExportsToConsole(string breakOnSpecificFunction = "") { HashSet <string> uniqueExports = new HashSet <string>(); foreach (string filePath in Program.GetLibraryFiles()) { List <string> exportsForFile = UnmanagedUtility.GetExports(filePath); foreach (string exportName in exportsForFile) { if (exportName == breakOnSpecificFunction) { Console.WriteLine($"BREAK: {breakOnSpecificFunction} for {Path.GetFileName(filePath)}"); Console.ReadLine(); } uniqueExports.Add(exportName); } Console.WriteLine(filePath); } foreach (string uniqueExportName in uniqueExports) { Console.WriteLine(uniqueExportName); } }