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.List;
26 import java.util.Observable;
27 import java.util.Observer;
28 import java.util.logging.Level;
29 import javax.swing.JOptionPane;
30 import javax.swing.SwingUtilities;
31 import org.openide.nodes.AbstractNode;
32 import org.openide.nodes.ChildFactory;
33 import org.openide.nodes.Children;
34 import org.openide.nodes.Node;
35 import org.openide.nodes.Sheet;
36 import org.openide.util.NbBundle;
37 import org.openide.util.lookup.Lookups;
38 import org.openide.windows.WindowManager;
64 NbBundle.getMessage(
DeletedContent.class,
"DeletedContent.fsDelFilter.text")),
67 NbBundle.getMessage(
DeletedContent.class,
"DeletedContent.allDelFilter.text"));
75 this.displayName = displayName;
88 return this.displayName;
92 public <T> T
accept(AutopsyItemVisitor<T> v) {
102 public <T> T accept(AutopsyItemVisitor<T> v) {
103 return v.visit(
this);
113 "DeletedContent.deletedContentsNode.name");
120 super.setDisplayName(NAME);
122 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file-icon-deleted.png");
132 return v.
visit(
this);
137 Sheet s = super.createSheet();
138 Sheet.Set ss = s.get(Sheet.PROPERTIES);
140 ss = Sheet.createPropertiesSet();
144 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"DeletedContent.createSheet.name.name"),
145 NbBundle.getMessage(
this.getClass(),
"DeletedContent.createSheet.name.displayName"),
146 NbBundle.getMessage(
this.getClass(),
"DeletedContent.createSheet.name.desc"),
183 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
185 public void propertyChange(PropertyChangeEvent evt) {
186 String eventType = evt.getPropertyName();
199 if (evt.getNewValue() == null) {
202 maxFilesDialogShown =
false;
215 protected boolean createKeys(List<DeletedContent.DeletedContentFilter> list) {
233 super(Children.create(
new DeletedContentChildren(
filter, skCase, null),
true), Lookups.singleton(
filter.getDisplayName()));
239 super(Children.create(
new DeletedContentChildren(
filter, skCase, o),
true), Lookups.singleton(
filter.getDisplayName()));
242 o.addObserver(
new DeletedContentNodeObserver());
246 super.setName(
filter.getName());
248 String tooltip =
filter.getDisplayName();
249 this.setShortDescription(tooltip);
250 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file-icon-deleted.png");
257 public void update(Observable o, Object arg) {
264 final long count = DeletedContentChildren.calculateItems(skCase,
filter);
266 super.setDisplayName(
filter.getDisplayName() +
" (" + count +
")");
271 return v.
visit(
this);
276 Sheet s = super.createSheet();
277 Sheet.Set ss = s.get(Sheet.PROPERTIES);
279 ss = Sheet.createPropertiesSet();
284 NbBundle.getMessage(
this.getClass(),
"DeletedContent.createSheet.filterType.name"),
285 NbBundle.getMessage(
this.getClass(),
"DeletedContent.createSheet.filterType.displayName"),
286 NbBundle.getMessage(
this.getClass(),
"DeletedContent.createSheet.filterType.desc"),
287 filter.getDisplayName()));
298 static class DeletedContentChildren
extends ChildFactory.Detachable<AbstractFile> {
303 private static final int MAX_OBJECTS = 10001;
308 this.filter = filter;
312 private final Observer observer =
new DeletedContentChildrenObserver();
316 public void update(Observable o, Object arg) {
322 protected void addNotify() {
323 if (notifier != null) {
324 notifier.addObserver(observer);
329 protected void removeNotify() {
330 if (notifier != null) {
331 notifier.deleteObserver(observer);
337 protected boolean createKeys(List<AbstractFile> list) {
338 List<AbstractFile> queryList = runFsQuery();
339 if (queryList.size() == MAX_OBJECTS) {
340 queryList.remove(queryList.size() - 1);
343 if (maxFilesDialogShown ==
false) {
344 maxFilesDialogShown =
true;
345 SwingUtilities.invokeLater(
new Runnable() {
348 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(this.getClass(),
349 "DeletedContent.createKeys.maxObjects.msg",
355 list.addAll(queryList);
359 static private String makeQuery(
DeletedContent.DeletedContentFilter filter) {
362 case FS_DELETED_FILTER:
363 query =
"dir_flags = " + TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue()
364 +
" AND meta_flags != " + TskData.TSK_FS_META_FLAG_ENUM.ORPHAN.getValue()
365 +
" AND type = " + TskData.TSK_DB_FILES_TYPE_ENUM.FS.getFileType();
368 case ALL_DELETED_FILTER:
371 +
"(dir_flags = " + TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC.getValue()
373 +
"meta_flags = " + TskData.TSK_FS_META_FLAG_ENUM.ORPHAN.getValue()
375 +
" AND type = " + TskData.TSK_DB_FILES_TYPE_ENUM.FS.getFileType()
377 +
" OR type = " + TskData.TSK_DB_FILES_TYPE_ENUM.CARVED.getFileType()
388 logger.log(Level.SEVERE,
"Unsupported filter type to get deleted content: {0}", filter);
392 query +=
" LIMIT " + MAX_OBJECTS;
396 private List<AbstractFile> runFsQuery() {
397 List<AbstractFile> ret =
new ArrayList<>();
399 String query = makeQuery(filter);
402 }
catch (TskCoreException e) {
403 logger.log(Level.SEVERE,
"Error getting files for the deleted content view using: " + query, e);
415 static long calculateItems(SleuthkitCase sleuthkitCase,
DeletedContent.DeletedContentFilter filter) {
417 return sleuthkitCase.countFilesWhere(makeQuery(filter));
418 }
catch (TskCoreException ex) {
419 logger.log(Level.SEVERE,
"Error getting deleted files search view count", ex);
426 return key.accept(
new ContentVisitor.Default<AbstractNode>() {
427 public FileNode visit(AbstractFile f) {
428 return new FileNode(f, false);
431 public FileNode visit(FsContent f) {
432 return new FileNode(f,
false);
436 public FileNode visit(LayoutFile f) {
437 return new FileNode(f,
false);
441 public FileNode visit(File f) {
442 return new FileNode(f,
false);
446 public FileNode visit(Directory f) {
447 return new FileNode(f,
false);
451 protected AbstractNode defaultVisit(Content di) {
452 throw new UnsupportedOperationException(NbBundle.getMessage(
this.getClass(),
453 "DeletedContent.createNodeForKey.typeNotSupported.msg",
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
public< T > T accept(AutopsyItemVisitor< T > v)
void update(Observable o, Object arg)
T visit(DataSourcesNode in)
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
DeletedContentsChildren(SleuthkitCase skCase)
static synchronized void removePropertyChangeListener(PropertyChangeListener listener)
void addIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized void addPropertyChangeListener(PropertyChangeListener listener)
List< AbstractFile > findAllFilesWhere(String sqlWhereClause)
Node createNodeForKey(DeletedContent.DeletedContentFilter key)
DeletedContent(SleuthkitCase skCase)
static boolean maxFilesDialogShown
void update(Observable o, Object arg)
DeletedContent.DeletedContentFilter filter
static Logger getLogger(String name)