mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 01:07:42 +00:00
Moved childfactory into parent and made comment about a bug in the code
This commit is contained in:
parent
2e10254a2e
commit
6ab5fef8f8
@ -1,128 +0,0 @@
|
|||||||
/*
|
|
||||||
* Autopsy Forensic Browser
|
|
||||||
*
|
|
||||||
* Copyright 2011-2014 Basis Technology Corp.
|
|
||||||
* Contact: carrier <at> sleuthkit <dot> org
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.sleuthkit.autopsy.datamodel;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import org.openide.util.NbBundle;
|
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
|
||||||
import org.openide.nodes.AbstractNode;
|
|
||||||
import org.openide.nodes.ChildFactory;
|
|
||||||
import org.openide.nodes.Node;
|
|
||||||
import org.sleuthkit.autopsy.core.UserPreferences;
|
|
||||||
import org.sleuthkit.datamodel.Content;
|
|
||||||
import org.sleuthkit.datamodel.ContentVisitor;
|
|
||||||
import org.sleuthkit.datamodel.DerivedFile;
|
|
||||||
import org.sleuthkit.datamodel.Directory;
|
|
||||||
import org.sleuthkit.datamodel.File;
|
|
||||||
import org.sleuthkit.datamodel.LocalFile;
|
|
||||||
import org.sleuthkit.datamodel.LayoutFile;
|
|
||||||
import org.sleuthkit.datamodel.SleuthkitCase;
|
|
||||||
import org.sleuthkit.datamodel.TskCoreException;
|
|
||||||
import org.sleuthkit.datamodel.TskData;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Child node factory for a specific file type - does the database query.
|
|
||||||
*/
|
|
||||||
public class FileTypeChildren extends ChildFactory<Content> {
|
|
||||||
|
|
||||||
private SleuthkitCase skCase;
|
|
||||||
private FileTypeExtensionFilters.SearchFilterInterface filter;
|
|
||||||
private static final Logger logger = Logger.getLogger(FileTypeChildren.class.getName());
|
|
||||||
|
|
||||||
FileTypeChildren(FileTypeExtensionFilters.SearchFilterInterface filter, SleuthkitCase skCase) {
|
|
||||||
this.filter = filter;
|
|
||||||
this.skCase = skCase;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get children count without actually loading all nodes
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
long calculateItems() {
|
|
||||||
try {
|
|
||||||
return skCase.countFilesWhere(createQuery());
|
|
||||||
} catch (TskCoreException ex) {
|
|
||||||
logger.log(Level.SEVERE, "Error getting file search view count", ex); //NON-NLS
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean createKeys(List<Content> list) {
|
|
||||||
try {
|
|
||||||
list.addAll(skCase.findAllFilesWhere(createQuery()));
|
|
||||||
} catch (TskCoreException ex) {
|
|
||||||
logger.log(Level.SEVERE, "Couldn't get search results", ex); //NON-NLS
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String createQuery(){
|
|
||||||
StringBuilder query = new StringBuilder();
|
|
||||||
query.append("(dir_type = ").append(TskData.TSK_FS_NAME_TYPE_ENUM.REG.getValue()).append(")"); //NON-NLS
|
|
||||||
if (UserPreferences.hideKnownFilesInViewsTree()) {
|
|
||||||
query.append(" AND (known IS NULL OR known != ").append(TskData.FileKnown.KNOWN.getFileKnownValue()).append(")"); //NON-NLS
|
|
||||||
}
|
|
||||||
query.append(" AND (0"); //NON-NLS
|
|
||||||
for(String s : filter.getFilter()){
|
|
||||||
query.append(" OR name LIKE '%").append(s).append("'"); //NON-NLS
|
|
||||||
}
|
|
||||||
query.append(')');
|
|
||||||
return query.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Node createNodeForKey(Content key) {
|
|
||||||
return key.accept(new ContentVisitor.Default<AbstractNode>() {
|
|
||||||
@Override
|
|
||||||
public FileNode visit(File f) {
|
|
||||||
return new FileNode(f, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DirectoryNode visit(Directory d) {
|
|
||||||
return new DirectoryNode(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LayoutFileNode visit(LayoutFile lf) {
|
|
||||||
return new LayoutFileNode(lf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalFileNode visit(DerivedFile df) {
|
|
||||||
return new LocalFileNode(df);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalFileNode visit(LocalFile lf) {
|
|
||||||
return new LocalFileNode(lf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected AbstractNode defaultVisit(Content di) {
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
NbBundle.getMessage(this.getClass(),
|
|
||||||
"FileTypeChildren.exception.notSupported.msg",
|
|
||||||
di.toString()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,11 +18,28 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.datamodel;
|
package org.sleuthkit.autopsy.datamodel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import org.openide.nodes.AbstractNode;
|
||||||
|
import org.openide.nodes.ChildFactory;
|
||||||
import org.openide.nodes.Children;
|
import org.openide.nodes.Children;
|
||||||
|
import org.openide.nodes.Node;
|
||||||
import org.openide.nodes.Sheet;
|
import org.openide.nodes.Sheet;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.openide.util.lookup.Lookups;
|
import org.openide.util.lookup.Lookups;
|
||||||
|
import org.sleuthkit.autopsy.core.UserPreferences;
|
||||||
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
|
import org.sleuthkit.datamodel.AbstractFile;
|
||||||
|
import org.sleuthkit.datamodel.Content;
|
||||||
|
import org.sleuthkit.datamodel.ContentVisitor;
|
||||||
|
import org.sleuthkit.datamodel.DerivedFile;
|
||||||
|
import org.sleuthkit.datamodel.Directory;
|
||||||
|
import org.sleuthkit.datamodel.File;
|
||||||
|
import org.sleuthkit.datamodel.LayoutFile;
|
||||||
|
import org.sleuthkit.datamodel.LocalFile;
|
||||||
import org.sleuthkit.datamodel.SleuthkitCase;
|
import org.sleuthkit.datamodel.SleuthkitCase;
|
||||||
|
import org.sleuthkit.datamodel.TskCoreException;
|
||||||
|
import org.sleuthkit.datamodel.TskData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node for a specific file type / extension
|
* Node for a specific file type / extension
|
||||||
@ -33,18 +50,24 @@ public class FileTypeNode extends DisplayableItemNode {
|
|||||||
SleuthkitCase skCase;
|
SleuthkitCase skCase;
|
||||||
|
|
||||||
FileTypeNode(FileTypeExtensionFilters.SearchFilterInterface filter, SleuthkitCase skCase) {
|
FileTypeNode(FileTypeExtensionFilters.SearchFilterInterface filter, SleuthkitCase skCase) {
|
||||||
super(Children.create(new FileTypeChildren(filter, skCase), true), Lookups.singleton(filter.getDisplayName()));
|
super(Children.create(new FileTypeChildFactory(filter, skCase), true), Lookups.singleton(filter.getDisplayName()));
|
||||||
|
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
this.skCase = skCase;
|
this.skCase = skCase;
|
||||||
|
|
||||||
super.setName(filter.getName());
|
super.setName(filter.getName());
|
||||||
|
|
||||||
|
/* There is a bug in the below code. The count becomes inaccurate when ZIP files
|
||||||
|
* blow up and when a 2nd data source is added. I think we need to change the overall
|
||||||
|
* design of this and have a singleton class (or some other place) that will store
|
||||||
|
* the results and each level can either ask it for the count or specific ids and
|
||||||
|
* it would be responsible for listening for case events and data events.
|
||||||
|
*/
|
||||||
//get count of children without preloading all children nodes
|
//get count of children without preloading all children nodes
|
||||||
final long count = new FileTypeChildren(filter, skCase).calculateItems();
|
final long count = new FileTypeChildFactory(filter, skCase).calculateItems();
|
||||||
//final long count = getChildren().getNodesCount(true);
|
//final long count = getChildren().getNodesCount(true);
|
||||||
|
|
||||||
super.setDisplayName(filter.getDisplayName() + " (" + count + ")");
|
super.setDisplayName(filter.getDisplayName() + " (" + count + ")");
|
||||||
|
|
||||||
this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/file-filter-icon.png"); //NON-NLS
|
this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/file-filter-icon.png"); //NON-NLS
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,4 +106,92 @@ public class FileTypeNode extends DisplayableItemNode {
|
|||||||
public boolean isLeafTypeNode() {
|
public boolean isLeafTypeNode() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Child node factory for a specific file type - does the database query.
|
||||||
|
*/
|
||||||
|
public static class FileTypeChildFactory extends ChildFactory<Content> {
|
||||||
|
private final SleuthkitCase skCase;
|
||||||
|
private final FileTypeExtensionFilters.SearchFilterInterface filter;
|
||||||
|
private final Logger logger = Logger.getLogger(FileTypeChildFactory.class.getName());
|
||||||
|
|
||||||
|
FileTypeChildFactory(FileTypeExtensionFilters.SearchFilterInterface filter, SleuthkitCase skCase) {
|
||||||
|
super();
|
||||||
|
this.filter = filter;
|
||||||
|
this.skCase = skCase;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get children count without actually loading all nodes
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
long calculateItems() {
|
||||||
|
try {
|
||||||
|
return skCase.countFilesWhere(createQuery());
|
||||||
|
} catch (TskCoreException ex) {
|
||||||
|
logger.log(Level.SEVERE, "Error getting file search view count", ex); //NON-NLS
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean createKeys(List<Content> list) {
|
||||||
|
try {
|
||||||
|
List<AbstractFile> files = skCase.findAllFilesWhere(createQuery());
|
||||||
|
list.addAll(files);
|
||||||
|
} catch (TskCoreException ex) {
|
||||||
|
logger.log(Level.SEVERE, "Couldn't get search results", ex); //NON-NLS
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createQuery() {
|
||||||
|
StringBuilder query = new StringBuilder();
|
||||||
|
query.append("(dir_type = ").append(TskData.TSK_FS_NAME_TYPE_ENUM.REG.getValue()).append(")"); //NON-NLS
|
||||||
|
if (UserPreferences.hideKnownFilesInViewsTree()) {
|
||||||
|
query.append(" AND (known IS NULL OR known != ").append(TskData.FileKnown.KNOWN.getFileKnownValue()).append(")"); //NON-NLS
|
||||||
|
}
|
||||||
|
query.append(" AND (0"); //NON-NLS
|
||||||
|
for (String s : filter.getFilter()) {
|
||||||
|
query.append(" OR name LIKE '%").append(s).append("'"); //NON-NLS
|
||||||
|
}
|
||||||
|
query.append(')');
|
||||||
|
return query.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node createNodeForKey(Content key) {
|
||||||
|
return key.accept(new ContentVisitor.Default<AbstractNode>() {
|
||||||
|
@Override
|
||||||
|
public FileNode visit(File f) {
|
||||||
|
return new FileNode(f, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DirectoryNode visit(Directory d) {
|
||||||
|
return new DirectoryNode(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LayoutFileNode visit(LayoutFile lf) {
|
||||||
|
return new LayoutFileNode(lf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalFileNode visit(DerivedFile df) {
|
||||||
|
return new LocalFileNode(df);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalFileNode visit(LocalFile lf) {
|
||||||
|
return new LocalFileNode(lf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AbstractNode defaultVisit(Content di) {
|
||||||
|
throw new UnsupportedOperationException(NbBundle.getMessage(this.getClass(), "FileTypeChildren.exception.notSupported.msg", di.toString()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,75 +0,0 @@
|
|||||||
/*
|
|
||||||
* Autopsy Forensic Browser
|
|
||||||
*
|
|
||||||
* Copyright 2011 Basis Technology Corp.
|
|
||||||
* Contact: carrier <at> sleuthkit <dot> org
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.sleuthkit.autopsy.datamodel;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import org.openide.nodes.ChildFactory;
|
|
||||||
import org.openide.nodes.Node;
|
|
||||||
import org.sleuthkit.autopsy.datamodel.FileTypeExtensionFilters.RootFilter;
|
|
||||||
import org.sleuthkit.datamodel.SleuthkitCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class FileTypesChildren extends ChildFactory<FileTypeExtensionFilters.SearchFilterInterface> {
|
|
||||||
|
|
||||||
private SleuthkitCase skCase;
|
|
||||||
private FileTypeExtensionFilters.RootFilter filter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param skCase
|
|
||||||
* @param filter Is null for root node
|
|
||||||
*/
|
|
||||||
public FileTypesChildren(SleuthkitCase skCase, FileTypeExtensionFilters.RootFilter filter) {
|
|
||||||
this.skCase = skCase;
|
|
||||||
this.filter = filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean createKeys(List<FileTypeExtensionFilters.SearchFilterInterface> list) {
|
|
||||||
// root node
|
|
||||||
if (filter == null) {
|
|
||||||
list.addAll(Arrays.asList(RootFilter.values()));
|
|
||||||
}
|
|
||||||
// document and executable has another level of nodes
|
|
||||||
else if (filter.equals(RootFilter.TSK_DOCUMENT_FILTER) ){
|
|
||||||
list.addAll(Arrays.asList(FileTypeExtensionFilters.DocumentFilter.values()));
|
|
||||||
}
|
|
||||||
else if (filter.equals(RootFilter.TSK_EXECUTABLE_FILTER) ){
|
|
||||||
list.addAll(Arrays.asList(FileTypeExtensionFilters.ExecutableFilter.values()));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Node createNodeForKey(FileTypeExtensionFilters.SearchFilterInterface key){
|
|
||||||
// make new nodes for the sub-nodes
|
|
||||||
if(key.getName().equals(FileTypeExtensionFilters.RootFilter.TSK_DOCUMENT_FILTER.getName())){
|
|
||||||
return new FileTypesNode(skCase, FileTypeExtensionFilters.RootFilter.TSK_DOCUMENT_FILTER);
|
|
||||||
}
|
|
||||||
else if(key.getName().equals(FileTypeExtensionFilters.RootFilter.TSK_EXECUTABLE_FILTER.getName())){
|
|
||||||
return new FileTypesNode(skCase, FileTypeExtensionFilters.RootFilter.TSK_EXECUTABLE_FILTER);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return new FileTypeNode(key, skCase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,7 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.datamodel;
|
package org.sleuthkit.autopsy.datamodel;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import org.openide.nodes.ChildFactory;
|
||||||
import org.openide.nodes.Children;
|
import org.openide.nodes.Children;
|
||||||
|
import org.openide.nodes.Node;
|
||||||
import org.openide.nodes.Sheet;
|
import org.openide.nodes.Sheet;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.openide.util.lookup.Lookups;
|
import org.openide.util.lookup.Lookups;
|
||||||
@ -76,4 +80,51 @@ public class FileTypesNode extends DisplayableItemNode {
|
|||||||
getName()));
|
getName()));
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static class FileTypesChildren extends ChildFactory<FileTypeExtensionFilters.SearchFilterInterface> {
|
||||||
|
|
||||||
|
private SleuthkitCase skCase;
|
||||||
|
private FileTypeExtensionFilters.RootFilter filter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param skCase
|
||||||
|
* @param filter Is null for root node
|
||||||
|
*/
|
||||||
|
public FileTypesChildren(SleuthkitCase skCase, FileTypeExtensionFilters.RootFilter filter) {
|
||||||
|
super();
|
||||||
|
this.skCase = skCase;
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean createKeys(List<FileTypeExtensionFilters.SearchFilterInterface> list) {
|
||||||
|
// root node
|
||||||
|
if (filter == null) {
|
||||||
|
list.addAll(Arrays.asList(FileTypeExtensionFilters.RootFilter.values()));
|
||||||
|
}
|
||||||
|
// document and executable has another level of nodes
|
||||||
|
else if (filter.equals(FileTypeExtensionFilters.RootFilter.TSK_DOCUMENT_FILTER)) {
|
||||||
|
list.addAll(Arrays.asList(FileTypeExtensionFilters.DocumentFilter.values()));
|
||||||
|
} else if (filter.equals(FileTypeExtensionFilters.RootFilter.TSK_EXECUTABLE_FILTER)) {
|
||||||
|
list.addAll(Arrays.asList(FileTypeExtensionFilters.ExecutableFilter.values()));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node createNodeForKey(FileTypeExtensionFilters.SearchFilterInterface key) {
|
||||||
|
// make new nodes for the sub-nodes
|
||||||
|
if (key.getName().equals(FileTypeExtensionFilters.RootFilter.TSK_DOCUMENT_FILTER.getName())) {
|
||||||
|
return new FileTypesNode(skCase, FileTypeExtensionFilters.RootFilter.TSK_DOCUMENT_FILTER);
|
||||||
|
} else if (key.getName().equals(FileTypeExtensionFilters.RootFilter.TSK_EXECUTABLE_FILTER.getName())) {
|
||||||
|
return new FileTypesNode(skCase, FileTypeExtensionFilters.RootFilter.TSK_EXECUTABLE_FILTER);
|
||||||
|
} else {
|
||||||
|
return new FileTypeNode(key, skCase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user