Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FilesSetsManager.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2014-2018 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.autopsy.modules.interestingitems;
20
21import java.io.File;
22import java.io.IOException;
23import java.nio.file.Paths;
24import java.util.ArrayList;
25import java.util.Arrays;
26import java.util.Collections;
27import java.util.HashMap;
28import java.util.List;
29import java.util.Map;
30import java.util.Observable;
31import org.apache.commons.io.FileUtils;
32import org.openide.util.NbBundle;
33import org.sleuthkit.autopsy.coreutils.PlatformUtil;
34import org.sleuthkit.autopsy.modules.interestingitems.FilesSet.Rule;
35import org.sleuthkit.autopsy.modules.interestingitems.FilesSet.Rule.MetaTypeCondition;
36
43public final class FilesSetsManager extends Observable {
44
45 @NbBundle.Messages({"FilesSetsManager.allFilesAndDirectories=All Files and Directories (Not Unallocated Space)",
46 "FilesSetsManager.allFilesDirectoriesAndUnallocated=All Files, Directories, and Unallocated Space"})
47 private static final List<String> ILLEGAL_FILE_NAME_CHARS = Collections.unmodifiableList(new ArrayList<>(Arrays.asList("\\", "/", ":", "*", "?", "\"", "<", ">")));
48 private static final List<String> ILLEGAL_FILE_PATH_CHARS = Collections.unmodifiableList(new ArrayList<>(Arrays.asList("\\", ":", "*", "?", "\"", "<", ">")));
49 private static final String LEGACY_FILES_SET_DEFS_FILE_NAME = "InterestingFilesSetDefs.xml"; //NON-NLS
50 private static final String INTERESTING_FILES_SET_DEFS_NAME = "InterestingFileSets.settings";
51 private static final String FILE_INGEST_FILTER_DEFS_NAME = "FileIngestFilterDefs.settings";
53 private static final String SETTINGS_PATH = PlatformUtil.getModuleConfigDirectory();
54 private static final String FILE_FILTER_PATH = Paths.get(SETTINGS_PATH, FILE_INGEST_FILTER_DEFS_NAME).toAbsolutePath().toString();
55 private static final String INTERESTING_ITEM_PATH = Paths.get(SETTINGS_PATH, INTERESTING_FILES_SET_DEFS_NAME).toAbsolutePath().toString();
56 private static final Object FILE_INGEST_FILTER_LOCK = new Object();
57 private static final Object INTERESTING_FILES_SET_LOCK = new Object();
58 private static FilesSetsManager instance;
59 private static final FilesSet FILES_DIRS_INGEST_FILTER = new FilesSet(
60 Bundle.FilesSetsManager_allFilesAndDirectories(), Bundle.FilesSetsManager_allFilesAndDirectories(), false, true, new HashMap<String, Rule>() {
61 {
62 put(Bundle.FilesSetsManager_allFilesAndDirectories(),
63 new Rule(Bundle.FilesSetsManager_allFilesAndDirectories(), null,
64 new MetaTypeCondition(MetaTypeCondition.Type.ALL), null, null, null, null, null));
65 }
66 });
68 Bundle.FilesSetsManager_allFilesDirectoriesAndUnallocated(), Bundle.FilesSetsManager_allFilesDirectoriesAndUnallocated(),
69 false, false, new HashMap<String, Rule>() {
70 {
71 put(Bundle.FilesSetsManager_allFilesDirectoriesAndUnallocated(),
72 new Rule(Bundle.FilesSetsManager_allFilesDirectoriesAndUnallocated(), null,
73 new MetaTypeCondition(MetaTypeCondition.Type.ALL), null, null, null, null, null));
74 }
75 });
76
77
81 public synchronized static FilesSetsManager getInstance() {
82 if (instance == null) {
84 }
85 return instance;
86 }
87
91 static String getFileFilterPath() {
92 return FILE_FILTER_PATH;
93 }
94
98 static String getInterestingItemPath() {
99 return INTERESTING_ITEM_PATH;
100 }
101
107 static List<String> getIllegalFileNameChars() {
108 return FilesSetsManager.ILLEGAL_FILE_NAME_CHARS;
109 }
110
117 static List<String> getIllegalFilePathChars() {
118 return FilesSetsManager.ILLEGAL_FILE_PATH_CHARS;
119 }
120
126 public static List<FilesSet> getStandardFileIngestFilters() {
128 }
129
138 public Map<String, FilesSet> getCustomFileIngestFilters() throws FilesSetsManagerException {
139 synchronized (FILE_INGEST_FILTER_LOCK) {
140 return FileSetsDefinitions.readSerializedDefinitions(PlatformUtil.getModuleConfigDirectory(), FILE_INGEST_FILTER_DEFS_NAME);
141 }
142 }
143
150 public static FilesSet getDefaultFilter() {
152 }
153
161 void setCustomFileIngestFilters(Map<String, FilesSet> filesSets) throws FilesSetsManagerException {
162 synchronized (FILE_INGEST_FILTER_LOCK) {
163 FileSetsDefinitions.writeDefinitionsFile(PlatformUtil.getModuleConfigDirectory(), FILE_INGEST_FILTER_DEFS_NAME, filesSets);
164 }
165 }
166
173 public Map<String, FilesSet> getInterestingFilesSets() throws FilesSetsManagerException {
174 synchronized (INTERESTING_FILES_SET_LOCK) {
175 return InterestingItemsFilesSetSettings.readDefinitionsFile(PlatformUtil.getModuleConfigDirectory(), INTERESTING_FILES_SET_DEFS_NAME, LEGACY_FILES_SET_DEFS_FILE_NAME);
176 }
177 }
178
186 void setInterestingFilesSets(Map<String, FilesSet> filesSets) throws FilesSetsManagerException {
187 synchronized (INTERESTING_FILES_SET_LOCK) {
188 InterestingItemsFilesSetSettings.writeDefinitionsFile(PlatformUtil.getModuleConfigDirectory(), INTERESTING_FILES_SET_DEFS_NAME, filesSets);
189 this.setChanged();
190 this.notifyObservers();
191 }
192 }
193
197 void upgradeConfig() throws IOException {
198 for (String fileName : new String[]{LEGACY_FILES_SET_DEFS_FILE_NAME, FILE_INGEST_FILTER_DEFS_NAME, INTERESTING_FILES_SET_DEFS_NAME }) {
199 File oldPath = Paths.get(LEGACY_SETTINGS_PATH, fileName).toFile();
200 File newPath = Paths.get(SETTINGS_PATH, fileName).toFile();
201
202 if (oldPath.exists() && !newPath.exists()) {
203 newPath.getParentFile().mkdirs();
204 FileUtils.copyFile(oldPath, newPath);
205 }
206 }
207 }
208
209 public static class FilesSetsManagerException extends Exception {
210
211 FilesSetsManagerException() {
212
213 }
214
215 FilesSetsManagerException(String message) {
216 super(message);
217 }
218
219 FilesSetsManagerException(String message, Throwable cause) {
220 super(message, cause);
221 }
222
223 FilesSetsManagerException(Throwable cause) {
224 super(cause);
225 }
226 }
227}

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.