コード例 #1
0
ファイル: ExportService.cs プロジェクト: ucswift/Dafuscator
        public void ExportTables(IEnumerable<Table> tables, string path, ConnectionString connectionString)
        {
            try
            {
                if (File.Exists(path))
                    File.Delete(path);

                StringBuilder sb = new StringBuilder();
                sb.Append("SET NOCOUNT ON\r\n\r\n");

                foreach (Table t in tables)
                {
                    Table table = _dataGenerationService.GenerateDataForTable(connectionString, t, true);
                    sb.Append(_sqlGenerationService.GenerateUpdateSqlForTable(table, true));
                }

                sb.Append("SET NOCOUNT OFF\r\n\r\n");

                using (StreamWriter writer = new StreamWriter(path))
                {
                    writer.Write(sb);
                }
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                throw;
            }
        }
コード例 #2
0
        public ObfuscationWorker(ISqlGenerationService sqlGenerationService, IDataGenerationService dataGenerationService,
			IDatabaseInteractionService databaseInteractionService, IEventAggregator eventAggregator, ConnectionString connectionString, Table table)
        {
            _sqlGenerationService = sqlGenerationService;
            _dataGenerationService = dataGenerationService;
            _databaseInteractionService = databaseInteractionService;
            _eventAggregator = eventAggregator;

            _table = table;
            _connectionString = connectionString;
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: BigBadJock/Dafuscator
        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;

                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);
                }
            }
        }
コード例 #4
0
ファイル: RunService.cs プロジェクト: BigBadJock/Dafuscator
        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;
        }
コード例 #5
0
 public bool TestConnection(ConnectionString connectionString)
 {
     return _databaseProvider.TestConnection(connectionString);
 }
コード例 #6
0
 public int ProcessSql(ConnectionString connectionString, string sql)
 {
     return _databaseProvider.ProcessSql(connectionString.GetConnectionString(), sql);
 }
コード例 #7
0
 public List<Table> GetTablesFromDatabase(ConnectionString connectionString)
 {
     return _databaseProvider.GetSchemaInformation(connectionString.GetConnectionString());
 }
コード例 #8
0
 public double GetRecrodCountForTable(ConnectionString connectionString, Table table)
 {
     return _databaseProvider.GetRecordCount(connectionString.GetConnectionString(), table);
 }
コード例 #9
0
 public HashSet<string> GetDataForColumn(ConnectionString connectionString, Table table, Column column)
 {
     return _databaseProvider.GetDataForColumn(connectionString.GetConnectionString(), table, column);
 }
コード例 #10
0
ファイル: ExportService.cs プロジェクト: ucswift/Dafuscator
        public void ExportTestTable(Table table, string path, ConnectionString connectionString)
        {
            try
            {
                if (File.Exists(path))
                    File.Delete(path);

                StringBuilder sb = new StringBuilder();

                sb.Append("BEGIN TRANSACTION\r\n\r\n");
                sb.Append("SET NOCOUNT ON\r\n\r\n");

                if (table.RecordCount > 1000)
                    table.RecordCount = 1000;

                table = _dataGenerationService.GenerateDataForTable(connectionString, table, false);
                string sql = _sqlGenerationService.GenerateUpdateSqlForTable(table, true);

                sb.Append(sql);
                sb.Append("SET NOCOUNT OFF\r\n\r\n");
                sb.Append("\r\n\r\nROLLBACK TRANSACTION\r\n\r\n");

                using (StreamWriter writer = new StreamWriter(path))
                {
                    writer.Write(sql);
                }
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                throw;
            }
        }
コード例 #11
0
        public Table GenerateDataForTable(ConnectionString connectionString, Table table, bool updateRecordCount)
        {
            if (table.AreAnyGeneratorsActive && table.HandlerType == TableHandlerTypes.None)
            {
                _eventAggregator.SendMessage<StatusUpdateEvent>(new StatusUpdateEvent(string.Format("Generating Data for table: {0}", table.FullTableName)));

                for (int i = 0; i < table.Columns.Count; i++)
                {
                    if (table.Columns[i].GeneratorType.HasValue && (table.Columns[i].GeneratorType.Value.Equals(SystemConstants.DefaultGuid) == false))
                    {
                        List<object> generationData = new List<object>();
                        double recordCount = 0;

                        if (updateRecordCount)
                        {
                            try
                            {
                                recordCount = _databaseInteractionService.GetRecrodCountForTable(connectionString, table);
                            }
                            catch
                            { }
                        }

                        if (recordCount <= 0)
                            recordCount = table.RecordCount;
                        else
                            table.RecordCount = recordCount;

                        generationData.Add(recordCount);

                        foreach (object o in table.Columns[i].GeneratorData)
                        {
                            if (o != null)
                                generationData.Add(o);
                        }

                        HashSet<string> existingColumnData = new HashSet<string>();

                        try
                        {
                            existingColumnData = _databaseInteractionService.GetDataForColumn(connectionString, table, table.Columns[i]);
                        }
                        catch
                        { }

                        table.Columns[i] = GenerateDataForColumn(table.Columns[i], generationData.ToArray(), existingColumnData);
                    }
                }
            }

            return table;
        }