19package org.sleuthkit.autopsy.modules.interestingitems;
22import java.io.FilenameFilter;
23import java.io.IOException;
24import java.util.HashMap;
26import java.util.function.Function;
27import java.util.logging.Level;
28import java.util.stream.Collectors;
29import org.openide.modules.InstalledFileLocator;
30import org.openide.modules.OnStart;
31import org.openide.util.NbBundle.Messages;
32import org.sleuthkit.autopsy.core.RuntimeProperties;
33import org.sleuthkit.autopsy.coreutils.Logger;
34import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
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()) {
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 boolean runningWithGUI
synchronized static Logger getLogger(String name)
static void error(String message)
boolean ingoresUnallocatedSpace()
Map< String, Rule > getRules()
boolean ignoresKnownFiles()
Map< String, FilesSet > getInterestingFilesSets()
static synchronized FilesSetsManager getInstance()
static final FilenameFilter DEFAULT_XML_FILTER
static final Logger LOGGER
static void copyOnNewer(Map< String, FilesSet > src, Map< String, FilesSet > dest)
static final String CONFIG_DIR
static Map< String, FilesSet > readStandardFileXML()
static void copyOnNewer(Map< String, FilesSet > src, Map< String, FilesSet > dest, boolean appendCustom)
static void addCustomFile(Map< String, FilesSet > dest, FilesSet srcFilesSet)
static void handleError(String message, Exception ex)