diff --git a/.gitignore b/.gitignore index 659adb6a24..53f67fc0b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,6 @@ -/Case/build/ -/CoreComponentInterfaces/build/ -/DirectoryTree/build/ -/CoreComponents/build/ /dist/ /build/ -/DataModel/build/ -/MenuActions/build/ -/Logging/build/ -/FileSearch/build/ +/*/build/ */nbproject/private/* /nbproject/private/* /DataModel/release/modules/lib/libewf.dll diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java index c571a43787..e3b2a929b1 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java @@ -60,7 +60,6 @@ class AddImageWizardIterator implements WizardDescriptor.Iterator= 7.8, can use WizardDescriptor.PROP_*: jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // Sets steps names for a panel jc.putClientProperty("WizardPanel_contentData", steps); diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/Case.java b/Case/src/org/sleuthkit/autopsy/casemodule/Case.java index 6f169581bd..ebc3ae8a29 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -54,7 +54,7 @@ import org.sleuthkit.datamodel.SleuthkitJNI.CaseDbHandle.AddImageProcess; */ public class Case { // change the CTL_MainWindow_Title in Bundle.properties as well if you change this value - private static final String autopsyVer = "3.0.0b2"; // current version of autopsy. Changed it when the version is changed + private static final String autopsyVer = "3.0.0b2"; // current version of autopsy. Change it when the version is changed private static final String appName = "Autopsy " + autopsyVer; /** @@ -150,8 +150,7 @@ public class Case { currentCase = newCase; pcs.firePropertyChange(CASE_CURRENT_CASE, null, currentCase); - //TODO: This will fire off a bunch of stuff in CaseListener.propertyChange() - // that should probably be migrated into here + // TODO: This will fire off a bunch of stuff in CaseListener.propertyChange() that should probably be migrated into here pcs.firePropertyChange(CASE_NAME, "", currentCase.name); RecentCases.getInstance().addRecentCase(currentCase.name, currentCase.configFilePath); // update the recent cases diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java b/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java index 48ebfeb639..295a01cfc2 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java @@ -37,6 +37,7 @@ import org.sleuthkit.autopsy.logging.Log; */ @ServiceProvider(service = CaseOpenAction.class) public final class CaseOpenAction implements ActionListener { + private static final Logger logger = Logger.getLogger(CaseOpenAction.class.getName()); JFileChooser fc = new JFileChooser(); GeneralFilter autFilter = new GeneralFilter(new String[]{".aut"}, "AUTOPSY File (*.aut)", false); @@ -73,7 +74,7 @@ public final class CaseOpenAction implements ActionListener { StartupWindow.getInstance().close(); } catch (Exception ex) { // no need to show the error message to the user. - // TODO: But maybe put the error message in the log in the future. + logger.log(Level.INFO, "Error closing startup window.", ex); } try { Case.open(path); // open the case diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java b/Case/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java index 8e07f6fbd2..9475e1e547 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java @@ -119,7 +119,6 @@ public final class NewCaseWizardAction extends CallableSystemAction { if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent) c; // Sets step number of a component - // TODO if using org.openide.dialogs >= 7.8, can use WizardDescriptor.PROP_*: jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // Sets steps names for a panel jc.putClientProperty("WizardPanel_contentData", steps); diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/OpenRecentCasePanel.java b/Case/src/org/sleuthkit/autopsy/casemodule/OpenRecentCasePanel.java index 4f0fc0903f..eaefdf7b1f 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/OpenRecentCasePanel.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/OpenRecentCasePanel.java @@ -191,7 +191,6 @@ class OpenRecentCasePanel extends javax.swing.JPanel { }// //GEN-END:initComponents private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed - // TODO add your handling code here: }//GEN-LAST:event_cancelButtonActionPerformed diff --git a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContent.java b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContent.java index ee8e1c78fb..a277680ce4 100644 --- a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContent.java +++ b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContent.java @@ -19,8 +19,8 @@ package org.sleuthkit.autopsy.corecomponentinterfaces; -import org.sleuthkit.autopsy.datamodel.ContentNode; import java.beans.PropertyChangeListener; +import org.openide.nodes.Node; import org.openide.windows.TopComponent; /** @@ -34,7 +34,7 @@ public interface DataContent extends PropertyChangeListener { * Sets the "selected" node in this class * @param selectedNode node to use */ - public void setNode(ContentNode selectedNode); + public void setNode(Node selectedNode); /** * Get the TopComponent that is used when displaying this DataContent diff --git a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java index 3cd4fbcf98..4ee9f424cd 100644 --- a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java +++ b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataContentViewer.java @@ -19,19 +19,19 @@ package org.sleuthkit.autopsy.corecomponentinterfaces; -import org.sleuthkit.autopsy.datamodel.ContentNode; import java.awt.Component; +import org.openide.nodes.Node; /** * Responsible for a tab in the {@link DataContent} component. Displays the - * contents of the node passed to {@link setNode(ContentNode)}. + * contents of the node passed to {@link setNode(Node)}. */ public interface DataContentViewer { /** * Sets the node to display in the viewer. When called with null, must * clear all references to previous nodes. */ - public void setNode(ContentNode selectedNode); + public void setNode(Node selectedNode); /** * Returns the title of this viewer. @@ -43,8 +43,7 @@ public interface DataContentViewer { * instance returned by the Lookup as a factory for the instances that * are actually used.) */ - // TODO: extract the factory method out into a seperate interface that - // is used for the Lookup. + // TODO: extract the factory method out into a seperate interface that is used for the Lookup. public DataContentViewer getInstance(); /** @@ -62,6 +61,6 @@ public interface DataContentViewer { * @param node Node to check for support * @return True if supported, else false */ - public boolean isSupported(ContentNode node); + public boolean isSupported(Node node); } diff --git a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java index 743666df89..4d5bf473e3 100644 --- a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java +++ b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResult.java @@ -18,7 +18,7 @@ */ package org.sleuthkit.autopsy.corecomponentinterfaces; -import org.sleuthkit.autopsy.datamodel.ContentNode; +import org.openide.nodes.Node; /** * The interface for the "top right component" window. @@ -30,7 +30,7 @@ public interface DataResult { /** * Sets the "selected" node in this class. */ - public void setNode(ContentNode selectedNode); + public void setNode(Node selectedNode); /** * Gets the unique TopComponent ID of this class. @@ -45,6 +45,13 @@ public interface DataResult { * @param title the given title (String) */ public void setTitle(String title); + + + /** + * Sets the descriptive context text at the top of the pane. + * @param pathText Descriptive text giving context for the current results + */ + public void setPath(String pathText); /** * Checks if this is the main (uncloseable) instance of DataResult diff --git a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResultViewer.java b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResultViewer.java index 6ef241e890..0e9b73df79 100644 --- a/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResultViewer.java +++ b/CoreComponentInterfaces/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataResultViewer.java @@ -20,8 +20,8 @@ package org.sleuthkit.autopsy.corecomponentinterfaces; -import org.sleuthkit.autopsy.datamodel.ContentNode; import java.awt.Component; +import org.openide.nodes.Node; /** * Interface for the different viewers that show a set of nodes in the DataResult area. @@ -34,7 +34,7 @@ public interface DataResultViewer { * Set the root node to display in this viewer. When called with null, must * clear all references to previous nodes. */ - public void setNode(ContentNode selectedNode); + public void setNode(Node selectedNode); /** * Gets the title of this viewer diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/AbstractDataResultViewer.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/AbstractDataResultViewer.java index 2b85a8fb9e..b2771c413e 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/AbstractDataResultViewer.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/AbstractDataResultViewer.java @@ -6,7 +6,7 @@ * * 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 + * You may obt ain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -28,15 +28,16 @@ import org.openide.nodes.Node; import org.openide.util.Lookup; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContent; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; -import org.sleuthkit.autopsy.datamodel.ContentNode; /** * Holds commonalities between all DataResultViewers */ -public abstract class AbstractDataResultViewer extends JPanel implements DataResultViewer, Provider, PropertyChangeListener { +public abstract class AbstractDataResultViewer extends JPanel implements + DataResultViewer, Provider, PropertyChangeListener { /** - * Propagates changes in the current select node from the DataResultViewer to the DataContentTopComponent + * Propagates changes in the current select node from the DataResultViewer + * to the DataContentTopComponent * * @param evt */ @@ -53,14 +54,14 @@ public abstract class AbstractDataResultViewer extends JPanel implements DataRes // change the cursor to "waiting cursor" for this operation this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { - Node originalSelectedNode = this.getOriginalSelectedNode(); + Node selectedNode = this.getSelectedNode(); // DataContent is designed to return only the default viewer DataContent dataContent = Lookup.getDefault().lookup(DataContent.class); - if (originalSelectedNode != null && originalSelectedNode instanceof ContentNode) { + if (selectedNode != null) { // there's a new/changed node to display - ContentNode newSelectedNode = (ContentNode) originalSelectedNode; // get the selected Node on the table + Node newSelectedNode = selectedNode; // get the selected Node on the table // push the node to default "DataContent" dataContent.setNode(newSelectedNode); } else { @@ -74,9 +75,8 @@ public abstract class AbstractDataResultViewer extends JPanel implements DataRes } /** - * Gets the current node, stripping off any FilterNode that this class might - * have wrapped it in. + * Gets the current node selected node * @return */ - public abstract Node getOriginalSelectedNode(); + public abstract Node getSelectedNode(); } diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java index 080a354f73..9a50602602 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentTopComponent.java @@ -26,15 +26,17 @@ import java.util.logging.Logger; import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import org.openide.nodes.Node; import org.openide.util.NbBundle; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; import org.openide.util.Lookup; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContent; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; +import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.datamodel.DataConversion; +import org.sleuthkit.datamodel.Content; /** * Top component that organizes all of the data content viewers. Doing a lookup on this class will @@ -45,7 +47,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC // reference to the "default" TC that always stays open private static DataContentTopComponent defaultInstance; - private ContentNode currentNode; + private Node currentNode; // set to true if this is the TC that always stays open and is the default place to display content private boolean isDefault; // Different DataContentViewers @@ -78,7 +80,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC this.outdated = true; } - void setNode(ContentNode selectedNode) { + void setNode(Node selectedNode) { this.wrapped.setNode(selectedNode); this.outdated = false; } @@ -92,7 +94,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC return this.outdated; } - boolean isSupported(ContentNode node) { + boolean isSupported(Node node) { return this.wrapped.isSupported(node); } } @@ -104,7 +106,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC * @param givenNode node to view content of * @return newly undocked instance */ - public static DataContentTopComponent createUndocked(String filePath, ContentNode givenNode) { + public static DataContentTopComponent createUndocked(String filePath, Node givenNode) { DataContentTopComponent dctc = new DataContentTopComponent(false, filePath); dctc.componentOpened(); @@ -219,16 +221,24 @@ public final class DataContentTopComponent extends TopComponent implements DataC } @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { // change the cursor to "waiting cursor" for this operation this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { + + + String defaultName = NbBundle.getMessage(DataContentTopComponent.class, "CTL_DataContentTopComponent"); // set the file path if (selectedNode == null) { - setName(NbBundle.getMessage(DataContentTopComponent.class, "CTL_DataContentTopComponent")); + setName(defaultName); } else { - String path = DataConversion.getformattedPath(selectedNode.getDisplayPath(), 0); - setName(path); + Content content = selectedNode.getLookup().lookup(Content.class); + if (content != null) { + String path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(selectedNode.getLookup().lookup(Content.class)), 0); + setName(path); + } else { + setName(defaultName); + } } currentNode = selectedNode; @@ -281,7 +291,7 @@ public final class DataContentTopComponent extends TopComponent implements DataC * * @param selectedNode the selected content Node */ - public void resetTabs(ContentNode selectedNode) { + public void resetTabs(Node selectedNode) { int totalTabs = dataContentTabbedPane.getTabCount(); diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java index c8995a7cfb..40c5549a2c 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerHex.java @@ -23,8 +23,8 @@ import java.awt.Cursor; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JTextPane; +import org.openide.nodes.Node; import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; import org.sleuthkit.autopsy.datamodel.DataConversion; import org.sleuthkit.datamodel.Content; @@ -272,12 +272,16 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont } @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { if (selectedNode != null) { - this.setDataView(selectedNode.getContent(), 0, false); - } else { - this.setDataView(null, 0, true); + Content content = (selectedNode).getLookup().lookup(Content.class); + if (content != null) { + this.setDataView(content, 0, false); + return; + } } + + this.setDataView(null, 0, true); } @Override @@ -317,7 +321,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont } @Override - public boolean isSupported(ContentNode node) { + public boolean isSupported(Node node) { return true; } diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java index 5defaf15ef..3a7aeaddc4 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerPicture.java @@ -29,8 +29,8 @@ import javax.imageio.ImageIO; import javax.swing.JPanel; import org.openide.nodes.Node; import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; +import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.TskException; /** @@ -83,14 +83,16 @@ public class DataContentViewerPicture extends javax.swing.JPanel implements Data // End of variables declaration//GEN-END:variables @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { // change the cursor to "waiting cursor" for this operation this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { if (selectedNode != null) { try { // read the byte of the image file - byte[] dataSource = selectedNode.getContent().read(0, selectedNode.getContent().getSize()); + + Content content = selectedNode.getLookup().lookup(Content.class); + byte[] dataSource = content.read(0, content.getSize()); // create the input stream for the content InputStream is = new ByteArrayInputStream(dataSource); @@ -129,9 +131,7 @@ public class DataContentViewerPicture extends javax.swing.JPanel implements Data } @Override - public boolean isSupported(ContentNode cNode) { - Node node = (Node) cNode; - + public boolean isSupported(Node node) { if (node != null) { // Note: only supports JPG, GIF, and PNG for now return node.getDisplayName().toLowerCase().endsWith(".jpg") diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java index 990ac9ac36..29f4a6e69f 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataContentViewerString.java @@ -22,8 +22,8 @@ import java.awt.Component; import java.awt.Cursor; import java.util.logging.Level; import java.util.logging.Logger; +import org.openide.nodes.Node; import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataContentViewer; import org.sleuthkit.autopsy.datamodel.DataConversion; import org.sleuthkit.datamodel.Content; @@ -266,12 +266,16 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC } @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { if (selectedNode != null) { - this.setDataView(selectedNode.getContent(), 0, false); - } else { - this.setDataView(null, 0, true); + Content content = selectedNode.getLookup().lookup(Content.class); + if (content != null) { + this.setDataView(content, 0, false); + return; + } } + + this.setDataView(null, 0, true); } @Override @@ -296,7 +300,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC } @Override - public boolean isSupported(ContentNode node) { + public boolean isSupported(Node node) { return true; } diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java index f893aa22c6..b57fa60a43 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultTopComponent.java @@ -32,21 +32,19 @@ import org.openide.windows.TopComponent; import org.openide.nodes.Node; import org.openide.util.Lookup; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; -import org.sleuthkit.autopsy.datamodel.DataConversion; /** * Top component which displays something. */ public final class DataResultTopComponent extends TopComponent implements DataResult, ChangeListener { - private ContentNode rootNode; + private Node rootNode; private PropertyChangeSupport pcs = new PropertyChangeSupport(this); private boolean isMain; - /** path to the icon used by the component and its open action */ -// static final String ICON_PATH = "SET/PATH/TO/ICON/HERE"; + private static String PREFERRED_ID = "NodeTableTopComponent"; + /** * Name of property change fired when a file search result is closed */ @@ -75,7 +73,7 @@ public final class DataResultTopComponent extends TopComponent implements DataRe this.outdated = true; } - void setNode(ContentNode selectedNode) { + void setNode(Node selectedNode) { this.wrapped.setNode(selectedNode); this.outdated = false; } @@ -112,8 +110,8 @@ public final class DataResultTopComponent extends TopComponent implements DataRe newDataResult.open(); // open it first so the component can be initialized // set the tree table view - newDataResult.setNode((ContentNode) givenNode); - newDataResult.directoryTablePath.setText(pathText); + newDataResult.setNode(givenNode); + newDataResult.setPath(pathText); return newDataResult; } @@ -283,21 +281,16 @@ public final class DataResultTopComponent extends TopComponent implements DataRe } @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { this.rootNode = selectedNode; - String path = ""; if (selectedNode != null) { - path = DataConversion.getformattedPath(selectedNode.getDisplayPath(), 0); - - int childrenCount = ((Node) selectedNode).getChildren().getNodesCount(true); + int childrenCount = selectedNode.getChildren().getNodesCount(true); this.numberMatchLabel.setText(Integer.toString(childrenCount)); } this.numberMatchLabel.setVisible(true); this.matchLabel.setVisible(true); - - this.directoryTablePath.setText(path); // set the node path - + resetTabs(selectedNode); // set the display on the current active tab @@ -312,6 +305,11 @@ public final class DataResultTopComponent extends TopComponent implements DataRe public void setTitle(String title) { setName(title); } + + @Override + public void setPath(String pathText) { + this.directoryTablePath.setText(pathText); + } @Override public boolean isMain() { @@ -349,7 +347,7 @@ public final class DataResultTopComponent extends TopComponent implements DataRe * * @param selectedNode the selected content Node */ - public void resetTabs(ContentNode selectedNode) { + public void resetTabs(Node selectedNode) { for (UpdateWrapper drv : this.viewers) { drv.resetComponent(); diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java index 834e2fea30..bedf96df7c 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerTable.java @@ -22,7 +22,7 @@ import java.awt.Component; import java.awt.Cursor; import java.awt.FontMetrics; import java.io.IOException; -import java.sql.SQLException; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -33,13 +33,11 @@ import org.openide.explorer.view.OutlineView; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; +import org.openide.nodes.Node.Property; import org.openide.nodes.Node.PropertySet; import org.openide.nodes.Sheet; import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; -// TODO We should not have anything specific to Image in here... -import org.sleuthkit.datamodel.Image; /** * DataResult sortable table viewer @@ -49,7 +47,6 @@ public class DataResultViewerTable extends AbstractDataResultViewer { private transient ExplorerManager em = new ExplorerManager(); private String firstColumnLabel = "Name"; - private boolean isImageNode; /** Creates new form DataResultViewerTable */ public DataResultViewerTable() { @@ -59,11 +56,10 @@ public class DataResultViewerTable extends AbstractDataResultViewer { // only allow one item to be selected at a time ov.getOutline().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - + // don't show the root node ov.getOutline().setRootVisible(false); - this.isImageNode = false; this.em.addPropertyChangeListener(this); } @@ -98,13 +94,6 @@ public class DataResultViewerTable extends AbstractDataResultViewer { }// //GEN-END:initComponents private void tableScrollPanelComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_tableScrollPanelComponentResized - if (this.tableScrollPanel.getWidth() < 700 && isImageNode) { - ((OutlineView) this.tableScrollPanel).getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - } else { - if (isImageNode) { - ((OutlineView) this.tableScrollPanel).getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); - } - } }//GEN-LAST:event_tableScrollPanelComponentResized // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane tableScrollPanel; @@ -116,14 +105,11 @@ public class DataResultViewerTable extends AbstractDataResultViewer { } @Override - public Node getOriginalSelectedNode() { + public Node getSelectedNode() { Node result = null; Node[] selectedNodes = this.getExplorerManager().getSelectedNodes(); if (selectedNodes.length > 0) { result = selectedNodes[0]; - if (result != null && result instanceof TableFilterNode) { - result = ((TableFilterNode) result).getOriginal(); - } } return result; } @@ -150,7 +136,7 @@ public class DataResultViewerTable extends AbstractDataResultViewer { } @Override - public void setNode(ContentNode selectedNode) { + public void setNode(Node selectedNode) { // change the cursor to "waiting cursor" for this operation this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { @@ -158,17 +144,15 @@ public class DataResultViewerTable extends AbstractDataResultViewer { if (selectedNode != null) { - hasChildren = ((Node) selectedNode).getChildren().getNodesCount() > 0; + hasChildren = selectedNode.getChildren().getNodesCount() > 0; } // if there's no selection node, do nothing if (hasChildren) { - Node root = (Node) selectedNode; + Node root = selectedNode; - if (root instanceof TableFilterNode) { - root = ((TableFilterNode) root).getOriginal(); - } else { + if (!(root instanceof TableFilterNode)) { root = new TableFilterNode(root, true); } @@ -176,7 +160,7 @@ public class DataResultViewerTable extends AbstractDataResultViewer { OutlineView ov = ((OutlineView) this.tableScrollPanel); - List tempProps = new ArrayList(Arrays.asList(getChildPropertyHeaders((Node) selectedNode))); + List tempProps = new ArrayList(Arrays.asList(getChildPropertyHeaders(selectedNode))); tempProps.remove(0); @@ -211,53 +195,43 @@ public class DataResultViewerTable extends AbstractDataResultViewer { // show the horizontal scroll panel and show all the content & header - if (!(selectedNode.getContent() instanceof Image)) { - this.isImageNode = false; - int totalColumns = props.length; - //int scrollWidth = ttv.getWidth(); - int scrollWidth = ov.getWidth(); - int minWidth = scrollWidth / totalColumns; - int margin = 4; - int startColumn = 1; - ov.getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + int totalColumns = props.length; - // get the fontmetrics - //FontMetrics metrics = ttv.getGraphics().getFontMetrics(); - FontMetrics metrics = ov.getGraphics().getFontMetrics(); + //int scrollWidth = ttv.getWidth(); + int scrollWidth = ov.getWidth(); + int minWidth = scrollWidth / totalColumns; + int margin = 4; + int startColumn = 1; + ov.getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - // get first 100 rows values for the table - Object[][] content = null; - try { - content = selectedNode.getRowValues(100); - } catch (SQLException ex) { - // TODO: potential exception is being ignored (see below), should be handled + // get the fontmetrics + //FontMetrics metrics = ttv.getGraphics().getFontMetrics(); + FontMetrics metrics = ov.getGraphics().getFontMetrics(); + + // get first 100 rows values for the table + Object[][] content = null; + content = getRowValues(selectedNode, 100); + + + if (content != null) { + // for the "Name" column + int nodeColWidth = getMaxColumnWidth(0, metrics, margin, 40, firstColumnLabel, content); // Note: 40 is the width of the icon + node lines. Change this value if those values change! + ov.getOutline().getColumnModel().getColumn(0).setPreferredWidth(nodeColWidth); + + // get the max for each other column + for (int colIndex = startColumn; colIndex < totalColumns; colIndex++) { + int colWidth = getMaxColumnWidth(colIndex, metrics, margin, 8, props, content); + ov.getOutline().getColumnModel().getColumn(colIndex).setPreferredWidth(colWidth); } + } - - if (content != null) { - // for the "Name" column - int nodeColWidth = getMaxColumnWidth(0, metrics, margin, 40, firstColumnLabel, content); // Note: 40 is the width of the icon + node lines. Change this value if those values change! - ov.getOutline().getColumnModel().getColumn(0).setPreferredWidth(nodeColWidth); - - // get the max for each other column - for (int colIndex = startColumn; colIndex < totalColumns; colIndex++) { - int colWidth = getMaxColumnWidth(colIndex, metrics, margin, 8, props, content); - ov.getOutline().getColumnModel().getColumn(colIndex).setPreferredWidth(colWidth); - } - } - - // if there's no content just auto resize all columns - if (!(content.length > 0)) { - // turn on the auto resize - ov.getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); - } - } else { - this.isImageNode = true; - // turn on the auto resize for image result - ov.getOutline().getColumnModel().getColumn(0).setPreferredWidth(175); + // if there's no content just auto resize all columns + if (!(content.length > 0)) { + // turn on the auto resize ov.getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); } + } else { Node emptyNode = new AbstractNode(Children.LEAF); em.setRootContext(emptyNode); // make empty node @@ -268,6 +242,32 @@ public class DataResultViewerTable extends AbstractDataResultViewer { this.setCursor(null); } } + + + private static Object[][] getRowValues(Node node, int rows) { + // how many rows are we returning + int maxRows = Math.min(rows, node.getChildren().getNodesCount()); + + Object[][] objs = new Object[maxRows][]; + + for (int i = 0; i < maxRows; i++) { + PropertySet[] props = node.getChildren().getNodeAt(i).getPropertySets(); + Property[] property = props[0].getProperties(); + objs[i] = new Object[property.length]; + + + for (int j = 0; j < property.length; j++) { + try { + objs[i][j] = property[j].getValue(); + } catch (IllegalAccessException ignore) { + objs[i][j] = "n/a"; + } catch (InvocationTargetException ignore) { + objs[i][j] = "n/a"; + } + } + } + return objs; + } @Override public String getTitle() { diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java index c0fdc0ea6b..b9a1d156ca 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/DataResultViewerThumbnail.java @@ -29,7 +29,6 @@ import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; import org.openide.util.lookup.ServiceProvider; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponentinterfaces.DataResultViewer; /** @@ -82,34 +81,23 @@ public class DataResultViewerThumbnail extends AbstractDataResultViewer { } @Override - public Node getOriginalSelectedNode() { + public Node getSelectedNode() { Node result = null; Node[] selectedNodes = this.getExplorerManager().getSelectedNodes(); if (selectedNodes.length > 0) { result = selectedNodes[0]; - if (result != null && result instanceof ThumbnailViewNode) { - result = ((ThumbnailViewNode) result).getOriginal(); - } } return result; } @Override - public void setNode(ContentNode givenNode) { + public void setNode(Node givenNode) { // change the cursor to "waiting cursor" for this operation this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { if (givenNode != null) { - Node root = (Node) givenNode; - - if (root instanceof ThumbnailViewNode) { - root = ((ThumbnailViewNode) root).getOriginal(); - } else { - Node temp = new AbstractNode(new ThumbnailViewChildren((ContentNode) root)); - root = temp; - } - + Node root = new AbstractNode(new ThumbnailViewChildren(givenNode)); em.setRootContext(root); } else { Node emptyNode = new AbstractNode(Children.LEAF); diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ProductInformationPanel.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ProductInformationPanel.java index d29e1ea8f3..49a71ce744 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ProductInformationPanel.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ProductInformationPanel.java @@ -170,7 +170,7 @@ private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:eve } catch (MalformedURLException ex) { //ignore } - url = null; // TODO add your handling code here: + url = null; }//GEN-LAST:event_jLabel1MouseClicked private void activateVerboseLogging(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_activateVerboseLogging diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/TableFilterNode.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/TableFilterNode.java index 33236fc791..4db898654d 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/TableFilterNode.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/TableFilterNode.java @@ -37,11 +37,6 @@ class TableFilterNode extends FilterNode { this.createChild = crChild; } - @Override - public Node getOriginal() { - return super.getOriginal(); - } - /** * Override the display name / header for the first (tree) column on the * "TreeTableView". diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java index 42916ee103..d06c7510d1 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewChildren.java @@ -20,31 +20,33 @@ package org.sleuthkit.autopsy.corecomponents; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; -import org.sleuthkit.autopsy.datamodel.ContentNode; +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.ContentVisitor; +import org.sleuthkit.datamodel.File; /** * Complementary class to ThumbnailViewNode */ class ThumbnailViewChildren extends FilterNode.Children { + + private static final IsSupportedContentVisitor isSupportedVisitor = new IsSupportedContentVisitor(); private int totalChildren; /** the constructor */ - ThumbnailViewChildren(ContentNode arg) { - super((Node) arg); + ThumbnailViewChildren(Node arg) { + super(arg); this.totalChildren = 1; } @Override protected Node copyNode(Node arg0) { - return new ThumbnailViewNode((ContentNode) arg0); + return new ThumbnailViewNode(arg0); } @Override protected Node[] createNodes(Node arg0) { - // filter out the FileNode and the "." and ".." directories - if (arg0 != null && //(arg0 instanceof FileNode && - isSupported(arg0)) { + if (arg0 != null && isSupported(arg0)) { totalChildren++; return new Node[]{this.copyNode(arg0)}; } else { @@ -58,7 +60,20 @@ class ThumbnailViewChildren extends FilterNode.Children { public static boolean isSupported(Node node) { if (node != null) { - String lowerName = node.getDisplayName().toLowerCase(); + Content content = node.getLookup().lookup(Content.class); + if (content != null) { + return content.accept(isSupportedVisitor); + } + } + return false; + } + + + private static class IsSupportedContentVisitor extends ContentVisitor.Default { + + @Override + public Boolean visit(File f) { + String lowerName = f.getName().toLowerCase(); // Note: only supports JPG, GIF, and PNG for now // TODO: replace giant OR with check if in list return lowerName.endsWith(".jpg") @@ -71,8 +86,11 @@ class ThumbnailViewChildren extends FilterNode.Children { //node.getName().toLowerCase().endsWith(".tiff") || //node.getName().toLowerCase().endsWith(".tga") || lowerName.endsWith(".png"); - } else { + } + + @Override + protected Boolean defaultVisit(Content cntnt) { return false; } - } + } } diff --git a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java index 304cdeea6c..c356ed3823 100644 --- a/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java +++ b/CoreComponents/src/org/sleuthkit/autopsy/corecomponents/ThumbnailViewNode.java @@ -30,8 +30,8 @@ import javax.swing.ImageIcon; import javax.swing.JFrame; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.logging.Log; +import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.TskException; /** @@ -40,20 +40,13 @@ import org.sleuthkit.datamodel.TskException; */ class ThumbnailViewNode extends FilterNode { - private ContentNode currentNode; - // for error handling private SoftReference iconCache; - private static Image defaultIcon = new ImageIcon("/org/sleuthkit/autopsy/images/file-icon.png").getImage(); + + private static final Image defaultIcon = new ImageIcon("/org/sleuthkit/autopsy/images/file-icon.png").getImage(); /** the constructor */ - ThumbnailViewNode(ContentNode arg) { - super((Node) arg, Children.LEAF); - this.currentNode = arg; - } - - @Override - public Node getOriginal() { - return super.getOriginal(); + ThumbnailViewNode(Node arg) { + super(arg, Children.LEAF); } @Override @@ -63,24 +56,30 @@ class ThumbnailViewNode extends FilterNode { if (iconCache != null) { icon = iconCache.get(); } - + if (icon == null) { - try { - System.out.println("generate"); - icon = generateIcon(); - iconCache = new SoftReference(icon); - } catch (TskException ex) { + Content content = this.getLookup().lookup(Content.class); + + if (content != null) { + try { + System.out.println("generate"); + icon = generateIcon(content); + } catch (TskException ex) { + icon = ThumbnailViewNode.defaultIcon; + } + } else { icon = ThumbnailViewNode.defaultIcon; } + + iconCache = new SoftReference(icon); } return icon; } - private Image generateIcon() throws TskException { - ContentNode temp = currentNode; - byte[] content = temp.read(0, temp.getContent().getSize()); - Image result = Toolkit.getDefaultToolkit().createImage(content); + static private Image generateIcon(Content content) throws TskException { + byte[] data = content.read(0, content.getSize()); + Image result = Toolkit.getDefaultToolkit().createImage(data); // scale the image MediaTracker mTracker = new MediaTracker(new JFrame()); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java index 6246f3402a..07c437892f 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentNode.java @@ -20,20 +20,10 @@ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; -import java.util.LinkedList; -import java.util.List; import org.openide.nodes.AbstractNode; import org.openide.util.lookup.Lookups; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.ContentVisitor; -import org.sleuthkit.datamodel.Directory; -import org.sleuthkit.datamodel.File; -import org.sleuthkit.datamodel.FileSystem; -import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.TskException; -import org.sleuthkit.datamodel.Volume; -import org.sleuthkit.datamodel.VolumeSystem; /** * Interface class that all Data nodes inherit from. @@ -53,7 +43,7 @@ abstract class AbstractContentNode extends AbstractNode imple AbstractContentNode(T content) { super(new ContentChildren(content), Lookups.singleton(content)); this.content = content; - super.setName(content.accept(systemName)); + super.setName(ContentUtils.getSystemName(content)); } @Override @@ -66,26 +56,6 @@ abstract class AbstractContentNode extends AbstractNode imple return super.getName(); } - /** - * Gets the ID of this node. - * - * @return ID the ID of this node - */ - public long getID() { - return content.getId(); - } - - /** - * Gets the row values for this node. The main purpose of this method is to - * get the 'x' number of the row values for this node to set the width of each - * column of the DataResult Table. Row values is the children and it's properties. - * - * @param rows the number of rows we want to show - * @return rowValues the row values for this node. - * @throws SQLException - */ - abstract public Object[][] getRowValues(int rows) throws SQLException; - /** * Reads the content of this node. * @@ -97,138 +67,4 @@ abstract class AbstractContentNode extends AbstractNode imple public byte[] read(long offset, long len) throws TskException { return content.read(offset, len); } - - /** - * Returns the content of this node. - * - * @return content the content of this node (can be image, volume, directory, or file) - */ - public Content getContent() { - return content; - } - - private static final ShortNameVisitor shortName = new ShortNameVisitor(); - - private static final GetPathVisitor getDisplayPath = new GetPathVisitor(shortName); - - /** - * Returns full path to this node. - * - * @return the path of this node - */ - public String[] getDisplayPath() { - return content.accept(getDisplayPath).toArray(new String[]{}); - } - - private static final SystemNameVisitor systemName = new SystemNameVisitor(); - - private static final GetPathVisitor getSystemPath = new GetPathVisitor(systemName); - - /** - * Returns full path to this node. - * - * @return the path of this node - */ - public String[] getSystemPath() { - return content.accept(getSystemPath).toArray(new String[]{}); - } - - private static class SystemNameVisitor extends ContentVisitor.Default { - SystemNameVisitor() {} - - @Override - protected String defaultVisit(Content cntnt) { - return cntnt.accept(shortName) + ":" + Long.toString(cntnt.getId()); - } - } - - private static class ShortNameVisitor extends ContentVisitor.Default { - ShortNameVisitor() {} - - @Override - protected String defaultVisit(Content cntnt) { - throw new UnsupportedOperationException("Can't get short name for given content type:" + cntnt.getClass()); - } - - @Override - public String visit(Directory dir) { - return DirectoryNode.nameForDirectory(dir); - } - - @Override - public String visit(File f) { - return FileNode.nameForFile(f); - } - - @Override - public String visit(Volume v) { - return VolumeNode.nameForVolume(v); - } - - @Override - public String visit(Image i) { - return ImageNode.nameForImage(i); - } - } - - private static class GetPathVisitor implements ContentVisitor> { - ContentVisitor toString; - - GetPathVisitor(ContentVisitor toString) { - this.toString = toString; - } - - @Override - public List visit(Directory dir) { - List path; - - if (dir.isRoot()) { - path = dir.getFileSystem().accept(this); - } else { - try { - path = dir.getParentDirectory().accept(this); - path.add(toString.visit(dir)); - } catch (TskException ex) { - throw new RuntimeException("Couldn't get directory path.", ex); - } - } - - return path; - } - - @Override - public List visit(File file) { - try { - List path = file.getParentDirectory().accept(this); - path.add(toString.visit(file)); - return path; - } catch (TskException ex) { - throw new RuntimeException("Couldn't get file path.", ex); - } - } - - @Override - public List visit(FileSystem fs) { - return fs.getParent().accept(this); - } - - @Override - public List visit(Image image) { - List path = new LinkedList(); - path.add(toString.visit(image)); - return path; - } - - @Override - public List visit(Volume volume) { - List path = volume.getParent().accept(this); - path.add(toString.visit(volume)); - return path; - } - - @Override - public List visit(VolumeSystem vs) { - return vs.getParent().accept(this); - } - } } diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java index 4ab314bb2b..0cd4d2bca5 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractFsContentNode.java @@ -51,7 +51,7 @@ abstract class AbstractFsContentNode extends AbstractConten // Note: this order matters for the search result, changed it if the order of property headers on the "KeywordSearchNode"changed ss.put(new NodeProperty(PROPERTY_NAME, "Name", "no description", content.getName())); - ss.put(new NodeProperty(PROPERTY_LOCATION, "Location", "no description", DataConversion.getformattedPath(this.getDisplayPath(), 0))); + ss.put(new NodeProperty(PROPERTY_LOCATION, "Location", "no description", DataConversion.getformattedPath(ContentUtils.getDisplayPath(content), 0))); ss.put(new NodeProperty("Modified Time", "Modified Time", "no description", content.getMtimeAsDate())); ss.put(new NodeProperty("Changed Time", "Changed Time", "no description", content.getCtimeAsDate())); ss.put(new NodeProperty("Access Time", "Access Time", "no description", content.getAtimeAsDate())); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java deleted file mode 100644 index 174f205ff2..0000000000 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentFilterNode.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011 Basis Technology Corp. - * Contact: carrier sleuthkit 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.sql.SQLException; -import org.openide.nodes.FilterNode; -import org.openide.nodes.Node; -import org.openide.util.Lookup; -import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.TskException; - -public class ContentFilterNode extends FilterNode implements ContentNode { - - public ContentFilterNode(ContentNode original) { - super((Node) original); - } - - public ContentFilterNode(ContentNode original, Children children) { - super((Node) original, children); - } - - public ContentFilterNode(ContentNode original, Children children, Lookup lookup) { - super((Node) original, children, lookup); - } - - - - @Override - public long getID() { - return ((ContentNode) super.getOriginal()).getID(); - } - - @Override - public Object[][] getRowValues(int rows) throws SQLException { - return ((ContentNode) super.getOriginal()).getRowValues(rows); - } - - @Override - public byte[] read(long offset, long len) throws TskException { - return ((ContentNode) super.getOriginal()).read(offset, len); - } - - @Override - public Content getContent() { - return ((ContentNode) super.getOriginal()).getContent(); - } - - @Override - public String[] getDisplayPath() { - return ((ContentNode) super.getOriginal()).getDisplayPath(); - } - - @Override - public String[] getSystemPath() { - return ((ContentNode) super.getOriginal()).getSystemPath(); - } - - @Override - public T accept(ContentNodeVisitor v) { - return ((ContentNode) super.getOriginal()).accept(v); - } -} diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java index b8d638a81d..d4a504a77e 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNode.java @@ -18,73 +18,12 @@ */ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; -import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.TskException; - /** * Interface class that all Data nodes inherit from. * Provides basic information such as ID, parent ID, etc. */ -public interface ContentNode { - /** - * Returns the programmatic name for this node. This is NOT the name to - * display to users, or the plain name of the Content object - use - * Node.getDisplayName() for that. - * - * @return name the programmatic name for this node - */ - public String getName(); - - /** - * Gets the ID of this node. - * - * @return ID the ID of this node - */ - public long getID(); - - /** - * Gets the row values for this node. The main purpose of this method is to - * get the 'x' number of the row values for this node to set the width of each - * column of the DataResult Table. Row values is the children and it's properties. - * - * @param rows the number of rows we want to show - * @return rowValues the row values for this node. - * @throws SQLException - */ - public Object[][] getRowValues(int rows) throws SQLException; - - /** - * Reads the content of this node. - * - * @param offset the starting offset - * @param len the length - * @return the bytes - * @throws TskException - */ - public byte[] read(long offset, long len) throws TskException; - - /** - * Returns the content of this node. - * - * @return content the content of this node (can be image, volume, directory, or file) - */ - public Content getContent(); - - /** - * Returns full path to this node. - * - * @return the path of this node - */ - public String[] getDisplayPath(); - - /** - * Returns full path to this node. - * - * @return the path of this node - */ - public String[] getSystemPath(); +interface ContentNode { /** * Visitor pattern support. @@ -93,5 +32,5 @@ public interface ContentNode { * @param v visitor * @return visitor return value */ - public T accept(ContentNodeVisitor v); + T accept(ContentNodeVisitor v); } diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNodeVisitor.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNodeVisitor.java index e31782487f..d95d92d817 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNodeVisitor.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentNodeVisitor.java @@ -22,7 +22,7 @@ package org.sleuthkit.autopsy.datamodel; * Interface for visitor pattern on ContentNodes * @param visit method return type */ -public interface ContentNodeVisitor { +interface ContentNodeVisitor { T visit(DirectoryNode dn); @@ -37,7 +37,7 @@ public interface ContentNodeVisitor { * specific visit types to not use the default behavior. * @param */ - static abstract public class Default implements ContentNodeVisitor { + static abstract class Default implements ContentNodeVisitor { /** * Default visit for all types diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java new file mode 100644 index 0000000000..9750d9489c --- /dev/null +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ContentUtils.java @@ -0,0 +1,323 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2011 Basis Technology Corp. + * Contact: carrier sleuthkit 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.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.ContentVisitor; +import org.sleuthkit.datamodel.Directory; +import org.sleuthkit.datamodel.File; +import org.sleuthkit.datamodel.FileSystem; +import org.sleuthkit.datamodel.FsContent; +import org.sleuthkit.datamodel.Image; +import org.sleuthkit.datamodel.TskException; +import org.sleuthkit.datamodel.Volume; +import org.sleuthkit.datamodel.VolumeSystem; + +/** + * Static class of utility methods for Content objects + */ +public final class ContentUtils { + + private final static Logger logger = Logger.getLogger(ContentUtils.class.getName()); + + // don't instantiate + private ContentUtils() { + throw new AssertionError(); + } + + private static final ShortNameVisitor shortName = new ShortNameVisitor(); + + private static final GetPathVisitor getDisplayPath = new GetPathVisitor(shortName); + + /** + * Returns full path to this node. + * + * @return the path of this node + */ + public static String[] getDisplayPath(Content content) { + return content.accept(getDisplayPath).toArray(new String[]{}); + } + + private static final SystemNameVisitor systemName = new SystemNameVisitor(); + + private static final GetPathVisitor getSystemPath = new GetPathVisitor(systemName); + + /** + * Returns full path to this node. + * + * @return the path of this node + */ + public static String[] getSystemPath(Content content) { + return content.accept(getSystemPath).toArray(new String[]{}); + } + + static String getSystemName(Content content) { + return content.accept(systemName); + } + + private static class SystemNameVisitor extends ContentVisitor.Default { + SystemNameVisitor() {} + + @Override + protected String defaultVisit(Content cntnt) { + return cntnt.accept(shortName) + ":" + Long.toString(cntnt.getId()); + } + } + + private static class ShortNameVisitor extends ContentVisitor.Default { + ShortNameVisitor() {} + + @Override + protected String defaultVisit(Content cntnt) { + throw new UnsupportedOperationException("Can't get short name for given content type:" + cntnt.getClass()); + } + + @Override + public String visit(Directory dir) { + return DirectoryNode.nameForDirectory(dir); + } + + @Override + public String visit(File f) { + return FileNode.nameForFile(f); + } + + @Override + public String visit(Volume v) { + return VolumeNode.nameForVolume(v); + } + + @Override + public String visit(Image i) { + return ImageNode.nameForImage(i); + } + } + + private static class GetPathVisitor implements ContentVisitor> { + ContentVisitor toString; + + GetPathVisitor(ContentVisitor toString) { + this.toString = toString; + } + + @Override + public List visit(Directory dir) { + List path; + + if (dir.isRoot()) { + path = dir.getFileSystem().accept(this); + } else { + try { + path = dir.getParentDirectory().accept(this); + path.add(toString.visit(dir)); + } catch (TskException ex) { + throw new RuntimeException("Couldn't get directory path.", ex); + } + } + + return path; + } + + @Override + public List visit(File file) { + try { + List path = file.getParentDirectory().accept(this); + path.add(toString.visit(file)); + return path; + } catch (TskException ex) { + throw new RuntimeException("Couldn't get file path.", ex); + } + } + + @Override + public List visit(FileSystem fs) { + return fs.getParent().accept(this); + } + + @Override + public List visit(Image image) { + List path = new LinkedList(); + path.add(toString.visit(image)); + return path; + } + + @Override + public List visit(Volume volume) { + List path = volume.getParent().accept(this); + path.add(toString.visit(volume)); + return path; + } + + @Override + public List visit(VolumeSystem vs) { + return vs.getParent().accept(this); + } + } + + + private static final int TO_FILE_BUFFER_SIZE = 8192; + + /** + * Reads all the data from any content object and writes it to a file. + * @param content Any content object. + * @param outputFile Will be created if it doesn't exist, and overwritten if + * it does + * @throws IOException + */ + public static void writeToFile(Content content, java.io.File outputFile) throws IOException { + + InputStream in = new ReadContentInputStream(content); + + boolean append = false; + FileOutputStream out = new FileOutputStream(outputFile, append); + + try { + byte[] buffer = new byte[TO_FILE_BUFFER_SIZE]; + int len = in.read(buffer); + while (len != -1) { + out.write(buffer, 0, len); + len = in.read(buffer); + } + } finally { + out.close(); + } + } + + /** + * Helper to ignore the '.' and '..' directories + */ + public static boolean isDotDirectory(Directory dir) { + String name = dir.getName(); + return name.equals(".") || name.equals(".."); + } + + + /** + * Extracts file/folder as given destination file, recursing into folders. + * Assumes there will be no collisions with existing directories/files, and + * that the directory to contain the destination file already exists. + */ + public static class ExtractFscContentVisitor extends ContentVisitor.Default { + + java.io.File dest; + + /** + * Make new extractor for a specific destination + * @param dest The file/folder visited will be extracted as this file + */ + public ExtractFscContentVisitor(java.io.File dest) { + this.dest = dest; + } + + /** + * Convenience method to make a new instance for given destination + * and extract given content + */ + public static void extract(Content cntnt, java.io.File dest) { + cntnt.accept(new ExtractFscContentVisitor(dest)); + } + + public Void visit(File f) { + try { + ContentUtils.writeToFile(f, dest); + } catch (IOException ex) { + logger.log(Level.SEVERE, + "Trouble extracting file to " + dest.getAbsolutePath(), + ex); + } + return null; + } + + @Override + public Void visit(Directory dir) { + + // don't extract . and .. directories + if (isDotDirectory(dir)) { + return null; + } + + dest.mkdir(); + + // member visitor to generate destination files for children + DestFileContentVisitor destFileCV = new DestFileContentVisitor(); + + try { + // recurse on children + for (Content child : dir.getChildren()) { + java.io.File childFile = child.accept(destFileCV); + ExtractFscContentVisitor childVisitor = + new ExtractFscContentVisitor(childFile); + child.accept(childVisitor); + } + } catch (TskException ex) { + logger.log(Level.SEVERE, + "Trouble fetching children to extract.", ex); + } + + return null; + } + + @Override + protected Void defaultVisit(Content cntnt) { + throw new UnsupportedOperationException("Can't extract a " + + cntnt.getClass().getSimpleName()); + } + + /** + * Helper visitor to get the destination file for a child Content object + */ + private class DestFileContentVisitor extends + ContentVisitor.Default { + + /** + * Get destination file by adding File/Directory name to the path + * of parent + */ + private java.io.File getFsContentDest(FsContent fsc) { + String path = dest.getAbsolutePath() + java.io.File.separator + + fsc.getName(); + return new java.io.File(path); + } + + @Override + public java.io.File visit(File f) { + return getFsContentDest(f); + } + + @Override + public java.io.File visit(Directory dir) { + return getFsContentDest(dir); + } + + @Override + protected java.io.File defaultVisit(Content cntnt) { + throw new UnsupportedOperationException("Can't get destination file for a " + + cntnt.getClass().getSimpleName()); + } + } + } +} diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java index 38d8622a0d..5c58b674a7 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/DirectoryNode.java @@ -66,40 +66,6 @@ public class DirectoryNode extends AbstractFsContentNode { return new Action[]{}; } - @Override - public Object[][] getRowValues(int rows) { - - // how many rows are we returning - int maxRows = rows; - if (this.getChildren().getNodesCount() < maxRows) { - maxRows = this.getChildren().getNodesCount(); - } - Object[][] objs = new Object[maxRows][]; - - for (int i = 0; i < maxRows; i++) { - PropertySet[] props = this.getChildren().getNodeAt(i).getPropertySets(); - Property[] property = props[0].getProperties(); - objs[i] = new Object[property.length - 1]; // - 1 because we don't want to show the location property - - // name property - try { - objs[i][0] = property[0].getValue(); - } catch (Exception ex) { - objs[i][0] = "n/a"; - } - - // the rest of the properties(not including the location property) - for (int j = 1; j < property.length - 1; j++) { - try { - objs[i][j] = property[j + 1].getValue(); - } catch (Exception ex) { - objs[i][j] = "n/a"; - } - } - } - return objs; - } - @Override public T accept(ContentNodeVisitor v) { return v.visit(this); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java index 0d7605d88c..fc255c2714 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/FileNode.java @@ -18,11 +18,8 @@ */ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; -import java.util.Arrays; import javax.swing.Action; import org.sleuthkit.datamodel.File; -import org.sleuthkit.datamodel.FsContent; import org.sleuthkit.datamodel.TskData; /** @@ -70,31 +67,6 @@ public class FileNode extends AbstractFsContentNode { return new Action[]{}; } - @Override - public Object[][] getRowValues(int rows) throws SQLException { - FsContent con = content; - Object[][] objs = new Object[1][16]; - Arrays.fill(objs, 0, 1, new Object[]{ - con.getName(), - con.getMtimeAsDate(), - con.getCtimeAsDate(), - con.getAtimeAsDate(), - con.getCrtimeAsDate(), - con.getSize(), - con.getDirFlagsAsString(), - con.getMetaFlagsAsString(), - con.getModeAsString(), - con.getUid(), - con.getGid(), - con.getMeta_addr(), - con.getAttr_type() + "-" + con.getAttr_id(), - con.getDirTypeAsString(), - con.getMetaTypeAsString(), - con.getKnown().getName() - }); - return objs; - } - @Override public T accept(ContentNodeVisitor v) { return v.visit(this); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ImageNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ImageNode.java index 9b5d85812c..8b8b0c9a71 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ImageNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ImageNode.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; import javax.swing.Action; import org.openide.nodes.Children; import org.openide.nodes.Sheet; @@ -52,33 +51,6 @@ public class ImageNode extends AbstractContentNode { this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/hard-drive-icon.jpg"); } - @Override - public Object[][] getRowValues(int rows) throws SQLException { - // how many rows are we returning - int maxRows = rows; - if (this.getChildren().getNodesCount() < maxRows) { - maxRows = this.getChildren().getNodesCount(); - } - Object[][] objs = new Object[maxRows][]; - - for (int i = 0; i < maxRows; i++) { - PropertySet[] props = this.getChildren().getNodeAt(i).getPropertySets(); - Property[] property = props[0].getProperties(); - objs[i] = new Object[property.length]; - - - // the rest of the properties(not including the location property) - for (int j = 0; j < property.length; j++) { - try { - objs[i][j] = property[j].getValue(); - } catch (Exception ex) { - objs[i][j] = "n/a"; - } - } - } - return objs; - } - @Override public Cookie getCookie(Class clazz) { Children ch = getChildren(); diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java new file mode 100644 index 0000000000..028cdedb48 --- /dev/null +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueNode.java @@ -0,0 +1,40 @@ + +package org.sleuthkit.autopsy.datamodel; + +import java.util.Map; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Sheet; + +public class KeyValueNode extends AbstractNode { + + KeyValueThing thing; + + public KeyValueNode(KeyValueThing thing, Children children) { + super(children); + this.setName(thing.getName()); + this.thing = thing; + } + + @Override + protected Sheet createSheet() { + Sheet s = super.createSheet(); + Sheet.Set ss = s.get(Sheet.PROPERTIES); + if (ss == null) { + ss = Sheet.createPropertiesSet(); + s.put(ss); + } + + // table view drops first column of properties under assumption + // that it contains the node's name + ss.put(new NodeProperty("Name", "Name", "n/a", thing.getName())); + + for (Map.Entry entry : thing.getMap().entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + ss.put(new NodeProperty(key, key, "n/a", value)); + } + + return s; + } +} diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueThing.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueThing.java new file mode 100644 index 0000000000..2c439db15f --- /dev/null +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/KeyValueThing.java @@ -0,0 +1,33 @@ +package org.sleuthkit.autopsy.datamodel; + +import java.util.Map; + +public class KeyValueThing { + Map map; + int id; + String name; + + /** + * + * @param map must iterate it keys and values in a consistent order + * (use of LinkedHashMap is recommended) + * @param id an arbitrary id representing the type of the thing + */ + public KeyValueThing(String name, Map map, int id) { + this.name = name; + this.map = map; + this.id = id; + } + + public int getId() { + return id; + } + + public Map getMap() { + return map; + } + + public String getName() { + return name; + } +} \ No newline at end of file diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ReadContentInputStream.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ReadContentInputStream.java new file mode 100644 index 0000000000..82ef86fb3d --- /dev/null +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ReadContentInputStream.java @@ -0,0 +1,90 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2011 Basis Technology Corp. + * Contact: carrier sleuthkit 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.io.IOException; +import java.io.InputStream; +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.TskException; + +/** + * InputStream to read bytes from a Content object's data + */ +class ReadContentInputStream extends InputStream { + + private long position; + private long length; + private Content content; + + ReadContentInputStream(Content content) { + this.content = content; + this.position = 0; + this.length = content.getSize(); + } + + @Override + public int read() throws IOException { + byte[] buff = new byte[1]; + return (read(buff) != -1) ? buff[0] : -1; + } + + @Override + public int read(byte[] b) throws IOException { + return read(b, 0, b.length); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + + // must return 0 for zero-length arrays + if (b.length == 0) { + return 0; + } + + // will get an error from TSK if we try to read an empty file + if (this.length == 0) { + return -1; + } + + if (position < length) { + // data remains to be read + + int lenToRead = (int) Math.min(len, length - position); + + try { + byte[] buff = content.read(position, lenToRead); + int lenRead = buff.length; + + if (lenRead == 0) { + // TSK could not read the whole file, ending partway + return -1; + } else { + System.arraycopy(buff, 0, b, off, lenRead); + position += lenRead; + return lenRead; + } + } catch (TskException ex) { + throw new IOException(ex); + } + } else { + // at end of file + return -1; + } + } +} \ No newline at end of file diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/VolumeNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/VolumeNode.java index c231d6d901..200ed8f1da 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/VolumeNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/VolumeNode.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; import javax.swing.Action; import org.openide.nodes.Sheet; import org.sleuthkit.datamodel.Volume; @@ -56,40 +55,6 @@ public class VolumeNode extends AbstractContentNode { this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/vol-icon.png"); } - @Override - public Object[][] getRowValues(int rows) throws SQLException { - - // how many rows are we returning - int maxRows = rows; - if (this.getChildren().getNodesCount() < maxRows) { - maxRows = this.getChildren().getNodesCount(); - } - Object[][] objs = new Object[maxRows][]; - - for (int i = 0; i < maxRows; i++) { - PropertySet[] props = this.getChildren().getNodeAt(i).getPropertySets(); - Property[] property = props[0].getProperties(); - objs[i] = new Object[property.length - 1]; // - 1 because we don't want to show the location property - - // name property - try { - objs[i][0] = property[0].getValue(); - } catch (Exception ex) { - objs[i][0] = "n/a"; - } - - // the rest of the properties(not including the location property) - for (int j = 1; j < property.length - 1; j++) { - try { - objs[i][j] = property[j + 1].getValue(); - } catch (Exception ex) { - objs[i][j] = "n/a"; - } - } - } - return objs; - } - /** * Right click action for volume node * diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ChangeViewAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ChangeViewAction.java index 6242d633bc..028c1e2e0b 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ChangeViewAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ChangeViewAction.java @@ -18,11 +18,11 @@ */ package org.sleuthkit.autopsy.directorytree; -import org.sleuthkit.autopsy.datamodel.ContentNode; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JMenu; import javax.swing.JMenuItem; +import org.openide.nodes.Node; import org.openide.util.actions.Presenter; import org.sleuthkit.autopsy.corecomponents.DataContentTopComponent; import org.sleuthkit.autopsy.corecomponents.DataContentViewerHex; @@ -37,10 +37,10 @@ import org.sleuthkit.autopsy.logging.Log; public class ChangeViewAction extends AbstractAction implements Presenter.Popup { private int type; // type 1 = hex view, 2 = string view - private ContentNode node; + private Node node; /** the constructor */ - public ChangeViewAction(String title, int viewType, ContentNode node) { + public ChangeViewAction(String title, int viewType, Node node) { super(title); this.type = viewType; this.node = node; diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterChildren.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterChildren.java index 128889a499..0179322bff 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterChildren.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterChildren.java @@ -18,6 +18,7 @@ */ package org.sleuthkit.autopsy.directorytree; +import org.openide.explorer.ExplorerManager; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; @@ -28,19 +29,17 @@ import org.openide.nodes.Node; * @author jantonius */ public class DataResultFilterChildren extends FilterNode.Children { + + ExplorerManager sourceEm; /** the constructor */ - public DataResultFilterChildren(Node arg) { + public DataResultFilterChildren(Node arg, ExplorerManager sourceEm) { super(arg); + this.sourceEm = sourceEm; } @Override protected Node copyNode(Node arg0) { - return new DataResultFilterNode(arg0); - } - - @Override - protected Node[] createNodes(Node arg0) { - return new Node[]{this.copyNode(arg0)}; + return new DataResultFilterNode(arg0, sourceEm); } } \ No newline at end of file diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java index d839be5bbb..34b0dbbeba 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DataResultFilterNode.java @@ -20,11 +20,9 @@ package org.sleuthkit.autopsy.directorytree; import java.awt.event.ActionEvent; import java.beans.PropertyVetoException; -import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import org.sleuthkit.autopsy.datamodel.ImageNode; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.datamodel.VolumeNode; import org.sleuthkit.autopsy.datamodel.FileNode; import org.sleuthkit.autopsy.datamodel.DirectoryNode; @@ -32,35 +30,32 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; -import javax.swing.JPanel; import org.openide.explorer.ExplorerManager; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; import org.openide.nodes.Sheet; -import org.sleuthkit.autopsy.datamodel.ContentNodeVisitor; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.TskException; +import org.sleuthkit.datamodel.ContentVisitor; +import org.sleuthkit.datamodel.Directory; +import org.sleuthkit.datamodel.File; +import org.sleuthkit.datamodel.Image; +import org.sleuthkit.datamodel.Volume; /** * This class wraps nodes as they are passed to the DataResult viewers. It * defines the actions that the node should have. */ -public class DataResultFilterNode extends FilterNode implements ContentNode { +public class DataResultFilterNode extends FilterNode{ + + private ExplorerManager sourceEm; + private final ContentVisitor> getActionsCV; - private Node currentNode; - // for error handling - private JPanel caller; - private String className = this.getClass().toString(); /** the constructor */ - public DataResultFilterNode(Node arg) { - super(arg, new DataResultFilterChildren(arg)); - this.currentNode = arg; - } - - @Override - public Node getOriginal() { - return super.getOriginal(); + public DataResultFilterNode(Node arg, ExplorerManager em) { + super(arg, new DataResultFilterChildren(arg, em)); + this.sourceEm = em; + getActionsCV = new GetActionsContentVisitor(); } /** @@ -68,39 +63,58 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { * table and the output view. * * @param popup - * @return actionss + * @return actions */ @Override public Action[] getActions(boolean popup) { List actions = new ArrayList(); + + actions.add(new NewWindowViewAction("View in New Window", getOriginal())); - - // right click action(s) for image node - if (this.currentNode instanceof ImageNode) { - actions.add(new NewWindowViewAction("View in New Window", (ImageNode) this.currentNode)); - actions.addAll(ShowDetailActionVisitor.getActions(((ImageNode) this.currentNode).getContent())); - } // right click action(s) for volume node - else if (this.currentNode instanceof VolumeNode) { - actions.add(new NewWindowViewAction("View in New Window", (VolumeNode) this.currentNode)); - //new ShowDetailActionVisitor("Volume Details", this.currentNode.getName(), (VolumeNode) this.currentNode), - actions.addAll(ShowDetailActionVisitor.getActions(((VolumeNode) this.currentNode).getContent())); - actions.add(new ChangeViewAction("View", 0, (ContentNode) currentNode)); - } // right click action(s) for directory node - else if (this.currentNode instanceof DirectoryNode) { - actions.add(new NewWindowViewAction("View in New Window", (DirectoryNode) this.currentNode)); - actions.add(new ChangeViewAction("View", 0, (ContentNode) currentNode)); - actions.add(new ExtractAction("Extract Directory", (DirectoryNode) this.currentNode)); - } // right click action(s) for the file node - else if (this.currentNode instanceof FileNode) { - actions.add(new ExternalViewerAction("Open File in External Viewer", (FileNode) this.currentNode)); - actions.add(new NewWindowViewAction("View in New Window", (FileNode) this.currentNode)); - actions.add(new ExtractAction("Extract", (FileNode) this.currentNode)); - actions.add(new ChangeViewAction("View", 0, (ContentNode) currentNode)); - } + Content nodeContent = this.getOriginal().getLookup().lookup(Content.class); + actions.addAll(nodeContent.accept(getActionsCV)); return actions.toArray(new Action[actions.size()]); } + + private class GetActionsContentVisitor extends ContentVisitor.Default> { + + @Override + public List visit(Image img) { + return ShowDetailActionVisitor.getActions(img); + } + + @Override + public List visit(Volume vol) { + List actions = new ArrayList(); + actions.addAll(ShowDetailActionVisitor.getActions(vol)); + actions.add(new ChangeViewAction("View", 0, getOriginal())); + return actions; + } + + @Override + public List visit(Directory dir) { + List actions = new ArrayList(); + actions.add(new ChangeViewAction("View", 0, getOriginal())); + actions.add(new ExtractAction("Extract Directory", getOriginal())); + return actions; + } + + @Override + public List visit(File f) { + List actions = new ArrayList(); + actions.add(new ExternalViewerAction("Open in External Viewer", getOriginal())); + actions.add(new ExtractAction("Extract", getOriginal())); + return actions; + } + + @Override + protected List defaultVisit(Content cntnt) { + return Collections.EMPTY_LIST; + } + + } /** * Double click action for the nodes that we want to pass to the directory @@ -111,11 +125,13 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { @Override public Action getPreferredAction() { // double click action(s) for volume node or directory node - if (this.currentNode instanceof VolumeNode || (this.currentNode instanceof DirectoryNode && !this.currentNode.getDisplayName().equals("."))) { + + final Node originalNode = this.getOriginal(); + + if (originalNode instanceof VolumeNode || (originalNode instanceof DirectoryNode && !originalNode.getDisplayName().equals("."))) { - if (this.currentNode instanceof DirectoryNode && this.currentNode.getDisplayName().equals("..")) { - ExplorerManager em = DirectoryTreeTopComponent.findInstance().getExplorerManager(); - Node[] selectedNode = em.getSelectedNodes(); + if (originalNode instanceof DirectoryNode && originalNode.getDisplayName().equals("..")) { + Node[] selectedNode = sourceEm.getSelectedNodes(); Node selectedContext = selectedNode[0]; final Node parentNode = selectedContext.getParentNode(); @@ -124,7 +140,7 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { @Override public void actionPerformed(ActionEvent e) { try { - DirectoryTreeTopComponent.findInstance().getExplorerManager().setSelectedNodes(new Node[]{parentNode}); + sourceEm.setSelectedNodes(new Node[]{parentNode}); } catch (PropertyVetoException ex) { Logger logger = Logger.getLogger(DataResultFilterNode.class.getName()); logger.log(Level.WARNING, "Error: can't open the parent directory.", ex); @@ -132,8 +148,7 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { } }; } else { - ExplorerManager em = DirectoryTreeTopComponent.findInstance().getExplorerManager(); - final Node[] parentNode = em.getSelectedNodes(); + final Node[] parentNode = sourceEm.getSelectedNodes(); final Node parentContext = parentNode[0]; return new AbstractAction() { @@ -141,12 +156,11 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { @Override public void actionPerformed(ActionEvent e) { if (parentContext != null) { - ExplorerManager em = DirectoryTreeTopComponent.findInstance().getExplorerManager(); for (int i = 0; i < parentContext.getChildren().getNodesCount(); i++) { Node selectedNode = parentContext.getChildren().getNodeAt(i); - if (selectedNode != null && selectedNode.getName().equals(currentNode.getName())) { + if (selectedNode != null && selectedNode.getName().equals(originalNode.getName())) { try { - em.setExploredContextAndSelection(selectedNode, new Node[]{selectedNode}); + sourceEm.setExploredContextAndSelection(selectedNode, new Node[]{selectedNode}); } catch (PropertyVetoException ex) { // throw an error here Logger logger = Logger.getLogger(DataResultFilterNode.class.getName()); @@ -158,12 +172,7 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { } }; } - - } // // right click action(s) for the file node - // if(this.currentNode instanceof FileNode){ - // // .. put the code here - // } - else { + } else { return null; } } @@ -189,40 +198,4 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { return propertySets; } - - @Override - public long getID() { - return ((ContentNode) currentNode).getID(); - } - - @Override - public Object[][] getRowValues(int rows) throws SQLException { - return ((ContentNode) currentNode).getRowValues(rows); - } - - @Override - public byte[] read(long offset, long len) throws TskException { - return ((ContentNode) currentNode).read(offset, len); - } - - @Override - public Content getContent() { - return ((ContentNode) currentNode).getContent(); - } - - @Override - public String[] getDisplayPath() { - return ((ContentNode) currentNode).getDisplayPath(); - } - - @Override - public T accept(ContentNodeVisitor v) { - // TODO: Figure out how visitors should be delegated - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public String[] getSystemPath() { - return ((ContentNode) currentNode).getSystemPath(); - } -} +} \ No newline at end of file diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterChildren.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterChildren.java index 8f365354e4..e9464e3e94 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterChildren.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterChildren.java @@ -46,11 +46,14 @@ class DirectoryTreeFilterChildren extends FilterNode.Children { @Override protected Node[] createNodes(Node arg0) { + + //TODO: ContentNode fix - replace with ContentVisitor + // filter out the FileNode and the "." and ".." directories if (arg0 != null && (arg0 instanceof ImageNode || arg0 instanceof VolumeNode || (arg0 instanceof DirectoryNode - && !((Directory) ((DirectoryNode) arg0).getContent()).getName().equals(".") - && !((Directory) ((DirectoryNode) arg0).getContent()).getName().equals("..")))) { + && !((DirectoryNode) arg0).getDisplayName().equals(".")) + && !((DirectoryNode) arg0).getDisplayName().equals(".."))) { return new Node[]{this.copyNode(arg0)}; } else { return new Node[]{}; diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java index 13d2b4e907..61d72ef610 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java @@ -23,29 +23,24 @@ import java.util.List; import javax.swing.Action; import org.openide.nodes.FilterNode; import org.openide.nodes.Node; -import org.sleuthkit.autopsy.casemodule.Case; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.Volume; /** * This class sets the actions for the nodes in the directory tree and creates * the children filter so that files and such are hidden from the tree. * */ -public class DirectoryTreeFilterNode extends FilterNode { +class DirectoryTreeFilterNode extends FilterNode { private static final Action collapseAll = new CollapseAction("Collapse All"); /** the constructor */ - public DirectoryTreeFilterNode(Node arg) { - super(arg, DirectoryTreeFilterChildren.createInstance(arg)); - } - - // TODO This seems bad. We should have this return the real original and modify code somewhere else to wrap it - @Override - public Node getOriginal() { - return new DataResultFilterNode(super.getOriginal()); + DirectoryTreeFilterNode(Node arg) { + super(arg, DirectoryTreeFilterChildren.createInstance(arg), + new ProxyLookup(Lookups.singleton(new OriginalNode(arg)), + arg.getLookup())); } /** @@ -58,7 +53,7 @@ public class DirectoryTreeFilterNode extends FilterNode { public Action[] getActions(boolean popup) { List actions = new ArrayList(); - Content content = super.getOriginal().getLookup().lookup(Content.class); + Content content = this.getLookup().lookup(Content.class); if (content != null) { actions.addAll(DirectoryTreeFilterNode.getActions(content)); actions.add(collapseAll); @@ -74,4 +69,17 @@ public class DirectoryTreeFilterNode extends FilterNode { return actions; } + + static class OriginalNode { + + private Node original; + + private OriginalNode(Node original) { + this.original = original; + } + + Node getNode() { + return original; + } + } } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java index f691f39e65..3e87fd6531 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeTopComponent.java @@ -44,9 +44,11 @@ import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent; +import org.sleuthkit.autopsy.datamodel.ContentUtils; +import org.sleuthkit.autopsy.datamodel.DataConversion; import org.sleuthkit.autopsy.datamodel.RootContentChildren; +import org.sleuthkit.datamodel.Content; /** * Top component which displays something. @@ -332,24 +334,10 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat }; } }; - /*try { + root = new DirectoryTreeFilterNode(root); - } catch (SQLException ex) { - JOptionPane.showMessageDialog(caller, "Error: problem making directory filter node.\n \nDetail: \n" + ex.getMessage() + " (at " + className + ").", "Error", JOptionPane.ERROR_MESSAGE); - }*/ - // TODO It seems that we can get rid of the first condition. root is an abstract node - if (root instanceof DirectoryTreeFilterNode) { - root = ((DirectoryTreeFilterNode) root).getOriginal(); - } else { -// try { - root = new DirectoryTreeFilterNode(root); -// } catch (SQLException ex) { -// JOptionPane.showMessageDialog(caller, "Error: problem making directory filter node.\n \nDetail: \n" + ex.getMessage() + " (at " + className + ").", "Error", JOptionPane.ERROR_MESSAGE); -// } - } - em.setRootContext(root); em.getRootContext().setName(currentCase.getName()); em.getRootContext().setDisplayName(currentCase.getName()); @@ -460,16 +448,12 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat * * @return node the original selected Node */ - // TODO Rename or get rid of it entirely. - public Node getOriginalSelectedNode() { + public Node getSelectedNode() { Node result = null; Node[] selectedNodes = this.getExplorerManager().getSelectedNodes(); if (selectedNodes.length > 0) { result = selectedNodes[0]; - if (result != null && result instanceof DirectoryTreeFilterNode) { - result = ((DirectoryTreeFilterNode) result).getOriginal(); - } } return result; } @@ -500,10 +484,10 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat em.getRootContext().setDisplayName(newCaseName); } } - + // changed current case if (changed.equals(Case.CASE_CURRENT_CASE)) { - + // case opened if (newValue != null) { resetHistoryListAndButtons(); @@ -546,8 +530,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat // change in node selection if (changed.equals(ExplorerManager.PROP_SELECTED_NODES)) { - - // Some lock that prevents certian Node operations is set during the + // Some lock that prevents certain Node operations is set during the // ExplorerManager selection-change, so we must handle changes after the // selection-change event is processed. EventQueue.invokeLater(new Runnable() { @@ -561,18 +544,21 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat // make sure dataResult is open dataResult.open(); - ContentNode node = (ContentNode) DirectoryTreeTopComponent.this.getOriginalSelectedNode(); - if (node != null) { + Node treeNode = DirectoryTreeTopComponent.this.getSelectedNode(); + if (treeNode != null) { + Node originNode = treeNode.getLookup().lookup(DirectoryTreeFilterNode.OriginalNode.class).getNode(); - //pcs.firePropertyChange(DataExplorer.EXPLORER_NODE_SELECTION_CHANGED, "", node); - int count = ((Node) node).getChildren().getNodesCount(true); + int count = originNode.getChildren().getNodesCount(true); if (count > 1000) { DirectoryTreeTopComponent.this.setCursor(null); JOptionPane.showMessageDialog(caller, "Note: The selected directory contains " + count + " child files and folders. It may take some time to display them.\n\nAlso note that in the current version of Autopsy this will also make certain functions very slow (thumbnail view in particular, should be fixed in a future version)", "Large Data", JOptionPane.INFORMATION_MESSAGE); DirectoryTreeTopComponent.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); } DirectoryTreeTopComponent.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - DirectoryTreeTopComponent.this.dataResult.setNode(node); + DirectoryTreeTopComponent.this.dataResult.setNode(new DataResultFilterNode(originNode, DirectoryTreeTopComponent.this.em)); + + String path = DataConversion.getformattedPath(ContentUtils.getDisplayPath(originNode.getLookup().lookup(Content.class)), 0); + DirectoryTreeTopComponent.this.dataResult.setPath(path); } // set the directory listing to be active diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java index 8b149605d7..f772b4528b 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExternalViewerAction.java @@ -21,49 +21,37 @@ package org.sleuthkit.autopsy.directorytree; import java.awt.Desktop; import java.awt.event.ActionEvent; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; -import javax.swing.JOptionPane; -import javax.swing.JPanel; import org.openide.nodes.Node; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.datamodel.FileNode; +import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.logging.Log; -import org.sleuthkit.datamodel.TskException; /** - * - * @author jantonius + * Extracts a File object to a temporary file in the case directory, and then + * tries to open it in the user's system with the default associated + * application. */ public class ExternalViewerAction extends AbstractAction { - private byte[] content; - private FileNode fileNode; - private String fileName; - private String extension; - // for error handling - private JPanel caller; - private String className = this.getClass().toString(); + private final static Logger logger = Logger.getLogger(ExternalViewerAction.class.getName()); + private org.sleuthkit.datamodel.File fileObject; - /** the constructor */ - public ExternalViewerAction(String title, FileNode fileNode) { + public ExternalViewerAction(String title, Node fileNode) { super(title); - this.fileNode = fileNode; - - long size = fileNode.getContent().getSize(); - String fullFileName = ((Node)fileNode).getDisplayName(); - if (fullFileName.contains(".") && size > 0) { - String tempFileName = fullFileName.substring(0, fullFileName.indexOf(".")); - String tempExtension = fullFileName.substring(fullFileName.indexOf(".")); - this.fileName = tempFileName; - this.extension = tempExtension; - } else { - this.fileName = fullFileName; - this.extension = ""; - this.setEnabled(false); // fix this later (right now only extract a file with extension) + this.fileObject = fileNode.getLookup().lookup(org.sleuthkit.datamodel.File.class); + + long size = fileObject.getSize(); + String fileName = fileObject.getName(); + int extPos = fileName.lastIndexOf('.'); + + // no point opening a file if it's empty, and java doesn't know how to + // find an application for files without an extension + if (!(size > 0) || extPos == -1) { + this.setEnabled(false); } } @@ -71,54 +59,31 @@ public class ExternalViewerAction extends AbstractAction { public void actionPerformed(ActionEvent e) { Log.noteAction(this.getClass()); + // Get the temp folder path of the case + String tempPath = Case.getCurrentCase().getTempDirectory(); + tempPath = tempPath + File.separator + this.fileObject.getName(); + + // create the temporary file + File tempFile = new File(tempPath); + if (tempFile.exists()) { + tempFile.delete(); + } try { - // @@@ Thing to do: maybe throw confirmation first??? - - // the menu should be disabled if we can't read the content (for example: on zero-sized file). - // Therefore, it should never throw the TSKException. - try { - this.content = fileNode.getContent().read(0, fileNode.getContent().getSize()); - } catch (TskException ex) { - Logger.getLogger(this.className).log(Level.WARNING, "Error: can't read the content of the file.", ex); - } - - // Get the temp folder path of the case - String tempPath = Case.getCurrentCase().getTempDirectory(); - tempPath = tempPath + File.separator + this.fileName + this.extension; - - // create the temporary file - File file = new File(tempPath); - if (file.exists()) { - file.delete(); - } - - file.createNewFile(); - - // convert char to byte - byte[] dataSource = new byte[content.length]; - for (int i = 0; i < content.length; i++) { - dataSource[i] = (byte) content[i]; - } - - FileOutputStream fos = new FileOutputStream(file); - //fos.write(dataSource); - fos.write(dataSource); - fos.close(); - - try { - Desktop.getDesktop().open(file); - } catch (IOException ex) { - // if can't open the file, throw the error saying: "File type not supported." - JOptionPane.showMessageDialog(caller, "Error: File type not supported.\n \nDetail: \n" + ex.getMessage() + " (at " + className + ").", "Error", JOptionPane.ERROR_MESSAGE); - } - - // delete the file on exit - file.deleteOnExit(); - + tempFile.createNewFile(); + ContentUtils.writeToFile(fileObject, tempFile); } catch (IOException ex) { // throw an error here - Logger.getLogger(this.className).log(Level.WARNING, "Error: can't open the external viewer for this file.", ex); + logger.log(Level.WARNING, "Can't save to temporary file.", ex); } + try { + Desktop.getDesktop().open(tempFile); + } catch (IOException ex) { + // if can't open the file, throw the error saying: "File type not supported." + logger.log(Level.WARNING, "File type not supported.", ex); + } + + // delete the file on exit + tempFile.deleteOnExit(); } } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java index d1c4adf529..3ea8aa522f 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ExtractAction.java @@ -18,201 +18,94 @@ */ package org.sleuthkit.autopsy.directorytree; -import org.sleuthkit.autopsy.datamodel.FileNode; -import java.io.*; import java.awt.event.ActionEvent; import javax.swing.JFileChooser; import java.io.File; import java.awt.Component; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.AbstractAction; -import javax.swing.JPanel; -import javax.swing.filechooser.FileFilter; +import javax.swing.JOptionPane; import org.openide.nodes.Node; -import org.sleuthkit.autopsy.casemodule.GeneralFilter; -import org.sleuthkit.autopsy.datamodel.ContentNode; -import org.sleuthkit.autopsy.datamodel.DirectoryNode; +import org.sleuthkit.autopsy.datamodel.ContentUtils; +import org.sleuthkit.autopsy.datamodel.ContentUtils.ExtractFscContentVisitor; import org.sleuthkit.autopsy.logging.Log; -import org.sleuthkit.datamodel.TskException; +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.ContentVisitor; +import org.sleuthkit.datamodel.Directory; +import org.sleuthkit.datamodel.FsContent; /** - * This is an action class to extract and save the bytes given as a file. - * - * @author jantonius + * Exports files and folders */ public final class ExtractAction extends AbstractAction { - private JFileChooser fc = new JFileChooser(); - private byte[] source; - private ContentNode contentNode; - private String fileName; - private String extension; - // for error handling - private JPanel caller; - private String className = this.getClass().toString(); + private static final InitializeContentVisitor initializeCV = new InitializeContentVisitor(); + private FsContent fsContent; - /** the constructor */ - public ExtractAction(String title, ContentNode contentNode) { + public ExtractAction(String title, Node contentNode) { super(title); - - String fullFileName = ((Node)contentNode).getDisplayName(); - - if (fullFileName.equals(".")) { - // . folders are not associated with their children in the database, - // so get original - Node parentNode = ((Node) contentNode).getParentNode(); - this.contentNode = (ContentNode) parentNode; - fullFileName = parentNode.getDisplayName(); - } else { - this.contentNode = contentNode; - } - long size = contentNode.getContent().getSize(); - - - - /** - * Checks first if the the selected it file or directory. If it's a file, - * check if the file size is bigger than 0. If it's a directory, check - * if it's not referring to the parent directory. Disables the menu otherwise. - */ - if ((contentNode instanceof FileNode && size > 0) || (contentNode instanceof DirectoryNode && !fullFileName.equals(".."))) { - if (contentNode instanceof FileNode && fullFileName.contains(".")) { - String tempFileName = fullFileName.substring(0, fullFileName.indexOf(".")); - String tempExtension = fullFileName.substring(fullFileName.indexOf(".")); - this.fileName = tempFileName; - this.extension = tempExtension; - } else { - this.fileName = fullFileName; - this.extension = ""; - } - } else { - this.fileName = fullFileName; - this.extension = ""; - this.setEnabled(false); // can't extract zero-sized file or ".." directory - } + Content tempContent = contentNode.getLookup().lookup(Content.class); + this.fsContent = tempContent.accept(initializeCV); + this.setEnabled(fsContent != null); } /** - * Converts and saves the bytes into the file. - * + * Returns the FsContent if it is supported, otherwise null + */ + private static class InitializeContentVisitor extends ContentVisitor.Default { + + @Override + public FsContent visit(org.sleuthkit.datamodel.File f) { + return f; + } + + @Override + public FsContent visit(Directory dir) { + return ContentUtils.isDotDirectory(dir) ? null : dir; + } + + @Override + protected FsContent defaultVisit(Content cntnt) { + return null; + } + } + + /** + * Asks user to choose destination, then extracts file/directory to + * destination (recursing on directories) * @param e the action event */ @Override public void actionPerformed(ActionEvent e) { Log.noteAction(this.getClass()); - // set the filter for FileNode - if (contentNode instanceof FileNode && !extension.equals("")) { - //FileFilter filter = new ExtensionFileFilter(extension.substring(1).toUpperCase() + " File (*" + extension + ")", new String[]{extension.substring(1)}); - String[] fileExt = {extension}; - FileFilter filter = new GeneralFilter(fileExt, extension.substring(1).toUpperCase() + " File (*" + extension + ")", false); - fc.setFileFilter(filter); - } - - - fc.setSelectedFile(new File(this.fileName)); - + JFileChooser fc = new JFileChooser(); + fc.setSelectedFile(new File(this.fsContent.getName())); int returnValue = fc.showSaveDialog((Component) e.getSource()); + if (returnValue == JFileChooser.APPROVE_OPTION) { - String path = fc.getSelectedFile().getPath() + extension; + File destination = fc.getSelectedFile(); - try { - // file extraction - if (contentNode instanceof FileNode) { - extractFile(path, (FileNode) contentNode); + // check that it's okay to overwrite existing file + if (destination.exists()) { + int choice = JOptionPane.showConfirmDialog( + (Component) e.getSource(), + "Destination file already exists, it will be overwritten.", + "Destination already exists!", + JOptionPane.OK_CANCEL_OPTION); + + if (choice != JOptionPane.OK_OPTION) { + return; } - // directory extraction - if (contentNode instanceof DirectoryNode) { - extractDirectory(path, (DirectoryNode) contentNode); + if (!destination.delete()) { + JOptionPane.showMessageDialog( + (Component) e.getSource(), + "Couldn't delete existing file."); } - } catch (Exception ex) { - Logger.getLogger(this.className).log(Level.WARNING, "Error: Couldn't extract file/directory.", ex); } + ExtractFscContentVisitor.extract(fsContent, destination); } - - } - - /** - * Extracts the content of the given fileNode into the given path. - * - * @param givenPath the path to extract the file - * @param fileNode the file node that contain the file - */ - private void extractFile(String givenPath, FileNode fileNode) throws Exception { - try { - if (fileNode.getContent().getSize() > 0) { - try { - this.source = fileNode.getContent().read(0, fileNode.getContent().getSize()); - } catch (TskException ex) { - throw new Exception("Error: can't read the content of the file.", ex); - } - } else { - this.source = new byte[0]; - } - - String path = givenPath; - - File file = new File(path); - if (file.exists()) { - file.delete(); - } - file.createNewFile(); - // convert char to byte - byte[] dataSource = new byte[source.length]; - for (int i = 0; i < source.length; i++) { - dataSource[i] = (byte) source[i]; - } - FileOutputStream fos = new FileOutputStream(file); - //fos.write(dataSource); - fos.write(dataSource); - fos.close(); - } catch (IOException ex) { - throw new Exception("Error while trying to extract the file.", ex); - } - } - - /** - * Extracts the content of the given directoryNode into the given path. - * - * @param givenPath the path to extract the directory - * @param dirNode the directory node that contain the directory - */ - private void extractDirectory(String givenPath, DirectoryNode dirNode) throws Exception { - String path = givenPath; - File dir = new File(path); - if (!dir.exists()) { - dir.mkdir(); - } - - int totalChildren = dirNode.getChildren().getNodesCount(); - for (int i = 0; i < totalChildren; i++) { - Node childNode = dirNode.getChildren().getNodeAt(i); - - if (childNode instanceof FileNode) { - FileNode fileNode = (FileNode) childNode; - String tempPath = path + File.separator + ((Node)fileNode).getDisplayName(); - try { - extractFile(tempPath, fileNode); - } catch (Exception ex) { - throw ex; - } - } - - if (childNode instanceof DirectoryNode) { - DirectoryNode dirNode2 = (DirectoryNode) childNode; - String dirNode2Name = ((Node)dirNode2).getDisplayName(); - - if (!dirNode2Name.trim().equals(".") && !dirNode2Name.trim().equals("..")) { - String tempPath = path + File.separator + dirNode2Name; - extractDirectory(tempPath, dirNode2); - } - } - } - - } } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java index 81d40916e7..60f0ff1718 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/NewWindowViewAction.java @@ -22,21 +22,23 @@ package org.sleuthkit.autopsy.directorytree; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import javax.swing.AbstractAction; +import org.openide.nodes.Node; import org.openide.windows.Mode; import org.openide.windows.WindowManager; -import org.sleuthkit.autopsy.datamodel.ContentNode; import org.sleuthkit.autopsy.datamodel.DataConversion; import org.sleuthkit.autopsy.corecomponents.DataContentTopComponent; +import org.sleuthkit.autopsy.datamodel.ContentUtils; import org.sleuthkit.autopsy.logging.Log; +import org.sleuthkit.datamodel.Content; /** * Opens new ContentViewer pane in a detached window */ class NewWindowViewAction extends AbstractAction{ - private ContentNode contentNode ; + private Node contentNode ; - NewWindowViewAction(String title, ContentNode contentNode){ + NewWindowViewAction(String title, Node contentNode){ super(title); this.contentNode = contentNode; } @@ -45,7 +47,7 @@ class NewWindowViewAction extends AbstractAction{ public void actionPerformed(ActionEvent e) { Log.noteAction(this.getClass()); - String[] filePaths = this.contentNode.getDisplayPath(); + String[] filePaths = ContentUtils.getDisplayPath((contentNode).getLookup().lookup(Content.class)); String filePath = DataConversion.getformattedPath(filePaths, 0); DataContentTopComponent dctc = DataContentTopComponent.createUndocked(filePath, this.contentNode); diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ShowDetailActionVisitor.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ShowDetailActionVisitor.java index 84e678cb1e..d4fa64a89c 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ShowDetailActionVisitor.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ShowDetailActionVisitor.java @@ -84,8 +84,7 @@ class ShowDetailActionVisitor extends ContentVisitor.Default { + @Override + public Action[] visit(Directory dir) { return new Action[]{ - new ChangeViewAction("View", 0, (ContentNode) currentNode), - new OpenParentFolderAction("Open Parent Directory", ((ContentNode) currentNode).getSystemPath()) - }; - } // right click action(s) for the file node - else if (this.currentNode instanceof FileNode) { + new ChangeViewAction("View", 0, getOriginal()), + new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath(dir)) + }; + } + + @Override + public Action[] visit(File f) { return new Action[]{ - new ExtractAction("Extract", (FileNode) this.currentNode), - new ChangeViewAction("View", 0, (ContentNode) currentNode), - new OpenParentFolderAction("Open Parent Directory", ((ContentNode) currentNode).getSystemPath()) - }; - } else { + new ExternalViewerAction("Open in External Viewer", getOriginal()), + new ExtractAction("Extract", getOriginal()), + new ChangeViewAction("View", 0, getOriginal()), + new OpenParentFolderAction("Open Parent Directory", ContentUtils.getSystemPath(f)) + }; + } + + @Override + protected Action[] defaultVisit(Content cntnt) { return new Action[]{}; } } + /** * Double click action for the nodes that we want to pass to the directory @@ -95,40 +92,4 @@ public class DataResultFilterNode extends FilterNode implements ContentNode { public Action getPreferredAction() { return null; } - - @Override - public long getID() { - return ((ContentNode) currentNode).getID(); - } - - @Override - public Object[][] getRowValues(int rows) throws SQLException { - return ((ContentNode) currentNode).getRowValues(rows); - } - - @Override - public byte[] read(long offset, long len) throws TskException { - return ((ContentNode) currentNode).read(offset, len); - } - - @Override - public Content getContent() { - return ((ContentNode) currentNode).getContent(); - } - - @Override - public String[] getDisplayPath() { - return ((ContentNode) currentNode).getDisplayPath(); - } - - @Override - public T accept(ContentNodeVisitor v) { - //TODO: figure out how to deal with visitors - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public String[] getSystemPath() { - return ((ContentNode) currentNode).getSystemPath(); - } } diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DateSearchPanel.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DateSearchPanel.java index 9af85af157..ac26878557 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/DateSearchPanel.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/DateSearchPanel.java @@ -82,7 +82,6 @@ class DateSearchPanel extends javax.swing.JPanel { } } - //TODO: calendar button stuff /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/FileSearchTopComponent.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/FileSearchTopComponent.java index e77b364823..7e15a79aa9 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/FileSearchTopComponent.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/FileSearchTopComponent.java @@ -338,4 +338,4 @@ public final class FileSearchTopComponent extends TopComponent implements DataEx public TopComponent getTopComponent() { return this; } -} +} \ No newline at end of file diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/FilterArea.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/FilterArea.java index c1e8e625cb..6a2dd1e130 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/FilterArea.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/FilterArea.java @@ -71,8 +71,10 @@ class FilterArea extends JPanel { private void init() { - // TODO: this icon (and its twin) should be used in the toggle button - // this.dateFiltersButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/filesearch/arrow_down.gif"))); // NOI18N + + + // Commmented-out code is for collapable filter areas +// this.dateFiltersButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/filesearch/arrow_down.gif"))); // NOI18N // toggleButton = new JButton(); // toggleButton.setAlignmentX(Component.CENTER_ALIGNMENT); diff --git a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java index aeb4b78098..6c088a166e 100644 --- a/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java +++ b/FileSearch/src/org/sleuthkit/autopsy/filesearch/SearchNode.java @@ -19,21 +19,15 @@ package org.sleuthkit.autopsy.filesearch; -import java.sql.SQLException; import java.util.ArrayList; import org.openide.nodes.AbstractNode; -import org.openide.nodes.Node.Property; -import org.sleuthkit.autopsy.datamodel.ContentNode; -import org.sleuthkit.autopsy.datamodel.ContentNodeVisitor; -import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.FsContent; -import org.sleuthkit.datamodel.TskException; /** * * @author jantonius */ -class SearchNode extends AbstractNode implements ContentNode { +class SearchNode extends AbstractNode { private SearchChildren children; @@ -46,69 +40,4 @@ class SearchNode extends AbstractNode implements ContentNode { public String getName() { return "Search Result"; } - - @Override - public long getID() { - return -1; // change this later when needed - } - - @Override - public Object[][] getRowValues(int rows) throws SQLException { - int totalNodes = children.getNodesCount(); - - Object[][] objs; - int maxRows = 0; - if(totalNodes > rows){ - objs = new Object[rows][]; - maxRows = rows; - } - else{ - objs = new Object[totalNodes][]; - maxRows = totalNodes; - } - - for(int i = 0; i < maxRows; i++){ - PropertySet[] props = children.getNodeAt(i).getPropertySets(); - Property[] property = props[0].getProperties(); - objs[i] = new Object[property.length]; - - for(int j = 0; j < property.length; j++){ - try { - objs[i][j] = property[j].getValue(); - } catch (Exception ex) { - objs[i][j] = "n/a"; - } - } - } - return objs; - } - - - @Override - public byte[] read(long offset, long len) throws TskException { - // change this in the future when needed - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public Content getContent() { - return null; - } - - @Override - public String[] getDisplayPath() { - return new String[]{"KeyWord Search Result:"}; - } - - @Override - public T accept(ContentNodeVisitor v) { - //TODO: figure out how to deal with visitors - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public String[] getSystemPath() { - // Shouldn't be used - throw new UnsupportedOperationException("Not supported yet."); - } } diff --git a/MenuActions/src/org/sleuthkit/autopsy/menuactions/SearchResultMenu.java b/MenuActions/src/org/sleuthkit/autopsy/menuactions/SearchResultMenu.java index 60eafc3b58..8b3b434b04 100644 --- a/MenuActions/src/org/sleuthkit/autopsy/menuactions/SearchResultMenu.java +++ b/MenuActions/src/org/sleuthkit/autopsy/menuactions/SearchResultMenu.java @@ -30,7 +30,7 @@ import org.sleuthkit.autopsy.directorytree.DirectoryTreeTopComponent; import org.sleuthkit.autopsy.filesearch.FileSearchTopComponent; /** - * Menu item lists DataResult tabs.w + * Menu item lists DataResult tabs. */ public class SearchResultMenu extends JMenuItem implements DynamicMenuContent {