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 {
47 private final Map<String, Rule>
rules =
new HashMap<>();
61 public FilesSet(String name, String description,
boolean ignoreKnownFiles,
boolean ignoreUnallocatedSpace, Map<String, Rule> rules) {
62 if ((name == null) || (name.isEmpty())) {
63 throw new IllegalArgumentException(
"Interesting files set name cannot be null or empty");
66 this.description = (description != null ? description :
"");
70 this.rules.putAll(rules);
121 return new HashMap<>(this.
rules);
133 if ((this.ignoreKnownFiles) && (file.getKnown() == TskData.FileKnown.KNOWN)) {
137 if ((this.ignoreUnallocatedSpace)
138 && (file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS)
139 || file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)
140 || file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS))) {
144 for (
Rule rule : rules.values()) {
145 if (rule.isSatisfied(file)) {
146 return rule.getName();
163 public final static class Rule implements Serializable {
165 private static final long serialVersionUID = 1L;
174 private final List<FileAttributeCondition>
conditions =
new ArrayList<>();
190 this.uuid = UUID.randomUUID().toString();
191 if (metaTypeCondition == null) {
192 throw new IllegalArgumentException(
"Interesting files set rule meta-type condition cannot be null");
202 this.conditions.add(this.metaTypeCondition);
205 if (this.fileSizeCondition != null) {
206 this.conditions.add(this.fileSizeCondition);
210 if (this.fileNameCondition != null) {
211 this.conditions.add(fileNameCondition);
215 if (this.mimeTypeCondition != null) {
216 this.conditions.add(mimeTypeCondition);
220 if (this.pathCondition != null) {
221 this.conditions.add(this.pathCondition);
224 if (this.dateCondition != null) {
225 this.conditions.add(this.dateCondition);
277 for (FileAttributeCondition condition : conditions) {
278 if (!condition.passes(file)) {
286 "# {0} - daysIncluded",
287 "FilesSet.rule.dateRule.toString=(modified within {0} day(s))"
293 if (fileNameCondition != null) {
294 return this.ruleName +
" (" + fileNameCondition.getTextToMatch() +
")";
295 }
else if (this.pathCondition != null) {
296 return this.ruleName +
" (" + pathCondition.
getTextToMatch() +
")";
297 }
else if (this.mimeTypeCondition != null) {
298 return this.ruleName +
" (" + mimeTypeCondition.
getMimeType() +
")";
299 }
else if (this.fileSizeCondition != null) {
302 }
else if (this.dateCondition != null) {
303 return this.ruleName + Bundle.FilesSet_rule_dateRule_toString(dateCondition.
getDaysIncluded());
305 return this.ruleName +
" ()";
335 static interface FileAttributeCondition
extends Serializable {
344 boolean passes(AbstractFile file);
352 private static final long serialVersionUID = 1L;
365 public boolean passes(AbstractFile file) {
366 return this.mimeType.equals(file.getMIMEType());
386 private static final long serialVersionUID = 1L;
402 this.symbol = symbol;
409 return LESS_THAN_EQUAL;
419 return GREATER_THAN_EQUAL;
421 throw new IllegalArgumentException(
"Invalid symbol");
460 throw new IllegalArgumentException(
"Invalid name for size unit.");
508 public boolean passes(AbstractFile file) {
509 long fileSize = file.getSize();
513 return fileSize > conditionSize;
514 case GREATER_THAN_EQUAL:
515 return fileSize >= conditionSize;
516 case LESS_THAN_EQUAL:
517 return fileSize <= conditionSize;
519 return fileSize < conditionSize;
521 return fileSize == conditionSize;
535 private static final long serialVersionUID = 1L;
557 public boolean passes(AbstractFile file) {
560 return file.isFile();
562 return file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR
563 || file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT_DIR;
564 case FILES_AND_DIRECTORIES:
565 return file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG
566 || file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR
567 || file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT_DIR;
588 static interface TextCondition
extends FileAttributeCondition {
595 String getTextToMatch();
613 boolean textMatches(String textToMatch);
671 return this.textMatcher.
isRegex();
687 public abstract boolean passes(AbstractFile file);
698 private static final long serialVersionUID = 1L;
719 public boolean passes(AbstractFile file) {
720 return this.
textMatches(file.getParentPath() +
"/");
730 static interface FileNameCondition
extends TextCondition {
740 private static final long serialVersionUID = 1L;
761 public boolean passes(AbstractFile file) {
802 public boolean passes(AbstractFile file) {
803 long dateThreshold = System.currentTimeMillis() / 1000 - daysIncluded *
SECS_PER_DAY;
804 return file.getCrtime() > dateThreshold || file.getMtime() > dateThreshold;
816 private static final long serialVersionUID = 1L;
827 super(extension.startsWith(
".") ? extension.substring(1) : extension,
false);
841 public boolean passes(AbstractFile file) {
885 private static final long serialVersionUID = 1L;
910 return subject.equalsIgnoreCase(textToMatch);
920 private static final long serialVersionUID = 1L;
932 this.pattern = Pattern.compile(Pattern.quote(textToMatch), Pattern.CASE_INSENSITIVE);
947 return pattern.matcher(subject).find();
956 private static final long serialVersionUID = 1L;
971 return this.regex.pattern();
982 return this.regex.matcher(subject).find();
String fileIsMemberOf(AbstractFile file)
ExtensionCondition(Pattern extension)
ParentPathCondition(Pattern path)
boolean passes(AbstractFile file)
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)
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
boolean passes(AbstractFile file)
final DateCondition dateCondition
final boolean ignoreUnallocatedSpace
boolean textMatches(String subject)
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)
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