From 451296449653d1a2980d59b7d0c6b465172d5ffc Mon Sep 17 00:00:00 2001 From: Dick Fickling Date: Mon, 27 Feb 2012 12:49:04 -0500 Subject: [PATCH] No longer assume that blackboard artifacts are associated with a File object, instead they are associated with any generic Content object --- .../datamodel/AbstractContentChildren.java | 12 ++-- .../datamodel/ArtifactStringContent.java | 13 ---- .../datamodel/BlackboardArtifactNode.java | 28 +++----- .../directorytree/ViewContextAction.java | 2 +- .../autopsy/recentactivity/ExtractIE.java | 2 +- .../org/sleuthkit/autopsy/report/report.java | 18 +++--- .../autopsy/report/reportAction.java | 64 +++++++++++++++++-- .../sleuthkit/autopsy/report/reportHTML.java | 62 ++++++++++++++++-- .../sleuthkit/autopsy/report/reportXML.java | 39 +++++++++-- 9 files changed, 178 insertions(+), 62 deletions(-) diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentChildren.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentChildren.java index ec2897ec97..f3bffb19f9 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentChildren.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/AbstractContentChildren.java @@ -63,7 +63,7 @@ abstract class AbstractContentChildren extends Keys { /** * Creates appropriate Node for each sub-class of Content */ - static class CreateSleuthkitNodeVisitor extends SleuthkitItemVisitor.Default { + static class CreateSleuthkitNodeVisitor extends SleuthkitItemVisitor.Default { @Override public AbstractContentNode visit(Directory drctr) { @@ -76,7 +76,7 @@ abstract class AbstractContentChildren extends Keys { } @Override - public AbstractNode visit(FileSystem fs) { + public AbstractContentNode visit(FileSystem fs) { return defaultVisit(fs); } @@ -91,22 +91,22 @@ abstract class AbstractContentChildren extends Keys { } @Override - public AbstractNode visit(VolumeSystem vs) { + public AbstractContentNode visit(VolumeSystem vs) { return defaultVisit(vs); } @Override - public AbstractNode visit(BlackboardArtifact.ARTIFACT_TYPE a) { + public AbstractContentNode visit(BlackboardArtifact.ARTIFACT_TYPE a) { return defaultVisit(a); } @Override - public AbstractNode visit(BlackboardArtifact ba) { + public AbstractContentNode visit(BlackboardArtifact ba) { return defaultVisit(ba); } @Override - protected AbstractNode defaultVisit(SleuthkitVisitableItem di) { + protected AbstractContentNode defaultVisit(SleuthkitVisitableItem di) { throw new UnsupportedOperationException("No Node defined for the given DisplayableItem"); } } diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/ArtifactStringContent.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/ArtifactStringContent.java index a8b32e54a7..17a009f617 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/ArtifactStringContent.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/ArtifactStringContent.java @@ -18,13 +18,11 @@ */ package org.sleuthkit.autopsy.datamodel; -import java.sql.SQLException; import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; -import org.sleuthkit.datamodel.File; import org.sleuthkit.datamodel.TskException; /** @@ -78,15 +76,4 @@ public class ArtifactStringContent implements StringContent{ } } - public static File getAssociatedFile(BlackboardArtifact artifact){ - try { - return artifact.getSleuthkitCase().getFileById(artifact.getObjectID()); - } catch (SQLException ex) { - logger.log(Level.WARNING, "SQL query threw exception", ex); - } catch (TskException ex) { - logger.log(Level.WARNING, "Getting file failed", ex); - } - throw new IllegalArgumentException("Couldn't get file from database"); - } - } diff --git a/DataModel/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java b/DataModel/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java index de447a5b71..0a780da352 100644 --- a/DataModel/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java +++ b/DataModel/src/org/sleuthkit/autopsy/datamodel/BlackboardArtifactNode.java @@ -25,12 +25,14 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; +import org.openide.nodes.Node; import org.openide.nodes.Sheet; import org.openide.util.Lookup; import org.openide.util.lookup.Lookups; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE; +import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.Directory; import org.sleuthkit.datamodel.File; import org.sleuthkit.datamodel.TskException; @@ -45,7 +47,7 @@ public class BlackboardArtifactNode extends AbstractNode implements DisplayableI static final Logger logger = Logger.getLogger(BlackboardArtifactNode.class.getName()); public BlackboardArtifactNode(BlackboardArtifact artifact) { - super(Children.LEAF, Lookups.singleton(getAssociatedFile(artifact))); + super(Children.LEAF, Lookups.singleton(getAssociatedContent(artifact))); //super(Children.LEAF, Lookups.singleton(new ArtifactStringContent(artifact))); this.artifact = artifact; this.setName(Long.toString(artifact.getArtifactID())); @@ -120,9 +122,9 @@ public class BlackboardArtifactNode extends AbstractNode implements DisplayableI return v.visit(this); } - public File getAssociatedFile(){ + public Content getAssociatedContent(){ try { - return artifact.getSleuthkitCase().getFileById(artifact.getObjectID()); + return artifact.getSleuthkitCase().getContentById(artifact.getObjectID()); } catch (SQLException ex) { logger.log(Level.WARNING, "SQL query threw exception", ex); } catch (TskException ex) { @@ -131,9 +133,9 @@ public class BlackboardArtifactNode extends AbstractNode implements DisplayableI throw new IllegalArgumentException("Couldn't get file from database"); } - public static File getAssociatedFile(BlackboardArtifact artifact){ + public static Content getAssociatedContent(BlackboardArtifact artifact){ try { - return artifact.getSleuthkitCase().getFileById(artifact.getObjectID()); + return artifact.getSleuthkitCase().getContentById(artifact.getObjectID()); } catch (SQLException ex) { logger.log(Level.WARNING, "SQL query threw exception", ex); } catch (TskException ex) { @@ -141,22 +143,10 @@ public class BlackboardArtifactNode extends AbstractNode implements DisplayableI } throw new IllegalArgumentException("Couldn't get file from database"); } - - public Directory getParentDirectory(){ - try{ - return getAssociatedFile().getParentDirectory(); - } catch (TskException ex) { - logger.log(Level.WARNING, "File has no parent", ex); - } - throw new IllegalArgumentException("Couldn't get context"); - } - public FileNode getContentNode() { - return new FileNode(getAssociatedFile()); + public Node getContentNode() { + return getAssociatedContent().accept(new AbstractContentChildren.CreateSleuthkitNodeVisitor()); } - public DirectoryNode getContextNode() { - return new DirectoryNode(getParentDirectory()); - } } diff --git a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java index 40e5eaa012..78a8358f39 100644 --- a/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java +++ b/DirectoryTree/src/org/sleuthkit/autopsy/directorytree/ViewContextAction.java @@ -67,7 +67,7 @@ class ViewContextAction extends AbstractAction { @Override public void run() { ReverseHierarchyVisitor vtor = new ReverseHierarchyVisitor(); - List hierarchy = node.getAssociatedFile().accept(vtor); + List hierarchy = node.getAssociatedContent().accept(vtor); Collections.reverse(hierarchy); Node generated = new DirectoryTreeFilterNode(new AbstractNode(new RootContentChildren(hierarchy))); Children genChilds = generated.getChildren(); diff --git a/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/ExtractIE.java b/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/ExtractIE.java index f6cf71dacd..eaf83429e7 100755 --- a/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/ExtractIE.java +++ b/RecentActivity/src/org/sleuthkit/autopsy/recentactivity/ExtractIE.java @@ -252,7 +252,7 @@ public class ExtractIE { // implements BrowserActivity { } // TODO: Need to fix this so we have the right obj_id - BlackboardArtifact bbart = tempDb.getFileById(artObjId).newArtifact(ARTIFACT_TYPE.TSK_WEB_HISTORY); + BlackboardArtifact bbart = tempDb.getContentById(artObjId).newArtifact(ARTIFACT_TYPE.TSK_WEB_HISTORY); Collection bbattributes = new ArrayList(); bbattributes.add(new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_URL.getTypeID(), "RecentActivity", "Internet Explorer", realurl)); diff --git a/Report/src/org/sleuthkit/autopsy/report/report.java b/Report/src/org/sleuthkit/autopsy/report/report.java index b66eac9702..5dadd47220 100644 --- a/Report/src/org/sleuthkit/autopsy/report/report.java +++ b/Report/src/org/sleuthkit/autopsy/report/report.java @@ -9,6 +9,8 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; @@ -40,7 +42,7 @@ public HashMap> getGenInfo() { } catch (Exception e) { - + Logger.getLogger(report.class.getName()).log(Level.INFO, "Exception occurred", e); } return reportMap; @@ -62,7 +64,7 @@ public HashMap> getWebHistory( } catch (Exception e) { - + Logger.getLogger(report.class.getName()).log(Level.INFO, "Exception occurred", e); } return reportMap; @@ -83,7 +85,7 @@ public HashMap> getWebCookie() } catch (Exception e) { - + Logger.getLogger(report.class.getName()).log(Level.INFO, "Exception occurred", e); } return reportMap; @@ -104,7 +106,7 @@ public HashMap> getWebBookmark } catch (Exception e) { - + Logger.getLogger(report.class.getName()).log(Level.INFO, "Exception occurred", e); } return reportMap; @@ -126,7 +128,7 @@ public HashMap> getWebDownload } catch (Exception e) { - + Logger.getLogger(report.class.getName()).log(Level.INFO, "Exception occurred", e); } return reportMap; @@ -148,7 +150,7 @@ public HashMap> getRecentObjec } catch (Exception e) { - + Logger.getLogger(report.class.getName()).log(Level.INFO, "Exception occurred", e); } return reportMap; @@ -170,7 +172,7 @@ public HashMap> getKeywordHit( } catch (Exception e) { - + Logger.getLogger(report.class.getName()).log(Level.INFO, "Exception occurred", e); } return reportMap; @@ -191,7 +193,7 @@ public HashMap> getHashHit() { } catch (Exception e) { - + Logger.getLogger(report.class.getName()).log(Level.INFO, "Exception occurred", e); } return reportMap; diff --git a/Report/src/org/sleuthkit/autopsy/report/reportAction.java b/Report/src/org/sleuthkit/autopsy/report/reportAction.java index 3e45863d9c..7c92836db5 100644 --- a/Report/src/org/sleuthkit/autopsy/report/reportAction.java +++ b/Report/src/org/sleuthkit/autopsy/report/reportAction.java @@ -4,18 +4,23 @@ */ package org.sleuthkit.autopsy.report; +import java.awt.Component; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.logging.Level; +import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import org.openide.awt.ActionRegistration; import org.openide.awt.ActionReference; import org.openide.awt.ActionReferences; import org.openide.awt.ActionID; +import org.openide.util.HelpCtx; import org.openide.util.NbBundle.Messages; +import org.openide.util.actions.CallableSystemAction; +import org.openide.util.actions.Presenter; import org.sleuthkit.autopsy.coreutils.Log; @ActionID(category = "Tools", @@ -25,10 +30,26 @@ id = "org.sleuthkit.autopsy.report.reportAction") @ActionReference(path = "Menu/Tools", position = 80) }) @Messages("CTL_reportAction=Run Report") -public final class reportAction implements ActionListener { +public final class reportAction extends CallableSystemAction implements Presenter.Toolbar{ + + private JButton toolbarButton = new JButton(); private static final String ACTION_NAME = "Report Filter"; + + public reportAction() { + // set action of the toolbar button + toolbarButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + reportAction.this.actionPerformed(e); + } + }); + + } + + @Override public void actionPerformed(ActionEvent e) { - try { + try { // create the popUp window for it final JFrame frame = new JFrame(ACTION_NAME); @@ -65,7 +86,42 @@ public final class reportAction implements ActionListener { } } - public void closeme(JFrame frame){ - frame.dispose(); + @Override + public void performAction() { + + } + + @Override + public String getName() { + return ACTION_NAME; + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + /** + * Returns the toolbar component of this action + * + * @return component the toolbar button + */ + @Override + public Component getToolbarPresenter() { + //ImageIcon icon = new ImageIcon(getClass().getResource("close-icon.png")); + //toolbarButton.setIcon(icon); + toolbarButton.setText(this.getName()); + return toolbarButton; + } + + /** + * Set this action to be enabled/disabled + * + * @param value whether to enable this action or not + */ + @Override + public void setEnabled(boolean value){ + super.setEnabled(value); + toolbarButton.setEnabled(value); } } \ No newline at end of file diff --git a/Report/src/org/sleuthkit/autopsy/report/reportHTML.java b/Report/src/org/sleuthkit/autopsy/report/reportHTML.java index 2e1582abe4..4da28cd1ab 100644 --- a/Report/src/org/sleuthkit/autopsy/report/reportHTML.java +++ b/Report/src/org/sleuthkit/autopsy/report/reportHTML.java @@ -10,13 +10,21 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Map.Entry; +import java.util.logging.Level; +import java.util.logging.Logger; import org.jdom.Comment; import org.jdom.Element; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; +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.SleuthkitCase; +import org.sleuthkit.datamodel.Volume; /** * @@ -64,11 +72,11 @@ public reportHTML (HashMap> re for (Entry> entry : report.entrySet()) { String artifact = "

Artifact"; Long objId = entry.getKey().getObjectID(); - File file = skCase.getFileById(objId); - Long filesize = file.getSize(); + Content cont = skCase.getContentById(objId); + Long filesize = cont.getSize(); artifact += " ID: " + objId.toString(); - artifact += "
Name: " + file.getName().toString() + ""; - artifact += "
Path: " + file.getParentPath(); + artifact += "
Name: " + cont.accept(new NameVisitor()) + ""; + artifact += "
Path: " + cont.accept(new PathVisitor()); artifact += "
Size: " + filesize.toString(); artifact += "

    "; @@ -131,9 +139,53 @@ public reportHTML (HashMap> re } catch(Exception e) { - + Logger.getLogger(reportHTML.class.getName()).log(Level.INFO, "Exception occurred", e); } } + private class NameVisitor extends ContentVisitor.Default { + @Override + protected String defaultVisit(Content cntnt) { + throw new UnsupportedOperationException("Not supported for " + cntnt.toString()); + } + + @Override + public String visit(Directory dir) { + return dir.getName(); + } + + @Override + public String visit(Image img) { + return img.getName(); + } + + @Override + public String visit(File fil) { + return fil.getName(); + } + } + + private class PathVisitor extends ContentVisitor.Default { + + @Override + protected String defaultVisit(Content cntnt) { + throw new UnsupportedOperationException("Not supported for " + cntnt.toString()); + } + + @Override + public String visit(Directory dir) { + return dir.getParentPath(); + } + + @Override + public String visit(Image img) { + return img.getName(); + } + + @Override + public String visit(File fil) { + return fil.getParentPath(); + } + } } \ No newline at end of file diff --git a/Report/src/org/sleuthkit/autopsy/report/reportXML.java b/Report/src/org/sleuthkit/autopsy/report/reportXML.java index db69987822..514e7a236a 100644 --- a/Report/src/org/sleuthkit/autopsy/report/reportXML.java +++ b/Report/src/org/sleuthkit/autopsy/report/reportXML.java @@ -11,6 +11,8 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Map.Entry; +import java.util.logging.Level; +import java.util.logging.Logger; import org.jdom.Comment; import org.jdom.Document; import org.jdom.Document.*; @@ -19,7 +21,11 @@ import org.jdom.output.XMLOutputter; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.ContentVisitor; +import org.sleuthkit.datamodel.Directory; import org.sleuthkit.datamodel.File; +import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.SleuthkitCase; public class reportXML { @@ -59,11 +65,11 @@ public class reportXML { for (Entry> entry : report.entrySet()) { Element artifact = new Element("Artifact"); Long objId = entry.getKey().getObjectID(); - File file = skCase.getFileById(objId); - Long filesize = file.getSize(); + Content cont = skCase.getContentById(objId); + Long filesize = cont.getSize(); artifact.setAttribute("ID", objId.toString()); - artifact.setAttribute("Name", file.getName().toString()); - artifact.setAttribute("Size", filesize.toString()); + artifact.setAttribute("Name", cont.accept(new NameVisitor())); + artifact.setAttribute("Size", filesize.toString()); // Get all the attributes for this guy for (BlackboardAttribute tempatt : entry.getValue()) @@ -142,7 +148,30 @@ public class reportXML { } catch (Exception e){ - + Logger.getLogger(reportXML.class.getName()).log(Level.INFO, "Exception occurred", e); } } + + private class NameVisitor extends ContentVisitor.Default { + + @Override + protected String defaultVisit(Content cntnt) { + throw new UnsupportedOperationException("Not supported for " + cntnt.toString()); + } + + @Override + public String visit(Directory dir) { + return dir.getName(); + } + + @Override + public String visit(Image img) { + return img.getName(); + } + + @Override + public String visit(File fil) { + return fil.getName(); + } + } }