Merge branch 'master' of https://github.com/sleuthkit/autopsy into ie_bookmark_parsing

This commit is contained in:
Jeff Wallace 2013-12-02 15:45:43 -05:00
commit 1c78e0c896
7 changed files with 267 additions and 266 deletions

View File

@ -362,6 +362,7 @@ public class DataResultPanel extends javax.swing.JPanel implements DataResult, C
this.rootNode.addNodeListener(dummyNodeListener);
}
resetTabs(selectedNode);
setupTabs(selectedNode);
if (selectedNode != null) {
@ -369,22 +370,9 @@ public class DataResultPanel extends javax.swing.JPanel implements DataResult, C
this.numberMatchLabel.setText(Integer.toString(childrenCount));
}
this.numberMatchLabel.setVisible(true);
resetTabs(selectedNode);
// set the display on the current active tab
int currentActiveTab = this.dataResultTabbedPanel.getSelectedIndex();
if (currentActiveTab != -1) {
UpdateWrapper drv = viewers.get(currentActiveTab);
drv.setNode(selectedNode);
}
}
private void setupTabs(final Node selectedNode) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
private void setupTabs(Node selectedNode) {
//update/disable tabs based on if supported for this node
int drvC = 0;
for (UpdateWrapper drv : viewers) {
@ -419,9 +407,6 @@ public class DataResultPanel extends javax.swing.JPanel implements DataResult, C
viewers.get(currentActiveTab).setNode(selectedNode);
}
}
});
}
@Override
public void setTitle(String title) {
@ -622,12 +607,22 @@ public class DataResultPanel extends javax.swing.JPanel implements DataResult, C
}
@Override
public void childrenAdded(NodeMemberEvent nme) {
public void childrenAdded(final NodeMemberEvent nme) {
Node[] delta = nme.getDelta();
if (load && containsReal(delta)) {
load = false;
if (SwingUtilities.isEventDispatchThread()) {
setupTabs(nme.getNode());
updateMatches();
} else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setupTabs(nme.getNode());
updateMatches();
}
});
}
}
}
@ -645,15 +640,10 @@ public class DataResultPanel extends javax.swing.JPanel implements DataResult, C
*
*/
private void updateMatches() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (rootNode != null && rootNode.getChildren() != null) {
setNumMatches(rootNode.getChildren().getNodesCount());
}
}
});
}
@Override
public void childrenRemoved(NodeMemberEvent nme) {

View File

@ -278,9 +278,6 @@ public class DataResultViewerTable extends AbstractDataResultViewer {
* @param root The parent Node of the ContentNodes
*/
private void setupTable(final Node root) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
//wrap to filter out children
//note: this breaks the tree view mode in this generic viewer,
//so wrap nodes earlier if want 1 level view
@ -379,8 +376,6 @@ public class DataResultViewerTable extends AbstractDataResultViewer {
ov.getOutline().setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
}
}
});
}
private static Object[][] getRowValues(Node node, int rows) {
// how many rows are we returning
@ -492,11 +487,20 @@ public class DataResultViewerTable extends AbstractDataResultViewer {
}
@Override
public void childrenAdded(NodeMemberEvent nme) {
public void childrenAdded(final NodeMemberEvent nme) {
Node[] delta = nme.getDelta();
if (load && containsReal(delta)) {
load = false;
if (SwingUtilities.isEventDispatchThread()) {
setupTable(nme.getNode());
} else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setupTable(nme.getNode());
}
});
}
}
}

View File

@ -24,12 +24,14 @@ import java.beans.PropertyVetoException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import org.sleuthkit.autopsy.coreutils.Logger;
import javax.swing.AbstractAction;
import javax.swing.SwingWorker;
import org.openide.nodes.AbstractNode;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.view.TreeView;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent;
@ -44,7 +46,14 @@ import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.datamodel.VolumeSystem;
/**
* View the directory content associated with the given Artifact
* View the directory content associated with the given Artifact in the DataResultViewer.
*
* 1. Expands the Directory Tree to the location of the parent Node of the
* associated Content.
* 2. Selects the parent Node of the associated Content in the Directory Tree,
* which causes the parent Node's Children to be visible in the DataResultViewer.
* 3. Waits for all the Children to be contentNode in the DataResultViewer and
* selects the Node that represents the Content.
*/
public class ViewContextAction extends AbstractAction {
@ -81,60 +90,115 @@ public class ViewContextAction extends AbstractAction {
Node generated = new DirectoryTreeFilterNode(new AbstractNode(new RootContentChildren(hierarchy)), true);
Children genChilds = generated.getChildren();
final DirectoryTreeTopComponent directoryTree = DirectoryTreeTopComponent.findInstance();
TreeView tree = directoryTree.getTree();
ExplorerManager man = directoryTree.getExplorerManager();
Node dirRoot = man.getRootContext();
Children dirChilds = dirRoot.getChildren();
Node imagesRoot = dirChilds.findChild(DataSourcesNode.NAME);
dirChilds = imagesRoot.getChildren();
final DirectoryTreeTopComponent dirTree = DirectoryTreeTopComponent.findInstance();
TreeView dirTreeView = dirTree.getTree();
ExplorerManager dirTreeExplorerManager = dirTree.getExplorerManager();
Node dirTreeRootNode = dirTreeExplorerManager.getRootContext();
Children dirChilds = dirTreeRootNode.getChildren();
Children currentChildren = dirChilds.findChild(DataSourcesNode.NAME).getChildren();
Node dirExplored = null;
// Find the parent node of the content in the directory tree
for (int i = 0; i < genChilds.getNodesCount() - 1; i++) {
Node currentGeneratedNode = genChilds.getNodeAt(i);
for (int j = 0; j < dirChilds.getNodesCount(); j++) {
Node currentDirectoryTreeNode = dirChilds.getNodeAt(j);
for (int j = 0; j < currentChildren.getNodesCount(); j++) {
Node currentDirectoryTreeNode = currentChildren.getNodeAt(j);
if (currentGeneratedNode.getDisplayName().equals(currentDirectoryTreeNode.getDisplayName())) {
dirExplored = currentDirectoryTreeNode;
tree.expandNode(dirExplored);
dirChilds = currentDirectoryTreeNode.getChildren();
dirTreeView.expandNode(dirExplored);
currentChildren = currentDirectoryTreeNode.getChildren();
break;
}
}
}
// Set the parent node of the content as the selection in the
// directory tree
try {
if (dirExplored != null) {
tree.expandNode(dirExplored);
man.setExploredContextAndSelection(dirExplored, new Node[]{dirExplored});
dirTreeView.expandNode(dirExplored);
dirTreeExplorerManager.setExploredContextAndSelection(dirExplored, new Node[]{dirExplored});
}
} catch (PropertyVetoException ex) {
logger.log(Level.WARNING, "Couldn't set selected node", ex);
}
// Another thread is needed because we have to wait for dataResult to populate
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
DataResultTopComponent dataResult = directoryTree.getDirectoryListing();
Node resultRoot = dataResult.getRootNode();
Children resultChilds = resultRoot.getChildren();
Node generated = content.accept(new RootContentChildren.CreateSleuthkitNodeVisitor());
for (int i = 0; i < resultChilds.getNodesCount(); i++) {
Node current = resultChilds.getNodeAt(i);
if (generated.getName().equals(current.getName())) {
dataResult.requestActive();
dataResult.setSelectedNodes(new Node[]{current});
DataResultTopComponent dataResultTC = dirTree.getDirectoryListing();
Node currentRootNodeOfDataResultTC = dataResultTC.getRootNode();
Node contentNode = content.accept(new RootContentChildren.CreateSleuthkitNodeVisitor());
new SelectionWorker(dataResultTC, contentNode.getName(), currentRootNodeOfDataResultTC).execute();
}
});
}
});
}
/**
* Waits for a Node's children to be generated, regardless of whether they
* are lazily loaded, then sets the correct selection in a specified
* DataResultTopComponent.
*/
private class SelectionWorker extends SwingWorker<Node[], Integer> {
DataResultTopComponent dataResultTC;
String nameOfNodeToSelect;
Node originalRootNodeOfDataResultTC;
SelectionWorker(DataResultTopComponent dataResult, String nameToSelect, Node originalRoot) {
this.dataResultTC = dataResult;
this.nameOfNodeToSelect = nameToSelect;
this.originalRootNodeOfDataResultTC = originalRoot;
}
@Override
protected Node[] doInBackground() throws Exception {
// Calls to Children::getNodes(true) block until all child Nodes have
// been created, regardless of whether they are created lazily.
// This means that this call will return the actual child Nodes
// and will *NEVER* return a proxy wait Node. This is done on the
// background thread to ensure we are not hanging the ui as it could
// be a lengthy operation.
return originalRootNodeOfDataResultTC.getChildren().getNodes(true);
}
@Override
protected void done() {
Node[] nodesDisplayedInDataResultViewer;
try {
nodesDisplayedInDataResultViewer = get();
} catch (InterruptedException | ExecutionException ex) {
logger.log(Level.WARNING, "Failed to get nodes in selection worker.", ex);
return;
}
// It is possible the user selected a different Node to be displayed
// in the DataResultViewer while the child Nodes were being generated.
// In that case, we don't want to set the selection because it the
// nodes returned from get() won't be in the DataResultTopComponent's
// ExplorerManager. If we did call setSelectedNodes, it would clear
// the current selection, which is not good.
if (dataResultTC.getRootNode().equals(originalRootNodeOfDataResultTC) == false) {
return;
}
// Find the correct node to select from the nodes that are displayed
// in the data result viewer and set it as the selection of the
// DataResultTopComponent.
for (Node node : nodesDisplayedInDataResultViewer) {
if (nameOfNodeToSelect.equals(node.getName())) {
dataResultTC.requestActive();
dataResultTC.setSelectedNodes(new Node[]{node});
DirectoryTreeTopComponent.getDefault().fireViewerComplete();
break;
}
}
}
});
}
});
}
/**

View File

@ -38,7 +38,6 @@ KeywordSearchPanel.settingsLabel.text=
KeywordSearchListsViewerPanel.searchAddButton.text=Search
KeywordSearchListsViewerPanel.manageListsButton.text=Manage Lists
KeywordSearchListsViewerPanel.ingestIndexLabel.text=Files Indexed:
KeywordSearchEditListPanel.selectorsCombo.toolTipText=Regular Expression selector type (optional)
KeywordSearchPanel.searchButton.text=
KeywordSearchPanel.cutMenuItem.text=Cut
KeywordSearchPanel.copyMenuItem.text=Copy

View File

@ -26,10 +26,10 @@ import java.util.List;
import java.util.logging.Level;
import org.sleuthkit.autopsy.coreutils.Logger;
import net.htmlparser.jericho.Attributes;
import net.htmlparser.jericho.Renderer;
import net.htmlparser.jericho.Source;
import net.htmlparser.jericho.StartTag;
import net.htmlparser.jericho.StartTagType;
import net.htmlparser.jericho.TextExtractor;
/**
* Uses Jericho HTML Parser to create a Reader for output, consisting of
@ -46,6 +46,15 @@ public class JerichoParserWrapper {
this.in = in;
}
/**
* Returns the reader, initialized in parse(), which will be
* null if parse() is not called or if parse() throws an error.
* @return Reader
*/
public Reader getReader() {
return reader;
}
/**
* Initialize the reader by parsing the InputStream, adding it to StringBuilder,
* and creating a StringReader from it.
@ -57,7 +66,7 @@ public class JerichoParserWrapper {
Source source = new Source(in);
source.fullSequentialParse();
StringBuilder text = new StringBuilder();
String text;
StringBuilder scripts = new StringBuilder();
StringBuilder links = new StringBuilder();
StringBuilder images = new StringBuilder();
@ -69,13 +78,7 @@ public class JerichoParserWrapper {
int numComments = 1;
int numOthers = 1;
// Extract text from the source
TextExtractor extractor = new TextExtractor(source);
// Split it at every ". " but keep the .
String[] lines = extractor.toString().split("(?<=\\. )");
for(String s : lines) {
text.append(s).append("\n");
}
text = renderHTMLAsPlainText(source);
// Get all the tags in the source
List<StartTag> tags = source.getAllStartTags();
@ -113,7 +116,7 @@ public class JerichoParserWrapper {
}
}
out.append(text.toString()).append("\n");
out.append(text).append("\n\n");
out.append("----------NONVISIBLE TEXT----------\n\n");
if(numScripts>1) {
@ -139,13 +142,14 @@ public class JerichoParserWrapper {
}
}
/**
* Returns the reader, initialized in parse(), which will be
* null if parse() is not called or if parse() throws an error.
* @return Reader
*/
public Reader getReader() {
return reader;
// Extract text from the source, nicely formatted with whitespace and
// newlines where appropriate.
private String renderHTMLAsPlainText(Source source) {
Renderer renderer = source.getRenderer();
renderer.setNewLine("\n");
renderer.setIncludeHyperlinkURLs(false);
renderer.setDecorateFontStyles(false);
renderer.setIncludeAlternateText(false);
return renderer.toString();
}
}

View File

@ -206,20 +206,16 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" max="-2" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="addWordField" max="32767" attributes="0"/>
<Component id="addWordField" min="-2" pref="216" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="addWordButton" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="deleteWordButton" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="chRegex" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="selectorsCombo" min="-2" pref="154" max="-2" attributes="0"/>
</Group>
<Component id="chRegex" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
@ -234,10 +230,7 @@
<Component id="addWordButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="7" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="selectorsCombo" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="chRegex" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="chRegex" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="7" max="-2" attributes="0"/>
<Component id="deleteWordButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
@ -276,19 +269,6 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chRegexActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="selectorsCombo">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/keywordsearch/Bundle.properties" key="KeywordSearchEditListPanel.selectorsCombo.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JComboBox&lt;String&gt;()"/>
</AuxValues>
</Component>
<Component class="javax.swing.JButton" name="deleteWordButton">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">

View File

@ -126,18 +126,6 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
break;
}
}
if (selected > -1 && selected < keywords.size()) {
Keyword k = keywords.get(selected);
BlackboardAttribute.ATTRIBUTE_TYPE selType = k.getType();
if (selType != null) {
selectorsCombo.setSelectedIndex(selType.ordinal());
} else {
//set to none (last item)
selectorsCombo.setSelectedIndex(selectorsCombo.getItemCount() - 1);
}
}
}
}
});
@ -195,15 +183,6 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
}
}
});
//selectors
selectorsCombo.setEnabled(false);
for (BlackboardAttribute.ATTRIBUTE_TYPE type : BlackboardAttribute.ATTRIBUTE_TYPE.values()) {
selectorsCombo.<String>addItem(type.getDisplayName());
}
selectorsCombo.<String>addItem("<none>");
selectorsCombo.setSelectedIndex(selectorsCombo.getItemCount() - 1);
}
/**
@ -251,7 +230,6 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
chRegex.setEnabled(listSet && (!ingestOngoing || !inIngest) && !isLocked);
keywordOptionsLabel.setEnabled(addWordButton.isEnabled() || chRegex.isEnabled());
keywordOptionsSeparator.setEnabled(addWordButton.isEnabled() || chRegex.isEnabled());
selectorsCombo.setEnabled(listSet && (!ingestOngoing || !inIngest) && !isLocked && chRegex.isSelected());
useForIngestCheckbox.setEnabled(listSet && (!ingestOngoing || !inIngest));
useForIngestCheckbox.setSelected(useForIngest);
ingestMessagesCheckbox.setEnabled(useForIngestCheckbox.isEnabled() && useForIngestCheckbox.isSelected());
@ -295,7 +273,6 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
addWordButton = new javax.swing.JButton();
addWordField = new javax.swing.JTextField();
chRegex = new javax.swing.JCheckBox();
selectorsCombo = new javax.swing.JComboBox<String>();
deleteWordButton = new javax.swing.JButton();
ingestMessagesCheckbox = new javax.swing.JCheckBox();
keywordsLabel = new javax.swing.JLabel();
@ -359,8 +336,6 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
}
});
selectorsCombo.setToolTipText(org.openide.util.NbBundle.getMessage(KeywordSearchEditListPanel.class, "KeywordSearchEditListPanel.selectorsCombo.toolTipText")); // NOI18N
deleteWordButton.setText(org.openide.util.NbBundle.getMessage(KeywordSearchEditListPanel.class, "KeywordSearchEditListPanel.deleteWordButton.text")); // NOI18N
deleteWordButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -373,17 +348,14 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
addKeywordPanelLayout.setHorizontalGroup(
addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(addKeywordPanelLayout.createSequentialGroup()
.addGroup(addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(addKeywordPanelLayout.createSequentialGroup()
.addComponent(addWordField)
.addComponent(addWordField, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(addWordButton))
.addComponent(deleteWordButton))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, addKeywordPanelLayout.createSequentialGroup()
.addComponent(chRegex)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(selectorsCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(chRegex, javax.swing.GroupLayout.Alignment.LEADING))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
addKeywordPanelLayout.setVerticalGroup(
@ -394,9 +366,7 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
.addComponent(addWordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(addWordButton))
.addGap(7, 7, 7)
.addGroup(addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(selectorsCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(chRegex))
.addComponent(chRegex)
.addGap(7, 7, 7)
.addComponent(deleteWordButton)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
@ -515,14 +485,6 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
String newWord = addWordField.getText().trim();
boolean isLiteral = !chRegex.isSelected();
final Keyword keyword = new Keyword(newWord, isLiteral);
if (!isLiteral) {
//get selector
int selI = this.selectorsCombo.getSelectedIndex();
if (selI < this.selectorsCombo.getItemCount() - 1) {
BlackboardAttribute.ATTRIBUTE_TYPE selector = BlackboardAttribute.ATTRIBUTE_TYPE.values()[selI];
keyword.setType(selector);
}
}
if (newWord.equals("")) {
return;
@ -620,7 +582,6 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
}//GEN-LAST:event_exportButtonActionPerformed
private void chRegexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chRegexActionPerformed
selectorsCombo.setEnabled(chRegex.isEnabled() && chRegex.isSelected());
}//GEN-LAST:event_chRegexActionPerformed
private void useForIngestCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useForIngestCheckboxActionPerformed
@ -659,7 +620,6 @@ private void useForIngestCheckboxActionPerformed(java.awt.event.ActionEvent evt)
private javax.swing.JPopupMenu rightClickMenu;
private javax.swing.JButton saveListButton;
private javax.swing.JMenuItem selectAllMenuItem;
private javax.swing.JComboBox selectorsCombo;
private javax.swing.JCheckBox useForIngestCheckbox;
// End of variables declaration//GEN-END:variables