19 package org.sleuthkit.autopsy.modules.interestingitems;
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
26 import java.util.UUID;
27 import java.util.regex.Pattern;
28 import org.openide.util.NbBundle;
40 public final class FilesSet implements Serializable {
51 private final Map<String, Rule>
rules =
new HashMap<>();
65 public FilesSet(String name, String description,
boolean ignoreKnownFiles,
boolean ignoreUnallocatedSpace, Map<String, Rule> rules) {
86 public FilesSet(String name, String description,
boolean ignoreKnownFiles,
boolean ignoreUnallocatedSpace, Map<String, Rule> rules,
87 boolean standardSet,
int versionNumber) {
88 if ((name == null) || (name.isEmpty())) {
89 throw new IllegalArgumentException(
"Interesting files set name cannot be null or empty");
92 if (versionNumber < 0) {
93 throw new IllegalArgumentException(
"version number must be >= 0");
100 this.description = (description != null ? description :
"");
104 this.rules.putAll(rules);
112 boolean isStandardSet() {
120 int getVersionNumber() {
171 return new HashMap<>(this.
rules);
183 if ((this.ignoreKnownFiles) && (file.getKnown() == TskData.FileKnown.KNOWN)) {
187 if ((this.ignoreUnallocatedSpace)
188 && (file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS)
189 || file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)
190 || file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS))) {
194 for (
Rule rule : rules.values()) {
195 if (rule.isSatisfied(file)) {
196 return rule.getName();
213 public final static class Rule implements Serializable {
215 private static final long serialVersionUID = 1L;
224 private final List<FileAttributeCondition>
conditions =
new ArrayList<>();
240 this.uuid = UUID.randomUUID().toString();
241 if (metaTypeCondition == null) {
242 throw new IllegalArgumentException(
"Interesting files set rule meta-type condition cannot be null");
252 this.conditions.add(this.metaTypeCondition);
255 if (this.fileSizeCondition != null) {
256 this.conditions.add(this.fileSizeCondition);
260 if (this.fileNameCondition != null) {
261 this.conditions.add(fileNameCondition);
265 if (this.mimeTypeCondition != null) {
266 this.conditions.add(mimeTypeCondition);
270 if (this.pathCondition != null) {
271 this.conditions.add(this.pathCondition);
274 if (this.dateCondition != null) {
275 this.conditions.add(this.dateCondition);
327 for (FileAttributeCondition condition : conditions) {
328 if (!condition.passes(file)) {
336 "# {0} - daysIncluded",
337 "FilesSet.rule.dateRule.toString=(modified within {0} day(s))"
343 if (fileNameCondition != null) {
344 return this.ruleName +
" (" + fileNameCondition.getTextToMatch() +
")";
345 }
else if (this.pathCondition != null) {
346 return this.ruleName +
" (" + pathCondition.
getTextToMatch() +
")";
347 }
else if (this.mimeTypeCondition != null) {
348 return this.ruleName +
" (" + mimeTypeCondition.
getMimeType() +
")";
349 }
else if (this.fileSizeCondition != null) {
352 }
else if (this.dateCondition != null) {
353 return this.ruleName + Bundle.FilesSet_rule_dateRule_toString(dateCondition.
getDaysIncluded());
355 return this.ruleName +
" ()";
385 static interface FileAttributeCondition
extends Serializable {
394 boolean passes(AbstractFile file);
402 private static final long serialVersionUID = 1L;
415 public boolean passes(AbstractFile file) {
416 return this.mimeType.equals(file.getMIMEType());
436 private static final long serialVersionUID = 1L;
452 this.symbol = symbol;
459 return LESS_THAN_EQUAL;
469 return GREATER_THAN_EQUAL;
471 throw new IllegalArgumentException(
"Invalid symbol");
510 throw new IllegalArgumentException(
"Invalid name for size unit.");
558 public boolean passes(AbstractFile file) {
559 long fileSize = file.getSize();
563 return fileSize > conditionSize;
564 case GREATER_THAN_EQUAL:
565 return fileSize >= conditionSize;
566 case LESS_THAN_EQUAL:
567 return fileSize <= conditionSize;
569 return fileSize < conditionSize;
571 return fileSize == conditionSize;
585 private static final long serialVersionUID = 1L;
607 public boolean passes(AbstractFile file) {
610 return file.isFile();
612 return file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR
613 || file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT_DIR;
614 case FILES_AND_DIRECTORIES:
615 return file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG
616 || file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR
617 || file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT_DIR;
638 static interface TextCondition
extends FileAttributeCondition {
645 String getTextToMatch();
663 boolean textMatches(String textToMatch);
706 AbstractTextCondition(List<String> values) {
729 return this.textMatcher.
isRegex();
745 public abstract boolean passes(AbstractFile file);
756 private static final long serialVersionUID = 1L;
777 public boolean passes(AbstractFile file) {
778 return this.
textMatches(file.getParentPath() +
"/");
788 static interface FileNameCondition
extends TextCondition {
798 private static final long serialVersionUID = 1L;
819 public boolean passes(AbstractFile file) {
859 public boolean passes(AbstractFile file) {
860 long dateThreshold = System.currentTimeMillis() / 1000 - daysIncluded *
SECS_PER_DAY;
861 return file.getCrtime() > dateThreshold || file.getMtime() > dateThreshold;
873 private static final long serialVersionUID = 1L;
910 public boolean passes(AbstractFile file) {
921 private static List<String>
normalize(List<String> extensions) {
922 List<String> values =
new ArrayList<>(extensions);
924 for (
int i = 0; i < values.size(); i++) {
939 return extension.startsWith(
".") ? extension.substring(1) : extension;
982 private static final long serialVersionUID = 1L;
1007 return subject.equalsIgnoreCase(textToMatch);
1017 private static final long serialVersionUID = 1L;
1029 this.pattern = Pattern.compile(Pattern.quote(textToMatch), Pattern.CASE_INSENSITIVE);
1044 return pattern.matcher(subject).find();
1054 private static final long serialVersionUID = 1L;
1070 return String.join(
",", this.valuesToMatch);
1080 for (String value : valuesToMatch) {
1081 if (value.equalsIgnoreCase(subject)) {
1095 private static final long serialVersionUID = 1L;
1110 return this.regex.pattern();
1121 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)
Rule(String ruleName, FileNameCondition fileNameCondition, MetaTypeCondition metaTypeCondition, ParentPathCondition pathCondition, MimeTypeCondition mimeTypeCondition, FileSizeCondition fileSizeCondition, DateCondition dateCondition)
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)
final DateCondition dateCondition
final boolean ignoreUnallocatedSpace
boolean textMatches(String subject)
final List< String > valuesToMatch
final boolean ignoreKnownFiles
COMPARATOR getComparator()
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
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)