19 package org.sleuthkit.autopsy.modules.interestingitems;
22 import java.io.FilenameFilter;
23 import java.util.HashMap;
25 import java.util.function.Function;
26 import java.util.logging.Level;
27 import java.util.stream.Collectors;
28 import org.openide.modules.InstalledFileLocator;
29 import org.openide.modules.OnStart;
30 import org.openide.util.NbBundle.Messages;
42 private static final String
CONFIG_DIR =
"InterestingFileSetRules";
46 public boolean accept(File dir, String name) {
47 return name.endsWith(
".xml");
56 Map<String, FilesSet> userConfiguredSettings = null;
60 LOGGER.log(Level.SEVERE,
"Unable to properly read user-configured interesting files sets.", ex);
63 if (userConfiguredSettings == null) {
64 userConfiguredSettings =
new HashMap<>();
68 copyOnNewer(standardInterestingFileSets, userConfiguredSettings,
true);
74 LOGGER.log(Level.SEVERE,
"Unable to write updated configuration for interesting files sets to config directory.", ex);
86 Map<String, FilesSet> standardInterestingFileSets =
new HashMap<>();
88 File[] standardFileSets = InstalledFileLocator.getDefault()
90 .listFiles(DEFAULT_XML_FILTER);
92 for (File standardFileSetsFile : standardFileSets) {
94 Map<String, FilesSet> thisFilesSet = InterestingItemsFilesSetSettings.readDefinitionsXML(standardFileSetsFile);
97 thisFilesSet = thisFilesSet.values()
99 .map((filesSet) -> getAsStandardFilesSet(filesSet,
true))
102 copyOnNewer(thisFilesSet, standardInterestingFileSets);
104 LOGGER.log(Level.WARNING, String.format(
"There was a problem importing the standard interesting file set at: %s.",
105 standardFileSetsFile.getAbsoluteFile()), ex);
108 return standardInterestingFileSets;
121 static FilesSet getAsStandardFilesSet(
FilesSet origFilesSet,
boolean standardFilesSet) {
129 origFilesSet.getVersionNumber()
141 private static void copyOnNewer(Map<String, FilesSet> src, Map<String, FilesSet> dest) {
156 private static void copyOnNewer(Map<String, FilesSet> src, Map<String, FilesSet> dest,
boolean appendCustom) {
157 for (Map.Entry<String,
FilesSet> srcEntry : src.entrySet()) {
158 String key = srcEntry.getKey();
159 FilesSet srcFileSet = srcEntry.getValue();
160 FilesSet destFileSet = dest.get(key);
161 if (destFileSet != null) {
164 if (appendCustom && srcFileSet.isStandardSet() != destFileSet.isStandardSet()) {
165 if (srcFileSet.isStandardSet()) {
167 dest.put(key, srcFileSet);
176 if (destFileSet.getVersionNumber() >= srcEntry.getValue().getVersionNumber()) {
181 dest.put(srcEntry.getKey(), srcEntry.getValue());
194 if (srcFilesSet.isStandardSet()) {
195 LOGGER.log(Level.SEVERE,
"An attempt to create a custom file that was a standard set.");
202 srcToAdd = getAsCustomFileSet(srcToAdd);
203 }
while (dest.containsKey(srcToAdd.
getName()));
205 dest.put(srcToAdd.
getName(), srcToAdd);
217 "# {0} - filesSetName",
218 "StandardInterestingFileSetsLoader.customSuffixed={0} (Custom)"
220 static FilesSet getAsCustomFileSet(FilesSet srcFilesSet) {
221 String customKey = Bundle.StandardInterestingFileSetsLoader_customSuffixed(srcFilesSet.getName());
224 srcFilesSet.getDescription(),
225 srcFilesSet.ignoresKnownFiles(),
226 srcFilesSet.ingoresUnallocatedSpace(),
227 srcFilesSet.getRules(),
229 srcFilesSet.getVersionNumber()
static void copyOnNewer(Map< String, FilesSet > src, Map< String, FilesSet > dest)
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 final Logger LOGGER