Ejemplo n.º 1
0
        public static void GetAllApps()
        {
            try
            {
            #if DEBUG
                stopwatch.Restart();
            #endif
                dbCore.DbOps.GetAllApps(out List <DbEntry> apps);
            #if DEBUG
                stopwatch.Stop();

                Console.WriteLine("Core.GetAllApps(): Took {0} seconds to get apps from database",
                                  stopwatch.Elapsed.TotalSeconds);
            #endif

                if (AddApp != null)
                {
                #if DEBUG
                    stopwatch.Restart();
                #endif
                    int counter = 0;

                    // TODO: Check file name and existence
                    foreach (DbEntry app in apps)
                    {
                        UpdateProgress?.Invoke("Populating apps table", $"{app.Developer} {app.Product}", counter,
                                               apps.Count);

                        AddApp?.Invoke(app);

                        counter++;
                    }
                #if DEBUG
                    stopwatch.Stop();

                    Console.WriteLine("Core.GetAllApps(): Took {0} seconds to add apps to the GUI",
                                      stopwatch.Elapsed.TotalSeconds);
                #endif
                }

                Finished?.Invoke();
            }
            catch (ThreadAbortException) {}
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    throw;
                }

                Failed?.Invoke($"Exception {ex.Message}\n{ex.InnerException}");
            #if DEBUG
                Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException);
            #endif
            }
        }
Ejemplo n.º 2
0
        public static void CheckDbForFiles()
        {
            try
            {
                long counter = 0;
            #if DEBUG
                stopwatch.Restart();
            #endif
                Dictionary <string, DbAppFile> knownFiles = new Dictionary <string, DbAppFile>();

                bool unknownFile = false;

                foreach (KeyValuePair <string, DbAppFile> kvp in Context.Hashes)
                {
                    // Empty file with size zero
                    if (kvp.Value.Sha256 == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
                    {
                        AddFileForApp(kvp.Key, kvp.Value.Sha256, true, kvp.Value.Crack);
                        counter++;

                        continue;
                    }

                    UpdateProgress?.Invoke(null, "Checking files in database", counter, Context.Hashes.Count);

                    AddFileForApp?.Invoke(kvp.Key, kvp.Value.Sha256, dbCore.DbOps.ExistsFile(kvp.Value.Sha256),
                                          kvp.Value.Crack);

                    if (dbCore.DbOps.ExistsFile(kvp.Value.Sha256))
                    {
                        counter++;
                        knownFiles.Add(kvp.Key, kvp.Value);
                    }
                    else
                    {
                        unknownFile = true;
                    }
                }
            #if DEBUG
                stopwatch.Stop();

                Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds to checks for file knowledge in the DB",
                                  stopwatch.Elapsed.TotalSeconds);

                stopwatch.Restart();
            #endif
                if (knownFiles.Count == 0 || unknownFile)
                {
                    Finished?.Invoke();

                    return;
                }

                UpdateProgress?.Invoke(null, "Retrieving apps from database", counter, Context.Hashes.Count);
                dbCore.DbOps.GetAllApps(out List <DbEntry> apps);
            #if DEBUG
                stopwatch.Stop();

                Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds get all apps from DB",
                                  stopwatch.Elapsed.TotalSeconds);
            #endif

                if (apps != null &&
                    apps.Count > 0)
                {
                    DbEntry[] appsArray = new DbEntry[apps.Count];
                    apps.CopyTo(appsArray);

                    long appCounter = 0;
                #if DEBUG
                    stopwatch.Restart();
                #endif

                    foreach (DbEntry app in appsArray)
                    {
                        UpdateProgress?.Invoke(null, $"Check application id {app.Id}", appCounter, appsArray.Length);

                        counter = 0;

                        foreach (KeyValuePair <string, DbAppFile> kvp in knownFiles)
                        {
                            UpdateProgress2?.Invoke(null, $"Checking for file {kvp.Value.Path}", counter,
                                                    knownFiles.Count);

                            if (!dbCore.DbOps.ExistsFileInApp(kvp.Value.Sha256, app.Id))
                            {
                                if (apps.Contains(app))
                                {
                                    apps.Remove(app);
                                }

                                // If one file is missing, the rest don't matter
                                break;
                            }

                            counter++;
                        }

                        if (apps.Count == 0)
                        {
                            break; // No apps left
                        }
                    }
                #if DEBUG
                    stopwatch.Stop();

                    Console.WriteLine("Core.CheckDbForFiles(): Took {0} seconds correlate all files with all known applications",
                                      stopwatch.Elapsed.TotalSeconds);
                #endif
                }

                if (AddApp != null)
                {
                    foreach (DbEntry app in apps)
                    {
                        AddApp?.Invoke(app);
                    }
                }

                Finished?.Invoke();
            }
            catch (ThreadAbortException) {}
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    throw;
                }

                Failed?.Invoke($"Exception {ex.Message}\n{ex.InnerException}");
            #if DEBUG
                Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException);
            #endif
            }
        }