Example #1
0
        public static bool SaveSession(WipeSession session, string path)
        {
            // check the parameters
            if(session == null || path == null) {
                throw new ArgumentNullException("session | path");
            }

            try {
                // create the store
                FileStore.FileStore store = new FileStore.FileStore();
                store.Encrypt = true;
                store.UseDPAPI = true;

                // add the file
                FileStore.StoreFile file = store.CreateFile("session.dat");
                byte[] data = SerializeSession(session);

                if(data == null) {
                    return false;
                }

                // write the file contents
                store.WriteFile(file, data, FileStore.StoreMode.Encrypted);
                return store.Save(path);
            }
            catch(Exception e) {
                Debug.ReportError("Error while saving session. Exception: {0}", e.Message);
                return false;
            }
        }
Example #2
0
        private void Export()
        {
            FileStore.FileStore store = new FileStore.FileStore();
            FileStore.StoreFile file = null;
            FileStore.StoreMode storeMode = FileStore.StoreMode.Normal;

            if(EncryptCheckbox.Checked) {
                SHA256Managed passwordHash = new SHA256Managed();
                store.Encrypt = true;
                store.EncryptionKey = passwordHash.ComputeHash(Encoding.ASCII.GetBytes(PasswordTextbox.Text));
                storeMode = FileStore.StoreMode.Encrypted;
            }

            // general settings
            if(GeneralCheckbox.Checked) {
                file = store.CreateFile("options.dat");
                store.WriteFile(file, SDOptionsFile.SerializeOptions(_options), storeMode);
            }

            // default plugin settings
            if(PluginCheckbox.Checked) {
                file = store.CreateFile("pluginSettings.dat");
                if(store.WriteFile(file, SecureDeleteLocations.GetPluginDefaultSettingsFilePath(), storeMode) == false) {
                    actionErrors.Add("Failed to export default plugin settings");
                }
            }

            // add methods
            if(MethodsCheckbox.Checked) {
                store.CreateFolder("methods");
                Dictionary<int, string> methodList = new Dictionary<int, string>();

                // add methods
                foreach(ListViewItem item in MethodList.Items) {
                    if(item.Checked) {
                        int id = (int)item.Tag;
                        string methodFile = Path.Combine(SecureDeleteLocations.GetMethodsFolder(),
                                                         id.ToString() + WipeMethodManager.MethodFileExtension);

                        file = store.CreateFile("methods\\" + Path.GetFileName(methodFile));
                        if(store.WriteFile(file, methodFile, storeMode) == false) {
                            actionErrors.Add("Failed to export wipe method " + item.Text);
                        }

                        // add to methd list
                        methodList.Add(id, item.Text);
                    }
                }

                // store the method list
                file = store.CreateFile("methods\\list.dat");
                store.WriteFile(file, SerializeMethodList(methodList), storeMode);
            }

            // scheduled tasks
            if(TasksCheckbox.Checked) {
                store.CreateFolder("tasks");

                // add task list
                file = store.CreateFile("tasks\\list.dat");
                store.WriteFile(file, SerializeTaskList(_options.SessionNames), storeMode);

                foreach(ListViewItem item in TaskList.Items) {
                    if(item.Checked) {
                        Guid taskId = (Guid)item.Tag;
                        string taskFile = SecureDeleteLocations.GetTaskFile(taskId);
                        string sessionFile = SecureDeleteLocations.GetSessionFile(taskId);

                        file = store.CreateFile("tasks\\" + Path.GetFileName(taskFile));
                        ScheduledTask task = new ScheduledTask();
                        TaskManager.LoadTask(taskFile, out task);
                        store.WriteFile(file, TaskManager.SerializeTask(task), storeMode);

                        file = store.CreateFile("tasks\\" + Path.GetFileName(sessionFile));
                        WipeSession session = new WipeSession();
                        SessionLoader.LoadSession(sessionFile, out session);
                        store.WriteFile(file, SessionSaver.SerializeSession(session), storeMode);
                    }
                }
            }

            // save
            if(store.Save(ExportPath.Text) == false) {
                actionErrors.Add("Failed to export to file " + ExportPath.Text);
            }
        }
        /// <summary>
        /// Save the history database to disk.
        /// </summary>
        public bool SaveHistory(string path)
        {
            if(path == null) {
                throw new ArgumentNullException("path");
            }

            try {
                // create the store
                FileStore.FileStore store = new FileStore.FileStore();
                store.Encrypt = true;
                store.UseDPAPI = true;

                // add the file
                FileStore.StoreFile file = store.CreateFile("history.dat");
                byte[] data = SerializeHistory(_categories);

                if(data == null) {
                    return false;
                }

                // write the file contents
                store.WriteFile(file, data, FileStore.StoreMode.Encrypted);
                return store.Save(path);
            }
            catch(Exception e) {
                Debug.ReportError("Error while saving task history. Exception: {0}", e.Message);
                return false;
            }
        }
        public static bool SaveOptions(SDOptions options, string path)
        {
            Debug.AssertNotNull(options, "Options is null");
            Debug.AssertNotNull(path, "Path is null");

            try {
                // create the store
                FileStore.FileStore store = new FileStore.FileStore();
                store.Encrypt = _encrypt;

                // set encryption key
                if(_password != null) {
                    SHA256Managed sha = new SHA256Managed();
                    store.EncryptionKey = sha.ComputeHash(Encoding.ASCII.GetBytes(_password));
                    store.UseDPAPI = false;
                }
                else {
                    store.UseDPAPI = true;
                }

                // add the file
                FileStore.StoreFile file = store.CreateFile("options.dat");
                byte[] data = SerializeOptions(options);

                if(data == null) {
                    return false;
                }

                // write the file contents
                store.WriteFile(file, data, FileStore.StoreMode.Encrypted);
                return store.Save(path);
            }
            catch(Exception e) {
                Debug.ReportError("Error while saving options. Exception: {0}", e.Message);
                return false;
            }
        }