19 package org.sleuthkit.autopsy.modules.interestingitems;
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
25 import java.util.UUID;
26 import java.util.regex.Pattern;
38 final class FilesSet {
40 private final String name;
41 private final String description;
42 private final boolean ignoreKnownFiles;
43 private final Map<String, Rule> rules =
new HashMap<>();
55 FilesSet(String name, String description,
boolean ignoreKnownFiles, Map<String, Rule> rules) {
56 if ((name == null) || (name.isEmpty())) {
57 throw new IllegalArgumentException(
"Interesting files set name cannot be null or empty");
60 this.description = (description != null ? description :
"");
61 this.ignoreKnownFiles = ignoreKnownFiles;
63 this.rules.putAll(rules);
81 String getDescription() {
82 return this.description;
94 boolean ignoresKnownFiles() {
95 return this.ignoreKnownFiles;
103 Map<String, Rule> getRules() {
104 return new HashMap<>(this.rules);
114 String fileIsMemberOf(AbstractFile file) {
115 if ((this.ignoreKnownFiles) && (file.getKnown() == TskData.FileKnown.KNOWN)) {
118 for (Rule rule : rules.values()) {
119 if (rule.isSatisfied(file)) {
120 return rule.getName();
127 public String toString() {
139 private final String uuid;
140 private final String ruleName;
141 private final FileNameFilter fileNameFilter;
142 private final MetaTypeFilter metaTypeFilter;
143 private final ParentPathFilter pathFilter;
144 private final List<FileAttributeFilter> filters =
new ArrayList<>();
154 Rule(String ruleName, FileNameFilter fileNameFilter, MetaTypeFilter metaTypeFilter, ParentPathFilter pathFilter) {
156 this.uuid = UUID.randomUUID().toString();
158 if (ruleName == null) {
159 throw new IllegalArgumentException(
"Interesting files set rule name cannot be null");
161 if (fileNameFilter == null) {
162 throw new IllegalArgumentException(
"Interesting files set rule file name filter cannot be null");
164 if (metaTypeFilter == null) {
165 throw new IllegalArgumentException(
"Interesting files set rule meta-type filter cannot be null");
167 this.ruleName = ruleName;
170 this.metaTypeFilter = metaTypeFilter;
171 this.filters.add(this.metaTypeFilter);
173 this.fileNameFilter = fileNameFilter;
174 this.filters.add(fileNameFilter);
176 this.pathFilter = pathFilter;
177 if (this.pathFilter != null) {
178 this.filters.add(this.pathFilter);
196 FileNameFilter getFileNameFilter() {
197 return this.fileNameFilter;
205 MetaTypeFilter getMetaTypeFilter() {
206 return this.metaTypeFilter;
214 ParentPathFilter getPathFilter() {
215 return this.pathFilter;
224 boolean isSatisfied(AbstractFile file) {
225 for (FileAttributeFilter filter : filters) {
226 if (!filter.passes(file)) {
237 public String toString() {
240 return this.ruleName +
" (" + fileNameFilter.getTextToMatch() +
")";
246 public String getUuid() {
254 static interface FileAttributeFilter {
262 boolean passes(AbstractFile file);
270 static final class MetaTypeFilter
implements FileAttributeFilter {
276 FILES_AND_DIRECTORIES
279 private final Type type;
286 MetaTypeFilter(Type type) {
294 public boolean passes(AbstractFile file) {
297 return file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG;
299 return file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR;
301 return file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG
302 || file.getMetaType() == TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR;
319 static interface TextFilter
extends FileAttributeFilter {
326 String getTextToMatch();
343 boolean textMatches(String textToMatch);
362 this.textMatcher =
new FilesSet.Rule.CaseInsensitivePartialStringComparisionMatcher(text);
364 this.textMatcher =
new FilesSet.Rule.CaseInsensitiveStringComparisionMatcher(text);
373 this.textMatcher =
new FilesSet.Rule.RegexMatcher(regex);
395 return this.textMatcher.
isRegex();
422 static final class ParentPathFilter
extends AbstractTextFilter {
429 ParentPathFilter(String path) {
438 ParentPathFilter(Pattern path) {
446 public boolean passes(AbstractFile file) {
447 return this.textMatches(file.getParentPath() +
"/");
456 static interface FileNameFilter
extends TextFilter {
464 static final class FullNameFilter
extends AbstractTextFilter implements FileNameFilter {
471 FullNameFilter(String name) {
480 FullNameFilter(Pattern name) {
488 public boolean passes(AbstractFile file) {
499 static final class ExtensionFilter
extends AbstractTextFilter implements FileNameFilter {
506 ExtensionFilter(String extension) {
510 super(extension.startsWith(
".") ? extension.substring(1) : extension,
false);
519 ExtensionFilter(Pattern extension) {
520 super(extension.pattern(),
false);
527 public boolean passes(AbstractFile file) {
603 return subject.equalsIgnoreCase(textToMatch);
624 this.pattern = Pattern.compile(Pattern.quote(textToMatch), Pattern.CASE_INSENSITIVE);
648 return pattern.matcher(subject).find();
674 return this.regex.pattern();
691 return this.regex.matcher(subject).find();
boolean textMatches(String subject)
final TextMatcher textMatcher
boolean textMatches(String subject)
boolean textMatches(String textToMatch)
boolean textMatches(String subject)
boolean textMatches(String subject)
abstract boolean passes(AbstractFile file)