Пример #1
0
        private static void PerformTask(Options options)
        {
            if (!String.IsNullOrEmpty(options.ProjectFile))
            {
                IDatabaseProjectService databaseProjectService = ObjectLocator.GetInstance <IDatabaseProjectService>();
                IEventAggregator        eventAggregator        = ObjectLocator.GetInstance <IEventAggregator>();

                Console.WriteLine(string.Format("Loading the Dafuscator project: {0}", options.ProjectFile));
                Database         db = databaseProjectService.GetDatabaseProject(options.ProjectFile);
                ConnectionString connetionString;

                if (!String.IsNullOrEmpty(options.ConnectionString))
                {
                    connetionString = new ConnectionString(options.ConnectionString);
                }
                else
                {
                    connetionString = db.ConnectionString;
                }
                db.ConnectionString = connetionString;
                eventAggregator.AddListener <StatusUpdateEvent>(e => Console.WriteLine(string.Format("{0}: {1}", DateTime.Now, e.Message)));

                if (!String.IsNullOrEmpty(options.ExportFile))
                {
                    Console.WriteLine(string.Format("Started exporting the Dafuscator project to {0}", options.ExportFile));
                    IExportService exportService = ObjectLocator.GetInstance <IExportService>();
                    exportService.ExportTables(db.Tables, options.ExportFile, connetionString);

                    Console.WriteLine("Finished exporting the Dafuscator project.");
                }
                else
                {
                    Console.WriteLine(string.Format("Started the obfuscation of the {0} database.", db.ConnectionString.DatabaseName));

                    IRunService    runService    = ObjectLocator.GetInstance <IRunService>();
                    IReportService reportService = ObjectLocator.GetInstance <IReportService>();

                    ObfuscationResult result = runService.ObfuscateDatabase(db);

                    string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    path = path + "\\Dafuscator";

                    if (Directory.Exists(path) == false)
                    {
                        Directory.CreateDirectory(path);
                    }

                    path = path +
                           string.Format("\\DatabaseObfuscationReport_{0}_{1}_{2}-{3}_{4}.txt", DateTime.Now.Month, DateTime.Now.Day,
                                         DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);

                    reportService.GenerateReportForObfucsationResult(result, path);

                    Console.WriteLine("Finished the obfuscation process in {0}", result.TimeElapsed);
                }
            }
        }
Пример #2
0
        private static void RunTable(object sender, ExecutedRoutedEventArgs e)
        {
            if (UIContext.Database != null)
            {
                BackgroundWorker worker     = new BackgroundWorker();
                MainWindow       mainWindow = (MainWindow)sender;
                mainWindow.loadingAnimation.Visibility = Visibility.Visible;

                worker.DoWork += delegate(object s, DoWorkEventArgs args)
                {
                    object[]    data       = args.Argument as object[];
                    IRunService runService = ObjectLocator.GetInstance <IRunService>();

                    ObfuscationResult result = runService.ObfuscateTable(UIContext.Database.ConnectionString, data[0] as Table);

                    args.Result = result;
                };

                worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
                {
                    mainWindow.loadingAnimation.Visibility = Visibility.Collapsed;
                    ObfuscationResult result = args.Result as ObfuscationResult;

                    MessageBox.Show(mainWindow, string.Format("Finished table obfuscation in {0}", result.TimeElapsed), "Table Obfuscation Finished",
                                    MessageBoxButton.OK, MessageBoxImage.Information);

                    IReportService reportService = ObjectLocator.GetInstance <IReportService>();

                    //string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
                    //path = path.Replace("file:\\", "");

                    string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    path = path + "\\Dafuscator";

                    if (Directory.Exists(path) == false)
                    {
                        Directory.CreateDirectory(path);
                    }

                    path = path +
                           string.Format("\\TableObfuscationReport_{0}_{1}_{2}-{3}_{4}.txt", DateTime.Now.Month, DateTime.Now.Day,
                                         DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute);

                    reportService.GenerateReportForObfucsationResult(result, path);
                };

                worker.RunWorkerAsync(new object[]
                {
                    mainWindow.ColumnsGrid.SelectedTable
                });
            }
            else
            {
                MessageBox.Show("There is no open database project, cannot obfuscate database.", "Error Saving", MessageBoxButton.OK,
                                MessageBoxImage.Exclamation);
            }
        }
Пример #3
0
        public void GenerateReportForObfucsationResult(ObfuscationResult obfuscationResult, string path)
        {
            StringBuilder report = new StringBuilder();

            report.AppendLine("");
            report.AppendLine("==========================================================");
            report.AppendLine("                      DAFUSCATOR                          ");
            report.AppendLine("==========================================================");
            report.AppendLine("");
            report.AppendLine("Report Type: Database Obfuscation Result Report");
            report.AppendLine("Report Date: " + DateTime.Now.Date);
            report.AppendLine("Database: " + obfuscationResult.DatabaseName);
            report.AppendLine("");
            report.AppendLine("Database Obfuscation Start: " + obfuscationResult.StartTimeStamp);
            report.AppendLine("Database Obfuscation Stop: " + obfuscationResult.FinsihedTimeStamp);
            report.AppendLine("Database Obfuscation Elapsed: " + obfuscationResult.TimeElapsed);
            report.AppendLine("");
            report.AppendLine("");

            var sorted = from r in obfuscationResult.TablesProcessed
                         orderby r.Key
                         select r;

            foreach (var d in sorted)
            {
                report.AppendLine(string.Format("{0}: {1}", d.Key, d.Value));
            }

            report.AppendLine("");
            report.AppendLine("                     Errors                               ");
            report.AppendLine("----------------------------------------------------------");
            report.AppendLine("");

            foreach (var d in obfuscationResult.ErroredTables)
            {
                report.AppendLine(string.Format("{0}: {1}", d.Key, d.Value));
                report.AppendLine("");
            }

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            using (StreamWriter writer = new StreamWriter(path))
            {
                writer.Write(report.ToString());
            }
        }
Пример #4
0
        public ObfuscationResult ObfuscateDatabase(Database database)
        {
            ObfuscationResult result = new ObfuscationResult();

            result.DatabaseName   = database.ConnectionString.DatabaseName;
            result.StartTimeStamp = DateTime.Now;

            try
            {
                Func <Table, ObfuscationWorker> getAndProcessObfuscationWorker = table =>
                {
                    var obfuscationWorker = new ObfuscationWorker(
                        _sqlGenerationService,
                        _dataGenerationService,
                        _databaseInteractionService,
                        _eventAggregator,
                        database.ConnectionString,
                        table);
                    obfuscationWorker.Process();
                    return(obfuscationWorker);
                };

                IEnumerable <ObfuscationWorker> obfuscationWorkers;
                obfuscationWorkers = database.Tables
                                     .AsParallel()
                                     .Select(getAndProcessObfuscationWorker);

                foreach (ObfuscationWorker worker in obfuscationWorkers)
                {
                    if (worker.ErrorOccured)
                    {
                        result.ErroredTables.Add(worker.Table.FullTableName, worker.ErrorString);
                    }
                    else
                    {
                        result.TablesProcessed.Add(worker.Table.FullTableName, worker.RowsProcessed);
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                throw;
            }

            result.FinsihedTimeStamp = DateTime.Now;
            return(result);
        }
Пример #5
0
        public ObfuscationResult ObfuscateTable(ConnectionString connectionString, Table table)
        {
            ObfuscationResult result = new ObfuscationResult();

            result.DatabaseName   = connectionString.DatabaseName;
            result.StartTimeStamp = DateTime.Now;

            if (table.AreAnyGeneratorsActive)
            {
                Table  newTable = _dataGenerationService.GenerateDataForTable(connectionString, table, true);
                string sql      = _sqlGenerationService.GenerateUpdateSqlForTable(newTable, false);

                if (String.IsNullOrEmpty(sql) == false)
                {
                    _eventAggregator.SendMessage <StatusUpdateEvent>(new StatusUpdateEvent(string.Format("Processing SQL query for table: {0}", table.FullTableName)));
                    int rowsProcessed = _databaseInteractionService.ProcessSql(connectionString, sql);

                    result.TablesProcessed.Add(table.FullTableName, rowsProcessed);
                }
            }

            result.FinsihedTimeStamp = DateTime.Now;
            return(result);
        }