19 package org.sleuthkit.autopsy.datamodel;
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.EnumSet;
26 import java.util.List;
27 import java.util.Objects;
28 import java.util.Observable;
29 import java.util.Observer;
31 import java.util.logging.Level;
32 import org.openide.nodes.AbstractNode;
33 import org.openide.nodes.ChildFactory;
34 import org.openide.nodes.Children;
35 import org.openide.nodes.Node;
36 import org.openide.nodes.Sheet;
37 import org.openide.util.NbBundle;
38 import org.openide.util.lookup.Lookups;
65 @NbBundle.Messages({
"DeletedContent.fsDelFilter.text=File System",
66 "DeletedContent.allDelFilter.text=All"})
69 FS_DELETED_FILTER(0,
"FS_DELETED_FILTER",
70 Bundle.DeletedContent_fsDelFilter_text()),
71 ALL_DELETED_FILTER(1,
"ALL_DELETED_FILTER",
72 Bundle.DeletedContent_allDelFilter_text());
81 this.displayName = displayName;
94 return this.displayName;
99 return visitor.
visit(
this);
109 this.datasourceObjId = dsObjId;
112 long filteringDataSourceObjId() {
117 public <T> T accept(AutopsyItemVisitor<T> visitor) {
118 return visitor.visit(
this);
127 @NbBundle.Messages(
"DeletedContent.deletedContentsNode.name=Deleted Files")
128 private static final String
NAME = Bundle.DeletedContent_deletedContentsNode_name();
133 super.setDisplayName(NAME);
134 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file-icon-deleted.png");
144 return visitor.
visit(
this);
149 "DeletedContent.createSheet.name.displayName=Name",
150 "DeletedContent.createSheet.name.desc=no description"})
152 Sheet sheet = super.createSheet();
153 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
154 if (sheetSet == null) {
155 sheetSet = Sheet.createPropertiesSet();
160 Bundle.DeletedContent_createSheet_name_displayName(),
161 Bundle.DeletedContent_createSheet_name_desc(),
168 return getClass().getName();
182 this.datasourceObjId = dsObjId;
210 private final PropertyChangeListener
pcl = (PropertyChangeEvent evt) -> {
211 String eventType = evt.getPropertyName();
249 if (evt.getNewValue() == null) {
252 maxFilesDialogShown =
false;
264 protected boolean createKeys(List<DeletedContent.DeletedContentFilter> list) {
282 super(Children.create(
new DeletedContentChildren(
filter, skCase, null, dsObjId),
true), Lookups.singleton(
filter.getDisplayName()));
284 this.datasourceObjId = dsObjId;
289 super(Children.create(
new DeletedContentChildren(
filter, skCase, o, dsObjId),
true), Lookups.singleton(
filter.getDisplayName()));
291 this.datasourceObjId = dsObjId;
293 o.addObserver(
new DeletedContentNodeObserver());
297 super.setName(
filter.getName());
299 String tooltip =
filter.getDisplayName();
300 this.setShortDescription(tooltip);
301 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file-icon-deleted.png");
309 public void update(Observable o, Object arg) {
316 final long count = DeletedContentChildren.calculateItems(skCase,
filter, datasourceObjId);
318 super.setDisplayName(
filter.getDisplayName() +
" (" + count +
")");
323 return visitor.
visit(
this);
328 "DeletedContent.createSheet.filterType.displayName=Type",
329 "DeletedContent.createSheet.filterType.desc=no description"})
331 Sheet sheet = super.createSheet();
332 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
333 if (sheetSet == null) {
334 sheetSet = Sheet.createPropertiesSet();
339 Bundle.DeletedContent_createSheet_filterType_displayName(),
340 Bundle.DeletedContent_createSheet_filterType_desc(),
341 filter.getDisplayName()));
361 static class DeletedContentChildren
extends ChildFactory.Detachable<AbstractFile> {
363 private final SleuthkitCase
skCase;
372 this.filter = filter;
377 private final Observer observer =
new DeletedContentChildrenObserver();
383 public void update(Observable o, Object arg) {
389 protected void addNotify() {
390 if (notifier != null) {
391 notifier.addObserver(observer);
396 protected void removeNotify() {
397 if (notifier != null) {
398 notifier.deleteObserver(observer);
403 protected boolean createKeys(List<AbstractFile> list) {
404 list.addAll(runFsQuery());
408 static private String makeQuery(
DeletedContent.DeletedContentFilter filter,
long filteringDSObjId) {
411 case FS_DELETED_FILTER:
412 query =
"dir_flags = " + TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue()
413 +
" AND meta_flags != " + TskData.TSK_FS_META_FLAG_ENUM.ORPHAN.getValue()
414 +
" AND type = " + TskData.TSK_DB_FILES_TYPE_ENUM.FS.getFileType();
417 case ALL_DELETED_FILTER:
420 +
"(dir_flags = " + TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue()
422 +
"meta_flags = " + TskData.TSK_FS_META_FLAG_ENUM.ORPHAN.getValue()
424 +
" AND type = " + TskData.TSK_DB_FILES_TYPE_ENUM.FS.getFileType()
426 +
" OR type = " + TskData.TSK_DB_FILES_TYPE_ENUM.CARVED.getFileType()
437 logger.log(Level.SEVERE,
"Unsupported filter type to get deleted content: {0}", filter);
441 if (UserPreferences.hideKnownFilesInViewsTree()) {
442 query +=
" AND (known != " + TskData.FileKnown.KNOWN.getFileKnownValue()
443 +
" OR known IS NULL)";
446 if (Objects.equals(CasePreferences.getGroupItemsInTreeByDataSource(),
true)) {
447 query +=
" AND data_source_obj_id = " + filteringDSObjId;
452 private List<AbstractFile> runFsQuery() {
453 List<AbstractFile> ret =
new ArrayList<>();
455 String query = makeQuery(filter, datasourceObjId);
457 ret = skCase.findAllFilesWhere(query);
458 }
catch (TskCoreException e) {
459 logger.log(Level.SEVERE,
"Error getting files for the deleted content view using: " + query, e);
474 static long calculateItems(SleuthkitCase sleuthkitCase,
DeletedContent.DeletedContentFilter filter,
long datasourceObjId) {
476 return sleuthkitCase.countFilesWhere(makeQuery(filter, datasourceObjId));
477 }
catch (TskCoreException ex) {
478 logger.log(Level.SEVERE,
"Error getting deleted files search view count", ex);
485 return key.accept(
new ContentVisitor.Default<AbstractNode>() {
486 public FileNode visit(AbstractFile f) {
487 return new FileNode(f, false);
490 public FileNode visit(FsContent f) {
491 return new FileNode(f,
false);
495 public FileNode visit(LayoutFile f) {
496 return new FileNode(f,
false);
500 public FileNode visit(File f) {
501 return new FileNode(f,
false);
505 public FileNode visit(Directory f) {
506 return new FileNode(f,
false);
510 public FileNode visit(VirtualDirectory f) {
511 return new FileNode(f,
false);
515 protected AbstractNode defaultVisit(Content di) {
516 throw new UnsupportedOperationException(
"Not supported for this type of Displayable Item: " + di.toString());
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
public< T > T accept(AutopsyItemVisitor< T > visitor)
void update(Observable o, Object arg)
static volatile boolean maxFilesDialogShown
static final Set< Case.Events > CASE_EVENTS_OF_INTEREST
final long datasourceObjId
T visit(DataSourcesNode in)
final DeletedContent.DeletedContentFilter filter
void removeIngestJobEventListener(final PropertyChangeListener listener)
DeletedContentFilter(int id, String name, String displayName)
boolean createKeys(List< DeletedContent.DeletedContentFilter > list)
SleuthkitCase getSleuthkitCase()
void addIngestJobEventListener(final PropertyChangeListener listener)
final PropertyChangeListener pcl
final long datasourceObjId
void addIngestModuleEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Node createNodeForKey(DeletedContent.DeletedContentFilter key)
DeletedContent(SleuthkitCase skCase)
DeletedContentsChildren(SleuthkitCase skCase, long dsObjId)
final long datasourceObjId
void update(Observable o, Object arg)
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
DeletedContent(SleuthkitCase skCase, long dsObjId)