19 package org.sleuthkit.autopsy.modules.interestingitems;
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.List;
27 import java.util.Map.Entry;
28 import java.util.UUID;
29 import java.util.regex.Pattern;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
43 public final class FilesSet implements Serializable {
54 private final Map<String, Rule>
rules;
74 public FilesSet(String name, String description,
boolean ignoreKnownFiles,
boolean ignoreUnallocatedSpace, Map<String, Rule> rules) {
95 public FilesSet(String name, String description,
boolean ignoreKnownFiles,
boolean ignoreUnallocatedSpace, Map<String, Rule> rules,
96 boolean standardSet,
int versionNumber) {
97 if ((name == null) || (name.isEmpty())) {
98 throw new IllegalArgumentException(
"Interesting files set name cannot be null or empty");
101 if (versionNumber < 0) {
102 throw new IllegalArgumentException(
"version number must be >= 0");
109 this.description = (description != null ? description :
"");
112 this.rules = rules == null ? Collections.emptyMap() :
new HashMap<>(
rules);
121 Map<String, Rule> inclusiveRules =
new HashMap<>();
122 Map<String, Rule> exclusiveRules =
new HashMap<>();
123 if (this.rules != null) {
124 for (Entry<String, Rule> ruleEntry : this.rules.entrySet()) {
125 if (ruleEntry.getValue().isExclusive()) {
126 exclusiveRules.put(ruleEntry.getKey(), ruleEntry.getValue());
128 inclusiveRules.put(ruleEntry.getKey(), ruleEntry.getValue());
140 boolean isStandardSet() {
148 int getVersionNumber() {
199 return new HashMap<>(this.
rules);
212 "FileSet_fileIsMemberOf_noInclusiveRules_ruleName=Not Excluded"
215 if ((this.ignoreKnownFiles) && (file.getKnown() == TskData.FileKnown.KNOWN)) {
219 if ((this.ignoreUnallocatedSpace)
220 && (file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS)
221 || file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)
222 || file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS))) {
226 if (inclusiveRules == null || exclusiveRules == null) {
232 if (inclusiveRules.isEmpty()) {
234 if (exclusiveRules.isEmpty()) {
238 ruleName = Bundle.FileSet_fileIsMemberOf_noInclusiveRules_ruleName();
244 for (
Rule rule : inclusiveRules.values()) {
245 if (rule.isSatisfied(file)) {
246 ruleName = rule.getName();
252 for (
Rule rule : exclusiveRules.values()) {
253 if (rule.isSatisfied(file)) {
272 public final static class Rule implements Serializable {
274 private static final long serialVersionUID = 1L;
284 private final List<FileAttributeCondition>
conditions =
new ArrayList<>();
306 this.uuid = UUID.randomUUID().toString();
307 if (metaTypeCondition == null) {
308 throw new IllegalArgumentException(
"Interesting files set rule meta-type condition cannot be null");
318 this.conditions.add(this.metaTypeCondition);
321 if (this.fileSizeCondition != null) {
322 this.conditions.add(this.fileSizeCondition);
326 if (this.fileNameCondition != null) {
327 this.conditions.add(fileNameCondition);
331 if (this.mimeTypeCondition != null) {
332 this.conditions.add(mimeTypeCondition);
336 if (this.pathCondition != null) {
337 this.conditions.add(this.pathCondition);
340 if (this.dateCondition != null) {
341 this.conditions.add(this.dateCondition);
393 return exclusive != null && exclusive ==
true;
404 for (FileAttributeCondition condition : conditions) {
405 if (!condition.passes(file)) {
413 "# {0} - daysIncluded",
414 "FilesSet.rule.dateRule.toString=(modified within {0} day(s))"
420 if (fileNameCondition != null) {
421 return this.ruleName +
" (" + fileNameCondition.getTextToMatch() +
")";
422 }
else if (this.pathCondition != null) {
423 return this.ruleName +
" (" + pathCondition.
getTextToMatch() +
")";
424 }
else if (this.mimeTypeCondition != null) {
425 return this.ruleName +
" (" + mimeTypeCondition.
getMimeType() +
")";
426 }
else if (this.fileSizeCondition != null) {
429 }
else if (this.dateCondition != null) {
430 return this.ruleName + Bundle.FilesSet_rule_dateRule_toString(dateCondition.
getDaysIncluded());
432 return this.ruleName +
" ()";
462 static interface FileAttributeCondition
extends Serializable {
471 boolean passes(AbstractFile file);
479 private static final long serialVersionUID = 1L;
492 public boolean passes(AbstractFile file) {
493 return this.mimeType.equals(file.getMIMEType());
513 private static final long serialVersionUID = 1L;
529 this.symbol = symbol;
536 return LESS_THAN_EQUAL;
546 return GREATER_THAN_EQUAL;
548 throw new IllegalArgumentException(
"Invalid symbol");
587 throw new IllegalArgumentException(
"Invalid name for size unit.");
635 public boolean passes(AbstractFile file) {
636 long fileSize = file.getSize();
640 return fileSize > conditionSize;
641 case GREATER_THAN_EQUAL:
642 return fileSize >= conditionSize;
643 case LESS_THAN_EQUAL:
644 return fileSize <= conditionSize;
646 return fileSize < conditionSize;
648 return fileSize == conditionSize;
662 private static final long serialVersionUID = 1L;
684 public boolean passes(AbstractFile file) {
687 return file.isFile();
689 return file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR
690 || file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT_DIR;
691 case FILES_AND_DIRECTORIES:
692 return file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG
693 || file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR
694 || file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT_DIR;
715 static interface TextCondition
extends FileAttributeCondition {
722 String getTextToMatch();
740 boolean textMatches(String textToMatch);
783 AbstractTextCondition(List<String> values) {
806 return this.textMatcher.
isRegex();
822 public abstract boolean passes(AbstractFile file);
833 private static final long serialVersionUID = 1L;
854 public boolean passes(AbstractFile file) {
855 return this.
textMatches(file.getParentPath() +
"/");
865 static interface FileNameCondition
extends TextCondition {
875 private static final long serialVersionUID = 1L;
896 public boolean passes(AbstractFile file) {
936 public boolean passes(AbstractFile file) {
937 long dateThreshold = System.currentTimeMillis() / 1000 - daysIncluded *
SECS_PER_DAY;
938 return file.getCrtime() > dateThreshold || file.getMtime() > dateThreshold;
950 private static final long serialVersionUID = 1L;
987 public boolean passes(AbstractFile file) {
998 private static List<String>
normalize(List<String> extensions) {
999 List<String> values =
new ArrayList<>(extensions);
1001 for (
int i = 0; i < values.size(); i++) {
1002 values.set(i,
normalize(values.get(i)));
1016 return extension.startsWith(
".") ? extension.substring(1) : extension;
1059 private static final long serialVersionUID = 1L;
1084 return subject.equalsIgnoreCase(textToMatch);
1094 private static final long serialVersionUID = 1L;
1106 this.pattern = Pattern.compile(Pattern.quote(textToMatch), Pattern.CASE_INSENSITIVE);
1121 return pattern.matcher(subject).find();
1131 private static final long serialVersionUID = 1L;
1147 return String.join(
",", this.valuesToMatch);
1157 for (String value : valuesToMatch) {
1158 if (value.equalsIgnoreCase(subject)) {
1172 private static final long serialVersionUID = 1L;
1187 return this.regex.pattern();
1198 return this.regex.matcher(subject).find();
String fileIsMemberOf(AbstractFile file)
ExtensionCondition(Pattern extension)
ParentPathCondition(Pattern path)
boolean passes(AbstractFile file)
static String normalize(String extension)
FileSizeCondition(COMPARATOR comparator, SIZE_UNIT unit, int sizeValue)
boolean textMatches(String textToMatch)
MetaTypeCondition getMetaTypeCondition()
COMPARATOR(String symbol)
final COMPARATOR comparator
ParentPathCondition getPathCondition()
FilesSet(String name, String description, boolean ignoreKnownFiles, boolean ignoreUnallocatedSpace, Map< String, Rule > rules)
abstract boolean passes(AbstractFile file)
boolean textMatches(String subject)
static SIZE_UNIT fromName(String name)
final ParentPathCondition pathCondition
DateCondition getDateCondition()
ParentPathCondition(String path)
FilesSet(String name, String description, boolean ignoreKnownFiles, boolean ignoreUnallocatedSpace, Map< String, Rule > rules, boolean standardSet, int versionNumber)
final MetaTypeCondition metaTypeCondition
boolean passes(AbstractFile file)
boolean textMatches(String subject)
MimeTypeCondition(String mimeType)
boolean isSatisfied(AbstractFile file)
final TextMatcher textMatcher
FullNameCondition(Pattern name)
final FileSizeCondition fileSizeCondition
static final long serialVersionUID
ExtensionCondition(List< String > extensions)
boolean passes(AbstractFile file)
Map< String, Rule > inclusiveRules
final DateCondition dateCondition
Rule(String ruleName, FileNameCondition fileNameCondition, MetaTypeCondition metaTypeCondition, ParentPathCondition pathCondition, MimeTypeCondition mimeTypeCondition, FileSizeCondition fileSizeCondition, DateCondition dateCondition, Boolean exclusive)
final boolean ignoreUnallocatedSpace
boolean textMatches(String subject)
final List< String > valuesToMatch
final boolean ignoreKnownFiles
COMPARATOR getComparator()
void divideInclusiveExclusive()
MimeTypeCondition getMimeTypeCondition()
boolean passes(AbstractFile file)
static final long SECS_PER_DAY
Map< String, Rule > getRules()
boolean textMatches(String subject)
SIZE_UNIT(long size, String name)
final Map< String, Rule > rules
Map< String, Rule > exclusiveRules
FileSizeCondition getFileSizeCondition()
boolean ignoresKnownFiles()
boolean passes(AbstractFile file)
ExtensionCondition(String extension)
final boolean standardSet
static List< String > normalize(List< String > extensions)
boolean passes(AbstractFile file)
FileNameCondition getFileNameCondition()
FullNameCondition(String name)
boolean ingoresUnallocatedSpace()
static COMPARATOR fromSymbol(String symbol)
final List< FileAttributeCondition > conditions
final MimeTypeCondition mimeTypeCondition
final FileNameCondition fileNameCondition
boolean textMatches(String subject)