19 package org.sleuthkit.autopsy.modules.interestingitems;
22 import java.io.FilenameFilter;
23 import java.io.IOException;
24 import java.util.HashMap;
26 import java.util.function.Function;
27 import java.util.logging.Level;
28 import java.util.stream.Collectors;
29 import org.openide.modules.InstalledFileLocator;
30 import org.openide.modules.OnStart;
31 import org.openide.util.NbBundle.Messages;
45 private static final String
CONFIG_DIR =
"InterestingFileSetRules";
49 public boolean accept(File dir, String name) {
50 return name.endsWith(
".xml");
56 "StandardInterestingFilesSetsLoader_cannotLoadStandard=Unable to properly read standard interesting files sets.",
57 "StandardInterestingFilesSetsLoader_cannotLoadUserConfigured=Unable to properly read user-configured interesting files sets.",
58 "StandardInterestingFilesSetsLoader_cannotUpdateInterestingFilesSets=Unable to write updated configuration for interesting files sets to config directory."
63 Map<String, FilesSet> standardInterestingFileSets = null;
67 handleError(Bundle.StandardInterestingFilesSetsLoader_cannotLoadStandard(), ex);
72 Map<String, FilesSet> userConfiguredSettings = null;
76 LOGGER.log(Level.SEVERE,
"Unable to properly read user-configured interesting files sets.", ex);
77 handleError(Bundle.StandardInterestingFilesSetsLoader_cannotLoadStandard(), ex);
82 copyOnNewer(standardInterestingFileSets, userConfiguredSettings,
true);
88 handleError(Bundle.StandardInterestingFilesSetsLoader_cannotUpdateInterestingFilesSets(), ex);
98 }
catch (IOException ex) {
99 LOGGER.log(Level.WARNING,
"There was an error while upgrading config paths.", ex);
110 LOGGER.log(Level.SEVERE, message, ex);
124 Map<String, FilesSet> standardInterestingFileSets =
new HashMap<>();
126 File configFolder = InstalledFileLocator.getDefault().locate(
129 if (configFolder == null || !configFolder.exists() || !configFolder.isDirectory()) {
133 File[] standardFileSets = configFolder.listFiles(DEFAULT_XML_FILTER);
135 for (File standardFileSetsFile : standardFileSets) {
137 Map<String, FilesSet> thisFilesSet = InterestingItemsFilesSetSettings.readDefinitionsXML(standardFileSetsFile);
140 thisFilesSet = thisFilesSet.values()
142 .map((filesSet) -> getAsStandardFilesSet(filesSet,
true))
145 copyOnNewer(thisFilesSet, standardInterestingFileSets);
147 LOGGER.log(Level.WARNING, String.format(
"There was a problem importing the standard interesting file set at: %s.",
148 standardFileSetsFile.getAbsoluteFile()), ex);
151 return standardInterestingFileSets;
164 static FilesSet getAsStandardFilesSet(
FilesSet origFilesSet,
boolean standardFilesSet) {
172 origFilesSet.getVersionNumber()
184 private static void copyOnNewer(Map<String, FilesSet> src, Map<String, FilesSet> dest) {
199 private static void copyOnNewer(Map<String, FilesSet> src, Map<String, FilesSet> dest,
boolean appendCustom) {
200 for (Map.Entry<String,
FilesSet> srcEntry : src.entrySet()) {
201 String key = srcEntry.getKey();
202 FilesSet srcFileSet = srcEntry.getValue();
203 FilesSet destFileSet = dest.get(key);
204 if (destFileSet != null) {
207 if (appendCustom && srcFileSet.isStandardSet() != destFileSet.isStandardSet()) {
208 if (srcFileSet.isStandardSet()) {
210 dest.put(key, srcFileSet);
219 if (destFileSet.getVersionNumber() >= srcEntry.getValue().getVersionNumber()) {
224 dest.put(srcEntry.getKey(), srcEntry.getValue());
237 if (srcFilesSet.isStandardSet()) {
238 LOGGER.log(Level.SEVERE,
"An attempt to create a custom file that was a standard set.");
245 srcToAdd = getAsCustomFileSet(srcToAdd);
246 }
while (dest.containsKey(srcToAdd.
getName()));
248 dest.put(srcToAdd.
getName(), srcToAdd);
260 "# {0} - filesSetName",
261 "StandardInterestingFileSetsLoader.customSuffixed={0} (Custom)"
263 static FilesSet getAsCustomFileSet(FilesSet srcFilesSet) {
264 String customKey = Bundle.StandardInterestingFileSetsLoader_customSuffixed(srcFilesSet.getName());
267 srcFilesSet.getDescription(),
268 srcFilesSet.ignoresKnownFiles(),
269 srcFilesSet.ingoresUnallocatedSpace(),
270 srcFilesSet.getRules(),
272 srcFilesSet.getVersionNumber()
static void copyOnNewer(Map< String, FilesSet > src, Map< String, FilesSet > dest)
static boolean runningWithGUI
static void handleError(String message, Exception ex)
Map< String, FilesSet > getInterestingFilesSets()
static synchronized FilesSetsManager getInstance()
static final FilenameFilter DEFAULT_XML_FILTER
static void copyOnNewer(Map< String, FilesSet > src, Map< String, FilesSet > dest, boolean appendCustom)
static final String CONFIG_DIR
static void addCustomFile(Map< String, FilesSet > dest, FilesSet srcFilesSet)
Map< String, Rule > getRules()
boolean ignoresKnownFiles()
synchronized static Logger getLogger(String name)
static Map< String, FilesSet > readStandardFileXML()
boolean ingoresUnallocatedSpace()
static void error(String message)
static final Logger LOGGER