Esempio n. 1
0
        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.");
        }
Esempio n. 3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            UnmanagedUtility.SendMessage(txtChallenge.Handle, UnmanagedUtility.EM_SETCUEBANNER, 0, "Enter seed data here");

            if (!Directory.Exists(Program.GetLibraryPath()))
            {
                Directory.CreateDirectory(Program.GetLibraryPath());
                MessageBox.Show("A library folder to contain DLL files was not found, so an empty folder has been created for you.\r\nThis application requires DLL files that match your ECU to operate.", "Notice");
            }

            LoadLibraryMetadata();
            TryRefreshKey();
        }
        /*
         * 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);
            }
        }
Esempio n. 5
0
 private void LibrarySelector_Load(object sender, EventArgs e)
 {
     UnmanagedUtility.SendMessage(txtFilter.Handle, UnmanagedUtility.EM_SETCUEBANNER, 0, "Filter library by file name or ECU name..");
     EnableDoubleBuffer(dgvResponse, true);
     DrawDatagrid();
 }
Esempio n. 6
0
 public void UnloadLibrary()
 {
     // WARNING: the instance will no longer be able to access native functions after this is called
     // This is a workaround if many DLLs have to be enumerated for their metadata -- Windows has a limit on the number of DLLs that can be loaded simultaneously
     UnmanagedUtility.FreeLibrary(dllHandle);
 }