From 0a31d56a5d991b149c878a4bc688e5a9c3145dd7 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Tue, 12 May 2015 12:02:34 -0400 Subject: [PATCH 01/79] Media player NPE fixed --- .../autopsy/corecomponents/FXVideoPanel.java | 82 ++++++++++--------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java index 809be1da89..d7fa6d4027 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java @@ -478,26 +478,28 @@ public class FXVideoPanel extends MediaViewVideoPanel { pauseButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { - Status status = mediaPlayer.getStatus(); + if (mediaPlayer != null) { + Status status = mediaPlayer.getStatus(); - switch (status) { - // If playing, pause - case PLAYING: - mediaPlayer.pause(); - break; - // If ready, paused or stopped, continue playing - case READY: - case PAUSED: - case STOPPED: - mediaPlayer.play(); - break; - default: - logger.log(Level.INFO, "MediaPlayer in unexpected state: " + status.toString()); //NON-NLS - // If the MediaPlayer is in an unexpected state, stop playback. - mediaPlayer.stop(); - setInfoLabelText(NbBundle.getMessage(this.getClass(), - "FXVideoPanel.pauseButton.infoLabel.playbackErr")); - break; + switch (status) { + // If playing, pause + case PLAYING: + mediaPlayer.pause(); + break; + // If ready, paused or stopped, continue playing + case READY: + case PAUSED: + case STOPPED: + mediaPlayer.play(); + break; + default: + logger.log(Level.INFO, "MediaPlayer in unexpected state: " + status.toString()); //NON-NLS + // If the MediaPlayer is in an unexpected state, stop playback. + mediaPlayer.stop(); + setInfoLabelText(NbBundle.getMessage(this.getClass(), + "FXVideoPanel.pauseButton.infoLabel.playbackErr")); + break; + } } } }); @@ -505,14 +507,16 @@ public class FXVideoPanel extends MediaViewVideoPanel { stopButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { - mediaPlayer.stop(); + if (mediaPlayer != null) { + mediaPlayer.stop(); + } } }); progressSlider.valueProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable o) { - if (progressSlider.isValueChanging()) { + if (progressSlider.isValueChanging() && mediaPlayer != null) { mediaPlayer.seek(duration.multiply(progressSlider.getValue() / 100.0)); } } @@ -634,17 +638,19 @@ public class FXVideoPanel extends MediaViewVideoPanel { @Override public void run() { - duration = mediaPlayer.getMedia().getDuration(); - long durationInMillis = (long) mediaPlayer.getMedia().getDuration().toMillis(); + if (mediaPlayer != null) { + duration = mediaPlayer.getMedia().getDuration(); + long durationInMillis = (long) mediaPlayer.getMedia().getDuration().toMillis(); - // pick out the total hours, minutes, seconds - long durationSeconds = (int) durationInMillis / 1000; - totalHours = (int) durationSeconds / 3600; - durationSeconds -= totalHours * 3600; - totalMinutes = (int) durationSeconds / 60; - durationSeconds -= totalMinutes * 60; - totalSeconds = (int) durationSeconds; - updateProgress(); + // pick out the total hours, minutes, seconds + long durationSeconds = (int) durationInMillis / 1000; + totalHours = (int) durationSeconds / 3600; + durationSeconds -= totalHours * 3600; + totalMinutes = (int) durationSeconds / 60; + durationSeconds -= totalMinutes * 60; + totalSeconds = (int) durationSeconds; + updateProgress(); + } } } @@ -657,12 +663,14 @@ public class FXVideoPanel extends MediaViewVideoPanel { @Override public void run() { - Duration beginning = mediaPlayer.getStartTime(); - mediaPlayer.stop(); - mediaPlayer.pause(); - pauseButton.setText(PLAY_TEXT); - updateSlider(beginning); - updateTime(beginning); + if (mediaPlayer != null) { + Duration beginning = mediaPlayer.getStartTime(); + mediaPlayer.stop(); + mediaPlayer.pause(); + pauseButton.setText(PLAY_TEXT); + updateSlider(beginning); + updateTime(beginning); + } } } From 0901b8b852c960e447b543308f61030b2dc5c8d3 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Wed, 13 May 2015 11:42:41 -0400 Subject: [PATCH 02/79] OOB on selecting no nodes is handled --- .../autopsy/directorytree/CollapseAction.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/CollapseAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/CollapseAction.java index d554f63e04..5ed8778618 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/CollapseAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/CollapseAction.java @@ -44,7 +44,14 @@ class CollapseAction extends AbstractAction { // Collapse all BeanTreeView tree = DirectoryTreeTopComponent.findInstance().getTree(); - collapseAll(tree, selectedNode[0]); + if(selectedNode.length != 0) { + collapseSelectedNode(tree, selectedNode[0]); + } else { + // If no node is selected, all the level-2 nodes (children of the + // root node) are collapsed. + for(Node childOfRoot: em.getRootContext().getChildren().getNodes()) + collapseSelectedNode(tree, childOfRoot); + } } /** @@ -53,13 +60,13 @@ class CollapseAction extends AbstractAction { * @param tree the given tree * @param currentNode the current selectedNode */ - private void collapseAll(BeanTreeView tree, Node currentNode) { + private void collapseSelectedNode(BeanTreeView tree, Node currentNode) { Children c = currentNode.getChildren(); for (Node next : c.getNodes()) { if (tree.isExpanded(next)) { - this.collapseAll(tree, next); + this.collapseSelectedNode(tree, next); } } From fc3fd857f28cca77d7edc9e8527da85da32f1102 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Wed, 13 May 2015 16:53:40 -0400 Subject: [PATCH 03/79] supported extensions revised --- Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java index 809be1da89..1353430ef0 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java @@ -79,7 +79,7 @@ import org.sleuthkit.datamodel.TskData; }) public class FXVideoPanel extends MediaViewVideoPanel { - private static final String[] EXTENSIONS = new String[]{".mov", ".m4v", ".flv", ".mp4", ".mpg", ".mpeg"}; //NON-NLS + private static final String[] EXTENSIONS = new String[]{".m4v", ".fxm", ".flv", ".m3u8", ".mp4", ".aif", ".aiff", ".mp3", "m4a", ".wav"}; //NON-NLS private static final List MIMETYPES = Arrays.asList("audio/x-aiff", "video/x-javafx", "video/x-flv", "application/vnd.apple.mpegurl", " audio/mpegurl", "audio/mpeg", "video/mp4", "audio/x-m4a", "video/x-m4v", "audio/x-wav"); //NON-NLS private static final Logger logger = Logger.getLogger(MediaViewVideoPanel.class.getName()); From 384bcd297f279c46c78f13b19c1539a8c9af27dc Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Thu, 14 May 2015 16:54:52 -0400 Subject: [PATCH 04/79] NPE in case of removed photorec carver job handled --- .../modules/photoreccarver/PhotoRecCarverFileIngestModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java index 1bcd4791c7..ec4beae595 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java @@ -239,7 +239,7 @@ final class PhotoRecCarverFileIngestModule implements FileIngestModule { */ @Override public void shutDown() { - if (refCounter.decrementAndGet(this.context.getJobId()) == 0) { + if (this.context != null && refCounter.decrementAndGet(this.context.getJobId()) == 0) { try { // The last instance of this module for an ingest job cleans out // the working paths map entry for the job and deletes the temp dir. From e1a9084e7adfac3e9a4615067a1d3c3e5f6f0a0d Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Fri, 15 May 2015 10:52:40 -0400 Subject: [PATCH 05/79] Run ingest option provided at appropriate directory tree nodes --- .../DirectoryTreeFilterNode.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java index 15da98c0b7..50417a1ec3 100755 --- a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java @@ -39,6 +39,7 @@ import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.Directory; import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.datamodel.VirtualDirectory; /** * This class sets the actions for the nodes in the directory tree and creates @@ -113,8 +114,22 @@ class DirectoryTreeFilterNode extends FilterNode { NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.openFileSrcByAttr.text"))); } - //ingest action - actions.add(new AbstractAction( + + VirtualDirectory virtualDirectory = this.getLookup().lookup(VirtualDirectory.class); + // determine if the virtualDireory is at root-level (Logical File Set). + boolean isRootVD = false; + if(virtualDirectory != null) { + try { + if(virtualDirectory.getParent() == null) + isRootVD = true; + } catch (TskCoreException ex) { + logger.log(Level.WARNING, "Error determining the parent of the virtual directory", ex); // NON-NLS + } + } + + //ingest action only if the selected node is img node or a root level virtual directory. + if(img != null || isRootVD) { + actions.add(new AbstractAction( NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.runIngestMods.text")) { @Override public void actionPerformed(ActionEvent e) { @@ -122,6 +137,7 @@ class DirectoryTreeFilterNode extends FilterNode { ingestDialog.display(); } }); + } } //check if delete actions should be added From aa8bd589394fe1d1a54b27ac66d3c94e2eb96fce Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Fri, 15 May 2015 10:59:21 -0400 Subject: [PATCH 06/79] Open file search by attribs option available for logical FS --- .../directorytree/DirectoryTreeFilterNode.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java index 50417a1ec3..9de9257ce3 100755 --- a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java @@ -107,13 +107,7 @@ class DirectoryTreeFilterNode extends FilterNode { actions.add(ExtractAction.getInstance()); } - // file search action final Image img = this.getLookup().lookup(Image.class); - if (img != null) { - actions.add(new FileSearchAction( - NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.openFileSrcByAttr.text"))); - } - VirtualDirectory virtualDirectory = this.getLookup().lookup(VirtualDirectory.class); // determine if the virtualDireory is at root-level (Logical File Set). @@ -127,6 +121,12 @@ class DirectoryTreeFilterNode extends FilterNode { } } + // file search action only if the selected node is img node or a root level virtual directory. + if (img != null || isRootVD) { + actions.add(new FileSearchAction( + NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.openFileSrcByAttr.text"))); + } + //ingest action only if the selected node is img node or a root level virtual directory. if(img != null || isRootVD) { actions.add(new AbstractAction( From 019d77f3750a472b9a95c5cc7f5125525d460e6f Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Fri, 15 May 2015 12:23:14 -0400 Subject: [PATCH 07/79] bail for thumbnail detection if non-supported mime type. --- .../autopsy/coreutils/ImageUtils.java | 55 ++++++++++++------- .../autopsy/imagegallery/ThumbnailCache.java | 1 + 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java index b5944cd2b4..b631602dc3 100755 --- a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java @@ -33,11 +33,9 @@ import java.util.List; import java.util.logging.Level; import javax.imageio.ImageIO; import javax.swing.ImageIcon; -import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.corelibs.ScalrWrapper; import org.sleuthkit.datamodel.AbstractFile; -import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE; import org.sleuthkit.datamodel.Content; @@ -55,7 +53,13 @@ public class ImageUtils { private static final Logger logger = Logger.getLogger(ImageUtils.class.getName()); private static final Image DEFAULT_ICON = new ImageIcon("/org/sleuthkit/autopsy/images/file-icon.png").getImage(); //NON-NLS private static final List SUPP_EXTENSIONS = Arrays.asList(ImageIO.getReaderFileSuffixes()); - private static final List SUPP_MIME_TYPES = Arrays.asList(ImageIO.getReaderMIMETypes()); + private static final List SUPP_MIME_TYPES; + + static { + SUPP_MIME_TYPES = Arrays.asList(ImageIO.getReaderMIMETypes()); + //SUPP_MIME_TYPES.add("image/x-ms-bmp"); + } + /** * Get the default Icon, which is the icon for a file. * @return @@ -88,14 +92,17 @@ public class ImageUtils { return true; } } + // if the file type is known and we don't support it, bail + if (attributes.size() > 0) { + return false; + } } catch (TskCoreException ex) { logger.log(Level.WARNING, "Error while getting file signature from blackboard.", ex); //NON-NLS } - final String extension = f.getNameExtension(); - // if we have an extension, check it + final String extension = f.getNameExtension(); if (extension.equals("") == false) { // Note: thumbnail generator only supports JPG, GIF, and PNG for now if (SUPP_EXTENSIONS.contains(extension)) { @@ -109,7 +116,8 @@ public class ImageUtils { /** - * Get an icon of a specified size. + * Get a thumbnail of a specified size. Generates the image if it is + * not already cached. * * @param content * @param iconSize @@ -118,6 +126,7 @@ public class ImageUtils { public static Image getIcon(Content content, int iconSize) { Image icon; // If a thumbnail file is already saved locally + // @@@ Bug here in that we do not refer to size in the cache. File file = getFile(content.getId()); if (file.exists()) { try { @@ -125,7 +134,7 @@ public class ImageUtils { if (bicon == null) { icon = DEFAULT_ICON; } else if (bicon.getWidth() != iconSize) { - icon = generateAndSaveIcon(content, iconSize); + icon = generateAndSaveIcon(content, iconSize, file); } else { icon = bicon; } @@ -134,18 +143,17 @@ public class ImageUtils { icon = DEFAULT_ICON; } } else { // Make a new icon - icon = generateAndSaveIcon(content, iconSize); + icon = generateAndSaveIcon(content, iconSize, file); } return icon; } /** - * Get the cached file of the icon. Generates the icon and its file if it - * doesn't already exist, so this method guarantees to return a file that - * exists. + * Get a thumbnail of a specified size. Generates the image if it is + * not already cached. * @param content * @param iconSize - * @return + * @return File object for cached image. Is guaranteed to exist. */ public static File getIconFile(Content content, int iconSize) { if (getIcon(content, iconSize) != null) { @@ -155,13 +163,12 @@ public class ImageUtils { } /** - * Get the cached file of the content object with the given id. - * - * The returned file may not exist. + * Get a file object for where the cached icon should exist. The returned file may not exist. * * @param id * @return */ + // TODO: This should be private and be renamed to something like getCachedThumbnailLocation(). public static File getFile(long id) { return new File(Case.getCurrentCase().getCacheDirectory() + File.separator + id + ".png"); } @@ -223,18 +230,24 @@ public class ImageUtils { } - private static Image generateAndSaveIcon(Content content, int iconSize) { + /** + * Generate an icon and save it to specified location. + * @param content File to generate icon for + * @param iconSize + * @param saveFile Location to save thumbnail to + * @return Generated icon or null on error + */ + private static Image generateAndSaveIcon(Content content, int iconSize, File saveFile) { Image icon = null; try { icon = generateIcon(content, iconSize); if (icon == null) { return DEFAULT_ICON; } else { - File f = getFile(content.getId()); - if (f.exists()) { - f.delete(); + if (saveFile.exists()) { + saveFile.delete(); } - ImageIO.write((BufferedImage) icon, "png", getFile(content.getId())); //NON-NLS + ImageIO.write((BufferedImage) icon, "png", saveFile); //NON-NLS } } catch (IOException ex) { logger.log(Level.WARNING, "Could not write cache thumbnail: " + content, ex); //NON-NLS @@ -243,7 +256,7 @@ public class ImageUtils { } /* - * Generate a scaled image + * Generate and return a scaled image */ private static BufferedImage generateIcon(Content content, int iconSize) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ThumbnailCache.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ThumbnailCache.java index ee7c74e981..e22eb75488 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ThumbnailCache.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ThumbnailCache.java @@ -153,6 +153,7 @@ public enum ThumbnailCache { } private static File getCacheFile(long id) { + // @@@ should use ImageUtils.getFile(); return new File(Case.getCurrentCase().getCacheDirectory() + File.separator + id + ".png"); } From f63725d64f30e12ed41aed491722cb45beaf2398 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Fri, 15 May 2015 13:10:47 -0400 Subject: [PATCH 08/79] the x-ms-bmp formt added --- Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java index b631602dc3..919c4dfc1d 100755 --- a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java @@ -56,8 +56,11 @@ public class ImageUtils { private static final List SUPP_MIME_TYPES; static { - SUPP_MIME_TYPES = Arrays.asList(ImageIO.getReaderMIMETypes()); - //SUPP_MIME_TYPES.add("image/x-ms-bmp"); + SUPP_MIME_TYPES = new ArrayList(); + for (String mimeType : Arrays.asList(ImageIO.getReaderMIMETypes())) { + SUPP_MIME_TYPES.add(mimeType); + } + SUPP_MIME_TYPES.add("image/x-ms-bmp"); } /** From 1174a7798e8cab9f0ed20ce4a0b9fa6d5ccd1f63 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Fri, 15 May 2015 13:44:13 -0400 Subject: [PATCH 09/79] minor directorytreefilternode.getActions() refactoring --- .../DirectoryTreeFilterNode.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java index 9de9257ce3..dbbb906a4e 100755 --- a/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/DirectoryTreeFilterNode.java @@ -112,31 +112,29 @@ class DirectoryTreeFilterNode extends FilterNode { VirtualDirectory virtualDirectory = this.getLookup().lookup(VirtualDirectory.class); // determine if the virtualDireory is at root-level (Logical File Set). boolean isRootVD = false; - if(virtualDirectory != null) { + if (virtualDirectory != null) { try { - if(virtualDirectory.getParent() == null) + if (virtualDirectory.getParent() == null) { isRootVD = true; + } } catch (TskCoreException ex) { logger.log(Level.WARNING, "Error determining the parent of the virtual directory", ex); // NON-NLS } } - // file search action only if the selected node is img node or a root level virtual directory. + // 'run ingest' action and 'file search' action are added only if the + // selected node is img node or a root level virtual directory. if (img != null || isRootVD) { actions.add(new FileSearchAction( NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.openFileSrcByAttr.text"))); - } - - //ingest action only if the selected node is img node or a root level virtual directory. - if(img != null || isRootVD) { actions.add(new AbstractAction( - NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.runIngestMods.text")) { - @Override - public void actionPerformed(ActionEvent e) { - final RunIngestModulesDialog ingestDialog = new RunIngestModulesDialog(Collections.singletonList(content)); - ingestDialog.display(); - } - }); + NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.runIngestMods.text")) { + @Override + public void actionPerformed(ActionEvent e) { + final RunIngestModulesDialog ingestDialog = new RunIngestModulesDialog(Collections.singletonList(content)); + ingestDialog.display(); + } + }); } } From b2d8c2fc504dadfdaf42a9aaed1fa377ea0b7495 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Fri, 15 May 2015 14:56:13 -0400 Subject: [PATCH 10/79] Added WizardPathValidator interface and service provider lookup --- .../AddImageWizardChooseDataSourceVisual.java | 11 ++++ .../WizardPathValidator.java | 52 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java index b4c15cc0e2..624c38383f 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java @@ -38,6 +38,7 @@ import javax.swing.event.DocumentEvent; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; +import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; import org.sleuthkit.autopsy.coreutils.Logger; /** @@ -55,6 +56,8 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { private Map datasourceProcessorsMap = new HashMap<>(); + List pathValidatorList = new ArrayList<>(); + List coreDSPTypes = new ArrayList<>(); /** @@ -75,6 +78,8 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { typePanel.setLayout(new BorderLayout()); discoverDataSourceProcessors(); + + discoverWizardPathValidators(); // set up the DSP type combobox typeComboBox.removeAllItems(); @@ -128,6 +133,12 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { } } } + + private void discoverWizardPathValidators() { + for (WizardPathValidator pathValidator : Lookup.getDefault().lookupAll(WizardPathValidator.class)) { + pathValidatorList.add(pathValidator); + } + } private void dspSelectionChanged() { // update the current panel to selection diff --git a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java new file mode 100644 index 0000000000..9cebb1411d --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java @@ -0,0 +1,52 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2011-2014 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.corecomponentinterfaces; + +/* + * Defines an interface used by the Add DataSource wizard to validate path for selected + * case and/or data source. + * + * Different Autopsy implementations and modes may have its unique attributes and + * may need to be processed differently. + * + * The WizardPathValidator interface defines a uniform mechanism for the Autopsy UI + * to: + * - Validate path for selected case. + * - Validate path for selected data source. + */ +public interface WizardPathValidator { + + /** + * Validates case path. + * + * @param path Absolute path to case file. + * @return String Error message if path is invalid, empty string otherwise. + * + */ + String validateCasePath(String path); + + /** + * Validates data source path. + * + * @param path Absolute path to data source file. + * @return String Error message if path is invalid, empty string otherwise. + * + */ + String validateDataSourcePath(String path); +} From 1950f45425ce120c2c5acb64bc018e0be03d4e4b Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Fri, 15 May 2015 15:20:21 -0400 Subject: [PATCH 11/79] fxvideopanel code refactored --- .../autopsy/corecomponents/FXVideoPanel.java | 99 ++++++++++--------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java index d7fa6d4027..4dcc9a2ab3 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java @@ -478,28 +478,29 @@ public class FXVideoPanel extends MediaViewVideoPanel { pauseButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { - if (mediaPlayer != null) { - Status status = mediaPlayer.getStatus(); + if (mediaPlayer == null) + return; - switch (status) { - // If playing, pause - case PLAYING: - mediaPlayer.pause(); - break; - // If ready, paused or stopped, continue playing - case READY: - case PAUSED: - case STOPPED: - mediaPlayer.play(); - break; - default: - logger.log(Level.INFO, "MediaPlayer in unexpected state: " + status.toString()); //NON-NLS - // If the MediaPlayer is in an unexpected state, stop playback. - mediaPlayer.stop(); - setInfoLabelText(NbBundle.getMessage(this.getClass(), - "FXVideoPanel.pauseButton.infoLabel.playbackErr")); - break; - } + Status status = mediaPlayer.getStatus(); + + switch (status) { + // If playing, pause + case PLAYING: + mediaPlayer.pause(); + break; + // If ready, paused or stopped, continue playing + case READY: + case PAUSED: + case STOPPED: + mediaPlayer.play(); + break; + default: + logger.log(Level.INFO, "MediaPlayer in unexpected state: " + status.toString()); //NON-NLS + // If the MediaPlayer is in an unexpected state, stop playback. + mediaPlayer.stop(); + setInfoLabelText(NbBundle.getMessage(this.getClass(), + "FXVideoPanel.pauseButton.infoLabel.playbackErr")); + break; } } }); @@ -507,16 +508,20 @@ public class FXVideoPanel extends MediaViewVideoPanel { stopButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { - if (mediaPlayer != null) { - mediaPlayer.stop(); - } + if (mediaPlayer == null) + return; + + mediaPlayer.stop(); } }); progressSlider.valueProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable o) { - if (progressSlider.isValueChanging() && mediaPlayer != null) { + if(mediaPlayer == null) + return; + + if (progressSlider.isValueChanging()) { mediaPlayer.seek(duration.multiply(progressSlider.getValue() / 100.0)); } } @@ -563,6 +568,8 @@ public class FXVideoPanel extends MediaViewVideoPanel { * media. */ private void updateProgress() { + if(mediaPlayer == null) + return; Duration currentTime = mediaPlayer.getCurrentTime(); updateSlider(currentTime); updateTime(currentTime); @@ -638,19 +645,20 @@ public class FXVideoPanel extends MediaViewVideoPanel { @Override public void run() { - if (mediaPlayer != null) { - duration = mediaPlayer.getMedia().getDuration(); - long durationInMillis = (long) mediaPlayer.getMedia().getDuration().toMillis(); + if (mediaPlayer == null) + return; + + duration = mediaPlayer.getMedia().getDuration(); + long durationInMillis = (long) mediaPlayer.getMedia().getDuration().toMillis(); - // pick out the total hours, minutes, seconds - long durationSeconds = (int) durationInMillis / 1000; - totalHours = (int) durationSeconds / 3600; - durationSeconds -= totalHours * 3600; - totalMinutes = (int) durationSeconds / 60; - durationSeconds -= totalMinutes * 60; - totalSeconds = (int) durationSeconds; - updateProgress(); - } + // pick out the total hours, minutes, seconds + long durationSeconds = (int) durationInMillis / 1000; + totalHours = (int) durationSeconds / 3600; + durationSeconds -= totalHours * 3600; + totalMinutes = (int) durationSeconds / 60; + durationSeconds -= totalMinutes * 60; + totalSeconds = (int) durationSeconds; + updateProgress(); } } @@ -663,14 +671,15 @@ public class FXVideoPanel extends MediaViewVideoPanel { @Override public void run() { - if (mediaPlayer != null) { - Duration beginning = mediaPlayer.getStartTime(); - mediaPlayer.stop(); - mediaPlayer.pause(); - pauseButton.setText(PLAY_TEXT); - updateSlider(beginning); - updateTime(beginning); - } + if (mediaPlayer == null) + return; + + Duration beginning = mediaPlayer.getStartTime(); + mediaPlayer.stop(); + mediaPlayer.pause(); + pauseButton.setText(PLAY_TEXT); + updateSlider(beginning); + updateTime(beginning); } } From d3a389498ba145bfe803c538833aeea360811ae5 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Fri, 15 May 2015 16:27:58 -0400 Subject: [PATCH 12/79] Modified add data source wizard to use WizardPathValidator service providers --- .../AddImageWizardChooseDataSourceVisual.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java index 624c38383f..f1b08d9276 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java @@ -311,7 +311,22 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { */ public void updateUI(DocumentEvent e) { // Enable the Next button if the current DSP panel is valid - this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid()); + if (!getCurrentDSProcessor().isPanelValid()) { + return; + } + + // check if the is a WizardPathValidator service provider + if (!pathValidatorList.isEmpty()){ + // call WizardPathValidator service provider + String errorMsg = pathValidatorList.get(0).validateDataSourcePath(""); + if (errorMsg.isEmpty()) { + this.wizPanel.enableNextButton(true); + } else { + // ELTODO - display error message + } + } else { + // validate locally + } } @SuppressWarnings("rawtypes") From c6b262391e43b3a29d07f391c2150368874a1e61 Mon Sep 17 00:00:00 2001 From: Sidhesh Mhatre Date: Fri, 15 May 2015 16:42:19 -0400 Subject: [PATCH 13/79] Added supported format reference --- .../org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java index 1353430ef0..4fd40c1693 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java @@ -78,7 +78,9 @@ import org.sleuthkit.datamodel.TskData; @ServiceProvider(service = FrameCapture.class) }) public class FXVideoPanel extends MediaViewVideoPanel { - + + // Refer to https://docs.oracle.com/javafx/2/api/javafx/scene/media/package-summary.html + // for Javafx supported formats private static final String[] EXTENSIONS = new String[]{".m4v", ".fxm", ".flv", ".m3u8", ".mp4", ".aif", ".aiff", ".mp3", "m4a", ".wav"}; //NON-NLS private static final List MIMETYPES = Arrays.asList("audio/x-aiff", "video/x-javafx", "video/x-flv", "application/vnd.apple.mpegurl", " audio/mpegurl", "audio/mpeg", "video/mp4", "audio/x-m4a", "video/x-m4v", "audio/x-wav"); //NON-NLS private static final Logger logger = Logger.getLogger(MediaViewVideoPanel.class.getName()); From 765be69f6c4cffaea527d19a87bef5545c957d0d Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Mon, 18 May 2015 09:41:41 -0400 Subject: [PATCH 14/79] code formatted --- .../autopsy/corecomponents/FXVideoPanel.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java index 4dcc9a2ab3..4a9ab863bf 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/FXVideoPanel.java @@ -478,8 +478,9 @@ public class FXVideoPanel extends MediaViewVideoPanel { pauseButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { - if (mediaPlayer == null) + if (mediaPlayer == null) { return; + } Status status = mediaPlayer.getStatus(); @@ -508,8 +509,9 @@ public class FXVideoPanel extends MediaViewVideoPanel { stopButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { - if (mediaPlayer == null) + if (mediaPlayer == null) { return; + } mediaPlayer.stop(); } @@ -518,8 +520,9 @@ public class FXVideoPanel extends MediaViewVideoPanel { progressSlider.valueProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable o) { - if(mediaPlayer == null) + if (mediaPlayer == null) { return; + } if (progressSlider.isValueChanging()) { mediaPlayer.seek(duration.multiply(progressSlider.getValue() / 100.0)); @@ -568,8 +571,9 @@ public class FXVideoPanel extends MediaViewVideoPanel { * media. */ private void updateProgress() { - if(mediaPlayer == null) - return; + if (mediaPlayer == null) { + return; + } Duration currentTime = mediaPlayer.getCurrentTime(); updateSlider(currentTime); updateTime(currentTime); @@ -645,8 +649,9 @@ public class FXVideoPanel extends MediaViewVideoPanel { @Override public void run() { - if (mediaPlayer == null) + if (mediaPlayer == null) { return; + } duration = mediaPlayer.getMedia().getDuration(); long durationInMillis = (long) mediaPlayer.getMedia().getDuration().toMillis(); @@ -671,8 +676,9 @@ public class FXVideoPanel extends MediaViewVideoPanel { @Override public void run() { - if (mediaPlayer == null) + if (mediaPlayer == null) { return; + } Duration beginning = mediaPlayer.getStartTime(); mediaPlayer.stop(); From c0b55cda80dbc53737913c947806704410c78cdd Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Mon, 18 May 2015 10:35:07 -0400 Subject: [PATCH 15/79] Minor changes --- .../autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java index f1b08d9276..099d777ca9 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java @@ -326,6 +326,7 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { } } else { // validate locally + this.wizPanel.enableNextButton(true); } } From 0df6a09f4357c9d2c2a92f34c5bdebd9b352aa61 Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Mon, 18 May 2015 10:49:27 -0400 Subject: [PATCH 16/79] Added comments to DataSourceProcessor interfaces --- .../DataSourceProcessor.java | 47 ++++++------- .../DataSourceProcessorCallback.java | 69 +++++++++++-------- .../DataSourceProcessorProgressMonitor.java | 4 +- 3 files changed, 65 insertions(+), 55 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessor.java b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessor.java index e150e871ac..20a004c516 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessor.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessor.java @@ -21,28 +21,25 @@ package org.sleuthkit.autopsy.corecomponentinterfaces; import javax.swing.JPanel; -/* - * Defines an interface used by the Add DataSource wizard to discover different - * Data SourceProcessors. +/** + * Interface used by the Add DataSource wizard to allow different + * types of data sources to be added to a case. Examples of data + * sources include disk images, local files, etc. * - * Each data source may have its unique attributes and may need to be processed - * differently. - * - * The DataSourceProcessor interface defines a uniform mechanism for the Autopsy UI + * The interface provides a uniform mechanism for the Autopsy UI * to: - * - collect details for the data source to be processed. - * - Process the data source in the background - * - Be notified when the processing is complete + * - Collect details from the user about the data source to be processed. + * - Process the data source in the background and add data to the database + * - Provides progress feedback to the user / UI. */ public interface DataSourceProcessor { - /* + /** * The DSP Panel may fire Property change events * The caller must enure to add itself as a listener and * then react appropriately to the events */ enum DSP_PANEL_EVENT { - UPDATE_UI, // the content of JPanel has changed that MAY warrant updates to the caller UI FOCUS_NEXT // the caller UI may move focus the the next UI element, following the panel. }; @@ -51,39 +48,43 @@ public interface DataSourceProcessor { /** * Returns the type of Data Source it handles. * This name gets displayed in the drop-down listbox - **/ + */ String getDataSourceType(); /** * Returns the picker panel to be displayed along with any other - * runtime options supported by the data source handler. - **/ + * runtime options supported by the data source handler. The + * DSP is responsible for storing the settings so that a later + * call to run() will have the user-specified settings. + * + * Should be less than 544 pixels wide and 173 pixels high. + */ JPanel getPanel(); /** * Called to validate the input data in the panel. * Returns true if no errors, or * Returns false if there is an error. - **/ + */ boolean isPanelValid(); /** - * Called to invoke the handling of Data source in the background. - * Returns after starting the background thread - * @param settings wizard settings to read/store properties - * @param progressPanel progress panel to be updated while processing + * Called to invoke the handling of data source in the background. + * Returns after starting the background thread. * - **/ + * @param progressPanel progress panel to be updated while processing + * @param dspCallback Contains the callback method DataSourceProcessorCallback.done() that the DSP must call when the background thread finishes with errors and status. + */ void run(DataSourceProcessorProgressMonitor progressPanel, DataSourceProcessorCallback dspCallback); /** * Called to cancel the background processing. - **/ + */ void cancel(); /** * Called to reset/reinitialize the DSP. - **/ + */ void reset(); } diff --git a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorCallback.java b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorCallback.java index 1b69c03c17..6fca9d08a6 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorCallback.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorCallback.java @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.sleuthkit.autopsy.corecomponentinterfaces; import java.awt.EventQueue; @@ -25,42 +24,52 @@ import org.sleuthkit.datamodel.Content; /** * Abstract class for a callback for a DataSourceProcessor. - * - * Ensures that DSP invokes the caller overridden method, doneEDT(), - * in the EDT thread. - * + * + * Ensures that DSP invokes the caller overridden method, doneEDT(), in the EDT + * thread. + * */ public abstract class DataSourceProcessorCallback { - - public enum DataSourceProcessorResult - { - NO_ERRORS, - CRITICAL_ERRORS, - NONCRITICAL_ERRORS, + + public enum DataSourceProcessorResult { + NO_ERRORS, + CRITICAL_ERRORS, + NONCRITICAL_ERRORS, }; + - /* - * Invoke the caller supplied callback function on the EDT thread + /** + * Called by a DSP implementation when it is done adding a data source + * to the database. Users of the DSP can override this method if they do + * not want to be notified on the EDT. Otherwise, this method will call + * doneEDT() with the same arguments. + * @param result Code for status + * @param errList List of error strings + * @param newContents List of root Content objects that were added to database. Typically only one is given. */ - public void done(DataSourceProcessorResult result, List errList, List newContents) - { - + public void done(DataSourceProcessorResult result, List errList, List newContents) { + final DataSourceProcessorResult resultf = result; final List errListf = errList; final List newContentsf = newContents; - - // Invoke doneEDT() that runs on the EDT . - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - doneEDT(resultf, errListf, newContentsf ); - - } - }); + + // Invoke doneEDT() that runs on the EDT . + EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + doneEDT(resultf, errListf, newContentsf); + } + }); } - - /* - * calling code overrides to provide its own calllback - */ - public abstract void doneEDT(DataSourceProcessorResult result, List errList, List newContents); + + /** + * Called by done() if the default implementation is used. Users of DSPs + * that have UI updates to do after the DSP is finished adding the DS can + * implement this method to receive the updates on the EDT. + * + * @param result Code for status + * @param errList List of error strings + * @param newContents List of root Content objects that were added to database. Typically only one is given. + */ + public abstract void doneEDT(DataSourceProcessorResult result, List errList, List newContents); }; diff --git a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorProgressMonitor.java b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorProgressMonitor.java index 7495979d71..28001a9d62 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorProgressMonitor.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorProgressMonitor.java @@ -18,10 +18,10 @@ */ package org.sleuthkit.autopsy.corecomponentinterfaces; -/* +/** * An GUI agnostic DataSourceProcessorProgressMonitor interface for DataSourceProcesssors to * indicate progress. - * It models after a JProgressbar though it could use any underlying implementation + * It models after a JProgressbar though it could use any underlying implementation (or NoOps) */ public interface DataSourceProcessorProgressMonitor { From cc88d8a77e5d54b4f7b6bedbfc89af075000b416 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Mon, 18 May 2015 10:52:07 -0400 Subject: [PATCH 17/79] removed unnecessary sorts --- .../src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java | 4 ---- .../src/org/sleuthkit/autopsy/keywordsearch/Server.java | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java index 72e564c11b..aef452b7d5 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java @@ -340,7 +340,6 @@ class LuceneQuery implements KeywordSearchQuery { List snippetList = highlightResponse.get(docId).get(Server.Schema.TEXT.toString()); // list is null if there wasn't a snippet if (snippetList != null) { - snippetList.sort(null); snippet = EscapeUtil.unEscapeHtml(snippetList.get(0)).trim(); } } @@ -440,7 +439,6 @@ class LuceneQuery implements KeywordSearchQuery { //docs says makes sense for the original Highlighter only, but not really //analyze all content SLOW! consider lowering q.setParam("hl.maxAnalyzedChars", Server.HL_ANALYZE_CHARS_UNLIMITED); //NON-NLS - q.setParam("hl.preserveMulti", true); //NON-NLS try { QueryResponse response = solrServer.query(q, METHOD.POST); @@ -453,8 +451,6 @@ class LuceneQuery implements KeywordSearchQuery { if (contentHighlights == null) { return ""; } else { - // Sort contentHighlights in order to get consistently same snippet. - contentHighlights.sort(null); // extracted content is HTML-escaped, but snippet goes in a plain text field return EscapeUtil.unEscapeHtml(contentHighlights.get(0)).trim(); } diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java index 370d7b1ab6..003c8e437d 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java @@ -1037,8 +1037,7 @@ public class Server { filterQuery = filterQuery + Server.ID_CHUNK_SEP + chunkID; } q.addFilterQuery(filterQuery); - // sort the TEXT field - q.setSortField(Schema.TEXT.toString(), SolrQuery.ORDER.asc); + q.setFields(Schema.TEXT.toString()); try { // Get the first result. SolrDocument solrDocument = solrCore.query(q).getResults().get(0); From 5e997614a5d94592aec4bd7685a0f9a4c8cf823c Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Mon, 18 May 2015 10:55:31 -0400 Subject: [PATCH 18/79] Added comments to DataSourceProcessor interfaces --- .../corecomponentinterfaces/DataSourceProcessor.java | 4 ++-- .../DataSourceProcessorCallback.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessor.java b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessor.java index 20a004c516..f76f6b29a1 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessor.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessor.java @@ -40,8 +40,8 @@ public interface DataSourceProcessor { * then react appropriately to the events */ enum DSP_PANEL_EVENT { - UPDATE_UI, // the content of JPanel has changed that MAY warrant updates to the caller UI - FOCUS_NEXT // the caller UI may move focus the the next UI element, following the panel. + UPDATE_UI, ///< the content of JPanel has changed that MAY warrant updates to the caller UI + FOCUS_NEXT ///< the caller UI may move focus the the next UI element, following the panel. }; diff --git a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorCallback.java b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorCallback.java index 6fca9d08a6..76acfd2efc 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorCallback.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/DataSourceProcessorCallback.java @@ -32,9 +32,9 @@ import org.sleuthkit.datamodel.Content; public abstract class DataSourceProcessorCallback { public enum DataSourceProcessorResult { - NO_ERRORS, - CRITICAL_ERRORS, - NONCRITICAL_ERRORS, + NO_ERRORS, ///< No errors were encountered while ading the data source + CRITICAL_ERRORS, ///< No data was added to the database. There were fundamental errors processing the data (such as no data or system failure). + NONCRITICAL_ERRORS, ///< There was data added to the database, but there were errors from data corruption or a small number of minor issues. }; From e38474ab1a86afee3c45be2ac4731e88fc4948c5 Mon Sep 17 00:00:00 2001 From: Eamonn Saunders Date: Mon, 18 May 2015 10:51:52 -0400 Subject: [PATCH 19/79] Return immediately after indexing unallocated space, otherwise it gets processed twice. --- .../autopsy/keywordsearch/KeywordSearchIngestModule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index 12fb92e5c0..66fb3cd6ad 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -454,6 +454,7 @@ public final class KeywordSearchIngestModule implements FileIngestModule { // unallocated and unused blocks can only have strings extracted from them. if ((aType.equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) || aType.equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS))) { extractStringsAndIndex(aFile); + return; } final long size = aFile.getSize(); From 30a84fdceb14f8440aec15a3a37cd166d47ce8a3 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Tue, 19 May 2015 13:15:07 -0400 Subject: [PATCH 20/79] getFileType() added and used --- .../exif/ExifParserFileIngestModule.java | 10 +++- .../modules/filetypeid/FileTypeDetector.java | 46 +++++++++++++++++++ .../sevenzip/SevenZipIngestModule.java | 31 ++++--------- .../KeywordSearchIngestModule.java | 34 ++++---------- 4 files changed, 74 insertions(+), 47 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java index a045f48a5e..7cc563a7a2 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java @@ -34,6 +34,7 @@ import java.util.Collection; import java.util.Date; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; +import org.openide.util.Exceptions; import org.sleuthkit.autopsy.coreutils.ImageUtils; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.ingest.FileIngestModule; @@ -41,6 +42,7 @@ import org.sleuthkit.autopsy.ingest.IngestJobContext; import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.autopsy.ingest.ModuleDataEvent; import org.sleuthkit.autopsy.ingest.IngestModuleReferenceCounter; +import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; @@ -63,6 +65,7 @@ public final class ExifParserFileIngestModule implements FileIngestModule { private volatile boolean filesToFire = false; private long jobId; private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter(); + private static FileTypeDetector fileTypeDetector; ExifParserFileIngestModule() { } @@ -71,6 +74,11 @@ public final class ExifParserFileIngestModule implements FileIngestModule { public void startUp(IngestJobContext context) throws IngestModuleException { jobId = context.getJobId(); refCounter.incrementAndGet(jobId); + try { + fileTypeDetector = new FileTypeDetector(); + } catch (FileTypeDetector.FileTypeDetectorInitException ex) { + logger.log(Level.WARNING, "Error initializing FileTypeDetector", ex); // NON-NLS + } } @@ -197,7 +205,7 @@ public final class ExifParserFileIngestModule implements FileIngestModule { * @return true if to be processed */ private boolean parsableFormat(AbstractFile f) { - return ImageUtils.isJpegFileHeader(f); + return fileTypeDetector.getFileType(f).equals("image/jpeg"); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index bd7418d2a2..08631210ec 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -18,11 +18,14 @@ */ package org.sleuthkit.autopsy.modules.filetypeid; +import java.util.ArrayList; import java.util.Map; import java.util.SortedSet; +import java.util.logging.Level; import org.apache.tika.Tika; import org.apache.tika.mime.MediaType; import org.apache.tika.mime.MimeTypes; +import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; @@ -37,6 +40,7 @@ public class FileTypeDetector { private static final int BUFFER_SIZE = 64 * 1024; private final byte buffer[] = new byte[BUFFER_SIZE]; private final Map userDefinedFileTypes; + private static final Logger logger = Logger.getLogger(FileTypeDetector.class.getName()); /** * Constructs an object that detects the type of a file by an inspection of @@ -93,6 +97,48 @@ public class FileTypeDetector { return false; } + /** + * This method returns a string representing the mimetype of the provided + * abstractFile. Blackboard-lookup is performed to check if the mimetype has + * been already detected. If not, mimetype is determined using Apache Tika. + * + * @param abstractFile the file whose mimetype is to be determined. + * @return mimetype of the abstractFile is returned. Null value returned in + * case of error. + */ + public synchronized String getFileType(AbstractFile abstractFile) { + String identifiedFileType = null; + + // check BB + ArrayList attributes = null; + try { + attributes = abstractFile.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); + } catch (TskCoreException ex) { + logger.log(Level.WARNING, "Error performing mimetype blackboard-lookup for " + abstractFile.getName(), ex); + } + for (BlackboardAttribute attribute : attributes) { + identifiedFileType = attribute.getValueString(); + break; + } + + if (identifiedFileType != null) { + return identifiedFileType; + } + + try { + // check UDF and TDF + identifiedFileType = detectAndPostToBlackboard(abstractFile); + if (identifiedFileType != null) { + return identifiedFileType; + } + } catch (TskCoreException ex) { + logger.log(Level.WARNING, "Error determining the mimetype for " + abstractFile.getName(), ex); + return null; + } + + return null; + } + /** * Detect the MIME type of a file, posting it to the blackboard if detection * succeeds. diff --git a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java index 9ccb53ae17..70413e532a 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java @@ -62,6 +62,7 @@ import org.sleuthkit.autopsy.ingest.ModuleDataEvent; import org.sleuthkit.autopsy.ingest.IngestModuleReferenceCounter; import net.sf.sevenzipjbinding.ArchiveFormat; import static net.sf.sevenzipjbinding.ArchiveFormat.RAR; +import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector; /** * 7Zip ingest module extracts supported archives, adds extracted DerivedFiles, @@ -87,13 +88,10 @@ public final class SevenZipIngestModule implements FileIngestModule { private static final long MIN_FREE_DISK_SPACE = 1 * 1000 * 1000000L; //1GB //counts archive depth private ArchiveDepthCountTree archiveDepthCountTree; - //buffer for checking file headers and signatures - private static final int readHeaderSize = 4; - private final byte[] fileHeaderBuffer = new byte[readHeaderSize]; - private static final int ZIP_SIGNATURE_BE = 0x504B0304; private IngestJobContext context; private long jobId; private final static IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter(); + private static FileTypeDetector fileTypeDetector; SevenZipIngestModule() { } @@ -103,6 +101,12 @@ public final class SevenZipIngestModule implements FileIngestModule { this.context = context; jobId = context.getJobId(); + try { + fileTypeDetector = new FileTypeDetector(); + } catch (FileTypeDetector.FileTypeDetectorInitException ex) { + logger.log(Level.WARNING, "Error initializing FileTypeDetector", ex); // NON-NLS + } + final Case currentCase = Case.getCurrentCase(); moduleDirRelative = Case.getModulesOutputDirRelPath() + File.separator + ArchiveFileExtractorModuleFactory.getModuleName(); @@ -657,24 +661,7 @@ public final class SevenZipIngestModule implements FileIngestModule { * @return true if zip file, false otherwise */ private boolean isZipFileHeader(AbstractFile file) { - if (file.getSize() < readHeaderSize) { - return false; - } - - try { - int bytesRead = file.read(fileHeaderBuffer, 0, readHeaderSize); - if (bytesRead != readHeaderSize) { - return false; - } - } catch (TskCoreException ex) { - //ignore if can't read the first few bytes, not a ZIP - return false; - } - - ByteBuffer bytes = ByteBuffer.wrap(fileHeaderBuffer); - int signature = bytes.getInt(); - - return signature == ZIP_SIGNATURE_BE; + return fileTypeDetector.getFileType(file).equals("application/zip"); //NON-NLS } /** diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index 80462dd1af..a891f2721b 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -74,7 +74,8 @@ public final class KeywordSearchIngestModule implements FileIngestModule { private final IngestServices services = IngestServices.getInstance(); private Ingester ingester = null; private Indexer indexer; - //only search images from current ingest, not images previously ingested/indexed + private static FileTypeDetector fileTypeDetector; +//only search images from current ingest, not images previously ingested/indexed //accessed read-only by searcher thread private boolean startedSearching = false; @@ -130,6 +131,11 @@ public final class KeywordSearchIngestModule implements FileIngestModule { jobId = context.getJobId(); dataSourceId = context.getDataSource().getId(); + try { + fileTypeDetector = new FileTypeDetector(); + } catch (FileTypeDetector.FileTypeDetectorInitException ex) { + logger.log(Level.WARNING, "Error initializing FileTypeDetector", ex); // NON-NLS + } ingester = Server.getIngester(); this.context = context; @@ -469,30 +475,10 @@ public final class KeywordSearchIngestModule implements FileIngestModule { return; } - - - // try to get the file type from the BB - String detectedFormat = null; - try { - ArrayList attributes = aFile.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); - for (BlackboardAttribute attribute : attributes) { - detectedFormat = attribute.getValueString(); - break; - } - } catch (TskCoreException ex) { - } - // else, use FileType module to detect the format + String detectedFormat = fileTypeDetector.getFileType(aFile); if (detectedFormat == null) { - try { - detectedFormat = new FileTypeDetector().detectAndPostToBlackboard(aFile); - } catch (FileTypeDetector.FileTypeDetectorInitException | TskCoreException ex) { - logger.log(Level.WARNING, "Could not detect format using file type detector for file: {0}", aFile); //NON-NLS - return; - } - if (detectedFormat == null) { - logger.log(Level.WARNING, "Could not detect format using file type detector for file: {0}", aFile); //NON-NLS - return; - } + logger.log(Level.WARNING, "Could not detect format using fileTypeDetector for file: {0}", aFile); //NON-NLS + return; } // we skip archive formats that are opened by the archive module. From 715bc3c2cd66a3ccaf4f2e14aaf151c465a74bf6 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Tue, 19 May 2015 15:56:35 -0400 Subject: [PATCH 21/79] empty string returned in case of error --- .../modules/filetypeid/FileTypeDetector.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index 08631210ec..d09c6a9ea0 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -103,40 +103,39 @@ public class FileTypeDetector { * been already detected. If not, mimetype is determined using Apache Tika. * * @param abstractFile the file whose mimetype is to be determined. - * @return mimetype of the abstractFile is returned. Null value returned in - * case of error. + * @return mimetype of the abstractFile is returned. Empty String returned + * in case of error. */ public synchronized String getFileType(AbstractFile abstractFile) { - String identifiedFileType = null; + String identifiedFileType = ""; // check BB - ArrayList attributes = null; try { - attributes = abstractFile.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); + ArrayList attributes = abstractFile.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); + for (BlackboardAttribute attribute : attributes) { + identifiedFileType = attribute.getValueString(); + break; + } + if (identifiedFileType != null && !identifiedFileType.isEmpty()) { + return identifiedFileType; + } } catch (TskCoreException ex) { logger.log(Level.WARNING, "Error performing mimetype blackboard-lookup for " + abstractFile.getName(), ex); } - for (BlackboardAttribute attribute : attributes) { - identifiedFileType = attribute.getValueString(); - break; - } - - if (identifiedFileType != null) { - return identifiedFileType; - } try { // check UDF and TDF identifiedFileType = detectAndPostToBlackboard(abstractFile); - if (identifiedFileType != null) { + if (identifiedFileType != null && !identifiedFileType.isEmpty()) { return identifiedFileType; } } catch (TskCoreException ex) { - logger.log(Level.WARNING, "Error determining the mimetype for " + abstractFile.getName(), ex); - return null; + logger.log(Level.WARNING, "Error determining the mimetype for " + abstractFile.getName(), ex); // NON-NLS + return ""; // NON-NLS } - return null; + logger.log(Level.WARNING, "Unable to determine the mimetype for {0}", abstractFile.getName()); // NON-NLS + return ""; // NON-NLS } /** From d0739092727eb463cde9fa362dbd6a09d8dc85e6 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Tue, 19 May 2015 16:12:40 -0400 Subject: [PATCH 22/79] IngestModuleException thrown when FileTypeDetector not instantiated --- .../autopsy/modules/exif/ExifParserFileIngestModule.java | 1 + .../sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java | 1 + .../autopsy/keywordsearch/KeywordSearchIngestModule.java | 1 + 3 files changed, 3 insertions(+) diff --git a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java index 7cc563a7a2..3462e3a146 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java @@ -78,6 +78,7 @@ public final class ExifParserFileIngestModule implements FileIngestModule { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { logger.log(Level.WARNING, "Error initializing FileTypeDetector", ex); // NON-NLS + throw new IngestModuleException("Error initializing FileTypeDetector"); // NON-NLS } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java index 70413e532a..6c93b8ebed 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java @@ -105,6 +105,7 @@ public final class SevenZipIngestModule implements FileIngestModule { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { logger.log(Level.WARNING, "Error initializing FileTypeDetector", ex); // NON-NLS + throw new IngestModuleException("Error initializing FileTypeDetector"); // NON-NLS } final Case currentCase = Case.getCurrentCase(); diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index a891f2721b..56e39927e4 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -135,6 +135,7 @@ public final class KeywordSearchIngestModule implements FileIngestModule { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { logger.log(Level.WARNING, "Error initializing FileTypeDetector", ex); // NON-NLS + throw new IngestModuleException("Error initializing FileTypeDetector"); // NON-NLS } ingester = Server.getIngester(); this.context = context; From 48c67a6b40a10048ac580f464305d557f5d0c360 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Tue, 19 May 2015 16:26:07 -0400 Subject: [PATCH 23/79] refactored the SUPP_MIME_TYPES assignment in ImageUtils.java --- Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java index 919c4dfc1d..2bbb74d823 100755 --- a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java @@ -53,13 +53,8 @@ public class ImageUtils { private static final Logger logger = Logger.getLogger(ImageUtils.class.getName()); private static final Image DEFAULT_ICON = new ImageIcon("/org/sleuthkit/autopsy/images/file-icon.png").getImage(); //NON-NLS private static final List SUPP_EXTENSIONS = Arrays.asList(ImageIO.getReaderFileSuffixes()); - private static final List SUPP_MIME_TYPES; - + private static final List SUPP_MIME_TYPES = new ArrayList(Arrays.asList(ImageIO.getReaderMIMETypes())); static { - SUPP_MIME_TYPES = new ArrayList(); - for (String mimeType : Arrays.asList(ImageIO.getReaderMIMETypes())) { - SUPP_MIME_TYPES.add(mimeType); - } SUPP_MIME_TYPES.add("image/x-ms-bmp"); } From 0046f727328923a2424230557aa87f0d7f083aef Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Tue, 19 May 2015 16:39:42 -0400 Subject: [PATCH 24/79] Appropriate Levels logged. Unused imports removed --- .../autopsy/modules/exif/ExifParserFileIngestModule.java | 4 +--- .../autopsy/modules/sevenzip/SevenZipIngestModule.java | 3 +-- .../autopsy/keywordsearch/KeywordSearchIngestModule.java | 4 +--- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java index 3462e3a146..85d6bf49c2 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java @@ -34,8 +34,6 @@ import java.util.Collection; import java.util.Date; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; -import org.openide.util.Exceptions; -import org.sleuthkit.autopsy.coreutils.ImageUtils; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.ingest.FileIngestModule; import org.sleuthkit.autopsy.ingest.IngestJobContext; @@ -77,7 +75,7 @@ public final class ExifParserFileIngestModule implements FileIngestModule { try { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { - logger.log(Level.WARNING, "Error initializing FileTypeDetector", ex); // NON-NLS + logger.log(Level.SEVERE, "Error initializing FileTypeDetector", ex); // NON-NLS throw new IngestModuleException("Error initializing FileTypeDetector"); // NON-NLS } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java index 6c93b8ebed..b4277230be 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java @@ -24,7 +24,6 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -104,7 +103,7 @@ public final class SevenZipIngestModule implements FileIngestModule { try { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { - logger.log(Level.WARNING, "Error initializing FileTypeDetector", ex); // NON-NLS + logger.log(Level.SEVERE, "Error initializing FileTypeDetector", ex); // NON-NLS throw new IngestModuleException("Error initializing FileTypeDetector"); // NON-NLS } diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index 40fae2a471..bc87c20564 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -37,8 +37,6 @@ import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.autopsy.keywordsearch.Ingester.IngesterException; import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector; import org.sleuthkit.datamodel.AbstractFile; -import org.sleuthkit.datamodel.BlackboardAttribute; -import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskData; import org.sleuthkit.datamodel.TskData.FileKnown; @@ -134,7 +132,7 @@ public final class KeywordSearchIngestModule implements FileIngestModule { try { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { - logger.log(Level.WARNING, "Error initializing FileTypeDetector", ex); // NON-NLS + logger.log(Level.SEVERE, "Error initializing FileTypeDetector", ex); // NON-NLS throw new IngestModuleException("Error initializing FileTypeDetector"); // NON-NLS } ingester = Server.getIngester(); From e98d821ae456601b55b6f81fd8a3ff944b98a0b9 Mon Sep 17 00:00:00 2001 From: harvv Date: Tue, 19 May 2015 20:40:03 -0700 Subject: [PATCH 25/79] fix small error (inverted logic) obvious error that prevents process() from running in the normal case; could be confusing to newcomers (which is who examples are really aimed toward) --- .../org/sleuthkit/autopsy/examples/SampleFileIngestModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/examples/SampleFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/examples/SampleFileIngestModule.java index a6dc6af76b..e3420e0468 100755 --- a/Core/src/org/sleuthkit/autopsy/examples/SampleFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/examples/SampleFileIngestModule.java @@ -98,7 +98,7 @@ class SampleFileIngestModule implements FileIngestModule { @Override public IngestModule.ProcessResult process(AbstractFile file) { - if (attrId != -1) { + if (attrId == -1) { return IngestModule.ProcessResult.ERROR; } From 08160fc52f23325d98c809f32021625d6314d3c9 Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Wed, 20 May 2015 00:04:04 -0400 Subject: [PATCH 26/79] update to ingest job settings --- docs/doxygen/modIngest.dox | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/doxygen/modIngest.dox b/docs/doxygen/modIngest.dox index 8bbcbd043b..ffea77385d 100755 --- a/docs/doxygen/modIngest.dox +++ b/docs/doxygen/modIngest.dox @@ -271,17 +271,22 @@ that the samples do not do anything particularly useful. Autopsy allows you to provide a graphical panel that will be displayed when the user decides to enable the ingest module. This panel is supposed to be for settings that the user may turn on or off for different data sources. + To provide options for each ingest job: - Update org.sleuthkit.autopsy.ingest.IngestModuleFactory.hasIngestJobSettingsPanel() in your factory class to return true. -- Update org.sleuthkit.autopsy.ingest.IngestModuleFactory.getIngestJobSettingsPanel() in your factory class to return a IngestModuleIngestJobSettingsPanel that displays the needed configuration options and returns a IngestModuleIngestJobSettings object based on the settings. This will get passed in the last configuration setting that was used, so that you can populate the panel accordlingly and the user doesn't have to choose new settings. -- Create a class based on org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings to store the settings. +- Update org.sleuthkit.autopsy.ingest.IngestModuleFactory.getIngestJobSettingsPanel() in your factory class to return a IngestModuleIngestJobSettingsPanel that displays the needed configuration options. The org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettingsPanel.getSettings() method should return an instance of a org.sleutkit.autopsy.ingest.IngestModuleIngestJobSettings object based on the user-specified settings (see next bullet). +- Create a class that implements org.sleutkit.autopsy.ingest.IngestModuleIngestJobSettings. Your IngestModuleIngestJobSettingsPanel should store settings in here. This class needs to be Serializable, so keep all data types simple or mark them as transient with some custom deserialization code. You should also set the serialVersionUID (see http://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it). +- If you decide to store settings internal to the module (NOT RECOMMENDED), the getSettings() method can return an instance of NoIngestModuleIngestJobSettings. +- Your instance of IngestModuleIngestJobSettings will be saved and passed to your panel the next time so that you can pre-populate it accordingly. + +Your panel should create the IngestModuleIngestJobSettings class to store the settings and that will be passed back into your factory with each call to createDataSourceIngestModule() or createFileIngestModule(). The way that we have implemented this in Autopsy modules is that the factory casts the IngestModuleINgestJobSettings object to the module-specific implementation and then passes it into the constructor of the ingest module. The ingest module can then call whatever getter methods that were defined based on the panel settings. -Your panel should create the IngestModuleIngestJobSettings class to store the settings and that will be passed back into your factory with each call to createDataSourceIngestModule() or createFileIngestModule(). The factory should cast it to its internal class that implements IngestModuleIngestJobSettings and pass that object into the constructor of its ingest module so that it can use the settings when it runs. You can also implement the getDefaultIngestJobSettings() method to return an instance of your IngestModuleIngestJobSettings class with default settings. Autopsy will call this when the module has not been run before. NOTE: We recommend storing simple data in the IngestModuleIngestJobSettings-based class. In the case of our hash lookup module, we store the string names of the hash databases to do lookups in. We then get the hash database handles in the call to startUp() using the global module settings. + NOTE: The main benefit of using the IngestModuleIngestJobSettings-based class to store settings (versus some static variables in your package) are: - When multiple jobs are running at the same time, each can have their own settings. - Autopsy persists them so that the last used settings get passed into the call to getIngestJobSettingsPanel() and you don't need to save them yoursevles to provide the user the benefit of re-using the last settings. From 615b6dc53b403a5c15c006d325fa61c40aada343 Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Wed, 20 May 2015 00:05:51 -0400 Subject: [PATCH 27/79] updated docs footer --- docs/doxygen/footer.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/doxygen/footer.html b/docs/doxygen/footer.html index 983a55f487..08c9a6d5fb 100755 --- a/docs/doxygen/footer.html +++ b/docs/doxygen/footer.html @@ -1,5 +1,5 @@
-

Copyright © 2012-2014 Basis Technology. Generated on: $date
+

Copyright © 2012-2015 Basis Technology. Generated on: $date
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

From 91648425fb17a23e03378978b47ae28fd91f229d Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Wed, 20 May 2015 08:33:43 -0400 Subject: [PATCH 28/79] updated link to JNI blackboard page --- docs/doxygen/platformConcepts.dox | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/doxygen/platformConcepts.dox b/docs/doxygen/platformConcepts.dox index 7884fc6bfd..f76ea35f66 100755 --- a/docs/doxygen/platformConcepts.dox +++ b/docs/doxygen/platformConcepts.dox @@ -44,12 +44,10 @@ The blackboard allows modules to communicate with each other and the UI. It has The blackboard is not unique to Autopsy. It is part of The Sleuth Kit datamodel and The Sleuth Kit Framework. In the name of reducing the amount of documentation that we need to maintain, we provide links here to those documentation sources. -- Details on the blackboard concepts (artifacts versus attributes) can be found at http://sleuthkit.org/sleuthkit/docs/framework-docs/mod_bbpage.html. These documents are about the C++ implementation of the blackboard, but it is the same concepts. -- Details of the Java classes can be found in \ref jni_blackboard section of the The Sleuth Kit JNI documents (http://sleuthkit.org/sleuthkit/docs/jni-docs/). +- \ref mod_bbpage (http://sleuthkit.org/sleuthkit/docs/jni-docs/mod_bbpage.html) - -\subsection mod_dev_other_services Framework Services and Utilities +\section mod_dev_other_services Framework Services and Utilities The following are basic services that are available to any module. They are provided here to be used as a reference. When you are developing your module and feel like something should be provided by the framework, then refer to this list to find out where it could be. If you don't find it, let us know and we'll talk about adding it for other writers to benefit. From 22b50d55705532d1fd816649773baf0dee6b15fd Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Wed, 20 May 2015 11:54:47 -0400 Subject: [PATCH 29/79] FileTypeDetector made non-static field in ingest modules --- .../autopsy/modules/exif/ExifParserFileIngestModule.java | 2 +- .../autopsy/modules/filetypeid/FileTypeDetector.java | 4 ++-- .../autopsy/modules/sevenzip/SevenZipIngestModule.java | 2 +- .../autopsy/keywordsearch/KeywordSearchIngestModule.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java index 85d6bf49c2..1f7ae3ed9a 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java @@ -63,7 +63,7 @@ public final class ExifParserFileIngestModule implements FileIngestModule { private volatile boolean filesToFire = false; private long jobId; private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter(); - private static FileTypeDetector fileTypeDetector; + private FileTypeDetector fileTypeDetector; ExifParserFileIngestModule() { } diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index d09c6a9ea0..6e775b93e8 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -106,7 +106,7 @@ public class FileTypeDetector { * @return mimetype of the abstractFile is returned. Empty String returned * in case of error. */ - public synchronized String getFileType(AbstractFile abstractFile) { + public String getFileType(AbstractFile abstractFile) { String identifiedFileType = ""; // check BB @@ -147,7 +147,7 @@ public class FileTypeDetector { * @return The MIME type name id detection was successful, null otherwise. * @throws TskCoreException if there is an error posting to the blackboard. */ - public synchronized String detectAndPostToBlackboard(AbstractFile file) throws TskCoreException { + public String detectAndPostToBlackboard(AbstractFile file) throws TskCoreException { String mimeType = detect(file); if (null != mimeType) { /** diff --git a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java index b4277230be..c72b5ec4f3 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java @@ -90,7 +90,7 @@ public final class SevenZipIngestModule implements FileIngestModule { private IngestJobContext context; private long jobId; private final static IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter(); - private static FileTypeDetector fileTypeDetector; + private FileTypeDetector fileTypeDetector; SevenZipIngestModule() { } diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index bc87c20564..9bc0a6442b 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -72,7 +72,7 @@ public final class KeywordSearchIngestModule implements FileIngestModule { private final IngestServices services = IngestServices.getInstance(); private Ingester ingester = null; private Indexer indexer; - private static FileTypeDetector fileTypeDetector; + private FileTypeDetector fileTypeDetector; //only search images from current ingest, not images previously ingested/indexed //accessed read-only by searcher thread From 60b7ef57ee3e1070c95cf40599878c35fe244301 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 20 May 2015 13:54:12 -0400 Subject: [PATCH 30/79] Added verification for path being on C drive, modified ImageFilePanel --- .../AddImageWizardChooseDataSourceVisual.java | 31 +------ .../autopsy/casemodule/Bundle.properties | 1 + .../autopsy/casemodule/Bundle_ja.properties | 1 + .../autopsy/casemodule/ImageFilePanel.form | 17 +++- .../autopsy/casemodule/ImageFilePanel.java | 87 +++++++++++++++++-- 5 files changed, 101 insertions(+), 36 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java index 099d777ca9..328d307935 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java @@ -38,7 +38,6 @@ import javax.swing.event.DocumentEvent; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; -import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; import org.sleuthkit.autopsy.coreutils.Logger; /** @@ -55,8 +54,6 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { private JPanel currentPanel; private Map datasourceProcessorsMap = new HashMap<>(); - - List pathValidatorList = new ArrayList<>(); List coreDSPTypes = new ArrayList<>(); @@ -78,8 +75,6 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { typePanel.setLayout(new BorderLayout()); discoverDataSourceProcessors(); - - discoverWizardPathValidators(); // set up the DSP type combobox typeComboBox.removeAllItems(); @@ -132,13 +127,7 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { logger.log(Level.SEVERE, "discoverDataSourceProcessors(): A DataSourceProcessor already exists for type = {0}", dsProcessor.getDataSourceType()); //NON-NLS } } - } - - private void discoverWizardPathValidators() { - for (WizardPathValidator pathValidator : Lookup.getDefault().lookupAll(WizardPathValidator.class)) { - pathValidatorList.add(pathValidator); - } - } + } private void dspSelectionChanged() { // update the current panel to selection @@ -311,23 +300,7 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { */ public void updateUI(DocumentEvent e) { // Enable the Next button if the current DSP panel is valid - if (!getCurrentDSProcessor().isPanelValid()) { - return; - } - - // check if the is a WizardPathValidator service provider - if (!pathValidatorList.isEmpty()){ - // call WizardPathValidator service provider - String errorMsg = pathValidatorList.get(0).validateDataSourcePath(""); - if (errorMsg.isEmpty()) { - this.wizPanel.enableNextButton(true); - } else { - // ELTODO - display error message - } - } else { - // validate locally - this.wizPanel.enableNextButton(true); - } + this.wizPanel.enableNextButton(getCurrentDSProcessor().isPanelValid()); } @SuppressWarnings("rawtypes") diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index cdbed0aa1f..ed71b9c592 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -230,3 +230,4 @@ AddImageWizardIngestConfigPanel.CANCEL_BUTTON.text=Cancel NewCaseVisualPanel1.rbSingleUserCase.text=Single-user NewCaseVisualPanel1.rbMultiUserCase.text=Multi-user NewCaseVisualPanel1.lbBadMultiUserSettings.text= +ImageFilePanel.errorLabel.text=Error Label diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties index 0d2bd7e942..75be232976 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties @@ -215,3 +215,4 @@ XMLCaseManagement.open.msgDlg.notAutCase.title=\u30a8\u30e9\u30fc ImageFilePanel.noFatOrphansCheckbox.text=FAT\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u306e\u30aa\u30fc\u30d5\u30a1\u30f3\u30d5\u30a1\u30a4\u30eb\u306f\u7121\u8996 LocalDiskPanel.noFatOrphansCheckbox.text=FAT\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u306e\u30aa\u30fc\u30d5\u30a1\u30f3\u30d5\u30a1\u30a4\u30eb\u306f\u7121\u8996 AddImageWizardIngestConfigPanel.CANCEL_BUTTON.text=\u30ad\u30e3\u30f3\u30bb\u30eb +ImageFilePanel.errorLabel.text=\u30a8\u30e9\u30fc\u30e9\u30d9\u30eb diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.form b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.form index b4dbaafd63..bfccc9bdd9 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.form +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.form @@ -43,6 +43,7 @@ + @@ -57,7 +58,9 @@ - + + + @@ -66,7 +69,7 @@ - + @@ -131,5 +134,15 @@ + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java index 045fe691a4..c389a30fd6 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java @@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.casemodule; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.File; +import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.SimpleTimeZone; @@ -36,6 +37,11 @@ import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.openide.util.Lookup; +import org.sleuthkit.autopsy.casemodule.Case.CaseType; +import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; import org.sleuthkit.autopsy.coreutils.Logger; /** @@ -47,6 +53,9 @@ public class ImageFilePanel extends JPanel implements DocumentListener { private static final Logger logger = Logger.getLogger(ImageFilePanel.class.getName()); private PropertyChangeSupport pcs = null; private JFileChooser fc = new JFileChooser(); + + List pathValidatorList = new ArrayList<>(); + private static final Pattern driveLetterPattern = Pattern.compile("^([Cc]):.*$"); // Externally supplied name is used to store settings private String contextName; @@ -62,6 +71,9 @@ public class ImageFilePanel extends JPanel implements DocumentListener { fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); + errorLabel.setVisible(false); + discoverWizardPathValidators(); + boolean firstFilter = true; for (FileFilter filter: fileChooserFilters ) { if (firstFilter) { // set the first on the list as the default selection @@ -76,7 +88,7 @@ public class ImageFilePanel extends JPanel implements DocumentListener { this.contextName = context; pcs = new PropertyChangeSupport(this); - createTimeZoneList(); + createTimeZoneList(); } /** @@ -97,7 +109,11 @@ public class ImageFilePanel extends JPanel implements DocumentListener { pathTextField.getDocument().addDocumentListener(this); } - + private void discoverWizardPathValidators() { + for (WizardPathValidator pathValidator : Lookup.getDefault().lookupAll(WizardPathValidator.class)) { + pathValidatorList.add(pathValidator); + } + } /** * This method is called from within the constructor to initialize the form. @@ -115,6 +131,7 @@ public class ImageFilePanel extends JPanel implements DocumentListener { timeZoneComboBox = new javax.swing.JComboBox(); noFatOrphansCheckbox = new javax.swing.JCheckBox(); descLabel = new javax.swing.JLabel(); + errorLabel = new javax.swing.JLabel(); setMinimumSize(new java.awt.Dimension(0, 65)); setPreferredSize(new java.awt.Dimension(403, 65)); @@ -139,6 +156,9 @@ public class ImageFilePanel extends JPanel implements DocumentListener { org.openide.awt.Mnemonics.setLocalizedText(descLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.descLabel.text")); // NOI18N + errorLabel.setForeground(new java.awt.Color(255, 0, 0)); + org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.errorLabel.text")); // NOI18N + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -158,7 +178,8 @@ public class ImageFilePanel extends JPanel implements DocumentListener { .addComponent(noFatOrphansCheckbox) .addGroup(layout.createSequentialGroup() .addGap(21, 21, 21) - .addComponent(descLabel))) + .addComponent(descLabel)) + .addComponent(errorLabel)) .addGap(0, 20, Short.MAX_VALUE)) ); layout.setVerticalGroup( @@ -169,7 +190,9 @@ public class ImageFilePanel extends JPanel implements DocumentListener { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(browseButton) .addComponent(pathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) + .addGap(3, 3, 3) + .addComponent(errorLabel) + .addGap(1, 1, 1) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(timeZoneLabel) .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) @@ -177,7 +200,7 @@ public class ImageFilePanel extends JPanel implements DocumentListener { .addComponent(noFatOrphansCheckbox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(descLabel) - .addContainerGap(13, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// //GEN-END:initComponents @@ -211,6 +234,7 @@ public class ImageFilePanel extends JPanel implements DocumentListener { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton browseButton; private javax.swing.JLabel descLabel; + private javax.swing.JLabel errorLabel; private javax.swing.JCheckBox noFatOrphansCheckbox; private javax.swing.JLabel pathLabel; private javax.swing.JTextField pathTextField; @@ -263,9 +287,62 @@ public class ImageFilePanel extends JPanel implements DocumentListener { boolean isExist = Case.pathExists(path); boolean isPhysicalDrive = Case.isPhysicalDrive(path); boolean isPartition = Case.isPartition(path); + + if (!isImagePathValid(path)) { + return false; + } return (isExist || isPhysicalDrive || isPartition); } + + + private boolean isImagePathValid(String path){ + + errorLabel.setVisible(false); + String errorString = ""; + boolean valid = false; + + // check if the is a WizardPathValidator service provider + if (!pathValidatorList.isEmpty()) { + // call WizardPathValidator service provider + errorString = pathValidatorList.get(0).validateDataSourcePath(path); + if (errorString.isEmpty()) { + valid = true; + } + } else { + // validate locally + if (Case.getCurrentCase().getCaseType() == CaseType.MULTI_USER_CASE) { + // check that path is not on "C:" drive + if (pathOnCDrive(path)) { + errorString = "Path to data source is on \"C:\" drive"; + } else { + valid = true; + } + } else { + // single user case - no validation + valid = true; + } + } + + // set error string + if (!errorString.isEmpty()){ + errorLabel.setVisible(true); + errorLabel.setText(errorString); + } + + return valid; + } + + /** + * Checks whether a file path contains drive letter defined by pattern. + * + * @param filePath Input file absolute path + * @return true if path matches the pattern, false otherwise. + */ + private boolean pathOnCDrive(String filePath) { + Matcher m = driveLetterPattern.matcher(filePath); + return m.find(); + } public void storeSettings() { From 68fc925a1af44e564544c6129b2aaa6cf692a152 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 20 May 2015 14:11:00 -0400 Subject: [PATCH 31/79] Using NbBundle for error messages --- .../autopsy/casemodule/Bundle.properties | 1 + .../autopsy/casemodule/ImageFilePanel.java | 16 +++++----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index ed71b9c592..7fc183f612 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -231,3 +231,4 @@ NewCaseVisualPanel1.rbSingleUserCase.text=Single-user NewCaseVisualPanel1.rbMultiUserCase.text=Multi-user NewCaseVisualPanel1.lbBadMultiUserSettings.text= ImageFilePanel.errorLabel.text=Error Label +ImageFilePanel.DataSourceOnCDriveError.text=Path to data source is on \"C:\" drive \ No newline at end of file diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java index c389a30fd6..c0b81e54e5 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java @@ -300,27 +300,20 @@ public class ImageFilePanel extends JPanel implements DocumentListener { errorLabel.setVisible(false); String errorString = ""; - boolean valid = false; // check if the is a WizardPathValidator service provider if (!pathValidatorList.isEmpty()) { // call WizardPathValidator service provider errorString = pathValidatorList.get(0).validateDataSourcePath(path); - if (errorString.isEmpty()) { - valid = true; - } } else { // validate locally if (Case.getCurrentCase().getCaseType() == CaseType.MULTI_USER_CASE) { // check that path is not on "C:" drive if (pathOnCDrive(path)) { - errorString = "Path to data source is on \"C:\" drive"; - } else { - valid = true; - } + errorString = NbBundle.getMessage(this.getClass(), "ImageFilePanel.DataSourceOnCDriveError.text"); //NON-NLS + } } else { - // single user case - no validation - valid = true; + // single user case - no validation needed } } @@ -328,9 +321,10 @@ public class ImageFilePanel extends JPanel implements DocumentListener { if (!errorString.isEmpty()){ errorLabel.setVisible(true); errorLabel.setText(errorString); + return false; } - return valid; + return true; } /** From 2f7297101e0afe16820b41b3b8bf7c609f6b743b Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 20 May 2015 16:01:21 -0400 Subject: [PATCH 32/79] Modified local files panel --- .../autopsy/casemodule/Bundle.properties | 2 +- .../autopsy/casemodule/ImageFilePanel.java | 11 +++- .../autopsy/casemodule/LocalDiskPanel.form | 2 +- .../autopsy/casemodule/LocalDiskPanel.java | 64 +++++++++++++++++++ 4 files changed, 74 insertions(+), 5 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index 7fc183f612..217c9e2e09 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -231,4 +231,4 @@ NewCaseVisualPanel1.rbSingleUserCase.text=Single-user NewCaseVisualPanel1.rbMultiUserCase.text=Multi-user NewCaseVisualPanel1.lbBadMultiUserSettings.text= ImageFilePanel.errorLabel.text=Error Label -ImageFilePanel.DataSourceOnCDriveError.text=Path to data source is on \"C:\" drive \ No newline at end of file +DataSourceOnCDriveError.text=Path to data source is on \"C:\" drive \ No newline at end of file diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java index c0b81e54e5..29ac4694fd 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java @@ -55,7 +55,7 @@ public class ImageFilePanel extends JPanel implements DocumentListener { private JFileChooser fc = new JFileChooser(); List pathValidatorList = new ArrayList<>(); - private static final Pattern driveLetterPattern = Pattern.compile("^([Cc]):.*$"); + private final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$"); // Externally supplied name is used to store settings private String contextName; @@ -295,7 +295,12 @@ public class ImageFilePanel extends JPanel implements DocumentListener { return (isExist || isPhysicalDrive || isPartition); } - + /** + * Validates path to selected data source. Calls WizardPathValidator service provider + * if one is available. Otherwise performs path validation locally. + * @param path Absolute path to the selected data source + * @return true if path is valid, false otherwise. + */ private boolean isImagePathValid(String path){ errorLabel.setVisible(false); @@ -310,7 +315,7 @@ public class ImageFilePanel extends JPanel implements DocumentListener { if (Case.getCurrentCase().getCaseType() == CaseType.MULTI_USER_CASE) { // check that path is not on "C:" drive if (pathOnCDrive(path)) { - errorString = NbBundle.getMessage(this.getClass(), "ImageFilePanel.DataSourceOnCDriveError.text"); //NON-NLS + errorString = NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text"); //NON-NLS } } else { // single user case - no validation needed diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.form b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.form index d71086457c..55707d9f0c 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.form +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.form @@ -61,7 +61,7 @@ - + diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java index 38d067c153..d0b773c4e1 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java @@ -31,6 +31,8 @@ import java.util.SimpleTimeZone; import java.util.TimeZone; import java.util.concurrent.CancellationException; import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.swing.ComboBoxModel; import javax.swing.JLabel; import javax.swing.JList; @@ -42,6 +44,7 @@ import javax.swing.border.EmptyBorder; import javax.swing.event.ListDataListener; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; +import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; import org.sleuthkit.autopsy.coreutils.LocalDisk; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; @@ -64,6 +67,9 @@ final class LocalDiskPanel extends JPanel { private LocalDiskModel model; private boolean enableNext = false; + + List pathValidatorList = new ArrayList<>(); + private final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$"); /** * Creates new form LocalDiskPanel @@ -225,8 +231,66 @@ final class LocalDiskPanel extends JPanel { */ //@Override public boolean validatePanel() { + + if (!isImagePathValid(getContentPaths())) { + return false; + } + return enableNext; } + + /** + * Validates path to selected data source. Calls WizardPathValidator service provider + * if one is available. Otherwise performs path validation locally. + * @param path Absolute path to the selected data source + * @return true if path is valid, false otherwise. + */ + private boolean isImagePathValid(String path){ + + errorLabel.setVisible(false); + String errorString = ""; + String newPath = path; + if (path.length() > 4) { + // "Local Disk" panel pre-pends "\\.\" in front of all drive letter and drive names + newPath = path.substring(4, path.length()); + } + + // check if the is a WizardPathValidator service provider + if (!pathValidatorList.isEmpty()) { + // call WizardPathValidator service provider + errorString = pathValidatorList.get(0).validateDataSourcePath(newPath); + } else { + // validate locally + if (Case.getCurrentCase().getCaseType() == Case.CaseType.MULTI_USER_CASE) { + // check that path is not on "C:" drive + if (pathOnCDrive(newPath)) { + errorString = NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text"); //NON-NLS + } + } else { + // single user case - no validation needed + } + } + + // set error string + if (!errorString.isEmpty()){ + errorLabel.setVisible(true); + errorLabel.setText(errorString); + return false; + } + + return true; + } + + /** + * Checks whether a file path contains drive letter defined by pattern. + * + * @param filePath Input file absolute path + * @return true if path matches the pattern, false otherwise. + */ + private boolean pathOnCDrive(String filePath) { + Matcher m = driveLetterPattern.matcher(filePath); + return m.find(); + } //@Override public void reset() { From 9f603eb11665f05704d157691e6539e88397c373 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 20 May 2015 16:26:44 -0400 Subject: [PATCH 33/79] Integrated local files panel --- .../autopsy/casemodule/Bundle.properties | 3 +- .../autopsy/casemodule/Bundle_ja.properties | 1 + .../autopsy/casemodule/LocalDiskPanel.java | 5 +- .../autopsy/casemodule/LocalFilesPanel.form | 23 ++++- .../autopsy/casemodule/LocalFilesPanel.java | 93 ++++++++++++++++++- 5 files changed, 113 insertions(+), 12 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index 217c9e2e09..0e694fe40d 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -231,4 +231,5 @@ NewCaseVisualPanel1.rbSingleUserCase.text=Single-user NewCaseVisualPanel1.rbMultiUserCase.text=Multi-user NewCaseVisualPanel1.lbBadMultiUserSettings.text= ImageFilePanel.errorLabel.text=Error Label -DataSourceOnCDriveError.text=Path to data source is on \"C:\" drive \ No newline at end of file +DataSourceOnCDriveError.text=Path to data source is on \"C:\" drive +LocalFilesPanel.errorLabel.text=Error Label diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties index 75be232976..07845b238f 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties @@ -216,3 +216,4 @@ ImageFilePanel.noFatOrphansCheckbox.text=FAT\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9 LocalDiskPanel.noFatOrphansCheckbox.text=FAT\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u306e\u30aa\u30fc\u30d5\u30a1\u30f3\u30d5\u30a1\u30a4\u30eb\u306f\u7121\u8996 AddImageWizardIngestConfigPanel.CANCEL_BUTTON.text=\u30ad\u30e3\u30f3\u30bb\u30eb ImageFilePanel.errorLabel.text=\u30a8\u30e9\u30fc\u30e9\u30d9\u30eb +LocalFilesPanel.errorLabel.text=\u30a8\u30e9\u30fc\u30e9\u30d9\u30eb diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java index d0b773c4e1..c4d362111e 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java @@ -70,6 +70,7 @@ final class LocalDiskPanel extends JPanel { List pathValidatorList = new ArrayList<>(); private final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$"); + private final int prePendedStringLength = 4; // "Local Disk" panel pre-pends "\\.\" in front of all drive letter and drive names /** * Creates new form LocalDiskPanel @@ -250,9 +251,9 @@ final class LocalDiskPanel extends JPanel { errorLabel.setVisible(false); String errorString = ""; String newPath = path; - if (path.length() > 4) { + if (path.length() > prePendedStringLength) { // "Local Disk" panel pre-pends "\\.\" in front of all drive letter and drive names - newPath = path.substring(4, path.length()); + newPath = path.substring(prePendedStringLength, path.length()); } // check if the is a WizardPathValidator service provider diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.form b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.form index cf08c9c38f..eb9d6182bb 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.form +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.form @@ -60,6 +60,10 @@ + + + + @@ -67,15 +71,16 @@ - + + - + - - + + @@ -136,5 +141,15 @@ + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java index 256276809b..7f4b1da7c1 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java @@ -21,6 +21,9 @@ package org.sleuthkit.autopsy.casemodule; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Set; import java.util.TreeSet; import javax.swing.JFileChooser; @@ -30,6 +33,9 @@ import org.openide.util.NbBundle; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; import org.sleuthkit.autopsy.coreutils.Logger; /** * Add input wizard subpanel for adding local files / dirs to the case @@ -42,6 +48,10 @@ import org.sleuthkit.autopsy.coreutils.Logger; private static LocalFilesPanel instance; public static final String FILES_SEP = ","; private static final Logger logger = Logger.getLogger(LocalFilesPanel.class.getName()); + + List pathValidatorList = new ArrayList<>(); + private final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$"); + /** * Creates new form LocalFilesPanel */ @@ -91,8 +101,72 @@ import org.sleuthkit.autopsy.coreutils.Logger; //@Override public boolean validatePanel() { + + if (!isImagePathValid(getContentPaths())) { + return false; + } + return enableNext; } + + /** + * Validates path to selected data source. Calls WizardPathValidator service provider + * if one is available. Otherwise performs path validation locally. + * @param path Absolute path to the selected data source + * @return true if path is valid, false otherwise. + */ + private boolean isImagePathValid(String path){ + + errorLabel.setVisible(false); + String errorString = ""; + + // Path variable for "Local files" module is a coma separated string containg multiple paths + List pathsList = Arrays.asList(path.split(",")); + + for (String currentPath : pathsList) { + // check if the is a WizardPathValidator service provider + if (!pathValidatorList.isEmpty()) { + // call WizardPathValidator service provider + errorString = pathValidatorList.get(0).validateDataSourcePath(currentPath); + if (!errorString.isEmpty()) { + break; + } + } else { + // validate locally + if (Case.getCurrentCase().getCaseType() == Case.CaseType.MULTI_USER_CASE) { + // check that path is not on "C:" drive + if (pathOnCDrive(currentPath)) { + errorString = NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text"); //NON-NLS + if (!errorString.isEmpty()) { + break; + } + } + } else { + // single user case - no validation needed + } + } + } + + // set error string + if (!errorString.isEmpty()){ + errorLabel.setVisible(true); + errorLabel.setText(errorString); + return false; + } + + return true; + } + + /** + * Checks whether a file path contains drive letter defined by pattern. + * + * @param filePath Input file absolute path + * @return true if path matches the pattern, false otherwise. + */ + private boolean pathOnCDrive(String filePath) { + Matcher m = driveLetterPattern.matcher(filePath); + return m.find(); + } //@Override public void select() { @@ -149,6 +223,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; clearButton = new javax.swing.JButton(); jScrollPane2 = new javax.swing.JScrollPane(); selectedPaths = new javax.swing.JTextArea(); + errorLabel = new javax.swing.JLabel(); localFileChooser.setApproveButtonText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.localFileChooser.approveButtonText")); // NOI18N localFileChooser.setApproveButtonToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.localFileChooser.approveButtonToolTipText")); // NOI18N @@ -184,6 +259,9 @@ import org.sleuthkit.autopsy.coreutils.Logger; selectedPaths.setToolTipText(org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.selectedPaths.toolTipText")); // NOI18N jScrollPane2.setViewportView(selectedPaths); + errorLabel.setForeground(new java.awt.Color(255, 0, 0)); + org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(LocalFilesPanel.class, "LocalFilesPanel.errorLabel.text")); // NOI18N + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -198,19 +276,23 @@ import org.sleuthkit.autopsy.coreutils.Logger; .addComponent(selectButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(clearButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(2, 2, 2)) + .addGroup(layout.createSequentialGroup() + .addComponent(errorLabel) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(infoLabel) .addGap(5, 5, 5) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(selectButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE) - .addComponent(clearButton)) - .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) - .addGap(0, 0, 0)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(clearButton))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(errorLabel)) ); }// //GEN-END:initComponents @@ -258,6 +340,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton clearButton; + private javax.swing.JLabel errorLabel; private javax.swing.JLabel infoLabel; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; From e22fd06a6456158ef393e2849996a002a40308cf Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 20 May 2015 17:09:15 -0400 Subject: [PATCH 34/79] Bug fixes --- .../autopsy/casemodule/ImageFilePanel.java | 3 +++ .../autopsy/casemodule/LocalDiskPanel.java | 15 +++++++++++++-- .../autopsy/casemodule/LocalFilesPanel.java | 14 +++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java index 29ac4694fd..0420bce1d8 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java @@ -109,6 +109,9 @@ public class ImageFilePanel extends JPanel implements DocumentListener { pathTextField.getDocument().addDocumentListener(this); } + /** + * Discovers WizardPathValidator service providers + */ private void discoverWizardPathValidators() { for (WizardPathValidator pathValidator : Lookup.getDefault().lookupAll(WizardPathValidator.class)) { pathValidatorList.add(pathValidator); diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java index c4d362111e..9e009a74e3 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java @@ -42,6 +42,7 @@ import javax.swing.ListCellRenderer; import javax.swing.SwingWorker; import javax.swing.border.EmptyBorder; import javax.swing.event.ListDataListener; +import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; @@ -99,11 +100,21 @@ final class LocalDiskPanel extends JPanel { model = new LocalDiskModel(); diskComboBox.setModel(model); diskComboBox.setRenderer(model); - + + errorLabel.setVisible(false); errorLabel.setText(""); diskComboBox.setEnabled(false); - + discoverWizardPathValidators(); } + + /** + * Discovers WizardPathValidator service providers + */ + private void discoverWizardPathValidators() { + for (WizardPathValidator pathValidator : Lookup.getDefault().lookupAll(WizardPathValidator.class)) { + pathValidatorList.add(pathValidator); + } + } /** * This method is called from within the constructor to initialize the form. diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java index 7f4b1da7c1..21e556bc51 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java @@ -35,6 +35,7 @@ import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import java.util.logging.Level; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.openide.util.Lookup; import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; import org.sleuthkit.autopsy.coreutils.Logger; /** @@ -69,10 +70,20 @@ import org.sleuthkit.autopsy.coreutils.Logger; private void customInit() { localFileChooser.setMultiSelectionEnabled(true); + discoverWizardPathValidators(); + errorLabel.setVisible(false); selectedPaths.setText(""); - } + /** + * Discovers WizardPathValidator service providers + */ + private void discoverWizardPathValidators() { + for (WizardPathValidator pathValidator : Lookup.getDefault().lookupAll(WizardPathValidator.class)) { + pathValidatorList.add(pathValidator); + } + } + //@Override public String getContentPaths() { //TODO consider interface change to return list of paths instead @@ -178,6 +189,7 @@ import org.sleuthkit.autopsy.coreutils.Logger; currentFiles.clear(); selectedPaths.setText(""); enableNext = false; + errorLabel.setVisible(false); //pcs.firePropertyChange(AddImageWizardChooseDataSourceVisual.EVENT.UPDATE_UI.toString(), false, true); } From 9fcb1a30363882c85d47401a6814cb0336b1f403 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 20 May 2015 17:29:27 -0400 Subject: [PATCH 35/79] Bug fixes --- .../org/sleuthkit/autopsy/casemodule/ImageFilePanel.java | 4 ++++ .../org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java | 8 +++++++- .../org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java index 0420bce1d8..855077f5f6 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java @@ -309,6 +309,10 @@ public class ImageFilePanel extends JPanel implements DocumentListener { errorLabel.setVisible(false); String errorString = ""; + if (path.isEmpty()) { + return false; // no need for error message as the module sets path to "" at startup + } + // check if the is a WizardPathValidator service provider if (!pathValidatorList.isEmpty()) { // call WizardPathValidator service provider diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java index 9e009a74e3..38e90acee9 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java @@ -261,9 +261,15 @@ final class LocalDiskPanel extends JPanel { errorLabel.setVisible(false); String errorString = ""; + + if (path.isEmpty()) { + return false; // no need for error message as the module sets path to "" at startup + } + String newPath = path; if (path.length() > prePendedStringLength) { - // "Local Disk" panel pre-pends "\\.\" in front of all drive letter and drive names + // "Local Disk" panel pre-pends "\\.\" in front of all drive letter and drive names. + // Path validators expect a "standard" path as input, i.e. one that starts with a drive letter. newPath = path.substring(prePendedStringLength, path.length()); } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java index 21e556bc51..5fe07b097f 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java @@ -131,6 +131,10 @@ import org.sleuthkit.autopsy.coreutils.Logger; errorLabel.setVisible(false); String errorString = ""; + if (path.isEmpty()) { + return false; // no need for error message as the module sets path to "" at startup + } + // Path variable for "Local files" module is a coma separated string containg multiple paths List pathsList = Arrays.asList(path.split(",")); From 3ecab54625bfa059cbaba3ced4e3c4a2f6726302 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Thu, 21 May 2015 09:56:42 -0400 Subject: [PATCH 36/79] Added case type to WizardPathValidator, modified new case panel --- .../autopsy/casemodule/Bundle.properties | 1 + .../autopsy/casemodule/Bundle_ja.properties | 1 + .../autopsy/casemodule/ImageFilePanel.java | 2 +- .../autopsy/casemodule/LocalDiskPanel.java | 2 +- .../autopsy/casemodule/LocalFilesPanel.java | 6 +- .../casemodule/NewCaseVisualPanel1.form | 76 ++++++--- .../casemodule/NewCaseVisualPanel1.java | 151 +++++++++++++++--- .../WizardPathValidator.java | 8 +- 8 files changed, 202 insertions(+), 45 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index 0e694fe40d..de512b48b3 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -233,3 +233,4 @@ NewCaseVisualPanel1.lbBadMultiUserSettings.text= ImageFilePanel.errorLabel.text=Error Label DataSourceOnCDriveError.text=Path to data source is on \"C:\" drive LocalFilesPanel.errorLabel.text=Error Label +NewCaseVisualPanel1.errorLabel.text=Error Label diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties index 07845b238f..a3d3832f82 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle_ja.properties @@ -217,3 +217,4 @@ LocalDiskPanel.noFatOrphansCheckbox.text=FAT\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9 AddImageWizardIngestConfigPanel.CANCEL_BUTTON.text=\u30ad\u30e3\u30f3\u30bb\u30eb ImageFilePanel.errorLabel.text=\u30a8\u30e9\u30fc\u30e9\u30d9\u30eb LocalFilesPanel.errorLabel.text=\u30a8\u30e9\u30fc\u30e9\u30d9\u30eb +NewCaseVisualPanel1.errorLabel.text=\u30a8\u30e9\u30fc\u30e9\u30d9\u30eb diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java index 855077f5f6..599182fc41 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java @@ -316,7 +316,7 @@ public class ImageFilePanel extends JPanel implements DocumentListener { // check if the is a WizardPathValidator service provider if (!pathValidatorList.isEmpty()) { // call WizardPathValidator service provider - errorString = pathValidatorList.get(0).validateDataSourcePath(path); + errorString = pathValidatorList.get(0).validateDataSourcePath(path, Case.getCurrentCase().getCaseType()); } else { // validate locally if (Case.getCurrentCase().getCaseType() == CaseType.MULTI_USER_CASE) { diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java index 38e90acee9..b10e054785 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java @@ -276,7 +276,7 @@ final class LocalDiskPanel extends JPanel { // check if the is a WizardPathValidator service provider if (!pathValidatorList.isEmpty()) { // call WizardPathValidator service provider - errorString = pathValidatorList.get(0).validateDataSourcePath(newPath); + errorString = pathValidatorList.get(0).validateDataSourcePath(newPath, Case.getCurrentCase().getCaseType()); } else { // validate locally if (Case.getCurrentCase().getCaseType() == Case.CaseType.MULTI_USER_CASE) { diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java index 5fe07b097f..0e52e59563 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java @@ -36,6 +36,7 @@ import java.util.logging.Level; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.openide.util.Lookup; +import org.sleuthkit.autopsy.casemodule.Case.CaseType; import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; import org.sleuthkit.autopsy.coreutils.Logger; /** @@ -137,18 +138,19 @@ import org.sleuthkit.autopsy.coreutils.Logger; // Path variable for "Local files" module is a coma separated string containg multiple paths List pathsList = Arrays.asList(path.split(",")); + CaseType currentCaseType = Case.getCurrentCase().getCaseType(); for (String currentPath : pathsList) { // check if the is a WizardPathValidator service provider if (!pathValidatorList.isEmpty()) { // call WizardPathValidator service provider - errorString = pathValidatorList.get(0).validateDataSourcePath(currentPath); + errorString = pathValidatorList.get(0).validateDataSourcePath(currentPath, currentCaseType); if (!errorString.isEmpty()) { break; } } else { // validate locally - if (Case.getCurrentCase().getCaseType() == Case.CaseType.MULTI_USER_CASE) { + if (currentCaseType == Case.CaseType.MULTI_USER_CASE) { // check that path is not on "C:" drive if (pathOnCDrive(currentPath)) { errorString = NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text"); //NON-NLS diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.form b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.form index 37314730b4..dc370e00cd 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.form +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.form @@ -23,33 +23,49 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + - - + - @@ -73,12 +89,14 @@ - + - + + + @@ -158,6 +176,9 @@ + + + @@ -168,6 +189,9 @@ + + + @@ -182,5 +206,15 @@ + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java index 82584797f1..7ae8a2858c 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java @@ -22,13 +22,18 @@ import org.openide.util.NbBundle; import java.awt.*; import java.io.File; +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.swing.JFileChooser; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import org.openide.util.Lookup; import org.sleuthkit.autopsy.casemodule.Case.CaseType; import org.sleuthkit.autopsy.core.UserPreferences; +import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; import org.sleuthkit.datamodel.CaseDbConnectionInfo; import org.sleuthkit.datamodel.TskData.DbType; @@ -41,9 +46,13 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { private JFileChooser fc = new JFileChooser(); private NewCaseWizardPanel1 wizPanel; + java.util.List pathValidatorList = new ArrayList<>(); + private final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$"); NewCaseVisualPanel1(NewCaseWizardPanel1 wizPanel) { initComponents(); + discoverWizardPathValidators(); + errorLabel.setVisible(false); lbBadMultiUserSettings.setText(""); this.wizPanel = wizPanel; caseNameTextField.getDocument().addDocumentListener(this); @@ -145,6 +154,7 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { rbSingleUserCase = new javax.swing.JRadioButton(); rbMultiUserCase = new javax.swing.JRadioButton(); lbBadMultiUserSettings = new javax.swing.JLabel(); + errorLabel = new javax.swing.JLabel(); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.jLabel1.text_1")); // NOI18N @@ -171,14 +181,27 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { caseTypeButtonGroup.add(rbSingleUserCase); org.openide.awt.Mnemonics.setLocalizedText(rbSingleUserCase, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.rbSingleUserCase.text")); // NOI18N + rbSingleUserCase.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + rbSingleUserCaseActionPerformed(evt); + } + }); caseTypeButtonGroup.add(rbMultiUserCase); org.openide.awt.Mnemonics.setLocalizedText(rbMultiUserCase, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.rbMultiUserCase.text")); // NOI18N + rbMultiUserCase.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + rbMultiUserCaseActionPerformed(evt); + } + }); lbBadMultiUserSettings.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N lbBadMultiUserSettings.setForeground(new java.awt.Color(255, 0, 0)); org.openide.awt.Mnemonics.setLocalizedText(lbBadMultiUserSettings, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.lbBadMultiUserSettings.text")); // NOI18N + errorLabel.setForeground(new java.awt.Color(255, 0, 0)); + org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(NewCaseVisualPanel1.class, "NewCaseVisualPanel1.errorLabel.text")); // NOI18N + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -186,27 +209,37 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel2) .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(caseDirTextField, javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 58, Short.MAX_VALUE) + .addComponent(lbBadMultiUserSettings, javax.swing.GroupLayout.PREFERRED_SIZE, 372, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(jLabel1) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(caseDirLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(caseParentDirTextField)) + .addGroup(layout.createSequentialGroup() + .addComponent(caseNameLabel) + .addGap(26, 26, 26) + .addComponent(caseNameTextField))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(caseDirBrowseButton))) + .addContainerGap()) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() .addComponent(rbSingleUserCase) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(rbMultiUserCase)) - .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(caseDirLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(caseParentDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(caseNameLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(caseNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(caseDirTextField, javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lbBadMultiUserSettings, javax.swing.GroupLayout.PREFERRED_SIZE, 372, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(caseDirBrowseButton))) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(errorLabel)) + .addGap(0, 0, Short.MAX_VALUE)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -226,11 +259,13 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(caseDirTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(rbSingleUserCase) .addComponent(rbMultiUserCase)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(errorLabel) + .addGap(1, 1, 1) .addComponent(lbBadMultiUserSettings, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); @@ -261,6 +296,16 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { } }//GEN-LAST:event_caseDirBrowseButtonActionPerformed + private void rbSingleUserCaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbSingleUserCaseActionPerformed + this.wizPanel.fireChangeEvent(); + updateUI(null); // DocumentEvent is not used inside updateUI + }//GEN-LAST:event_rbSingleUserCaseActionPerformed + + private void rbMultiUserCaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbMultiUserCaseActionPerformed + this.wizPanel.fireChangeEvent(); + updateUI(null); // DocumentEvent is not used inside updateUI + }//GEN-LAST:event_rbMultiUserCaseActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton caseDirBrowseButton; private javax.swing.JLabel caseDirLabel; @@ -269,6 +314,7 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { private javax.swing.JTextField caseNameTextField; private javax.swing.JTextField caseParentDirTextField; private javax.swing.ButtonGroup caseTypeButtonGroup; + private javax.swing.JLabel errorLabel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel lbBadMultiUserSettings; @@ -320,9 +366,17 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { * @param e the document event */ public void updateUI(DocumentEvent e) { + + // Note: DocumentEvent e can be null when called from rbSingleUserCaseActionPerformed() + // and rbMultiUserCaseActionPerformed(). String caseName = getCaseName(); String parentDir = getCaseParentDir(); + + if (!isImagePathValid(parentDir)) { + wizPanel.setIsFinish(false); + return; + } if (!caseName.equals("") && !parentDir.equals("")) { caseDirTextField.setText(parentDir + caseName); @@ -332,4 +386,65 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { wizPanel.setIsFinish(false); } } + + /** + * Validates path to selected data source. Calls WizardPathValidator service provider + * if one is available. Otherwise performs path validation locally. + * @param path Absolute path to the selected data source + * @return true if path is valid, false otherwise. + */ + private boolean isImagePathValid(String path){ + + errorLabel.setVisible(false); + String errorString = ""; + + if (path.isEmpty()) { + return false; // no need for error message as the module sets path to "" at startup + } + + // check if the is a WizardPathValidator service provider + if (!pathValidatorList.isEmpty()) { + // call WizardPathValidator service provider + errorString = pathValidatorList.get(0).validateDataSourcePath(path, getCaseType()); + } else { + // validate locally + if (getCaseType() == Case.CaseType.MULTI_USER_CASE) { + // check that path is not on "C:" drive + if (pathOnCDrive(path)) { + errorString = NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text"); //NON-NLS + } + } else { + // single user case - no validation needed + } + } + + // set error string + if (!errorString.isEmpty()){ + errorLabel.setVisible(true); + errorLabel.setText(errorString); + return false; + } + + return true; + } + + /** + * Checks whether a file path contains drive letter defined by pattern. + * + * @param filePath Input file absolute path + * @return true if path matches the pattern, false otherwise. + */ + private boolean pathOnCDrive(String filePath) { + Matcher m = driveLetterPattern.matcher(filePath); + return m.find(); + } + + /** + * Discovers WizardPathValidator service providers + */ + private void discoverWizardPathValidators() { + for (WizardPathValidator pathValidator : Lookup.getDefault().lookupAll(WizardPathValidator.class)) { + pathValidatorList.add(pathValidator); + } + } } diff --git a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java index 9cebb1411d..045e91198a 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java @@ -18,6 +18,8 @@ */ package org.sleuthkit.autopsy.corecomponentinterfaces; +import org.sleuthkit.autopsy.casemodule.Case; + /* * Defines an interface used by the Add DataSource wizard to validate path for selected * case and/or data source. @@ -36,17 +38,19 @@ public interface WizardPathValidator { * Validates case path. * * @param path Absolute path to case file. + * @param caseType Case type * @return String Error message if path is invalid, empty string otherwise. * */ - String validateCasePath(String path); + String validateCasePath(String path, Case.CaseType caseType); /** * Validates data source path. * * @param path Absolute path to data source file. + * @param caseType Case type * @return String Error message if path is invalid, empty string otherwise. * */ - String validateDataSourcePath(String path); + String validateDataSourcePath(String path, Case.CaseType caseType); } From adfbdf78e71ac9b4343a6b1448fef5537cd44aaa Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Thu, 21 May 2015 10:14:03 -0400 Subject: [PATCH 37/79] Modified error text --- Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties | 3 ++- .../org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index de512b48b3..35a6d6a7ae 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -231,6 +231,7 @@ NewCaseVisualPanel1.rbSingleUserCase.text=Single-user NewCaseVisualPanel1.rbMultiUserCase.text=Multi-user NewCaseVisualPanel1.lbBadMultiUserSettings.text= ImageFilePanel.errorLabel.text=Error Label -DataSourceOnCDriveError.text=Path to data source is on \"C:\" drive +DataSourceOnCDriveError.text=Path to multi-user data source is on \"C:\" drive +NewCaseVisualPanel1.CaseFolderOnCDriveError.text=Path to multi-user case folder is on \"C:\" drive LocalFilesPanel.errorLabel.text=Error Label NewCaseVisualPanel1.errorLabel.text=Error Label diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java index 7ae8a2858c..0749da0d5e 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java @@ -411,7 +411,7 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { if (getCaseType() == Case.CaseType.MULTI_USER_CASE) { // check that path is not on "C:" drive if (pathOnCDrive(path)) { - errorString = NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text"); //NON-NLS + errorString = NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnCDriveError.text"); //NON-NLS } } else { // single user case - no validation needed From 1c6f61258809989d96c3f7801c1a19df5201110a Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Thu, 21 May 2015 10:50:43 -0400 Subject: [PATCH 38/79] Image resizing exception handled. Image cropped instead --- .../sleuthkit/autopsy/coreutils/ImageUtils.java | 14 +++++++++++--- .../sleuthkit/autopsy/corelibs/ScalrWrapper.java | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java index 2bbb74d823..b4d89e5a9d 100755 --- a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java @@ -53,7 +53,7 @@ public class ImageUtils { private static final Logger logger = Logger.getLogger(ImageUtils.class.getName()); private static final Image DEFAULT_ICON = new ImageIcon("/org/sleuthkit/autopsy/images/file-icon.png").getImage(); //NON-NLS private static final List SUPP_EXTENSIONS = Arrays.asList(ImageIO.getReaderFileSuffixes()); - private static final List SUPP_MIME_TYPES = new ArrayList(Arrays.asList(ImageIO.getReaderMIMETypes())); + private static final List SUPP_MIME_TYPES = new ArrayList<>(Arrays.asList(ImageIO.getReaderMIMETypes())); static { SUPP_MIME_TYPES.add("image/x-ms-bmp"); } @@ -259,9 +259,10 @@ public class ImageUtils { private static BufferedImage generateIcon(Content content, int iconSize) { InputStream inputStream = null; + BufferedImage bi = null; try { inputStream = new ReadContentInputStream(content); - BufferedImage bi = ImageIO.read(inputStream); + bi = ImageIO.read(inputStream); if (bi == null) { logger.log(Level.WARNING, "No image reader for file: " + content.getName()); //NON-NLS return null; @@ -269,7 +270,14 @@ public class ImageUtils { BufferedImage biScaled = ScalrWrapper.resizeFast(bi, iconSize); return biScaled; - } catch (OutOfMemoryError e) { + } catch (IllegalArgumentException e) { + // if resizing does not work due to extremely small height/width ratio, + // crop the image instead. + BufferedImage biCropped = ScalrWrapper.cropImage(bi, iconSize > bi.getWidth() ? + bi.getWidth() : iconSize, iconSize > bi.getHeight() ? bi.getHeight() : iconSize); + return biCropped; + } + catch (OutOfMemoryError e) { logger.log(Level.WARNING, "Could not scale image (too large): " + content.getName(), e); //NON-NLS return null; } catch (Exception e) { diff --git a/CoreLibs/src/org/sleuthkit/autopsy/corelibs/ScalrWrapper.java b/CoreLibs/src/org/sleuthkit/autopsy/corelibs/ScalrWrapper.java index ef2cf7c876..a5ee9d1c68 100644 --- a/CoreLibs/src/org/sleuthkit/autopsy/corelibs/ScalrWrapper.java +++ b/CoreLibs/src/org/sleuthkit/autopsy/corelibs/ScalrWrapper.java @@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.corelibs; import java.awt.image.BufferedImage; +import java.awt.image.BufferedImageOp; import org.imgscalr.Scalr; import org.imgscalr.Scalr.Method; @@ -48,4 +49,8 @@ import org.imgscalr.Scalr.Method; public static synchronized BufferedImage resizeFast(BufferedImage input, int width, int height) { return Scalr.resize(input, Method.SPEED, Scalr.Mode.AUTOMATIC, width, height, Scalr.OP_ANTIALIAS); } + + public static synchronized BufferedImage cropImage(BufferedImage input, int width, int height) { + return Scalr.crop(input, width, height, (BufferedImageOp) null); + } } From f4e93f52a67a04946d9e192de7f32e987bf2507b Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Thu, 21 May 2015 11:45:43 -0400 Subject: [PATCH 39/79] replace ternary operator with Math.min() --- Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java index b4d89e5a9d..f8ad010859 100755 --- a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java @@ -273,8 +273,7 @@ public class ImageUtils { } catch (IllegalArgumentException e) { // if resizing does not work due to extremely small height/width ratio, // crop the image instead. - BufferedImage biCropped = ScalrWrapper.cropImage(bi, iconSize > bi.getWidth() ? - bi.getWidth() : iconSize, iconSize > bi.getHeight() ? bi.getHeight() : iconSize); + BufferedImage biCropped = ScalrWrapper.cropImage(bi, Math.min(iconSize, bi.getWidth()), Math.min(iconSize, bi.getHeight())); return biCropped; } catch (OutOfMemoryError e) { From 3a1733607c06e27421bb172ab2a8dc73be64ca34 Mon Sep 17 00:00:00 2001 From: Karl Mortensen Date: Thu, 21 May 2015 11:46:57 -0400 Subject: [PATCH 40/79] Add getCaseType(Path) --- .../autopsy/casemodule/Bundle.properties | 1 + .../sleuthkit/autopsy/casemodule/Case.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index cdbed0aa1f..1251b2d194 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -137,6 +137,7 @@ Case.createCaseDir.exception.cantCreateReportsDir=Could not create reports outpu Case.createCaseDir.exception.gen=Could not create case directory\: {0} Case.OpenEventChannel.FailPopup.ErrMsg=Failed to connect to any other nodes that may be collaborating on this case. Case.OpenEventChannel.FailPopup.Title=Connection Failure +Case.GetCaseTypeGivenPath.Failure=Unable to get case type CaseDeleteAction.closeConfMsg.text=Are you sure want to close and delete this case? \n\ Case Name\: {0}\n\ Case Directory\: {1} diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 33a2b00386..94899b9289 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -43,6 +43,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; +import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.actions.CallableSystemAction; @@ -747,6 +748,24 @@ public class Case implements SleuthkitCase.ErrorObserver { return this.caseType; } + /** + * Get the case type within an .aut file. Defaults to single-user case if + * there is a problem. + * + * @param thePath the path to the file, example: C:\folder\case.aut + * @return The case type contained in the .aut file. + */ + public static CaseType getCaseType(Path thePath) { + try { + XMLCaseManagement xmlcm = new XMLCaseManagement(); + xmlcm.open(thePath.toString()); + return xmlcm.getCaseType(); + } catch (CaseActionException ex) { + logger.log(Level.SEVERE, NbBundle.getMessage(Case.class, "Case.GetCaseTypeGivenPath.Failure"), ex); // NON-NLS + return CaseType.SINGLE_USER_CASE; + } + } + /** * Gets the full path to the temp directory of this case. Will create it if * it does not already exist. From 24bc7c14f732676e4a86c0f08f52787425e5bbfa Mon Sep 17 00:00:00 2001 From: APriestman Date: Fri, 22 May 2015 09:35:50 -0400 Subject: [PATCH 41/79] Fixed bug where the incorrect category name was being displayed when grouping by category. For speed, now stores hash set hits in memory. Fixed bug where hash hit count would never update after a group was created, even if files were added/removed Changed category zero count to be bases on other counts and not stored separately. --- .../actions/CategorizeAction.java | 7 +- .../imagegallery/datamodel/Category.java | 2 +- .../imagegallery/datamodel/DrawableDB.java | 119 ++++++++++++------ .../imagegallery/datamodel/DrawableFile.java | 12 +- .../imagegallery/grouping/DrawableGroup.java | 20 ++- .../imagegallery/grouping/GroupManager.java | 38 +++--- .../imagegallery/gui/DrawableView.java | 11 +- .../gui/SingleDrawableViewBase.java | 2 +- .../gui/navpanel/GroupTreeCell.java | 12 +- 9 files changed, 144 insertions(+), 79 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 7cdd45b0ae..7fb5d140aa 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -100,17 +100,12 @@ public class CategorizeAction extends AddTagAction { //this is bad: treating tags as categories as long as their names start with prefix //TODO: abandon using tags for categories and instead add a new column to DrawableDB if (ct.getName().getDisplayName().startsWith(Category.CATEGORY_PREFIX)) { - LOGGER.log(Level.INFO, "removing old category from {0}", file.getName()); + //LOGGER.log(Level.INFO, "removing old category from {0}", file.getName()); Case.getCurrentCase().getServices().getTagsManager().deleteContentTag(ct); controller.getDatabase().decrementCategoryCount(Category.fromDisplayName(ct.getName().getDisplayName())); hadExistingCategory = true; } } - - // If the image was uncategorized, decrement the uncategorized count - if(! hadExistingCategory){ - controller.getDatabase().decrementCategoryCount(Category.ZERO); - } controller.getDatabase().incrementCategoryCount(Category.fromDisplayName(tagName.getDisplayName())); if (tagName != Category.ZERO.getTagName()) { // no tags for cat-0 diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index dcf0862875..030dc5329d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -66,7 +66,7 @@ public enum Category implements Comparable { private final static Set listeners = new HashSet<>(); public static void fireChange(Collection ids) { - Set listenersCopy = new HashSet(listeners); + Set listenersCopy = new HashSet<>(); synchronized (listeners) { listenersCopy.addAll(listeners); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index dc84f0e7da..1d69e88e84 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -50,6 +50,8 @@ import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.autopsy.imagegallery.grouping.GroupSortBy; import static org.sleuthkit.autopsy.imagegallery.grouping.GroupSortBy.GROUP_BY_VALUE; import org.sleuthkit.datamodel.AbstractFile; +import org.sleuthkit.datamodel.BlackboardArtifact; +import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TagName; @@ -1119,6 +1121,46 @@ public class DrawableDB { } } + @GuardedBy("hashSetMap") + private final Map> hashSetMap = new HashMap<>(); + + @GuardedBy("hashSetMap") + public boolean isInHashSet(Long id){ + if(! hashSetMap.containsKey(id)){ + updateHashSetsForFile(id); + } + return (! hashSetMap.get(id).isEmpty()); + } + + @GuardedBy("hashSetMap") + public Set getHashSetsForFile(Long id){ + if(! isInHashSet(id)){ + updateHashSetsForFile(id); + } + return hashSetMap.get(id); + } + + @GuardedBy("hashSetMap") + public void updateHashSetsForFile(Long id){ + + try { + List arts = ImageGalleryController.getDefault().getSleuthKitCase().getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT, id); + Set hashNames = new HashSet<>(); + for(BlackboardArtifact a:arts){ + List attrs = a.getAttributes(); + for(BlackboardAttribute attr:attrs){ + if(attr.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID()){ + hashNames.add(attr.getValueString()); + } + } + } + hashSetMap.put(id, hashNames); + } catch (IllegalStateException | TskCoreException ex) { + LOGGER.log(Level.WARNING, "could not access case during updateHashSetsForFile()", ex); + + } + } + /** * For performance reasons, keep a list of all file IDs currently in the image database. * Otherwise the database is queried many times to retrieve the same data. @@ -1144,6 +1186,12 @@ public class DrawableDB { } } + public int getNumberOfImageFilesInList(){ + synchronized (fileIDlist){ + return fileIDlist.size(); + } + } + public void initializeImageList(){ synchronized (fileIDlist){ dbReadLock(); @@ -1169,63 +1217,52 @@ public class DrawableDB { private final Map categoryCounts = new HashMap<>(); public void incrementCategoryCount(Category cat) throws TskCoreException{ - synchronized(categoryCounts){ - int count = getCategoryCount(cat); - count++; - categoryCounts.put(cat, count); + if(cat != Category.ZERO){ + synchronized(categoryCounts){ + int count = getCategoryCount(cat); + count++; + categoryCounts.put(cat, count); + } } } public void decrementCategoryCount(Category cat) throws TskCoreException{ - synchronized(categoryCounts){ - int count = getCategoryCount(cat); - count--; - categoryCounts.put(cat, count); + if(cat != Category.ZERO){ + synchronized(categoryCounts){ + int count = getCategoryCount(cat); + count--; + categoryCounts.put(cat, count); + } } } public int getCategoryCount(Category cat) throws TskCoreException{ synchronized(categoryCounts){ - if(categoryCounts.containsKey(cat)){ + if(cat == Category.ZERO){ + // Keeping track of the uncategorized files is a bit tricky while ingest + // is going on, so always use the list of file IDs we already have along with the + // other category counts instead of trying to track it separately. + int allOtherCatCount = getCategoryCount(Category.ONE) + getCategoryCount(Category.TWO) + getCategoryCount(Category.THREE) + + getCategoryCount(Category.FOUR) + getCategoryCount(Category.FIVE); + return getNumberOfImageFilesInList() - allOtherCatCount; + } + else if(categoryCounts.containsKey(cat)){ return categoryCounts.get(cat); } else{ try { - if (cat == Category.ZERO) { - - // Category Zero (Uncategorized) files will not be tagged as such - - // this is really just the default setting. So we count the number of files - // tagged with the other categories and subtract from the total. - int allOtherCatCount = 0; - TagName[] tns = {Category.FOUR.getTagName(), Category.THREE.getTagName(), Category.TWO.getTagName(), Category.ONE.getTagName(), Category.FIVE.getTagName()}; - for (TagName tn : tns) { - List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(tn); - for (ContentTag ct : contentTags) { - if(ct.getContent() instanceof AbstractFile){ - AbstractFile f = (AbstractFile)ct.getContent(); - if(this.isImageFile(f.getId())){ - allOtherCatCount++; - } - } - } - } - categoryCounts.put(cat, this.countAllFiles() - allOtherCatCount); - return categoryCounts.get(cat); - } else { - - int fileCount = 0; - List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(cat.getTagName()); - for (ContentTag ct : contentTags) { - if(ct.getContent() instanceof AbstractFile){ - AbstractFile f = (AbstractFile)ct.getContent(); - if(this.isImageFile(f.getId())){ - fileCount++; - } + int fileCount = 0; + List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(cat.getTagName()); + for (ContentTag ct : contentTags) { + if(ct.getContent() instanceof AbstractFile){ + AbstractFile f = (AbstractFile)ct.getContent(); + if(this.isImageFile(f.getId())){ + fileCount++; } } - categoryCounts.put(cat, fileCount); - return fileCount; } + categoryCounts.put(cat, fileCount); + return fileCount; } catch(IllegalStateException ex){ throw new TskCoreException("Case closed while getting files"); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java index 886f70e9a7..c04cb2c900 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableFile.java @@ -35,6 +35,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.WordUtils; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.ImageGalleryModule; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; @@ -97,8 +98,6 @@ public abstract class DrawableFile extends AbstractFile private final SimpleObjectProperty category = new SimpleObjectProperty<>(null); - private Collection hashHitSetNames; - private String make; private String model; @@ -116,16 +115,11 @@ public abstract class DrawableFile extends AbstractFile public abstract boolean isVideo(); - public Collection getHashHitSetNames() { - updateHashSets(); + synchronized public Collection getHashHitSetNames() { + Collection hashHitSetNames = ImageGalleryController.getDefault().getDatabase().getHashSetsForFile(getId()); return hashHitSetNames; } - @SuppressWarnings("unchecked") - private void updateHashSets() { - hashHitSetNames = (Collection) getValuesOfBBAttribute(BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME); - } - @Override public boolean isRoot() { return false; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java index 9ad39ac18f..d9cfdb70a4 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java @@ -65,18 +65,26 @@ public class DrawableGroup implements Comparable{ return getFilesWithHashSetHitsCount() / (double) getSize(); } - synchronized public int getFilesWithHashSetHitsCount() { + /** + * Call to indicate that an image has been added or removed from the group, + * so the hash counts may not longer be accurate. + */ + synchronized public void invalidateHashSetHitsCount(){ + filesWithHashSetHitsCount = -1; + } + + synchronized public int getFilesWithHashSetHitsCount() { //TODO: use the drawable db for this ? -jm if (filesWithHashSetHitsCount < 0) { filesWithHashSetHitsCount = 0; for (Long fileID : fileIds()) { + try { - long artcount = ImageGalleryController.getDefault().getSleuthKitCase().getBlackboardArtifactsCount(BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT, fileID); - if (artcount > 0) { + if(ImageGalleryController.getDefault().getDatabase().isInHashSet(fileID)){ filesWithHashSetHitsCount++; } - } catch (IllegalStateException | TskCoreException ex) { - LOGGER.log(Level.WARNING, "could not access case during getFilesWithHashSetHitsCount()", ex); + } catch (IllegalStateException | NullPointerException ex) { + LOGGER.log(Level.WARNING, "could not access case during getFilesWithHashSetHitsCount()"); break; } } @@ -112,10 +120,12 @@ public class DrawableGroup implements Comparable{ if (fileIDs.contains(f) == false) { fileIDs.add(f); } + invalidateHashSetHitsCount(); } synchronized public void removeFile(Long f) { fileIDs.removeAll(f); + invalidateHashSetHitsCount(); } // By default, sort by group key name diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index 39871d3cf7..3bda6a2410 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -281,18 +281,21 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { final DrawableGroup group = getGroupForKey(groupKey); if (group != null) { group.removeFile(fileID); - if (group.fileIds().isEmpty()) { - synchronized (groupMap) { - groupMap.remove(groupKey, group); - } - Platform.runLater(() -> { - analyzedGroups.remove(group); - synchronized (unSeenGroups) { - unSeenGroups.remove(group); + + // If we're grouping by category, we don't want to remove empty groups. + if(! group.groupKey.getValueDisplayName().startsWith("CAT-")){ + if (group.fileIds().isEmpty()) { + synchronized (groupMap) { + groupMap.remove(groupKey, group); } - }); + Platform.runLater(() -> { + analyzedGroups.remove(group); + synchronized (unSeenGroups) { + unSeenGroups.remove(group); + } + }); + } } - } } @@ -487,7 +490,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { for (TagName tn : tns) { List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(tn); for (ContentTag ct : contentTags) { - if (ct.getContent() instanceof AbstractFile && ImageGalleryModule.isSupportedAndNotKnown((AbstractFile) ct.getContent())) { + if (ct.getContent() instanceof AbstractFile && db.isImageFile(((AbstractFile) ct.getContent()).getId())) { files.add(ct.getContent().getId()); } } @@ -499,7 +502,8 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { List files = new ArrayList<>(); List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(category.getTagName()); for (ContentTag ct : contentTags) { - if (ct.getContent() instanceof AbstractFile && ImageGalleryModule.isSupportedAndNotKnown((AbstractFile) ct.getContent())) { + if (ct.getContent() instanceof AbstractFile && db.isImageFile(((AbstractFile) ct.getContent()).getId())) { + files.add(ct.getContent().getId()); } } @@ -529,7 +533,8 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { List files = new ArrayList<>(); List contentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByTagName(tagName); for (ContentTag ct : contentTags) { - if (ct.getContent() instanceof AbstractFile && ImageGalleryModule.isSupportedAndNotKnown((AbstractFile) ct.getContent())) { + if (ct.getContent() instanceof AbstractFile && db.isImageFile(((AbstractFile) ct.getContent()).getId())) { + files.add(ct.getContent().getId()); } } @@ -649,7 +654,10 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { if (checkAnalyzed != null) { // => the group is analyzed, so add it to the ui populateAnalyzedGroup(gk, checkAnalyzed); } - } + } + else{ + g.invalidateHashSetHitsCount(); + } } } @@ -668,6 +676,8 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * innertask? -jm */ for (final long fileId : fileIDs) { + + db.updateHashSetsForFile(fileId); //get grouping(s) this file would be in Set> groupsForFile = getGroupKeysForFileID(fileId); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java index b7a58534f5..9de7704d7a 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/DrawableView.java @@ -1,6 +1,7 @@ package org.sleuthkit.autopsy.imagegallery.gui; import java.util.Collection; +import java.util.logging.Level; import javafx.application.Platform; import javafx.scene.layout.Border; import javafx.scene.layout.BorderStroke; @@ -9,6 +10,7 @@ import javafx.scene.layout.BorderWidths; import javafx.scene.layout.CornerRadii; import javafx.scene.layout.Region; import javafx.scene.paint.Color; +import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.imagegallery.TagUtils; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; @@ -56,7 +58,14 @@ public interface DrawableView extends Category.CategoryListener, TagUtils.TagLis void handleTagsChanged(Collection ids); default boolean hasHashHit() { - return getFile().getHashHitSetNames().isEmpty() == false; + try{ + return getFile().getHashHitSetNames().isEmpty() == false; + } catch (NullPointerException ex){ + // I think this happens when we're in the process of removing images from the view while + // also trying to update it? + Logger.getLogger(DrawableView.class.getName()).log(Level.WARNING, "Error looking up hash set hits"); + return false; + } } static Border getCategoryBorder(Category category) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SingleDrawableViewBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SingleDrawableViewBase.java index 7ff83043af..92037461c6 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SingleDrawableViewBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SingleDrawableViewBase.java @@ -370,7 +370,7 @@ public abstract class SingleDrawableViewBase extends AnchorPane implements Drawa } else { Category.registerListener(this); TagUtils.registerListener(this); - + getFile(); updateSelectionState(); updateCategoryBorder(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java index bd43ed4b9b..f5e2b138dc 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java @@ -60,7 +60,17 @@ class GroupTreeCell extends TreeCell { //if number of files in this group changes (eg file is recategorized), update counts tNode.getGroup().fileIds().addListener((Observable o) -> { Platform.runLater(() -> { - setText(name + " (" + getNumerator() + getDenominator() + ")"); + + String groupName; // The "name" variable set earlier is generally not correct at this point + if((getItem() == null) || (getItem().getGroup() == null) || + (getItem().getGroup().groupKey == null)){ + groupName = ""; + } + else{ + groupName = getItem().getGroup().groupKey.getValueDisplayName(); + } + + setText(groupName + " (" + getNumerator() + getDenominator() + ")"); }); }); From 6c7f10a68d43a187ba83fd6393b167371a7e54b2 Mon Sep 17 00:00:00 2001 From: APriestman Date: Fri, 22 May 2015 10:30:59 -0400 Subject: [PATCH 42/79] Added comments about caching. --- .../autopsy/imagegallery/datamodel/DrawableDB.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java index 1d69e88e84..30ad021681 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/DrawableDB.java @@ -1121,6 +1121,16 @@ public class DrawableDB { } } + /* + * The following groups of functions are used to store information in memory instead + * of in the database. Due to the change listeners in the GUI, this data is requested + * many, many times when browsing the images, and especially when making any + * changes to things like categories. + * + * I don't like having multiple copies of the data, but these were causing major + * bottlenecks when they were all database lookups. + */ + @GuardedBy("hashSetMap") private final Map> hashSetMap = new HashMap<>(); From 34c5a1d6c905c2377b12e713d43735567be6c2c4 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Fri, 22 May 2015 11:22:49 -0400 Subject: [PATCH 43/79] Resource bundle updated. Unalloc Unused blocks marked as octet-stream --- .../autopsy/modules/exif/Bundle.properties | 1 + .../modules/exif/ExifParserFileIngestModule.java | 5 +++-- .../modules/filetypeid/FileTypeDetector.java | 14 ++++++++++++-- .../modules/filetypeid/FileTypeIdIngestModule.java | 9 --------- .../autopsy/modules/sevenzip/Bundle.properties | 1 + .../modules/sevenzip/SevenZipIngestModule.java | 4 ++-- .../autopsy/keywordsearch/Bundle.properties | 1 + .../keywordsearch/KeywordSearchIngestModule.java | 4 ++-- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/exif/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/exif/Bundle.properties index 2987fc2ae8..391cfdac7f 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/exif/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/exif/Bundle.properties @@ -6,3 +6,4 @@ OpenIDE-Module-Name=ExifParser OpenIDE-Module-Short-Description=Exif metadata ingest module ExifParserFileIngestModule.moduleName.text=Exif Parser ExifParserFileIngestModule.getDesc.text=Ingests JPEG files and retrieves their EXIF metadata. +ExifParserFileIngestModule.startUp.fileTypeDetectorInitializationException.msg=Error initializing the File Type Detector. \ No newline at end of file diff --git a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java index 1f7ae3ed9a..f3f7ea3313 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java @@ -34,6 +34,7 @@ import java.util.Collection; import java.util.Date; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; +import org.openide.util.NbBundle; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.ingest.FileIngestModule; import org.sleuthkit.autopsy.ingest.IngestJobContext; @@ -75,8 +76,8 @@ public final class ExifParserFileIngestModule implements FileIngestModule { try { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { - logger.log(Level.SEVERE, "Error initializing FileTypeDetector", ex); // NON-NLS - throw new IngestModuleException("Error initializing FileTypeDetector"); // NON-NLS + logger.log(Level.SEVERE, NbBundle.getMessage(this.getClass(), "ExifParserFileIngestModule.startUp.fileTypeDetectorInitializationException.msg"), ex); + throw new IngestModuleException(NbBundle.getMessage(this.getClass(), "ExifParserFileIngestModule.startUp.fileTypeDetectorInitializationException.msg")); } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index 6e775b93e8..4b8b9266e8 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -30,6 +30,7 @@ import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.datamodel.TskData; /** * Detects the type of a file by an inspection of its contents. @@ -143,12 +144,21 @@ public class FileTypeDetector { * succeeds. * * @param file The file to test. - * @param moduleName The name of the module posting to the blackboard. * @return The MIME type name id detection was successful, null otherwise. * @throws TskCoreException if there is an error posting to the blackboard. */ public String detectAndPostToBlackboard(AbstractFile file) throws TskCoreException { - String mimeType = detect(file); + + String mimeType; + // Consistently mark unallocated and unused space as file type application/octet-stream + if ((file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) + || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) + || (file.isFile() == false)) { + mimeType = MimeTypes.OCTET_STREAM; + } else { + mimeType = detect(file); + } + if (null != mimeType) { /** * Add the file type attribute to the general info artifact. Note diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java index f1fe3e26bd..142081a005 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java @@ -95,15 +95,6 @@ public class FileTypeIdIngestModule implements FileIngestModule { @Override public ProcessResult process(AbstractFile file) { - /** - * Skip unallocated space and unused blocks files. - */ - if ((file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) - || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) - || (file.isFile() == false)) { - return ProcessResult.OK; - } - /** * Skip known files if configured to do so. */ diff --git a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/Bundle.properties index f0540e3482..badd35146a 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/Bundle.properties @@ -29,3 +29,4 @@ SevenZipIngestModule.unpack.encrFileDetected.msg=Encrypted files in archive dete SevenZipIngestModule.unpack.encrFileDetected.details=Some files in archive\: {0} are encrypted. {1} extractor was unable to extract all files from this archive. SevenZipIngestModule.UnpackStream.write.exception.msg=Error writing unpacked file to\: {0} SevenZipIngestModule.UnpackedTree.exception.msg=Error adding a derived file to db\:{0} +SevenZipIngestModule.startUp.fileTypeDetectorInitializationException.msg=Error initializing the File Type Detector. diff --git a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java index c72b5ec4f3..59553ae89f 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java @@ -103,8 +103,8 @@ public final class SevenZipIngestModule implements FileIngestModule { try { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { - logger.log(Level.SEVERE, "Error initializing FileTypeDetector", ex); // NON-NLS - throw new IngestModuleException("Error initializing FileTypeDetector"); // NON-NLS + logger.log(Level.SEVERE, NbBundle.getMessage(this.getClass(), "SevenZipIngestModule.startUp.fileTypeDetectorInitializationException.msg"), ex); + throw new IngestModuleException(NbBundle.getMessage(this.getClass(), "SevenZipIngestModule.startUp.fileTypeDetectorInitializationException.msg")); } final Case currentCase = Case.getCurrentCase(); diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties index 03c68141f3..7e784739a7 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties @@ -283,3 +283,4 @@ KeywordSearchModuleFactory.createFileIngestModule.exception.msg=Expected setting SearchRunner.Searcher.done.err.msg=Error performing keyword search KeywordSearchGlobalSearchSettingsPanel.timeRadioButton5.toolTipText=Fastest overall, but no results until the end KeywordSearchGlobalSearchSettingsPanel.timeRadioButton5.text=No periodic searches +KeywordSearchIngestModule.startUp.fileTypeDetectorInitializationException.msg=Error initializing the File Type Detector. diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index 9bc0a6442b..5a4931574c 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -132,8 +132,8 @@ public final class KeywordSearchIngestModule implements FileIngestModule { try { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { - logger.log(Level.SEVERE, "Error initializing FileTypeDetector", ex); // NON-NLS - throw new IngestModuleException("Error initializing FileTypeDetector"); // NON-NLS + logger.log(Level.SEVERE, NbBundle.getMessage(this.getClass(), "KeywordSearchIngestModule.startUp.fileTypeDetectorInitializationException.msg"), ex); + throw new IngestModuleException(NbBundle.getMessage(this.getClass(), "KeywordSearchIngestModule.startUp.fileTypeDetectorInitializationException.msg")); } ingester = Server.getIngester(); this.context = context; From 404ea583b0c4d6e7208e07116b59b03d0428cb7c Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Mon, 25 May 2015 15:10:51 -0400 Subject: [PATCH 44/79] Bubble dialogs for exception firewall (common with Python modules), better Python load error --- .../autopsy/ingest/DataSourceIngestPipeline.java | 6 ++++++ .../sleuthkit/autopsy/ingest/FileIngestPipeline.java | 11 +++++++++++ .../org/sleuthkit/autopsy/python/Bundle.properties | 2 +- .../sleuthkit/autopsy/python/JythonModuleLoader.java | 3 ++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/ingest/DataSourceIngestPipeline.java b/Core/src/org/sleuthkit/autopsy/ingest/DataSourceIngestPipeline.java index 8e5fedbcf6..7bd84436d6 100755 --- a/Core/src/org/sleuthkit/autopsy/ingest/DataSourceIngestPipeline.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/DataSourceIngestPipeline.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.logging.Level; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.datamodel.Content; /** @@ -110,6 +111,11 @@ final class DataSourceIngestPipeline { logger.log(Level.INFO, "{0} analysis of {1} (jobId={2}) finished", new Object[]{module.getDisplayName(), this.job.getDataSource().getName(), this.job.getDataSource().getId()}); } catch (Throwable ex) { // Catch-all exception firewall errors.add(new IngestModuleError(module.getDisplayName(), ex)); + String msg = ex.getMessage(); + // Jython run-time errors don't seem to have a message, but have details in toString. + if (msg == null) + msg = ex.toString(); + MessageNotifyUtil.Notify.error(module.getDisplayName() + " Error", msg); } if (this.job.isCancelled()) { break; diff --git a/Core/src/org/sleuthkit/autopsy/ingest/FileIngestPipeline.java b/Core/src/org/sleuthkit/autopsy/ingest/FileIngestPipeline.java index 78db0b482d..7fb43176fc 100755 --- a/Core/src/org/sleuthkit/autopsy/ingest/FileIngestPipeline.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/FileIngestPipeline.java @@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.ingest; import java.util.ArrayList; import java.util.Date; import java.util.List; +import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.datamodel.AbstractFile; /** @@ -119,6 +120,11 @@ final class FileIngestPipeline { module.process(file); } catch (Throwable ex) { // Catch-all exception firewall errors.add(new IngestModuleError(module.getDisplayName(), ex)); + String msg = ex.getMessage(); + // Jython run-time errors don't seem to have a message, but have details in toString. + if (msg == null) + msg = ex.toString(); + MessageNotifyUtil.Notify.error(module.getDisplayName() + " Error", msg); } if (this.job.isCancelled()) { break; @@ -144,6 +150,11 @@ final class FileIngestPipeline { module.shutDown(); } catch (Throwable ex) { // Catch-all exception firewall errors.add(new IngestModuleError(module.getDisplayName(), ex)); + String msg = ex.getMessage(); + // Jython run-time errors don't seem to have a message, but have details in toString. + if (msg == null) + msg = ex.toString(); + MessageNotifyUtil.Notify.error(module.getDisplayName() + " Error", msg); } } this.running = false; diff --git a/Core/src/org/sleuthkit/autopsy/python/Bundle.properties b/Core/src/org/sleuthkit/autopsy/python/Bundle.properties index 27d48af5ef..9016f7518a 100755 --- a/Core/src/org/sleuthkit/autopsy/python/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/python/Bundle.properties @@ -1,2 +1,2 @@ JythonModuleLoader.errorMessages.failedToOpenModule=Failed to open {0}. See log for details. -JythonModuleLoader.errorMessages.failedToLoadModule=Failed to load {0} from {1}. See log for details. \ No newline at end of file +JythonModuleLoader.errorMessages.failedToLoadModule=Failed to load {0}. {1}. See log for details. \ No newline at end of file diff --git a/Core/src/org/sleuthkit/autopsy/python/JythonModuleLoader.java b/Core/src/org/sleuthkit/autopsy/python/JythonModuleLoader.java index 860a2eaaa4..50e9895fd2 100755 --- a/Core/src/org/sleuthkit/autopsy/python/JythonModuleLoader.java +++ b/Core/src/org/sleuthkit/autopsy/python/JythonModuleLoader.java @@ -81,8 +81,9 @@ public final class JythonModuleLoader { objects.add( createObjectFromScript(script, className, interfaceClass)); } catch (Exception ex) { logger.log(Level.SEVERE, String.format("Failed to load %s from %s", className, script.getAbsolutePath()), ex); //NON-NLS + // NOTE: using ex.toString() because the current version is always returning null for ex.getMessage(). DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( - NbBundle.getMessage(JythonModuleLoader.class, "JythonModuleLoader.errorMessages.failedToLoadModule", className, script.getAbsolutePath()), + NbBundle.getMessage(JythonModuleLoader.class, "JythonModuleLoader.errorMessages.failedToLoadModule", className, ex.toString()), NotifyDescriptor.ERROR_MESSAGE)); } } From 60a41bcfbc652eac3930cf697700d41ad4a69296 Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Mon, 25 May 2015 15:37:22 -0400 Subject: [PATCH 45/79] Updated python examples and docs --- docs/doxygen/Doxyfile | 2 +- docs/doxygen/modDevPython.dox | 2 +- docs/doxygen/modIngest.dox | 21 +- pythonExamples/README.txt | 18 +- ...estmodule.py => dataSourceIngestModule.py} | 132 +++++---- pythonExamples/fileIngestModule.py | 128 +++++++++ pythonExamples/fileIngestModuleWithGui.py | 203 +++++++++++++ pythonExamples/ingestmodule.py | 266 ------------------ 8 files changed, 420 insertions(+), 352 deletions(-) rename pythonExamples/{simpleingestmodule.py => dataSourceIngestModule.py} (58%) create mode 100755 pythonExamples/fileIngestModule.py create mode 100755 pythonExamples/fileIngestModuleWithGui.py delete mode 100755 pythonExamples/ingestmodule.py diff --git a/docs/doxygen/Doxyfile b/docs/doxygen/Doxyfile index 83dc78dafe..f3699e5c0e 100755 --- a/docs/doxygen/Doxyfile +++ b/docs/doxygen/Doxyfile @@ -113,7 +113,7 @@ ALWAYS_DETAILED_SEC = NO # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. -INLINE_INHERITED_MEMB = NO +INLINE_INHERITED_MEMB = YES # If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full # path before files name in the file list and in the header files. If set diff --git a/docs/doxygen/modDevPython.dox b/docs/doxygen/modDevPython.dox index f853842288..7ec3d3112c 100755 --- a/docs/doxygen/modDevPython.dox +++ b/docs/doxygen/modDevPython.dox @@ -60,7 +60,7 @@ To distribute and share your Python module, ZIP up the folder and send it around Jython allows you to access all of the Java classes. So, you should read the following sections of this document. All you should ignore is the Java environment setup sections. There are only two types of modules that you can make with Python. Those (along with a sample file) are listed below: -- Ingest Modules (both file-level and data source-level): https://github.com/sleuthkit/autopsy/blob/develop/pythonExamples/ingestmodule.py +- Ingest Modules (both file-level and data source-level): https://github.com/sleuthkit/autopsy/blob/develop/pythonExamples/ - Report Modules: https://github.com/sleuthkit/autopsy/blob/develop/pythonExamples/reportmodule.py */ diff --git a/docs/doxygen/modIngest.dox b/docs/doxygen/modIngest.dox index ffea77385d..0f3d4a1ebb 100755 --- a/docs/doxygen/modIngest.dox +++ b/docs/doxygen/modIngest.dox @@ -100,10 +100,12 @@ Before we cover the specific interfaces of the two different types of modules, l To create a data source ingest module: -# Create the ingest module class by either: - - Define a new class that implements (Java) or inherits (Jython) org.sleuthkit.autopsy.ingest.DataSourceIngestModule. If you are using Java, the NetBeans IDE + - Copy and paste the sample modules from: + - Java: Core/src/org/sleuthkit/autopsy/examples/SampleDataSourceIngestModule.java + - Python: pythonExamples/dataSourceIngestModule.py (https://github.com/sleuthkit/autopsy/tree/develop/pythonExamples) + - Or the manual approach is to define a new class that implements (Java) or inherits (Jython) org.sleuthkit.autopsy.ingest.DataSourceIngestModule. If you are using Java, the NetBeans IDE will complain that you have not implemented one or more of the required methods. You can use its "hints" to automatically generate stubs for the missing methods. - - Copy and paste the sample modules from org.sleuthkit.autopsy.examples.SampleDataSourceIngestModule or org.sleuthkit.autopsy.examples.ingestmodule.py. -# Configure your factory class to create instances of the new ingest module class. To do this, you will need to change the isDataSourceIngestModuleFactory() method to return true and have the createDataSourceIngestModule() method return a new instance of your ingest module. Both of these methods have default "no-op" implementations in the IngestModuleFactoryAdapter that we used. Your factory should have code similar to this Java code: \code @@ -119,8 +121,8 @@ You can use its "hints" to automatically generate stubs for the missing methods. \endcode -# Use this page, the sample, and the documentation for the org.sleuthkit.autopsy.ingest.DataSourceIngestModule interfaces to implement the startUp() and process() methods. - -The process() method is where all of the work of a data source ingest module is + - org.sleuthkit.autopsy.ingest.DataSourceIngestModule.startUp() is where any initialiation occurs. If your module has a critical failure and will not be able to run, your startUp method should throw an IngestModuleException to stop ingest. + - org.sleuthkit.autopsy.ingest.DataSourceIngestModule.process() is where all of the work of a data source ingest module is done. It will be called exactly once. The process() method receives a reference to an org.sleuthkit.datamodel.Content object and an org.sleuthkit.autopsy.ingest.DataSourceIngestModuleProgress object. @@ -140,10 +142,12 @@ org.sleuthkit.autopsy.casemodule.services.FileManager class. See To create a file ingest module: To create a data source ingest module: -# Create the ingest module class by either: - - Define a new class that implements (Java) or inherits (Jython) org.sleuthkit.autopsy.ingest.FileIngestModule. If you are using Java, the NetBeans IDE + - Copy and paste the sample modules from: + - Java: Core/src/org/sleuthkit/autopsy/examples/SampleFileIngestModule.java + - Python: pythonExamples/fileIngestModule.py (https://github.com/sleuthkit/autopsy/tree/develop/pythonExamples) + - Or the manual approach is to define a new class that implements (Java) or inherits (Jython) org.sleuthkit.autopsy.ingest.FileIngestModule. If you are using Java, the NetBeans IDE will complain that you have not implemented one or more of the required methods. You can use its "hints" to automatically generate stubs for the missing methods. - - Copy and paste the sample modules from org.sleuthkit.autopsy.examples.SampleDataSourceIngestModule or org.sleuthkit.autopsy.examples.ingestmodule.py. -# Configure your factory class to create instances of the new ingest module class. To do this, you will need to change the isFileIngestModuleFactory() method to return true and have the createFileIngestModule() method return a new instance of your ingest module. Both of these methods have default "no-op" implementations in the IngestModuleFactoryAdapter that we used. Your factory should have code similar to this Java code: \code @@ -160,9 +164,8 @@ You can use its "hints" to automatically generate stubs for the missing methods. -# Use this page, the sample, and the documentation for the org.sleuthkit.autopsy.ingest.FileIngestModule interface to implement the startUp(), and process(), and shutDown() methods. - - -The process() method is where all of the work of a file ingest module is + - org.sleuthkit.autopsy.ingest.FileIngestModule.startUp() should have any code that you need to initialize your module. If you have any startup errors, be sure to throw a IngestModuleException exception to stop ingest. + - org.sleuthkit.autopsy.ingest.FileIngestModule.process() is where all of the work of a file ingest module is done. It will be called repeatedly between startUp() and shutDown(), once for each file Autopsy feeds into the pipeline of which the module instance is a part. The process() method receives a reference to a org.sleuthkit.datamodel.AbstractFile diff --git a/pythonExamples/README.txt b/pythonExamples/README.txt index 3ea200a82e..fb17a7c101 100755 --- a/pythonExamples/README.txt +++ b/pythonExamples/README.txt @@ -1,7 +1,13 @@ -reportmodule.py -> Report module which implements GeneralReportModuleAdapter. -simpleingestmodule -> Data source ingest module without any GUI example code. -ingestmodule.py -> Both data source ingest module as well as file ingest module WITH an example of GUI code. +This folder contains sample python module files. They are public +domain, so you are free to copy and paste them and modify them to +your needs. + +See the developer guide for more details and how to use and load +the modules. + + http://sleuthkit.org/autopsy/docs/api-docs/3.1/index.html + +Each module in this folder should have a brief description about what they +can do. + -NOTE: The Python modules must be inside folder inside the folder opened by Tools > Plugins. -For example, place the ingestmodule.py inside folder ingest. Move that ingest folder inside opened by Tools > Plugins -The directory opened by Tools > Plugins is cleared every time the project is cleaned. \ No newline at end of file diff --git a/pythonExamples/simpleingestmodule.py b/pythonExamples/dataSourceIngestModule.py similarity index 58% rename from pythonExamples/simpleingestmodule.py rename to pythonExamples/dataSourceIngestModule.py index 548a12800d..2761acdaec 100755 --- a/pythonExamples/simpleingestmodule.py +++ b/pythonExamples/dataSourceIngestModule.py @@ -27,6 +27,10 @@ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. +# Simple data source-level ingest module for Autopsy. +# Search for TODO for the things that you need to change +# See http://sleuthkit.org/autopsy/docs/api-docs/3.1/index.html for documentation + import jarray from java.lang import System from org.sleuthkit.datamodel import SleuthkitCase @@ -35,87 +39,112 @@ from org.sleuthkit.datamodel import ReadContentInputStream from org.sleuthkit.datamodel import BlackboardArtifact from org.sleuthkit.datamodel import BlackboardAttribute from org.sleuthkit.autopsy.ingest import IngestModule +from org.sleuthkit.autopsy.ingest.IngestModule import IngestModuleException from org.sleuthkit.autopsy.ingest import DataSourceIngestModule from org.sleuthkit.autopsy.ingest import FileIngestModule from org.sleuthkit.autopsy.ingest import IngestModuleFactoryAdapter from org.sleuthkit.autopsy.ingest import IngestMessage from org.sleuthkit.autopsy.ingest import IngestServices +from org.sleuthkit.autopsy.coreutils import Logger from org.sleuthkit.autopsy.casemodule import Case from org.sleuthkit.autopsy.casemodule.services import Services from org.sleuthkit.autopsy.casemodule.services import FileManager -# Sample factory that defines basic functionality and features of the module -class SampleJythonIngestModuleFactory(IngestModuleFactoryAdapter): +# Factory that defines the name and details of the module and allows Autopsy +# to create instances of the modules that will do the analysis. +# TODO: Rename this to something more specific. Search and replace for it because it is used a few times +class SampleJythonDataSourceIngestModuleFactory(IngestModuleFactoryAdapter): + + # TODO: give it a unique name. Will be shown in module list, logs, etc. + moduleName = "Sample Data Source Module" + def getModuleDisplayName(self): - return "Sample Jython ingest module" - + return self.moduleName + + # TODO: Give it a description def getModuleDescription(self): - return "Sample Jython Ingest Module without GUI example code" + return "Sample module that does X, Y, and Z." def getModuleVersionNumber(self): return "1.0" - # Return true if module wants to get passed in a data source def isDataSourceIngestModuleFactory(self): return True - # can return null if isDataSourceIngestModuleFactory returns false def createDataSourceIngestModule(self, ingestOptions): + # TODO: Change the class name to the name you'll make below return SampleJythonDataSourceIngestModule() - # Return true if module wants to get called for each file - def isFileIngestModuleFactory(self): - return True - - # can return null if isFileIngestModuleFactory returns false - def createFileIngestModule(self, ingestOptions): - return SampleJythonFileIngestModule() - # Data Source-level ingest module. One gets created per data source. -# Queries for various files. -# If you don't need a data source-level module, delete this class. +# TODO: Rename this to something more specific. Could just remove "Factory" from above name. class SampleJythonDataSourceIngestModule(DataSourceIngestModule): def __init__(self): self.context = None + # Where any setup and configuration is done + # TODO: Add any setup code that you need here. def startUp(self, context): self.context = context - + # Throw an IngestModule.IngestModuleException exception if there was a problem setting up + # raise IngestModuleException(IngestModule(), "Oh No!") + + # Where the analysis is done. + # TODO: Add your analysis code in here. def process(self, dataSource, progressBar): if self.context.isJobCancelled(): return IngestModule.ProcessResult.OK + + logger = Logger.getLogger(SampleJythonDataSourceIngestModuleFactory.moduleName) - # Configure progress bar for 2 tasks - progressBar.switchToDeterminate(2) + # we don't know how much work there is yet + progressBar.switchToIndeterminate() autopsyCase = Case.getCurrentCase() sleuthkitCase = autopsyCase.getSleuthkitCase() services = Services(sleuthkitCase) fileManager = services.getFileManager() - # Get count of files with "test" in name. - fileCount = 0; + # For our example, we will use FileManager to get all + # files with the word "test" + # in the name and then count and read them files = fileManager.findFiles(dataSource, "%test%") + + numFiles = len(files) + logger.info("found " + str(numFiles) + " files") + progressBar.switchToDeterminate(numFiles) + fileCount = 0; for file in files: + + # Check if the user pressed cancel while we were busy + if self.context.isJobCancelled(): + return IngestModule.ProcessResult.OK + + logger.info("Processing file: " + file.getName()) fileCount += 1 - progressBar.progress(1) - if self.context.isJobCancelled(): - return IngestModule.ProcessResult.OK + # Make an artifact on the blackboard. TSK_INTERESTING_FILE_HIT is a generic type of + # artfiact. Refer to the developer docs for other examples. + art = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT) + att = BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID(), SampleJythonDataSourceIngestModuleFactory.moduleName, "Test file") + art.addAttribute(att) - # Get files by creation time. - currentTime = System.currentTimeMillis() / 1000 - minTime = currentTime - (14 * 24 * 60 * 60) # Go back two weeks. - otherFiles = sleuthkitCase.findAllFilesWhere("crtime > %d" % minTime) - for otherFile in otherFiles: - fileCount += 1 - progressBar.progress(1); + + # To further the example, this code will read the contents of the file and count the number of bytes + inputStream = ReadContentInputStream(file) + buffer = jarray.zeros(1024, "b") + totLen = 0 + readLen = inputStream.read(buffer) + while (readLen != -1): + totLen = totLen + readLen + readLen = inputStream.read(buffer) + + + # Update the progress bar + progressBar.progress(fileCount) - if self.context.isJobCancelled(): - return IngestModule.ProcessResult.OK; #Post a message to the ingest messages in box. message = IngestMessage.createMessage(IngestMessage.MessageType.DATA, @@ -123,38 +152,3 @@ class SampleJythonDataSourceIngestModule(DataSourceIngestModule): IngestServices.getInstance().postMessage(message) return IngestModule.ProcessResult.OK; - - -# File-level ingest module. One gets created per thread. -# Looks at the attributes of the passed in file. -# if you don't need a file-level module, delete this class. -class SampleJythonFileIngestModule(FileIngestModule): - - def startUp(self, context): - pass - - def process(self, file): - # If the file has a txt extension, post an artifact to the blackboard. - if file.getName().find("test") != -1: - art = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT) - att = BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID(), "Sample Jython File Ingest Module", "Text Files") - art.addAttribute(att) - - # Read the contents of the file. - inputStream = ReadContentInputStream(file) - buffer = jarray.zeros(1024, "b") - totLen = 0 - len = inputStream.read(buffer) - while (len != -1): - totLen = totLen + len - len = inputStream.read(buffer) - - # Send the size of the file to the ingest messages in box. - msgText = "Size of %s is %d bytes" % ((file.getName(), totLen)) - message = IngestMessage.createMessage(IngestMessage.MessageType.DATA, "Sample Jython File IngestModule", msgText) - ingestServices = IngestServices.getInstance().postMessage(message) - - return IngestModule.ProcessResult.OK - - def shutDown(self): - pass \ No newline at end of file diff --git a/pythonExamples/fileIngestModule.py b/pythonExamples/fileIngestModule.py new file mode 100755 index 0000000000..399592c2f3 --- /dev/null +++ b/pythonExamples/fileIngestModule.py @@ -0,0 +1,128 @@ +# Sample module in the public domain. Feel free to use this as a template +# for your modules (and you can remove this header and take complete credit +# and liability) +# +# Contact: Brian Carrier [carrier sleuthkit [dot] org] +# +# This is free and unencumbered software released into the public domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or +# distribute this software, either in source code form or as a compiled +# binary, for any purpose, commercial or non-commercial, and by any +# means. +# +# In jurisdictions that recognize copyright laws, the author or authors +# of this software dedicate any and all copyright interest in the +# software to the public domain. We make this dedication for the benefit +# of the public at large and to the detriment of our heirs and +# successors. We intend this dedication to be an overt act of +# relinquishment in perpetuity of all present and future rights to this +# software under copyright law. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + +# Simple file-level ingest module for Autopsy. +# Search for TODO for the things that you need to change +# See http://sleuthkit.org/autopsy/docs/api-docs/3.1/index.html for documentation + +import jarray +from java.lang import System +from org.sleuthkit.datamodel import SleuthkitCase +from org.sleuthkit.datamodel import AbstractFile +from org.sleuthkit.datamodel import ReadContentInputStream +from org.sleuthkit.datamodel import BlackboardArtifact +from org.sleuthkit.datamodel import BlackboardAttribute +from org.sleuthkit.autopsy.ingest import IngestModule +from org.sleuthkit.autopsy.ingest.IngestModule import IngestModuleException +from org.sleuthkit.autopsy.ingest import DataSourceIngestModule +from org.sleuthkit.autopsy.ingest import FileIngestModule +from org.sleuthkit.autopsy.ingest import IngestModuleFactoryAdapter +from org.sleuthkit.autopsy.ingest import IngestMessage +from org.sleuthkit.autopsy.ingest import IngestServices +from org.sleuthkit.autopsy.coreutils import Logger +from org.sleuthkit.autopsy.casemodule import Case +from org.sleuthkit.autopsy.casemodule.services import Services +from org.sleuthkit.autopsy.casemodule.services import FileManager + +# Factory that defines the name and details of the module and allows Autopsy +# to create instances of the modules that will do the anlaysis. +# TODO: Rename this to something more specific. Search and replace for it because it is used a few times +class SampleJythonFileIngestModuleFactory(IngestModuleFactoryAdapter): + + # TODO: give it a unique name. Will be shown in module list, logs, etc. + moduleName = "Sample file ingest Module" + + def getModuleDisplayName(self): + return self.moduleName + + # TODO: Give it a description + def getModuleDescription(self): + return "Sample module that does X, Y, and Z." + + def getModuleVersionNumber(self): + return "1.0" + + # Return true if module wants to get called for each file + def isFileIngestModuleFactory(self): + return True + + # can return null if isFileIngestModuleFactory returns false + def createFileIngestModule(self, ingestOptions): + return SampleJythonFileIngestModule() + + +# File-level ingest module. One gets created per thread. +# TODO: Rename this to something more specific. Could just remove "Factory" from above name. +# Looks at the attributes of the passed in file. +class SampleJythonFileIngestModule(FileIngestModule): + + # Where any setup and configuration is done + # TODO: Add any setup code that you need here. + def startUp(self, context): + self.logger = Logger.getLogger(SampleJythonFileIngestModuleFactory.moduleName) + self.filesFound = 0 + + # Throw an IngestModule.IngestModuleException exception if there was a problem setting up + # raise IngestModuleException(IngestModule(), "Oh No!") + pass + + # Where the analysis is done. Each file will be passed into here. + # TODO: Add your analysis code in here. + def process(self, file): + + # For an example, we will flag files with .txt in the name and make a blackboard artifact. + if file.getName().find(".txt") != -1: + + self.logger.info("Found a text file: " + file.getName()) + self.filesFound+=1 + + # Make an artifact on the blackboard. TSK_INTERESTING_FILE_HIT is a generic type of + # artfiact. Refer to the developer docs for other examples. + art = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT) + att = BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID(), SampleJythonFileIngestModuleFactory.moduleName, "Text Files") + art.addAttribute(att) + + + # To further the example, this code will read the contents of the file and count the number of bytes + inputStream = ReadContentInputStream(file) + buffer = jarray.zeros(1024, "b") + totLen = 0 + len = inputStream.read(buffer) + while (len != -1): + totLen = totLen + len + len = inputStream.read(buffer) + + return IngestModule.ProcessResult.OK + + # Where any shutdown code is run and resources are freed. + # TODO: Add any shutdown code that you need here. + def shutDown(self): + # As a final part of this example, we'll send a message to the ingest inbox with the number of files found (in this thread) + message = IngestMessage.createMessage(IngestMessage.MessageType.DATA, SampleJythonFileIngestModuleFactory.moduleName, str(self.filesFound) + " files found") + ingestServices = IngestServices.getInstance().postMessage(message) \ No newline at end of file diff --git a/pythonExamples/fileIngestModuleWithGui.py b/pythonExamples/fileIngestModuleWithGui.py new file mode 100755 index 0000000000..e1647eacb9 --- /dev/null +++ b/pythonExamples/fileIngestModuleWithGui.py @@ -0,0 +1,203 @@ +# Sample module in the public domain. Feel free to use this as a template +# for your modules (and you can remove this header and take complete credit +# and liability) +# +# Contact: Brian Carrier [carrier sleuthkit [dot] org] +# +# This is free and unencumbered software released into the public domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or +# distribute this software, either in source code form or as a compiled +# binary, for any purpose, commercial or non-commercial, and by any +# means. +# +# In jurisdictions that recognize copyright laws, the author or authors +# of this software dedicate any and all copyright interest in the +# software to the public domain. We make this dedication for the benefit +# of the public at large and to the detriment of our heirs and +# successors. We intend this dedication to be an overt act of +# relinquishment in perpetuity of all present and future rights to this +# software under copyright law. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + + +# Ingest module for Autopsy with GUI +# +# Difference between other modules in this folder is that it has a GUI +# for user options. This is not needed for very basic modules. If you +# don't need a configuration UI, start with the other sample module. +# +# Search for TODO for the things that you need to change +# See http://sleuthkit.org/autopsy/docs/api-docs/3.1/index.html for documentation + + +import jarray +from java.lang import System +from javax.swing import JCheckBox +from javax.swing import BoxLayout +from org.sleuthkit.autopsy.casemodule import Case +from org.sleuthkit.autopsy.casemodule.services import Services +from org.sleuthkit.autopsy.ingest import DataSourceIngestModule +from org.sleuthkit.autopsy.ingest import FileIngestModule +from org.sleuthkit.autopsy.ingest import IngestMessage +from org.sleuthkit.autopsy.ingest import IngestModule +from org.sleuthkit.autopsy.ingest.IngestModule import IngestModuleException +from org.sleuthkit.autopsy.ingest import IngestModuleFactoryAdapter +from org.sleuthkit.autopsy.ingest import IngestModuleIngestJobSettings +from org.sleuthkit.autopsy.ingest import IngestModuleIngestJobSettingsPanel +from org.sleuthkit.autopsy.ingest import IngestServices +from org.sleuthkit.autopsy.ingest import IngestModuleGlobalSettingsPanel +from org.sleuthkit.datamodel import BlackboardArtifact +from org.sleuthkit.datamodel import BlackboardAttribute +from org.sleuthkit.datamodel import ReadContentInputStream +from org.sleuthkit.autopsy.coreutils import Logger +from java.lang import IllegalArgumentException + +# TODO: Rename this to something more specific +class SampleFileIngestModuleWithUIFactory(IngestModuleFactoryAdapter): + def __init__(self): + self.settings = None + + # TODO: give it a unique name. Will be shown in module list, logs, etc. + moduleName = "Sample Data Source Module with UI" + + def getModuleDisplayName(self): + return self.moduleName + + # TODO: Give it a description + def getModuleDescription(self): + return "Sample module that does X, Y, and Z." + + def getModuleVersionNumber(self): + return "1.0" + + # TODO: Update class name to one that you create below + def getDefaultIngestJobSettings(self): + return SampleFileIngestModuleWithUISettings() + + # TODO: Keep enabled only if you need ingest job-specific settings UI + def hasIngestJobSettingsPanel(self): + return True + + # TODO: Update class names to ones that you create below + def getIngestJobSettingsPanel(self, settings): + if not isinstance(settings, SampleFileIngestModuleWithUISettings): + raise IllegalArgumentException("Expected settings argument to be instanceof SampleIngestModuleSettings") + self.settings = settings + return SampleFileIngestModuleWithUISettingsPanel(self.settings) + + + def isFileIngestModuleFactory(self): + return True + + + # TODO: Update class name to one that you create below + def createFileIngestModule(self, ingestOptions): + return SampleFileIngestModuleWithUI(self.settings) + + +# File-level ingest module. One gets created per thread. +# TODO: Rename this to something more specific. Could just remove "Factory" from above name. +# Looks at the attributes of the passed in file. +class SampleFileIngestModuleWithUI(FileIngestModule): + + # Autopsy will pass in the settings from the UI panel + def __init__(self, settings): + self.local_settings = settings + + + # Where any setup and configuration is done + # TODO: Add any setup code that you need here. + def startUp(self, context): + self.logger = Logger.getLogger(SampleFileIngestModuleWithUIFactory.moduleName) + + # As an example, determine if user configured a flag in UI + if self.local_settings.getFlag(): + self.logger.info("flag is set") + else: + self.logger.info("flag is not set") + + # Throw an IngestModule.IngestModuleException exception if there was a problem setting up + # raise IngestModuleException(IngestModule(), "Oh No!") + pass + + # Where the analysis is done. Each file will be passed into here. + # TODO: Add your analysis code in here. + def process(self, file): + # See code in pythonExamples/fileIngestModule.py for example code + return IngestModule.ProcessResult.OK + + # Where any shutdown code is run and resources are freed. + # TODO: Add any shutdown code that you need here. + def shutDown(self): + pass + +# Stores the settings that can be changed for each ingest job +# All fields in here must be serializable. It will be written to disk. +# TODO: Rename this class +class SampleFileIngestModuleWithUISettings(IngestModuleIngestJobSettings): + serialVersionUID = 1L + + def __init__(self): + self.flag = False + + def getVersionNumber(self): + return serialVersionUID + + # TODO: Define getters and settings for data you want to store from UI + def getFlag(self): + return self.flag + + def setFlag(self, flag): + self.flag = flag + + +# UI that is shown to user for each ingest job so they can configure the job. +# TODO: Rename this +class SampleFileIngestModuleWithUISettingsPanel(IngestModuleIngestJobSettingsPanel): + # Note, we can't use a self.settings instance variable. + # Rather, self.local_settings is used. + # https://wiki.python.org/jython/UserGuide#javabean-properties + # Jython Introspector generates a property - 'settings' on the basis + # of getSettings() defined in this class. Since only getter function + # is present, it creates a read-only 'settings' property. This auto- + # generated read-only property overshadows the instance-variable - + # 'settings' + + # We get passed in a previous version of the settings so that we can + # prepopulate the UI + # TODO: Update this for your UI + def __init__(self, settings): + self.local_settings = settings + self.initComponents() + self.customizeComponents() + + # TODO: Update this for your UI + def checkBoxEvent(self, event): + if self.checkbox.isSelected(): + self.local_settings.setFlag(True) + else: + self.local_settings.setFlag(False) + + # TODO: Update this for your UI + def initComponents(self): + self.setLayout(BoxLayout(self, BoxLayout.Y_AXIS)) + self.checkbox = JCheckBox("Flag", actionPerformed=self.checkBoxEvent) + self.add(self.checkbox) + + # TODO: Update this for your UI + def customizeComponents(self): + self.checkbox.setSelected(self.local_settings.getFlag()) + + # Return the settings used + def getSettings(self): + return self.local_settings + + diff --git a/pythonExamples/ingestmodule.py b/pythonExamples/ingestmodule.py deleted file mode 100755 index e0d6296136..0000000000 --- a/pythonExamples/ingestmodule.py +++ /dev/null @@ -1,266 +0,0 @@ -# Sample module in the public domain. Feel free to use this as a template -# for your modules (and you can remove this header and take complete credit -# and liability) -# -# Contact: Brian Carrier [carrier sleuthkit [dot] org] -# -# This is free and unencumbered software released into the public domain. -# -# Anyone is free to copy, modify, publish, use, compile, sell, or -# distribute this software, either in source code form or as a compiled -# binary, for any purpose, commercial or non-commercial, and by any -# means. -# -# In jurisdictions that recognize copyright laws, the author or authors -# of this software dedicate any and all copyright interest in the -# software to the public domain. We make this dedication for the benefit -# of the public at large and to the detriment of our heirs and -# successors. We intend this dedication to be an overt act of -# relinquishment in perpetuity of all present and future rights to this -# software under copyright law. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -# OTHER DEALINGS IN THE SOFTWARE. - -import jarray -from java.lang import System -from javax.swing import JCheckBox -from javax.swing import BoxLayout -from org.sleuthkit.autopsy.casemodule import Case -from org.sleuthkit.autopsy.casemodule.services import Services -from org.sleuthkit.autopsy.ingest import DataSourceIngestModule -from org.sleuthkit.autopsy.ingest import FileIngestModule -from org.sleuthkit.autopsy.ingest import IngestMessage -from org.sleuthkit.autopsy.ingest import IngestModule -from org.sleuthkit.autopsy.ingest import IngestModuleFactoryAdapter -from org.sleuthkit.autopsy.ingest import IngestModuleIngestJobSettings -from org.sleuthkit.autopsy.ingest import IngestModuleIngestJobSettingsPanel -from org.sleuthkit.autopsy.ingest import IngestServices -from org.sleuthkit.autopsy.ingest import IngestModuleGlobalSettingsPanel -from org.sleuthkit.datamodel import BlackboardArtifact -from org.sleuthkit.datamodel import BlackboardAttribute -from org.sleuthkit.datamodel import ReadContentInputStream -from org.sleuthkit.autopsy.coreutils import Logger -from java.lang import IllegalArgumentException - -# Sample factory that defines basic functionality and features of the module -# It implements IngestModuleFactoryAdapter which is a no-op implementation of -# IngestModuleFactory. -class SampleJythonIngestModuleFactory(IngestModuleFactoryAdapter): - def __init__(self): - self.settings = None - - def getModuleDisplayName(self): - return "Sample Jython(GUI) ingest module" - - def getModuleDescription(self): - return "Sample Jython Ingest Module with GUI example code" - - def getModuleVersionNumber(self): - return "1.0" - - def getDefaultIngestJobSettings(self): - return SampleIngestModuleSettings() - - def hasIngestJobSettingsPanel(self): - return True - - def getIngestJobSettingsPanel(self, settings): - if not isinstance(settings, SampleIngestModuleSettings): - raise IllegalArgumentException("Expected settings argument to be instanceof SampleIngestModuleSettings") - self.settings = settings - return SampleIngestModuleSettingsPanel(self.settings) - - # Return true if module wants to get passed in a data source - def isDataSourceIngestModuleFactory(self): - return True - - # can return null if isDataSourceIngestModuleFactory returns false - def createDataSourceIngestModule(self, ingestOptions): - return SampleJythonDataSourceIngestModule(self.settings) - - # Return true if module wants to get called for each file - - def isFileIngestModuleFactory(self): - return True - - # can return null if isFileIngestModuleFactory returns false - def createFileIngestModule(self, ingestOptions): - return SampleJythonFileIngestModule(self.settings) - - def hasGlobalSettingsPanel(self): - return True - - def getGlobalSettingsPanel(self): - globalSettingsPanel = SampleIngestModuleGlobalSettingsPanel(); - return globalSettingsPanel - - -class SampleIngestModuleGlobalSettingsPanel(IngestModuleGlobalSettingsPanel): - def __init__(self): - self.setLayout(BoxLayout(self, BoxLayout.Y_AXIS)) - checkbox = JCheckBox("Flag inside the Global Settings Panel") - self.add(checkbox) - - -class SampleJythonDataSourceIngestModule(DataSourceIngestModule): - ''' - Data Source-level ingest module. One gets created per data source. - Queries for various files. If you don't need a data source-level module, - delete this class. - ''' - - def __init__(self, settings): - self.local_settings = settings - self.context = None - - def startUp(self, context): - # Used to verify if the GUI checkbox event been recorded or not. - logger = Logger.getLogger("SampleJythonFileIngestModule") - if self.local_settings.getFlag(): - logger.info("flag is set") - else: - logger.info("flag is not set") - - self.context = context - - def process(self, dataSource, progressBar): - if self.context.isJobCancelled(): - return IngestModule.ProcessResult.OK - - # Configure progress bar for 2 tasks - progressBar.switchToDeterminate(2) - - autopsyCase = Case.getCurrentCase() - sleuthkitCase = autopsyCase.getSleuthkitCase() - services = Services(sleuthkitCase) - fileManager = services.getFileManager() - - # Get count of files with "test" in name. - fileCount = 0; - files = fileManager.findFiles(dataSource, "%test%") - for file in files: - fileCount += 1 - progressBar.progress(1) - - if self.context.isJobCancelled(): - return IngestModule.ProcessResult.OK - - # Get files by creation time. - currentTime = System.currentTimeMillis() / 1000 - minTime = currentTime - (14 * 24 * 60 * 60) # Go back two weeks. - otherFiles = sleuthkitCase.findAllFilesWhere("crtime > %d" % minTime) - for otherFile in otherFiles: - fileCount += 1 - progressBar.progress(1); - - if self.context.isJobCancelled(): - return IngestModule.ProcessResult.OK; - - # Post a message to the ingest messages in box. - message = IngestMessage.createMessage(IngestMessage.MessageType.DATA, - "Sample Jython Data Source Ingest Module", "Found %d files" % fileCount) - IngestServices.getInstance().postMessage(message) - - return IngestModule.ProcessResult.OK; - - -class SampleJythonFileIngestModule(FileIngestModule): - ''' - File-level ingest module. One gets created per thread. Looks at the - attributes of the passed in file. if you don't need a file-level module, - delete this class. - ''' - - def __init__(self, settings): - self.local_settings = settings - - def startUp(self, context): - # Used to verify if the GUI checkbox event been recorded or not. - logger = Logger.getLogger("SampleJythonFileIngestModule") - if self.local_settings.getFlag(): - logger.info("flag is set") - else: - logger.info("flag is not set") - pass - - def process(self, file): - # If the file has a txt extension, post an artifact to the blackboard. - if file.getName().find("test") != -1: - art = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT) - att = BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID(), - "Sample Jython File Ingest Module", "Text Files") - art.addAttribute(att) - - # Read the contents of the file. - inputStream = ReadContentInputStream(file) - buffer = jarray.zeros(1024, "b") - totLen = 0 - len = inputStream.read(buffer) - while (len != -1): - totLen = totLen + len - len = inputStream.read(buffer) - - # Send the size of the file to the ingest messages in box. - msgText = "Size of %s is %d bytes" % ((file.getName(), totLen)) - message = IngestMessage.createMessage(IngestMessage.MessageType.DATA, "Sample Jython File IngestModule", - msgText) - ingestServices = IngestServices.getInstance().postMessage(message) - - return IngestModule.ProcessResult.OK - - def shutDown(self): - pass - - -class SampleIngestModuleSettings(IngestModuleIngestJobSettings): - serialVersionUID = 1L - - def __init__(self): - self.flag = False - - def getVersionNumber(self): - return serialVersionUID - - def getFlag(self): - return self.flag - - def setFlag(self, flag): - self.flag = flag - - -class SampleIngestModuleSettingsPanel(IngestModuleIngestJobSettingsPanel): - # self.settings instance variable not used. Rather, self.local_settings is used. - # https://wiki.python.org/jython/UserGuide#javabean-properties - # Jython Introspector generates a property - 'settings' on the basis - # of getSettings() defined in this class. Since only getter function - # is present, it creates a read-only 'settings' property. This auto- - # generated read-only property overshadows the instance-variable - - # 'settings' - - def checkBoxEvent(self, event): - if self.checkbox.isSelected(): - self.local_settings.setFlag(True) - else: - self.local_settings.setFlag(False) - - def initComponents(self): - self.setLayout(BoxLayout(self, BoxLayout.Y_AXIS)) - self.checkbox = JCheckBox("Flag", actionPerformed=self.checkBoxEvent) - self.add(self.checkbox) - - def customizeComponents(self): - self.checkbox.setSelected(self.local_settings.getFlag()) - - def __init__(self, settings): - self.local_settings = settings - self.initComponents() - self.customizeComponents() - - def getSettings(self): - return self.local_settings \ No newline at end of file From 525b87d096712c6f4e0f670f2878746d9730394c Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Tue, 26 May 2015 09:35:47 -0400 Subject: [PATCH 46/79] Updated report interface variable name to make it more clear. Updated sample python report module --- .../modules/stix/STIXReportModule.java | 6 ++--- .../autopsy/report/FileReportModule.java | 4 ++-- .../autopsy/report/FileReportText.java | 4 ++-- .../autopsy/report/GeneralReportModule.java | 4 ++-- .../report/GeneralReportModuleAdapter.java | 2 +- .../autopsy/report/ReportBodyFile.java | 6 ++--- .../sleuthkit/autopsy/report/ReportExcel.java | 6 ++--- .../sleuthkit/autopsy/report/ReportHTML.java | 6 ++--- .../sleuthkit/autopsy/report/ReportKML.java | 8 +++---- .../autopsy/report/ReportModule.java | 8 +++---- .../autopsy/report/TableReportModule.java | 4 ++-- pythonExamples/reportmodule.py | 22 ++++++++++++++----- 12 files changed, 46 insertions(+), 34 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/stix/STIXReportModule.java b/Core/src/org/sleuthkit/autopsy/modules/stix/STIXReportModule.java index e9f7bd4c43..963cc717e6 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/stix/STIXReportModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/stix/STIXReportModule.java @@ -96,16 +96,16 @@ public class STIXReportModule implements GeneralReportModule { /** * . * - * @param path path to save the report + * @param baseReportDir path to save the report * @param progressPanel panel to update the report's progress */ @Override - public void generateReport(String path, ReportProgressPanel progressPanel) { + public void generateReport(String baseReportDir, ReportProgressPanel progressPanel) { // Start the progress bar and setup the report progressPanel.setIndeterminate(false); progressPanel.start(); progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "STIXReportModule.progress.readSTIX")); - reportPath = path + getRelativeFilePath(); + reportPath = baseReportDir + getRelativeFilePath(); // Check if the user wants to display all output or just hits reportAllResults = configPanel.getShowAllResults(); diff --git a/Core/src/org/sleuthkit/autopsy/report/FileReportModule.java b/Core/src/org/sleuthkit/autopsy/report/FileReportModule.java index e69f4c0ac8..393467685b 100755 --- a/Core/src/org/sleuthkit/autopsy/report/FileReportModule.java +++ b/Core/src/org/sleuthkit/autopsy/report/FileReportModule.java @@ -29,9 +29,9 @@ import org.sleuthkit.datamodel.AbstractFile; interface FileReportModule extends ReportModule { /** * Initialize the report which will be stored at the given path. - * @param path + * @param baseReportDir Base directory to store the report file in. Report should go into baseReportDir + getRelativeFilePath(). */ - public void startReport(String path); + public void startReport(String baseReportDir); /** * End the report. diff --git a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java index bdfd7c284c..2dd7e8b676 100755 --- a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java +++ b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java @@ -54,8 +54,8 @@ import org.sleuthkit.datamodel.AbstractFile; } @Override - public void startReport(String path) { - this.reportPath = path + FILE_NAME; + public void startReport(String baseReportDir) { + this.reportPath = baseReportDir + FILE_NAME; try { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(this.reportPath))); } catch (IOException ex) { diff --git a/Core/src/org/sleuthkit/autopsy/report/GeneralReportModule.java b/Core/src/org/sleuthkit/autopsy/report/GeneralReportModule.java index 08aa476b9f..8d5bf001b0 100644 --- a/Core/src/org/sleuthkit/autopsy/report/GeneralReportModule.java +++ b/Core/src/org/sleuthkit/autopsy/report/GeneralReportModule.java @@ -26,10 +26,10 @@ public interface GeneralReportModule extends ReportModule { * Called to generate the report. Method is responsible for saving the file at the * path specified and updating progress via the progressPanel object. * - * @param reportPath path to save the report + * @param baseReportDir Base directory that reports are being stored in. Report should go into baseReportDir + getRelativeFilePath(). * @param progressPanel panel to update the report's progress with */ - public void generateReport(String reportPath, ReportProgressPanel progressPanel); + public void generateReport(String baseReportDir, ReportProgressPanel progressPanel); /** * Returns the configuration panel for the report, which is displayed in diff --git a/Core/src/org/sleuthkit/autopsy/report/GeneralReportModuleAdapter.java b/Core/src/org/sleuthkit/autopsy/report/GeneralReportModuleAdapter.java index 6e8bc52500..f66b1c69a2 100755 --- a/Core/src/org/sleuthkit/autopsy/report/GeneralReportModuleAdapter.java +++ b/Core/src/org/sleuthkit/autopsy/report/GeneralReportModuleAdapter.java @@ -38,7 +38,7 @@ public abstract class GeneralReportModuleAdapter implements GeneralReportModule } @Override - public abstract void generateReport(String reportPath, ReportProgressPanel progressPanel); + public abstract void generateReport(String baseReportDir, ReportProgressPanel progressPanel); @Override public JPanel getConfigurationPanel() { diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportBodyFile.java b/Core/src/org/sleuthkit/autopsy/report/ReportBodyFile.java index d772871c79..1d79efc8c3 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportBodyFile.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportBodyFile.java @@ -63,17 +63,17 @@ import org.sleuthkit.datamodel.*; /** * Generates a body file format report for use with the MAC time tool. - * @param path path to save the report + * @param baseReportDir path to save the report * @param progressPanel panel to update the report's progress */ @Override @SuppressWarnings("deprecation") - public void generateReport(String path, ReportProgressPanel progressPanel) { + public void generateReport(String baseReportDir, ReportProgressPanel progressPanel) { // Start the progress bar and setup the report progressPanel.setIndeterminate(false); progressPanel.start(); progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportBodyFile.progress.querying")); - reportPath = path + "BodyFile.txt"; //NON-NLS + reportPath = baseReportDir + "BodyFile.txt"; //NON-NLS currentCase = Case.getCurrentCase(); skCase = currentCase.getSleuthkitCase(); diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportExcel.java b/Core/src/org/sleuthkit/autopsy/report/ReportExcel.java index c348e79f5c..8b9d6dd7cb 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportExcel.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportExcel.java @@ -58,12 +58,12 @@ import org.sleuthkit.datamodel.TskCoreException; /** * Start the Excel report by creating the Workbook, initializing styles, * and writing the summary. - * @param path path to save the report + * @param baseReportDir path to save the report */ @Override - public void startReport(String path) { + public void startReport(String baseReportDir) { // Set the path and save it for when the report is written to disk. - this.reportPath = path + getRelativeFilePath(); + this.reportPath = baseReportDir + getRelativeFilePath(); // Make a workbook. wb = new XSSFWorkbook(); diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java b/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java index 67a2cbbbf5..18d41df409 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java @@ -299,14 +299,14 @@ import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM; /** * Start this report by setting the path, refreshing member variables, * and writing the skeleton for the HTML report. - * @param path path to save the report + * @param baseReportDir path to save the report */ @Override - public void startReport(String path) { + public void startReport(String baseReportDir) { // Refresh the HTML report refresh(); // Setup the path for the HTML report - this.path = path + "HTML Report" + File.separator; //NON-NLS + this.path = baseReportDir + "HTML Report" + File.separator; //NON-NLS this.thumbsPath = this.path + "thumbs" + File.separator; //NON-NLS try { FileUtil.createFolder(new File(this.path)); diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportKML.java b/Core/src/org/sleuthkit/autopsy/report/ReportKML.java index 1f6c5a665b..fac72da35b 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportKML.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportKML.java @@ -70,18 +70,18 @@ class ReportKML implements GeneralReportModule { /** * Generates a body file format report for use with the MAC time tool. * - * @param path path to save the report + * @param baseReportDir path to save the report * @param progressPanel panel to update the report's progress */ @Override - public void generateReport(String path, ReportProgressPanel progressPanel) { + public void generateReport(String baseReportDir, ReportProgressPanel progressPanel) { // Start the progress bar and setup the report progressPanel.setIndeterminate(false); progressPanel.start(); progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportKML.progress.querying")); - reportPath = path + "ReportKML.kml"; //NON-NLS - String reportPath2 = path + "ReportKML.txt"; //NON-NLS + reportPath = baseReportDir + "ReportKML.kml"; //NON-NLS + String reportPath2 = baseReportDir + "ReportKML.txt"; //NON-NLS currentCase = Case.getCurrentCase(); skCase = currentCase.getSleuthkitCase(); diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportModule.java b/Core/src/org/sleuthkit/autopsy/report/ReportModule.java index 2d0ab6b0d2..7441835263 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportModule.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportModule.java @@ -40,11 +40,11 @@ interface ReportModule { /** * Gets the relative path of the report file, if any, generated by this - * module. The path should be relative to the time stamp subdirectory of - * reports directory. + * module. The path should be relative to the location that gets passed in + * to generateReport() (or similar). * - * @return Report file path relative to the time stamp subdirectory reports - * directory, may be null if the module does not produce a report file. + * @return Relative path to where report will be stored. + * May be null if the module does not produce a report file. */ public String getRelativeFilePath(); } diff --git a/Core/src/org/sleuthkit/autopsy/report/TableReportModule.java b/Core/src/org/sleuthkit/autopsy/report/TableReportModule.java index 448afe753f..cb5e9c3b28 100644 --- a/Core/src/org/sleuthkit/autopsy/report/TableReportModule.java +++ b/Core/src/org/sleuthkit/autopsy/report/TableReportModule.java @@ -35,9 +35,9 @@ import java.util.List; * Start the report. Open any output streams, initialize member variables, * write summary and navigation pages. Considered the "constructor" of the report. * - * @param path String path to save the report + * @param baseReportDir Directory to save the report file into. Report should go into baseReportDir + getRelativeFilePath(). */ - public void startReport(String path); + public void startReport(String baseReportDir); /** * End the report. Close all output streams and write any end-of-report diff --git a/pythonExamples/reportmodule.py b/pythonExamples/reportmodule.py index 566ad0f1c3..fc1c017905 100755 --- a/pythonExamples/reportmodule.py +++ b/pythonExamples/reportmodule.py @@ -27,25 +27,36 @@ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. + +# Report module for Autopsy. +# +# Search for TODO for the things that you need to change +# See http://sleuthkit.org/autopsy/docs/api-docs/3.1/index.html for documentation + from java.lang import System from org.sleuthkit.autopsy.casemodule import Case from org.sleuthkit.autopsy.report import GeneralReportModuleAdapter -# Sample module that writes a file with the number of files -# created in the last 2 weeks. +# TODO: Rename this to something more specific class SampleGeneralReportModule(GeneralReportModuleAdapter): + # TODO: Rename this. Will be shown to users when making a report def getName(self): return "Sample Jython Report Module" + # TODO: rewrite this def getDescription(self): return "A sample Jython report module" + # TODO: Update this to reflect where the report file will be written to def getRelativeFilePath(self): return "sampleReport.txt" - def generateReport(self, reportPath, progressBar): - # Configure progress bar for 2 tasks + # TODO: Update this method to make a report + def generateReport(self, baseReportDir, progressBar): + + # For an example, we write a file with the number of files created in the past 2 weeks + # Configure progress bar for 2 tasks progressBar.setIndeterminate(False) progressBar.start() progressBar.setMaximumProgress(2) @@ -62,9 +73,10 @@ class SampleGeneralReportModule(GeneralReportModuleAdapter): progressBar.increment() # Write the result to the report file. - report = open(reportPath + '\\' + self.getRelativeFilePath(), 'w') + report = open(baseReportDir + '\\' + self.getRelativeFilePath(), 'w') report.write("file count = %d" % fileCount) Case.getCurrentCase().addReport(report.name, "SampleGeneralReportModule", "Sample Python Report"); report.close() + progressBar.increment() progressBar.complete() \ No newline at end of file From 4dd9db30845a0c1d5b7ed0450fa80f9973a07453 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Tue, 26 May 2015 09:43:45 -0400 Subject: [PATCH 47/79] Unalloc space consistently marked as octet/stream --- .../modules/filetypeid/FileTypeDetector.java | 17 ++++++++--------- .../filetypeid/FileTypeIdIngestModule.java | 1 - 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index 4b8b9266e8..3f0b47d7f4 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -150,15 +150,7 @@ public class FileTypeDetector { public String detectAndPostToBlackboard(AbstractFile file) throws TskCoreException { String mimeType; - // Consistently mark unallocated and unused space as file type application/octet-stream - if ((file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) - || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) - || (file.isFile() == false)) { - mimeType = MimeTypes.OCTET_STREAM; - } else { - mimeType = detect(file); - } - + mimeType = detect(file); if (null != mimeType) { /** * Add the file type attribute to the general info artifact. Note @@ -180,6 +172,13 @@ public class FileTypeDetector { * @return The MIME type name id detection was successful, null otherwise. */ public String detect(AbstractFile file) throws TskCoreException { + // Consistently mark unallocated and unused space as file type application/octet-stream + if ((file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) + || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) + || (file.isFile() == false)) { + return MimeTypes.OCTET_STREAM; + } + String fileType = detectUserDefinedType(file); if (null == fileType) { try { diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java index 142081a005..6625c7c616 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java @@ -27,7 +27,6 @@ import org.sleuthkit.autopsy.ingest.IngestJobContext; import org.sleuthkit.autopsy.ingest.IngestMessage; import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.datamodel.AbstractFile; -import org.sleuthkit.datamodel.TskData; import org.sleuthkit.datamodel.TskData.FileKnown; import org.sleuthkit.autopsy.ingest.IngestModule.ProcessResult; import org.sleuthkit.autopsy.ingest.IngestModuleReferenceCounter; From e895be0fd708e9cc7a3caf344d087dfa8d592949 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Tue, 26 May 2015 09:50:47 -0400 Subject: [PATCH 48/79] Reworked add data source functionality to not use service provider architecture --- .../autopsy/casemodule/ImageFilePanel.java | 67 ++----------- .../autopsy/casemodule/LocalDiskPanel.java | 70 ++------------ .../autopsy/casemodule/LocalFilesPanel.java | 93 ++++--------------- .../casemodule/NewCaseVisualPanel1.java | 74 +++------------ .../WizardPathValidator.java | 56 ----------- .../coreutils/MultiUserPathValidator.java | 57 ++++++++++++ 6 files changed, 102 insertions(+), 315 deletions(-) delete mode 100644 Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java create mode 100644 Core/src/org/sleuthkit/autopsy/coreutils/MultiUserPathValidator.java diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java index 599182fc41..c009c6052f 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java @@ -21,7 +21,6 @@ package org.sleuthkit.autopsy.casemodule; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.File; -import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.SimpleTimeZone; @@ -37,12 +36,8 @@ import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import java.util.logging.Level; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.openide.util.Lookup; -import org.sleuthkit.autopsy.casemodule.Case.CaseType; -import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; /** * ImageTypePanel for adding an image file such as .img, .E0x, .00x, etc. @@ -53,9 +48,6 @@ public class ImageFilePanel extends JPanel implements DocumentListener { private static final Logger logger = Logger.getLogger(ImageFilePanel.class.getName()); private PropertyChangeSupport pcs = null; private JFileChooser fc = new JFileChooser(); - - List pathValidatorList = new ArrayList<>(); - private final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$"); // Externally supplied name is used to store settings private String contextName; @@ -72,7 +64,6 @@ public class ImageFilePanel extends JPanel implements DocumentListener { fc.setMultiSelectionEnabled(false); errorLabel.setVisible(false); - discoverWizardPathValidators(); boolean firstFilter = true; for (FileFilter filter: fileChooserFilters ) { @@ -109,14 +100,6 @@ public class ImageFilePanel extends JPanel implements DocumentListener { pathTextField.getDocument().addDocumentListener(this); } - /** - * Discovers WizardPathValidator service providers - */ - private void discoverWizardPathValidators() { - for (WizardPathValidator pathValidator : Lookup.getDefault().lookupAll(WizardPathValidator.class)) { - pathValidatorList.add(pathValidator); - } - } /** * This method is called from within the constructor to initialize the form. @@ -299,58 +282,20 @@ public class ImageFilePanel extends JPanel implements DocumentListener { } /** - * Validates path to selected data source. Calls WizardPathValidator service provider - * if one is available. Otherwise performs path validation locally. + * Validates path to selected data source. * @param path Absolute path to the selected data source * @return true if path is valid, false otherwise. */ - private boolean isImagePathValid(String path){ - - errorLabel.setVisible(false); - String errorString = ""; - - if (path.isEmpty()) { - return false; // no need for error message as the module sets path to "" at startup - } - - // check if the is a WizardPathValidator service provider - if (!pathValidatorList.isEmpty()) { - // call WizardPathValidator service provider - errorString = pathValidatorList.get(0).validateDataSourcePath(path, Case.getCurrentCase().getCaseType()); - } else { - // validate locally - if (Case.getCurrentCase().getCaseType() == CaseType.MULTI_USER_CASE) { - // check that path is not on "C:" drive - if (pathOnCDrive(path)) { - errorString = NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text"); //NON-NLS - } - } else { - // single user case - no validation needed - } - } - - // set error string - if (!errorString.isEmpty()){ + private boolean isImagePathValid(String path){ + errorLabel.setVisible(false); + if (!MultiUserPathValidator.isValid(path, Case.getCurrentCase().getCaseType())) { errorLabel.setVisible(true); - errorLabel.setText(errorString); + errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text")); return false; } - return true; } - /** - * Checks whether a file path contains drive letter defined by pattern. - * - * @param filePath Input file absolute path - * @return true if path matches the pattern, false otherwise. - */ - private boolean pathOnCDrive(String filePath) { - Matcher m = driveLetterPattern.matcher(filePath); - return m.find(); - } - - public void storeSettings() { String imagePathName = getContentPaths(); if (null != imagePathName ) { diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java index b10e054785..e109c40cf0 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java @@ -31,8 +31,6 @@ import java.util.SimpleTimeZone; import java.util.TimeZone; import java.util.concurrent.CancellationException; import java.util.logging.Level; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import javax.swing.ComboBoxModel; import javax.swing.JLabel; import javax.swing.JList; @@ -42,13 +40,12 @@ import javax.swing.ListCellRenderer; import javax.swing.SwingWorker; import javax.swing.border.EmptyBorder; import javax.swing.event.ListDataListener; -import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; -import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; import org.sleuthkit.autopsy.coreutils.LocalDisk; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; +import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; import org.sleuthkit.autopsy.coreutils.PlatformUtil; /** @@ -69,8 +66,6 @@ final class LocalDiskPanel extends JPanel { private boolean enableNext = false; - List pathValidatorList = new ArrayList<>(); - private final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$"); private final int prePendedStringLength = 4; // "Local Disk" panel pre-pends "\\.\" in front of all drive letter and drive names /** @@ -104,17 +99,7 @@ final class LocalDiskPanel extends JPanel { errorLabel.setVisible(false); errorLabel.setText(""); diskComboBox.setEnabled(false); - discoverWizardPathValidators(); - } - - /** - * Discovers WizardPathValidator service providers - */ - private void discoverWizardPathValidators() { - for (WizardPathValidator pathValidator : Lookup.getDefault().lookupAll(WizardPathValidator.class)) { - pathValidatorList.add(pathValidator); - } - } + } /** * This method is called from within the constructor to initialize the form. @@ -252,20 +237,11 @@ final class LocalDiskPanel extends JPanel { } /** - * Validates path to selected data source. Calls WizardPathValidator service provider - * if one is available. Otherwise performs path validation locally. + * Validates path to selected data source. * @param path Absolute path to the selected data source * @return true if path is valid, false otherwise. */ - private boolean isImagePathValid(String path){ - - errorLabel.setVisible(false); - String errorString = ""; - - if (path.isEmpty()) { - return false; // no need for error message as the module sets path to "" at startup - } - + private boolean isImagePathValid(String path){ String newPath = path; if (path.length() > prePendedStringLength) { // "Local Disk" panel pre-pends "\\.\" in front of all drive letter and drive names. @@ -273,42 +249,14 @@ final class LocalDiskPanel extends JPanel { newPath = path.substring(prePendedStringLength, path.length()); } - // check if the is a WizardPathValidator service provider - if (!pathValidatorList.isEmpty()) { - // call WizardPathValidator service provider - errorString = pathValidatorList.get(0).validateDataSourcePath(newPath, Case.getCurrentCase().getCaseType()); - } else { - // validate locally - if (Case.getCurrentCase().getCaseType() == Case.CaseType.MULTI_USER_CASE) { - // check that path is not on "C:" drive - if (pathOnCDrive(newPath)) { - errorString = NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text"); //NON-NLS - } - } else { - // single user case - no validation needed - } - } - - // set error string - if (!errorString.isEmpty()){ + errorLabel.setVisible(false); + if (!MultiUserPathValidator.isValid(newPath, Case.getCurrentCase().getCaseType())) { errorLabel.setVisible(true); - errorLabel.setText(errorString); + errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text")); return false; - } - + } return true; - } - - /** - * Checks whether a file path contains drive letter defined by pattern. - * - * @param filePath Input file absolute path - * @return true if path matches the pattern, false otherwise. - */ - private boolean pathOnCDrive(String filePath) { - Matcher m = driveLetterPattern.matcher(filePath); - return m.find(); - } + } //@Override public void reset() { diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java index 0e52e59563..2caf8dd09b 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java @@ -21,7 +21,6 @@ package org.sleuthkit.autopsy.casemodule; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.File; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; @@ -33,12 +32,9 @@ import org.openide.util.NbBundle; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import java.util.logging.Level; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.openide.util.Lookup; import org.sleuthkit.autopsy.casemodule.Case.CaseType; -import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; /** * Add input wizard subpanel for adding local files / dirs to the case */ @@ -51,9 +47,6 @@ import org.sleuthkit.autopsy.coreutils.Logger; public static final String FILES_SEP = ","; private static final Logger logger = Logger.getLogger(LocalFilesPanel.class.getName()); - List pathValidatorList = new ArrayList<>(); - private final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$"); - /** * Creates new form LocalFilesPanel */ @@ -71,18 +64,8 @@ import org.sleuthkit.autopsy.coreutils.Logger; private void customInit() { localFileChooser.setMultiSelectionEnabled(true); - discoverWizardPathValidators(); errorLabel.setVisible(false); selectedPaths.setText(""); - } - - /** - * Discovers WizardPathValidator service providers - */ - private void discoverWizardPathValidators() { - for (WizardPathValidator pathValidator : Lookup.getDefault().lookupAll(WizardPathValidator.class)) { - pathValidatorList.add(pathValidator); - } } //@Override @@ -122,68 +105,26 @@ import org.sleuthkit.autopsy.coreutils.Logger; } /** - * Validates path to selected data source. Calls WizardPathValidator service provider - * if one is available. Otherwise performs path validation locally. + * Validates path to selected data source. * @param path Absolute path to the selected data source * @return true if path is valid, false otherwise. */ - private boolean isImagePathValid(String path){ - - errorLabel.setVisible(false); - String errorString = ""; - - if (path.isEmpty()) { - return false; // no need for error message as the module sets path to "" at startup - } - - // Path variable for "Local files" module is a coma separated string containg multiple paths - List pathsList = Arrays.asList(path.split(",")); - CaseType currentCaseType = Case.getCurrentCase().getCaseType(); + private boolean isImagePathValid(String path) { + errorLabel.setVisible(false); - for (String currentPath : pathsList) { - // check if the is a WizardPathValidator service provider - if (!pathValidatorList.isEmpty()) { - // call WizardPathValidator service provider - errorString = pathValidatorList.get(0).validateDataSourcePath(currentPath, currentCaseType); - if (!errorString.isEmpty()) { - break; - } - } else { - // validate locally - if (currentCaseType == Case.CaseType.MULTI_USER_CASE) { - // check that path is not on "C:" drive - if (pathOnCDrive(currentPath)) { - errorString = NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text"); //NON-NLS - if (!errorString.isEmpty()) { - break; - } - } - } else { - // single user case - no validation needed - } - } - } - - // set error string - if (!errorString.isEmpty()){ - errorLabel.setVisible(true); - errorLabel.setText(errorString); - return false; - } - - return true; - } - - /** - * Checks whether a file path contains drive letter defined by pattern. - * - * @param filePath Input file absolute path - * @return true if path matches the pattern, false otherwise. - */ - private boolean pathOnCDrive(String filePath) { - Matcher m = driveLetterPattern.matcher(filePath); - return m.find(); - } + // Path variable for "Local files" module is a coma separated string containg multiple paths + List pathsList = Arrays.asList(path.split(",")); + CaseType currentCaseType = Case.getCurrentCase().getCaseType(); + + for (String currentPath : pathsList) { + if (!MultiUserPathValidator.isValid(currentPath, currentCaseType)) { + errorLabel.setVisible(true); + errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text")); + return false; + } + } + return true; + } //@Override public void select() { diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java index 0749da0d5e..a98c8694b3 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java @@ -22,18 +22,14 @@ import org.openide.util.NbBundle; import java.awt.*; import java.io.File; -import java.util.ArrayList; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import javax.swing.JFileChooser; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import org.openide.util.Lookup; import org.sleuthkit.autopsy.casemodule.Case.CaseType; import org.sleuthkit.autopsy.core.UserPreferences; -import org.sleuthkit.autopsy.corecomponentinterfaces.WizardPathValidator; +import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; import org.sleuthkit.datamodel.CaseDbConnectionInfo; import org.sleuthkit.datamodel.TskData.DbType; @@ -45,13 +41,10 @@ import org.sleuthkit.datamodel.TskData.DbType; final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { private JFileChooser fc = new JFileChooser(); - private NewCaseWizardPanel1 wizPanel; - java.util.List pathValidatorList = new ArrayList<>(); - private final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$"); + private NewCaseWizardPanel1 wizPanel; NewCaseVisualPanel1(NewCaseWizardPanel1 wizPanel) { initComponents(); - discoverWizardPathValidators(); errorLabel.setVisible(false); lbBadMultiUserSettings.setText(""); this.wizPanel = wizPanel; @@ -373,11 +366,6 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { String caseName = getCaseName(); String parentDir = getCaseParentDir(); - if (!isImagePathValid(parentDir)) { - wizPanel.setIsFinish(false); - return; - } - if (!caseName.equals("") && !parentDir.equals("")) { caseDirTextField.setText(parentDir + caseName); wizPanel.setIsFinish(true); @@ -385,66 +373,30 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { caseDirTextField.setText(""); wizPanel.setIsFinish(false); } + + if (!isImagePathValid(parentDir)) { + wizPanel.setIsFinish(false); + } } /** - * Validates path to selected data source. Calls WizardPathValidator service provider - * if one is available. Otherwise performs path validation locally. + * Validates path to selected data source. + * * @param path Absolute path to the selected data source * @return true if path is valid, false otherwise. */ - private boolean isImagePathValid(String path){ - + private boolean isImagePathValid(String path) { errorLabel.setVisible(false); - String errorString = ""; - + if (path.isEmpty()) { return false; // no need for error message as the module sets path to "" at startup } - // check if the is a WizardPathValidator service provider - if (!pathValidatorList.isEmpty()) { - // call WizardPathValidator service provider - errorString = pathValidatorList.get(0).validateDataSourcePath(path, getCaseType()); - } else { - // validate locally - if (getCaseType() == Case.CaseType.MULTI_USER_CASE) { - // check that path is not on "C:" drive - if (pathOnCDrive(path)) { - errorString = NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnCDriveError.text"); //NON-NLS - } - } else { - // single user case - no validation needed - } - } - - // set error string - if (!errorString.isEmpty()){ + if (!MultiUserPathValidator.isValid(path, getCaseType())) { errorLabel.setVisible(true); - errorLabel.setText(errorString); + errorLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnCDriveError.text")); return false; } - return true; - } - - /** - * Checks whether a file path contains drive letter defined by pattern. - * - * @param filePath Input file absolute path - * @return true if path matches the pattern, false otherwise. - */ - private boolean pathOnCDrive(String filePath) { - Matcher m = driveLetterPattern.matcher(filePath); - return m.find(); - } - - /** - * Discovers WizardPathValidator service providers - */ - private void discoverWizardPathValidators() { - for (WizardPathValidator pathValidator : Lookup.getDefault().lookupAll(WizardPathValidator.class)) { - pathValidatorList.add(pathValidator); - } - } + } } diff --git a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java deleted file mode 100644 index 045e91198a..0000000000 --- a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/WizardPathValidator.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2011-2014 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.corecomponentinterfaces; - -import org.sleuthkit.autopsy.casemodule.Case; - -/* - * Defines an interface used by the Add DataSource wizard to validate path for selected - * case and/or data source. - * - * Different Autopsy implementations and modes may have its unique attributes and - * may need to be processed differently. - * - * The WizardPathValidator interface defines a uniform mechanism for the Autopsy UI - * to: - * - Validate path for selected case. - * - Validate path for selected data source. - */ -public interface WizardPathValidator { - - /** - * Validates case path. - * - * @param path Absolute path to case file. - * @param caseType Case type - * @return String Error message if path is invalid, empty string otherwise. - * - */ - String validateCasePath(String path, Case.CaseType caseType); - - /** - * Validates data source path. - * - * @param path Absolute path to data source file. - * @param caseType Case type - * @return String Error message if path is invalid, empty string otherwise. - * - */ - String validateDataSourcePath(String path, Case.CaseType caseType); -} diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/MultiUserPathValidator.java b/Core/src/org/sleuthkit/autopsy/coreutils/MultiUserPathValidator.java new file mode 100644 index 0000000000..3bc4b3f4f7 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/coreutils/MultiUserPathValidator.java @@ -0,0 +1,57 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2013-2014 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.coreutils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.sleuthkit.autopsy.casemodule.Case; + +/** + * Validates absolute path to a data source depending on case type. + */ +public final class MultiUserPathValidator { + + private static final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$"); + public static boolean isValid(String path, Case.CaseType caseType) { + + if (caseType == Case.CaseType.MULTI_USER_CASE) { + // check that path is not on "C:" drive + if (pathOnCDrive(path)) { + return false; + } + } else { + // single user case - no validation needed + } + + return true; + } + + + /** + * Checks whether a file path contains drive letter defined by pattern. + * + * @param filePath Input file absolute path + * @return true if path matches the pattern, false otherwise. + */ + private static boolean pathOnCDrive(String filePath) { + Matcher m = driveLetterPattern.matcher(filePath); + return m.find(); + } +} \ No newline at end of file From 3c310f90b672618056fb2475e9822adc017fd9e4 Mon Sep 17 00:00:00 2001 From: Karl Mortensen Date: Tue, 26 May 2015 12:15:09 -0400 Subject: [PATCH 49/79] code review updates --- .../org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java | 2 +- .../org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java | 2 +- Core/src/org/sleuthkit/autopsy/core/UserPreferences.java | 2 +- .../autopsy/corecomponents/MultiUserSettingsPanel.java | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java index 82584797f1..4dd63ca497 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java @@ -49,7 +49,7 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { caseNameTextField.getDocument().addDocumentListener(this); caseParentDirTextField.getDocument().addDocumentListener(this); CaseDbConnectionInfo info = UserPreferences.getDatabaseConnectionInfo(); - if (info.getDbType() == DbType.UNKNOWN) { + if (info.getDbType() == DbType.SQLITE) { rbSingleUserCase.setSelected(true); rbSingleUserCase.setEnabled(false); rbMultiUserCase.setEnabled(false); diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java index 96e9a40442..e187937f43 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java @@ -99,7 +99,7 @@ import org.sleuthkit.datamodel.TskData.DbType; //TODO fix for local CaseType currentCaseType = CaseType.fromString(ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, ModuleSettings.CURRENT_CASE_TYPE)); CaseDbConnectionInfo info = UserPreferences.getDatabaseConnectionInfo(); - if ((currentCaseType==CaseType.SINGLE_USER_CASE) || ((info.getDbType() != DbType.UNKNOWN) && info.settingsValid())) { + if ((currentCaseType==CaseType.SINGLE_USER_CASE) || ((info.getDbType() != DbType.SQLITE) && info.settingsValid())) { AddImageAction addImageAction = SystemAction.get(AddImageAction.class); addImageAction.actionPerformed(null); } else { diff --git a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java index 3051ca840a..eb8da0234c 100755 --- a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java +++ b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java @@ -111,7 +111,7 @@ public final class UserPreferences { try { dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "UNKOWN")); } catch (Exception ex) { - dbType = DbType.UNKNOWN; + dbType = DbType.SQLITE; } return new CaseDbConnectionInfo( preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""), diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java index 4efe297203..a5c586ae72 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java @@ -398,7 +398,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { tbIndexingServerPort.setText(indexingServerPort); } - if (dbInfo.getDbType() == DbType.UNKNOWN) { + if (dbInfo.getDbType() == DbType.SQLITE) { cbEnableMultiUser.setSelected(false); } else { cbEnableMultiUser.setSelected(true); @@ -420,7 +420,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { void store() { - DbType dbType = DbType.UNKNOWN; + DbType dbType = DbType.SQLITE; if (cbEnableMultiUser.isSelected()) { dbType = DbType.POSTGRESQL; From 3d99f685c1bd5b6fe45b88a77268a4bbd983fee8 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Tue, 26 May 2015 13:35:11 -0400 Subject: [PATCH 50/79] Modified panels to treat C drive path as warning rather than error --- .../sleuthkit/autopsy/casemodule/ImageFilePanel.java | 11 +++++------ .../sleuthkit/autopsy/casemodule/LocalDiskPanel.java | 5 ++--- .../sleuthkit/autopsy/casemodule/LocalFilesPanel.java | 5 ++--- .../autopsy/casemodule/NewCaseVisualPanel1.java | 9 ++++----- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java index c009c6052f..c0a265420e 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java @@ -265,18 +265,18 @@ public class ImageFilePanel extends JPanel implements DocumentListener { * @return true if a proper image has been selected, false otherwise */ public boolean validatePanel() { + errorLabel.setVisible(false); String path = getContentPaths(); if (path == null || path.isEmpty()) { return false; } + // display warning if there is one (but don't disable "next" button) + isImagePathValid(path); + boolean isExist = Case.pathExists(path); boolean isPhysicalDrive = Case.isPhysicalDrive(path); boolean isPartition = Case.isPartition(path); - - if (!isImagePathValid(path)) { - return false; - } return (isExist || isPhysicalDrive || isPartition); } @@ -286,8 +286,7 @@ public class ImageFilePanel extends JPanel implements DocumentListener { * @param path Absolute path to the selected data source * @return true if path is valid, false otherwise. */ - private boolean isImagePathValid(String path){ - errorLabel.setVisible(false); + private boolean isImagePathValid(String path){ if (!MultiUserPathValidator.isValid(path, Case.getCurrentCase().getCaseType())) { errorLabel.setVisible(true); errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text")); diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java index e109c40cf0..206f8087fb 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java @@ -229,9 +229,8 @@ final class LocalDiskPanel extends JPanel { //@Override public boolean validatePanel() { - if (!isImagePathValid(getContentPaths())) { - return false; - } + // display warning if there is one (but don't disable "next" button) + isImagePathValid(getContentPaths()); return enableNext; } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java index 2caf8dd09b..b20bd71bb6 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java @@ -97,9 +97,8 @@ import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; //@Override public boolean validatePanel() { - if (!isImagePathValid(getContentPaths())) { - return false; - } + // display warning if there is one (but don't disable "next" button) + isImagePathValid(getContentPaths()); return enableNext; } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java index a98c8694b3..0cee4eab00 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java @@ -374,15 +374,14 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { wizPanel.setIsFinish(false); } - if (!isImagePathValid(parentDir)) { - wizPanel.setIsFinish(false); - } + // display warning if there is one (but don't disable "next" button) + isImagePathValid(parentDir); } /** - * Validates path to selected data source. + * Validates path to selected case output folder. * - * @param path Absolute path to the selected data source + * @param path Absolute path to the selected case folder * @return true if path is valid, false otherwise. */ private boolean isImagePathValid(String path) { From abe801e1515bdb29927f03eaeb98e23bb8a5731e Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Tue, 26 May 2015 14:39:55 -0400 Subject: [PATCH 51/79] python logger logs appropriate logging source --- pythonExamples/dataSourceIngestModule.py | 5 +++-- pythonExamples/fileIngestModule.py | 3 ++- pythonExamples/fileIngestModuleWithGui.py | 7 ++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pythonExamples/dataSourceIngestModule.py b/pythonExamples/dataSourceIngestModule.py index 2761acdaec..7d6a535aaa 100755 --- a/pythonExamples/dataSourceIngestModule.py +++ b/pythonExamples/dataSourceIngestModule.py @@ -33,6 +33,7 @@ import jarray from java.lang import System +from java.util.logging import Level from org.sleuthkit.datamodel import SleuthkitCase from org.sleuthkit.datamodel import AbstractFile from org.sleuthkit.datamodel import ReadContentInputStream @@ -113,7 +114,7 @@ class SampleJythonDataSourceIngestModule(DataSourceIngestModule): files = fileManager.findFiles(dataSource, "%test%") numFiles = len(files) - logger.info("found " + str(numFiles) + " files") + logger.logp(Level.INFO, SampleJythonDataSourceIngestModule.__name__, "process", "found " + str(numFiles) + " files") progressBar.switchToDeterminate(numFiles) fileCount = 0; for file in files: @@ -122,7 +123,7 @@ class SampleJythonDataSourceIngestModule(DataSourceIngestModule): if self.context.isJobCancelled(): return IngestModule.ProcessResult.OK - logger.info("Processing file: " + file.getName()) + logger.logp(Level.INFO, SampleJythonDataSourceIngestModule.__name__, "process", "Processing file: " + file.getName()) fileCount += 1 # Make an artifact on the blackboard. TSK_INTERESTING_FILE_HIT is a generic type of diff --git a/pythonExamples/fileIngestModule.py b/pythonExamples/fileIngestModule.py index 399592c2f3..579348ad36 100755 --- a/pythonExamples/fileIngestModule.py +++ b/pythonExamples/fileIngestModule.py @@ -33,6 +33,7 @@ import jarray from java.lang import System +from java.util.logging import Level from org.sleuthkit.datamodel import SleuthkitCase from org.sleuthkit.datamodel import AbstractFile from org.sleuthkit.datamodel import ReadContentInputStream @@ -99,7 +100,7 @@ class SampleJythonFileIngestModule(FileIngestModule): # For an example, we will flag files with .txt in the name and make a blackboard artifact. if file.getName().find(".txt") != -1: - self.logger.info("Found a text file: " + file.getName()) + self.logger.logp(Level.INFO, SampleJythonFileIngestModule.__name__, "process", "Found a text file: " + file.getName()) self.filesFound+=1 # Make an artifact on the blackboard. TSK_INTERESTING_FILE_HIT is a generic type of diff --git a/pythonExamples/fileIngestModuleWithGui.py b/pythonExamples/fileIngestModuleWithGui.py index e1647eacb9..7780dcf3f2 100755 --- a/pythonExamples/fileIngestModuleWithGui.py +++ b/pythonExamples/fileIngestModuleWithGui.py @@ -40,6 +40,7 @@ import jarray from java.lang import System +from java.util.logging import Level from javax.swing import JCheckBox from javax.swing import BoxLayout from org.sleuthkit.autopsy.casemodule import Case @@ -117,12 +118,12 @@ class SampleFileIngestModuleWithUI(FileIngestModule): # TODO: Add any setup code that you need here. def startUp(self, context): self.logger = Logger.getLogger(SampleFileIngestModuleWithUIFactory.moduleName) - + # As an example, determine if user configured a flag in UI if self.local_settings.getFlag(): - self.logger.info("flag is set") + self.logger.logp(Level.INFO, SampleFileIngestModuleWithUI.__name__, "startUp", "flag is set") else: - self.logger.info("flag is not set") + self.logger.logp(Level.INFO, SampleFileIngestModuleWithUI.__name__, "startUp", "flag is not set") # Throw an IngestModule.IngestModuleException exception if there was a problem setting up # raise IngestModuleException(IngestModule(), "Oh No!") From b8dc1ad97a4e66416485460a69d0cf22a1666b35 Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 26 May 2015 14:44:55 -0400 Subject: [PATCH 52/79] fix progress bar not going away --- .../autopsy/timeline/TimeLineController.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/timeline/TimeLineController.java b/Core/src/org/sleuthkit/autopsy/timeline/TimeLineController.java index 4cf3b20713..e57dddb509 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/TimeLineController.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/TimeLineController.java @@ -58,7 +58,6 @@ import org.joda.time.Interval; import org.joda.time.ReadablePeriod; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; -import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.casemodule.Case; @@ -100,7 +99,7 @@ public class TimeLineController { private static final Logger LOGGER = Logger.getLogger(TimeLineController.class.getName()); private static final String DO_REPOPULATE_MESSAGE = NbBundle.getMessage(TimeLineController.class, - "Timeline.do_repopulate.msg"); + "Timeline.do_repopulate.msg"); private static final ReadOnlyObjectWrapper timeZone = new ReadOnlyObjectWrapper<>(TimeZone.getDefault()); @@ -359,7 +358,7 @@ public class TimeLineController { private long getCaseLastArtifactID(final SleuthkitCase sleuthkitCase) { long caseLastArtfId = -1; String query = "select Max(artifact_id) as max_id from blackboard_artifacts"; // NON-NLS - + try (CaseDbQuery dbQuery = sleuthkitCase.executeQuery(query)) { ResultSet resultSet = dbQuery.getResultSet(); while (resultSet.next()) { @@ -481,12 +480,12 @@ public class TimeLineController { if (newLOD == DescriptionLOD.FULL && count > 10_000) { int showConfirmDialog = JOptionPane.showConfirmDialog(mainFrame, - NbBundle.getMessage(this.getClass(), - "Timeline.pushDescrLOD.confdlg.msg", - NumberFormat.getInstance().format(count)), - NbBundle.getMessage(TimeLineTopComponent.class, - "Timeline.pushDescrLOD.confdlg.details"), - JOptionPane.YES_NO_OPTION); + NbBundle.getMessage(this.getClass(), + "Timeline.pushDescrLOD.confdlg.msg", + NumberFormat.getInstance().format(count)), + NbBundle.getMessage(TimeLineTopComponent.class, + "Timeline.pushDescrLOD.confdlg.details"), + JOptionPane.YES_NO_OPTION); shouldContinue = (showConfirmDialog == JOptionPane.YES_OPTION); } @@ -570,6 +569,12 @@ public class TimeLineController { monitorTask(selectTimeAndTypeTask); } + /** + * submit a task for execution and add it to the list of tasks whose + * progress is monitored and displayed in the progress bar + * + * @param task + */ synchronized public void monitorTask(final Task task) { if (task != null) { Platform.runLater(() -> { @@ -603,9 +608,16 @@ public class TimeLineController { break; case SCHEDULED: case RUNNING: + case SUCCEEDED: case CANCELLED: case FAILED: + tasks.remove(task); + if (tasks.isEmpty() == false) { + progress.bind(tasks.get(0).progressProperty()); + message.bind(tasks.get(0).messageProperty()); + taskTitle.bind(tasks.get(0).titleProperty()); + } break; } }); @@ -634,7 +646,7 @@ public class TimeLineController { return JOptionPane.showConfirmDialog(mainFrame, DO_REPOPULATE_MESSAGE, NbBundle.getMessage(TimeLineTopComponent.class, - "Timeline.showLastPopulatedWhileIngestingConf.confDlg.details"), + "Timeline.showLastPopulatedWhileIngestingConf.confDlg.details"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); From 3fb33da0c86a0db0eddff078b4f69eb079280a86 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Tue, 26 May 2015 20:36:42 -0400 Subject: [PATCH 53/79] Moved static Case.getCaseType() to new CaseMetadata class --- .../sleuthkit/autopsy/casemodule/Case.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 94899b9289..33a2b00386 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -43,7 +43,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; -import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.actions.CallableSystemAction; @@ -748,24 +747,6 @@ public class Case implements SleuthkitCase.ErrorObserver { return this.caseType; } - /** - * Get the case type within an .aut file. Defaults to single-user case if - * there is a problem. - * - * @param thePath the path to the file, example: C:\folder\case.aut - * @return The case type contained in the .aut file. - */ - public static CaseType getCaseType(Path thePath) { - try { - XMLCaseManagement xmlcm = new XMLCaseManagement(); - xmlcm.open(thePath.toString()); - return xmlcm.getCaseType(); - } catch (CaseActionException ex) { - logger.log(Level.SEVERE, NbBundle.getMessage(Case.class, "Case.GetCaseTypeGivenPath.Failure"), ex); // NON-NLS - return CaseType.SINGLE_USER_CASE; - } - } - /** * Gets the full path to the temp directory of this case. Will create it if * it does not already exist. From 6fa65783a6b4ad6e8ec73fe6f450efcdcafaa618 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Tue, 26 May 2015 21:15:43 -0400 Subject: [PATCH 54/79] Made CaseMetadata.CaseMetadataException class static --- .../autopsy/casemodule/CaseMetadata.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Core/src/org/sleuthkit/autopsy/casemodule/CaseMetadata.java diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/CaseMetadata.java b/Core/src/org/sleuthkit/autopsy/casemodule/CaseMetadata.java new file mode 100644 index 0000000000..8ea3e923ab --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/casemodule/CaseMetadata.java @@ -0,0 +1,72 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2011-2015 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.casemodule; + +import java.nio.file.Path; + +/** + * Provides access to case metadata. + */ +public final class CaseMetadata { + + /** + * Exception thrown by the CaseMetadata class when there is a problem + * accessing the metadata for a case. + */ + public final static class CaseMetadataException extends Exception { + + private CaseMetadataException(String message) { + super(message); + } + + private CaseMetadataException(String message, Throwable cause) { + super(message, cause); + } + } + + private final Case.CaseType caseType; + + /** + * Constructs an object that provides access to case metadata. + * + * @param metadataFilePath + */ + public CaseMetadata(Path metadataFilePath) throws CaseMetadataException { + try { + // NOTE: This class will eventually replace XMLCaseManagement. + // This constructor should parse all of the metadata. In the future, + // case metadata may be moved into the case database. + XMLCaseManagement metadata = new XMLCaseManagement(); + metadata.open(metadataFilePath.toString()); + this.caseType = metadata.getCaseType(); + } catch (CaseActionException ex) { + throw new CaseMetadataException(ex.getLocalizedMessage(), ex); + } + } + + /** + * Gets the case type. + * + * @return The case type. + */ + public Case.CaseType getCaseType(Path thePath) { + return this.caseType; + } + +} From 595111175415e0a14a9a24049ded72eb6dcbd778 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 27 May 2015 11:13:49 -0400 Subject: [PATCH 55/79] Modified panels per review feedback --- .../sleuthkit/autopsy/casemodule/Bundle.properties | 6 +++--- .../sleuthkit/autopsy/casemodule/ImageFilePanel.java | 9 +++------ .../sleuthkit/autopsy/casemodule/LocalDiskPanel.java | 11 ++++------- .../sleuthkit/autopsy/casemodule/LocalFilesPanel.java | 10 ++++------ 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index 35a6d6a7ae..4f1698b58d 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -58,7 +58,7 @@ LocalDiskPanel.diskLabel.text=Select a local disk: MissingImageDialog.selectButton.text=Select Image MissingImageDialog.titleLabel.text=Search for missing image MissingImageDialog.cancelButton.text=Cancel -LocalDiskPanel.errorLabel.text=Error Label +LocalDiskPanel.errorLabel.text= LocalFilesPanel.infoLabel.text=Add local files and folders: LocalFilesPanel.selectButton.text=Add LocalFilesPanel.localFileChooser.dialogTitle=Select Local Files or Folders @@ -230,8 +230,8 @@ AddImageWizardIngestConfigPanel.CANCEL_BUTTON.text=Cancel NewCaseVisualPanel1.rbSingleUserCase.text=Single-user NewCaseVisualPanel1.rbMultiUserCase.text=Multi-user NewCaseVisualPanel1.lbBadMultiUserSettings.text= -ImageFilePanel.errorLabel.text=Error Label +ImageFilePanel.errorLabel.text= DataSourceOnCDriveError.text=Path to multi-user data source is on \"C:\" drive NewCaseVisualPanel1.CaseFolderOnCDriveError.text=Path to multi-user case folder is on \"C:\" drive -LocalFilesPanel.errorLabel.text=Error Label +LocalFilesPanel.errorLabel.text= NewCaseVisualPanel1.errorLabel.text=Error Label diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java index c0a265420e..83e02d349d 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java @@ -272,7 +272,7 @@ public class ImageFilePanel extends JPanel implements DocumentListener { } // display warning if there is one (but don't disable "next" button) - isImagePathValid(path); + warnIfPathIsInvalid(path); boolean isExist = Case.pathExists(path); boolean isPhysicalDrive = Case.isPhysicalDrive(path); @@ -282,17 +282,14 @@ public class ImageFilePanel extends JPanel implements DocumentListener { } /** - * Validates path to selected data source. + * Validates path to selected data source and displays warning if it is invalid. * @param path Absolute path to the selected data source - * @return true if path is valid, false otherwise. */ - private boolean isImagePathValid(String path){ + private void warnIfPathIsInvalid(String path){ if (!MultiUserPathValidator.isValid(path, Case.getCurrentCase().getCaseType())) { errorLabel.setVisible(true); errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text")); - return false; } - return true; } public void storeSettings() { diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java index 206f8087fb..eb07ddab2d 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java @@ -170,7 +170,7 @@ final class LocalDiskPanel extends JPanel { .addComponent(noFatOrphansCheckbox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(descLabel) - .addContainerGap(21, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables @@ -230,17 +230,16 @@ final class LocalDiskPanel extends JPanel { public boolean validatePanel() { // display warning if there is one (but don't disable "next" button) - isImagePathValid(getContentPaths()); + warnIfPathIsInvalid(getContentPaths()); return enableNext; } /** - * Validates path to selected data source. + * Validates path to selected data source and displays warning if it is invalid. * @param path Absolute path to the selected data source - * @return true if path is valid, false otherwise. */ - private boolean isImagePathValid(String path){ + private void warnIfPathIsInvalid(String path){ String newPath = path; if (path.length() > prePendedStringLength) { // "Local Disk" panel pre-pends "\\.\" in front of all drive letter and drive names. @@ -252,9 +251,7 @@ final class LocalDiskPanel extends JPanel { if (!MultiUserPathValidator.isValid(newPath, Case.getCurrentCase().getCaseType())) { errorLabel.setVisible(true); errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text")); - return false; } - return true; } //@Override diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java index b20bd71bb6..efcb4439b0 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java @@ -98,17 +98,16 @@ import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; public boolean validatePanel() { // display warning if there is one (but don't disable "next" button) - isImagePathValid(getContentPaths()); + warnIfPathIsInvalid(getContentPaths()); return enableNext; } /** - * Validates path to selected data source. + * Validates path to selected data source and displays warning if it is invalid. * @param path Absolute path to the selected data source - * @return true if path is valid, false otherwise. */ - private boolean isImagePathValid(String path) { + private void warnIfPathIsInvalid(String path) { errorLabel.setVisible(false); // Path variable for "Local files" module is a coma separated string containg multiple paths @@ -119,10 +118,9 @@ import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; if (!MultiUserPathValidator.isValid(currentPath, currentCaseType)) { errorLabel.setVisible(true); errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text")); - return false; + return; } } - return true; } //@Override From 46a8090aa2bf1783f49ffba0809b636e0107cb52 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 27 May 2015 13:07:32 -0400 Subject: [PATCH 56/79] Testing things --- .../autopsy/casemodule/CaseNewAction.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java b/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java index 3be5ec7c57..b035783086 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java @@ -20,6 +20,8 @@ package org.sleuthkit.autopsy.casemodule; import java.awt.event.ActionEvent; +import org.openide.util.HelpCtx; +import org.openide.util.actions.CallableSystemAction; import org.openide.util.actions.SystemAction; import org.openide.util.lookup.ServiceProvider; @@ -29,7 +31,7 @@ import org.openide.util.lookup.ServiceProvider; * @author jantonius */ @ServiceProvider(service = CaseNewActionInterface.class) -public final class CaseNewAction implements CaseNewActionInterface { +public final class CaseNewAction extends CallableSystemAction implements CaseNewActionInterface { private NewCaseWizardAction wizard = SystemAction.get(NewCaseWizardAction.class); @@ -41,4 +43,18 @@ public final class CaseNewAction implements CaseNewActionInterface { public void actionPerformed(ActionEvent e) { wizard.performAction(); } + + @Override + public void performAction() { + } + + @Override + public String getName() { + return "New Case"; + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } } From 09aa1b243e15a12116850ad0f052471ab291f168 Mon Sep 17 00:00:00 2001 From: jmillman Date: Wed, 27 May 2015 13:15:30 -0400 Subject: [PATCH 57/79] remove unused variable --- .../autopsy/imagegallery/actions/CategorizeAction.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 7fb5d140aa..f69d2e63f5 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -95,7 +95,6 @@ public class CategorizeAction extends AddTagAction { //remove old category tag if necessary List allContentTags = Case.getCurrentCase().getServices().getTagsManager().getContentTagsByContent(file); - boolean hadExistingCategory = false; for (ContentTag ct : allContentTags) { //this is bad: treating tags as categories as long as their names start with prefix //TODO: abandon using tags for categories and instead add a new column to DrawableDB @@ -103,7 +102,6 @@ public class CategorizeAction extends AddTagAction { //LOGGER.log(Level.INFO, "removing old category from {0}", file.getName()); Case.getCurrentCase().getServices().getTagsManager().deleteContentTag(ct); controller.getDatabase().decrementCategoryCount(Category.fromDisplayName(ct.getName().getDisplayName())); - hadExistingCategory = true; } } From a750a970a6635b1c19e2db17e07db5ac94838088 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 27 May 2015 13:31:40 -0400 Subject: [PATCH 58/79] Fixes for new case open panel --- .../sleuthkit/autopsy/casemodule/CaseNewAction.java | 11 +++++++++++ Core/src/org/sleuthkit/autopsy/core/layer.xml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java b/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java index b035783086..3303f4889c 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java @@ -57,4 +57,15 @@ public final class CaseNewAction extends CallableSystemAction implements CaseNew public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; } + + /** + * 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); + } } diff --git a/Core/src/org/sleuthkit/autopsy/core/layer.xml b/Core/src/org/sleuthkit/autopsy/core/layer.xml index 6eaba7d184..c8f37f5318 100644 --- a/Core/src/org/sleuthkit/autopsy/core/layer.xml +++ b/Core/src/org/sleuthkit/autopsy/core/layer.xml @@ -44,7 +44,7 @@ - + From b04fa81b53c959b33efbcdd536e48828670ca50b Mon Sep 17 00:00:00 2001 From: jmillman Date: Wed, 27 May 2015 13:30:25 -0400 Subject: [PATCH 59/79] fix categorization ui update errors - remove old listeners when updating treecell item. cleanup GroupTreeCell - invalidateHashSetHitsCount before adding/removing files to make sure it is seen during listner involation - cleanup GroupTreeItem and NavPanel - add comment to GroupManager --- .../imagegallery/grouping/DrawableGroup.java | 20 ++- .../imagegallery/grouping/GroupManager.java | 66 ++++----- .../gui/navpanel/GroupTreeCell.java | 132 ++++++++++-------- .../gui/navpanel/GroupTreeItem.java | 87 +++++------- .../imagegallery/gui/navpanel/NavPanel.java | 119 ++++++++-------- 5 files changed, 208 insertions(+), 216 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java index d9cfdb70a4..457f1a07e7 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java @@ -25,14 +25,12 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.datamodel.BlackboardArtifact; -import org.sleuthkit.datamodel.TskCoreException; /** * Represents a set of image/video files in a group. The UI listens to changes * to the group membership and updates itself accordingly. */ -public class DrawableGroup implements Comparable{ +public class DrawableGroup implements Comparable { private static final Logger LOGGER = Logger.getLogger(DrawableGroup.class.getName()); @@ -69,18 +67,18 @@ public class DrawableGroup implements Comparable{ * Call to indicate that an image has been added or removed from the group, * so the hash counts may not longer be accurate. */ - synchronized public void invalidateHashSetHitsCount(){ + synchronized public void invalidateHashSetHitsCount() { filesWithHashSetHitsCount = -1; } - - synchronized public int getFilesWithHashSetHitsCount() { + + synchronized public int getFilesWithHashSetHitsCount() { //TODO: use the drawable db for this ? -jm if (filesWithHashSetHitsCount < 0) { filesWithHashSetHitsCount = 0; for (Long fileID : fileIds()) { try { - if(ImageGalleryController.getDefault().getDatabase().isInHashSet(fileID)){ + if (ImageGalleryController.getDefault().getDatabase().isInHashSet(fileID)) { filesWithHashSetHitsCount++; } } catch (IllegalStateException | NullPointerException ex) { @@ -117,20 +115,20 @@ public class DrawableGroup implements Comparable{ } synchronized public void addFile(Long f) { + invalidateHashSetHitsCount(); if (fileIDs.contains(f) == false) { fileIDs.add(f); } - invalidateHashSetHitsCount(); } synchronized public void removeFile(Long f) { - fileIDs.removeAll(f); invalidateHashSetHitsCount(); + fileIDs.removeAll(f); } - + // By default, sort by group key name @Override - public int compareTo(DrawableGroup other){ + public int compareTo(DrawableGroup other) { return this.groupKey.getValueDisplayName().compareTo(other.groupKey.getValueDisplayName()); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index 3bda6a2410..72c288b817 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -281,9 +281,11 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { final DrawableGroup group = getGroupForKey(groupKey); if (group != null) { group.removeFile(fileID); - + // If we're grouping by category, we don't want to remove empty groups. - if(! group.groupKey.getValueDisplayName().startsWith("CAT-")){ + if (group.groupKey.getValueDisplayName().startsWith("CAT-")) { + return; + } else { if (group.fileIds().isEmpty()) { synchronized (groupMap) { groupMap.remove(groupKey, group); @@ -320,13 +322,13 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * was still running) */ if (task == null || (task.isCancelled() == false)) { DrawableGroup g = makeGroup(groupKey, filesInGroup); - + populateAnalyzedGroup(g, task); } } - + private synchronized > void populateAnalyzedGroup(final DrawableGroup g, ReGroupTask task) { - + if (task == null || (task.isCancelled() == false)) { final boolean groupSeen = db.isGroupSeen(g.groupKey); Platform.runLater(() -> { @@ -430,7 +432,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * @return */ @SuppressWarnings({"unchecked"}) - public > List findValuesForAttribute(DrawableAttribute groupBy) { + public > List findValuesForAttribute(DrawableAttribute groupBy) { List values; try { switch (groupBy.attrName) { @@ -456,12 +458,12 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } return values; - } catch(TskCoreException ex){ + } catch (TskCoreException ex) { LOGGER.log(Level.WARNING, "TSK error getting list of type " + groupBy.getDisplayName()); return new ArrayList(); } - - } + + } public List getFileIDsInGroup(GroupKey groupKey) throws TskCoreException { switch (groupKey.getAttribute().attrName) { @@ -515,14 +517,17 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { throw ex; } } - + /** * Count the number of files with the given category. * This is faster than getFileIDsWithCategory and should be used if only the * counts are needed and not the file IDs. + * * @param category Category to match against + * * @return Number of files with the given category - * @throws TskCoreException + * + * @throws TskCoreException */ public int countFilesWithCategory(Category category) throws TskCoreException { return db.getCategoryCount(category); @@ -581,10 +586,10 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { */ public > void regroup(final DrawableAttribute groupBy, final GroupSortBy sortBy, final SortOrder sortOrder, Boolean force) { - if(! Case.isCaseOpen()){ + if (!Case.isCaseOpen()) { return; } - + //only re-query the db if the group by attribute changed or it is forced if (groupBy != getGroupBy() || force == true) { setGroupBy(groupBy); @@ -613,15 +618,11 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } } - - /** * an executor to submit async ui related background tasks to. */ final ExecutorService regroupExecutor = Executors.newSingleThreadExecutor(new BasicThreadFactory.Builder().namingPattern("ui task -%d").build()); - - public ReadOnlyDoubleProperty regroupProgress() { return regroupProgress.getReadOnlyProperty(); } @@ -630,6 +631,8 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * handle {@link FileUpdateEvent} sent from Db when files are * inserted/updated * + * TODO: why isn't this just two methods! + * * @param evt */ @Override @@ -643,10 +646,10 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { for (GroupKey gk : groupsForFile) { removeFromGroup(gk, fileId); - + DrawableGroup g = getGroupForKey(gk); - if (g == null){ + if (g == null) { // It may be that this was the last unanalyzed file in the group, so test // whether the group is now fully analyzed. //TODO: use method in groupmanager ? @@ -654,8 +657,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { if (checkAnalyzed != null) { // => the group is analyzed, so add it to the ui populateAnalyzedGroup(gk, checkAnalyzed); } - } - else{ + } else { g.invalidateHashSetHitsCount(); } } @@ -676,7 +678,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { * innertask? -jm */ for (final long fileId : fileIDs) { - + db.updateHashSetsForFile(fileId); //get grouping(s) this file would be in @@ -698,13 +700,13 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { } } } - - Category.fireChange(fileIDs); + if (evt.getChangedAttribute() == DrawableAttribute.CATEGORY) { + Category.fireChange(fileIDs); + } if (evt.getChangedAttribute() == DrawableAttribute.TAGS) { TagUtils.fireChange(fileIDs); } break; - } } @@ -753,10 +755,10 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { synchronized (groupMap) { groupMap.clear(); } - + // Get the list of group keys final List vals = findValuesForAttribute(groupBy); - + // Make a list of each group final List groups = new ArrayList<>(); @@ -777,22 +779,22 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { List checkAnalyzed = checkAnalyzed(groupKey); if (checkAnalyzed != null) { // != null => the group is analyzed, so add it to the ui - + // makeGroup will create the group and add it to the map groupMap, but does not // update anything else DrawableGroup g = makeGroup(groupKey, checkAnalyzed); groups.add(g); } } - + // Sort the group list Collections.sort(groups, sortBy.getGrpComparator(sortOrder)); - + // Officially add all groups in order - for(DrawableGroup g:groups){ + for (DrawableGroup g : groups) { populateAnalyzedGroup(g, ReGroupTask.this); } - + updateProgress(1, 1); return null; } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java index f5e2b138dc..2f34aec2e1 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java @@ -1,8 +1,28 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2013-15 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.imagegallery.gui.navpanel; +import static java.util.Objects.isNull; +import java.util.Optional; import javafx.application.Platform; +import javafx.beans.InvalidationListener; import javafx.beans.Observable; -import javafx.scene.Node; import javafx.scene.control.OverrunStyle; import javafx.scene.control.Tooltip; import javafx.scene.control.TreeCell; @@ -13,103 +33,95 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.grouping.DrawableGroup; /** - * A {@link Node} in the tree that listens to its associated group. Manages - * visual representation of TreeNode in Tree. Listens to properties of group - * that don't impact hierarchy and updates ui to reflect them + * A cell in the NavPanel tree that listens to its associated group's fileids. + * Manages visual representation of TreeNode in Tree. Listens to properties of + * group that don't impact hierarchy and updates ui to reflect them */ class GroupTreeCell extends TreeCell { /** * icon to use if this cell's TreeNode doesn't represent a group but just a - * folder(with no DrawableFiles) in the hierarchy. + * folder(with no DrawableFiles) in the file system hierarchy. */ private static final Image EMPTY_FOLDER_ICON = new Image("org/sleuthkit/autopsy/imagegallery/images/folder.png"); + /** + * reference to listener that allows us to remove it from a group when a new + * group is assigned to this Cell + */ + private InvalidationListener listener; + public GroupTreeCell() { + //TODO: move this to .css file //adjust indent, default is 10 which uses up a lot of space. setStyle("-fx-indent:5;"); //since end of path is probably more interesting put ellipsis at front setTextOverrun(OverrunStyle.LEADING_ELLIPSIS); + Platform.runLater(() -> { + prefWidthProperty().bind(getTreeView().widthProperty().subtract(15)); + }); + } @Override - synchronized protected void updateItem(final TreeNode tNode, boolean empty) { - super.updateItem(tNode, empty); - prefWidthProperty().bind(getTreeView().widthProperty().subtract(15)); + protected synchronized void updateItem(final TreeNode tNode, boolean empty) { + //if there was a previous group, remove the listener + Optional.ofNullable(getItem()) + .map(TreeNode::getGroup) + .ifPresent((DrawableGroup t) -> { + t.fileIds().removeListener(listener); + }); - if (tNode == null || empty) { + super.updateItem(tNode, empty); + + if (isNull(tNode) || empty) { Platform.runLater(() -> { setTooltip(null); setText(null); setGraphic(null); }); } else { - final String name = StringUtils.defaultIfBlank(tNode.getPath(), DrawableGroup.UNKNOWN); - Platform.runLater(() -> { - setTooltip(new Tooltip(name)); - }); - + final String groupName = StringUtils.defaultIfBlank(tNode.getPath(), DrawableGroup.UNKNOWN); - if (tNode.getGroup() == null) { + if (isNull(tNode.getGroup())) { + //"dummy" group in file system tree <=> a folder with no drawables Platform.runLater(() -> { - setText(name); + setTooltip(new Tooltip(groupName)); + setText(groupName); setGraphic(new ImageView(EMPTY_FOLDER_ICON)); }); } else { - //if number of files in this group changes (eg file is recategorized), update counts - tNode.getGroup().fileIds().addListener((Observable o) -> { + listener = (Observable o) -> { + final String countsText = getCountsText(); Platform.runLater(() -> { - - String groupName; // The "name" variable set earlier is generally not correct at this point - if((getItem() == null) || (getItem().getGroup() == null) || - (getItem().getGroup().groupKey == null)){ - groupName = ""; - } - else{ - groupName = getItem().getGroup().groupKey.getValueDisplayName(); - } - - setText(groupName + " (" + getNumerator() + getDenominator() + ")"); + setText(groupName + countsText); }); - }); + }; + //if number of files in this group changes (eg file is recategorized), update counts via listener + tNode.getGroup().fileIds().addListener(listener); + //... and use icon corresponding to group type + final Image icon = tNode.getGroup().groupKey.getAttribute().getIcon(); + final String countsText = getCountsText(); Platform.runLater(() -> { - //this TreeNode has a group so append counts to name ... - setText(name + " (" + getNumerator() + getDenominator() + ")"); - //... and use icon corresponding to group type - setGraphic(new ImageView(tNode.getGroup().groupKey.getAttribute().getIcon())); + setTooltip(new Tooltip(groupName)); + setGraphic(new ImageView(icon)); + setText(groupName + countsText); }); - } } } - /** - * @return the Numerator of the count to append to the group name = number - * of hashset hits + "/" - */ - synchronized private String getNumerator() { - try { - final String numerator = (getItem().getGroup().groupKey.getAttribute() != DrawableAttribute.HASHSET) - ? getItem().getGroup().getFilesWithHashSetHitsCount() + "/" - : ""; - return numerator; - } catch (NullPointerException e) { - //instead of this try catch block, remove the listener when assigned a null treeitem / group - return ""; - } - } + private synchronized String getCountsText() { + final String counts = Optional.ofNullable(getItem()) + .map(TreeNode::getGroup) + .map((DrawableGroup t) -> { + return " (" + ((t.groupKey.getAttribute() == DrawableAttribute.HASHSET) + ? Integer.toString(t.getSize()) + : t.getFilesWithHashSetHitsCount() + "/" + t.getSize()) + ")"; + }).orElse(""); //if item is null or group is null - /** - * @return the Denominator of the count to append to the group name = number - * of files in group - */ - synchronized private Integer getDenominator() { - try { - return getItem().getGroup().getSize(); - } catch (NullPointerException ex) { - return 0; - } + return counts; } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeItem.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeItem.java index 2c6b2d3666..37925b47bb 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeItem.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeItem.java @@ -37,10 +37,28 @@ import org.sleuthkit.autopsy.imagegallery.grouping.DrawableGroup; */ class GroupTreeItem extends TreeItem implements Comparable { + static GroupTreeItem getTreeItemForGroup(GroupTreeItem root, DrawableGroup grouping) { + if (Objects.equals(root.getValue().getGroup(), grouping)) { + return root; + } else { + synchronized (root.getChildren()) { + for (TreeItem child : root.getChildren()) { + final GroupTreeItem childGTI = (GroupTreeItem) child; + + GroupTreeItem val = getTreeItemForGroup(childGTI, grouping); + if (val != null) { + return val; + } + } + } + } + return null; + } + /** * maps a path segment to the child item of this item with that path segment */ - private Map childMap = new HashMap<>(); + private final Map childMap = new HashMap<>(); /** * the comparator if any used to sort the children of this item */ @@ -68,7 +86,7 @@ class GroupTreeItem extends TreeItem implements Comparable implements Comparable { + synchronized (getChildren()) { + getChildren().add(newTreeItem); } }); @@ -109,14 +124,11 @@ class GroupTreeItem extends TreeItem implements Comparable { + synchronized (getChildren()) { + getChildren().add(newTreeItem); + if (comp != null) { + FXCollections.sort(getChildren(), comp); } } }); @@ -129,7 +141,7 @@ class GroupTreeItem extends TreeItem implements Comparable path, DrawableGroup g, Boolean tree) { @@ -147,12 +159,9 @@ class GroupTreeItem extends TreeItem implements Comparable { + synchronized (getChildren()) { + getChildren().add(newTreeItem); } }); @@ -169,14 +178,11 @@ class GroupTreeItem extends TreeItem implements Comparable { + synchronized (getChildren()) { + getChildren().add(newTreeItem); + if (comp != null) { + FXCollections.sort(getChildren(), comp); } } }); @@ -189,24 +195,6 @@ class GroupTreeItem extends TreeItem implements Comparable child : root.getChildren()) { - final GroupTreeItem childGTI = (GroupTreeItem) child; - - GroupTreeItem val = getTreeItemForGroup(childGTI, grouping); - if (val != null) { - return val; - } - } - } - } - return null; - } - GroupTreeItem getTreeItemForPath(List path) { // end of recursion if (path.isEmpty()) { @@ -253,4 +241,5 @@ class GroupTreeItem extends TreeItem implements Comparable sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,6 @@ package org.sleuthkit.autopsy.imagegallery.gui.navpanel; import java.net.URL; import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.ResourceBundle; import javafx.application.Platform; @@ -41,23 +40,21 @@ import javafx.scene.control.TreeView; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; import org.apache.commons.lang3.StringUtils; -import org.openide.util.Exceptions; import org.sleuthkit.autopsy.coreutils.ThreadConfined; import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; import org.sleuthkit.autopsy.imagegallery.grouping.DrawableGroup; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupSortBy; import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewState; -import org.sleuthkit.datamodel.TskCoreException; /** * Display two trees. one shows all folders (groups) and calls out folders with * images. the user can select folders with images to see them in the main * GroupPane The other shows folders with hash set hits. + * + * //TODO: there is too much code duplication between the navTree and the + * hashTree. Extract the common code to some new class. */ public class NavPanel extends TabPane { @@ -170,24 +167,15 @@ public class NavPanel extends TabPane { removeFromNavTree(g); removeFromHashTree(g); } - if(change.wasPermutated()){ + if (change.wasPermutated()) { // Handle this afterward wasPermuted = true; } } - - if(wasPermuted){ - // Remove everything and add it again in the new order - for(DrawableGroup g:controller.getGroupManager().getAnalyzedGroups()){ - removeFromNavTree(g); - removeFromHashTree(g); - } - for(DrawableGroup g:controller.getGroupManager().getAnalyzedGroups()){ - insertIntoNavTree(g); - if (g.getFilesWithHashSetHitsCount() > 0) { - insertIntoHashTree(g); - } - } + + if (wasPermuted) { + rebuildTrees(); + } }); @@ -205,6 +193,27 @@ public class NavPanel extends TabPane { }); } + private void rebuildTrees() { + navTreeRoot = new GroupTreeItem("", null, sortByBox.getSelectionModel().selectedItemProperty().get()); + hashTreeRoot = new GroupTreeItem("", null, sortByBox.getSelectionModel().selectedItemProperty().get()); + + ObservableList groups = controller.getGroupManager().getAnalyzedGroups(); + + for (DrawableGroup g : groups) { + insertIntoNavTree(g); + if (g.getFilesWithHashSetHitsCount() > 0) { + insertIntoHashTree(g); + } + } + + Platform.runLater(() -> { + navTree.setRoot(navTreeRoot); + navTreeRoot.setExpanded(true); + hashTree.setRoot(hashTreeRoot); + hashTreeRoot.setExpanded(true); + }); + } + private void updateControllersGroup() { final TreeItem selectedItem = activeTreeProperty.get().getSelectionModel().getSelectedItem(); if (selectedItem != null && selectedItem.getValue() != null && selectedItem.getValue().getGroup() != null) { @@ -216,11 +225,6 @@ public class NavPanel extends TabPane { hashTreeRoot.resortChildren(sortByBox.getSelectionModel().getSelectedItem()); } - private void insertIntoHashTree(DrawableGroup g) { - initHashTree(); - hashTreeRoot.insert(g.groupKey.getValueDisplayName(), g, false); - } - /** * Set the tree to the passed in group * @@ -234,27 +238,29 @@ public class NavPanel extends TabPane { final GroupTreeItem treeItemForGroup = ((GroupTreeItem) activeTreeProperty.get().getRoot()).getTreeItemForPath(path); if (treeItemForGroup != null) { - /* When we used to run the below code on the FX thread, it would - * get into infinite loops when the next group button was pressed quickly - * because the udpates became out of order and History could not keep - * track of what was current. Currently (4/2/15), this method is - * already on the FX thread, so it is OK. */ + /* When we used to run the below code on the FX thread, it would + * get into infinite loops when the next group button was pressed + * quickly because the udpates became out of order and History could + * not + * keep track of what was current. + * + * Currently (4/2/15), this method is already on the FX thread, so + * it is OK. */ //Platform.runLater(() -> { - TreeItem ti = treeItemForGroup; - while (ti != null) { - ti.setExpanded(true); - ti = ti.getParent(); - } - int row = activeTreeProperty.get().getRow(treeItemForGroup); - if (row != -1) { - activeTreeProperty.get().getSelectionModel().select(treeItemForGroup); - activeTreeProperty.get().scrollTo(row); - } - //}); + TreeItem ti = treeItemForGroup; + while (ti != null) { + ti.setExpanded(true); + ti = ti.getParent(); + } + int row = activeTreeProperty.get().getRow(treeItemForGroup); + if (row != -1) { + activeTreeProperty.get().getSelectionModel().select(treeItemForGroup); + activeTreeProperty.get().scrollTo(row); + } + //}); //end Platform.runLater } } - @SuppressWarnings("fallthrough") private static List groupingToPath(DrawableGroup g) { if (g.groupKey.getAttribute() == DrawableAttribute.PATH) { @@ -269,11 +275,14 @@ public class NavPanel extends TabPane { } } + private void insertIntoHashTree(DrawableGroup g) { + initHashTree(); + hashTreeRoot.insert(groupingToPath(g), g, false); + } + private void insertIntoNavTree(DrawableGroup g) { initNavTree(); - List path = groupingToPath(g); - - navTreeRoot.insert(path, g, true); + navTreeRoot.insert(groupingToPath(g), g, true); } private void removeFromNavTree(DrawableGroup g) { @@ -313,22 +322,4 @@ public class NavPanel extends TabPane { }); } } - - //these are not used anymore, but could be usefull at some point - //TODO: remove them or find a use and undeprecate - @Deprecated - private void rebuildNavTree() { - navTreeRoot = new GroupTreeItem("", null, sortByBox.getSelectionModel().selectedItemProperty().get()); - - ObservableList groups = controller.getGroupManager().getAnalyzedGroups(); - - for (DrawableGroup g : groups) { - insertIntoNavTree(g); - } - - Platform.runLater(() -> { - navTree.setRoot(navTreeRoot); - navTreeRoot.setExpanded(true); - }); - } } From 9e925bb0b786e38eb1ff17d83340f90a867ba611 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 27 May 2015 14:13:14 -0400 Subject: [PATCH 60/79] Refactored PathValidator and error label --- Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties | 6 +++--- .../org/sleuthkit/autopsy/casemodule/ImageFilePanel.java | 4 ++-- .../org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java | 4 ++-- .../org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java | 4 ++-- .../sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java | 4 ++-- .../{MultiUserPathValidator.java => PathValidator.java} | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) rename Core/src/org/sleuthkit/autopsy/coreutils/{MultiUserPathValidator.java => PathValidator.java} (92%) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index 29eb25b0cc..8afd1f5cdb 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -58,7 +58,7 @@ LocalDiskPanel.diskLabel.text=Select a local disk: MissingImageDialog.selectButton.text=Select Image MissingImageDialog.titleLabel.text=Search for missing image MissingImageDialog.cancelButton.text=Cancel -LocalDiskPanel.errorLabel.text= +LocalDiskPanel.errorLabel.text=Error Label LocalFilesPanel.infoLabel.text=Add local files and folders: LocalFilesPanel.selectButton.text=Add LocalFilesPanel.localFileChooser.dialogTitle=Select Local Files or Folders @@ -231,8 +231,8 @@ AddImageWizardIngestConfigPanel.CANCEL_BUTTON.text=Cancel NewCaseVisualPanel1.rbSingleUserCase.text=Single-user NewCaseVisualPanel1.rbMultiUserCase.text=Multi-user NewCaseVisualPanel1.lbBadMultiUserSettings.text= -ImageFilePanel.errorLabel.text= +ImageFilePanel.errorLabel.text=Error Label DataSourceOnCDriveError.text=Path to multi-user data source is on \"C:\" drive NewCaseVisualPanel1.CaseFolderOnCDriveError.text=Path to multi-user case folder is on \"C:\" drive -LocalFilesPanel.errorLabel.text= +LocalFilesPanel.errorLabel.text=Error Label NewCaseVisualPanel1.errorLabel.text=Error Label diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java index 83e02d349d..e9f518eb80 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java @@ -37,7 +37,7 @@ import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; +import org.sleuthkit.autopsy.coreutils.PathValidator; /** * ImageTypePanel for adding an image file such as .img, .E0x, .00x, etc. @@ -286,7 +286,7 @@ public class ImageFilePanel extends JPanel implements DocumentListener { * @param path Absolute path to the selected data source */ private void warnIfPathIsInvalid(String path){ - if (!MultiUserPathValidator.isValid(path, Case.getCurrentCase().getCaseType())) { + if (!PathValidator.isValid(path, Case.getCurrentCase().getCaseType())) { errorLabel.setVisible(true); errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text")); } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java index eb07ddab2d..7e03c59268 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java @@ -45,7 +45,7 @@ import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; import org.sleuthkit.autopsy.coreutils.LocalDisk; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; -import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; +import org.sleuthkit.autopsy.coreutils.PathValidator; import org.sleuthkit.autopsy.coreutils.PlatformUtil; /** @@ -248,7 +248,7 @@ final class LocalDiskPanel extends JPanel { } errorLabel.setVisible(false); - if (!MultiUserPathValidator.isValid(newPath, Case.getCurrentCase().getCaseType())) { + if (!PathValidator.isValid(newPath, Case.getCurrentCase().getCaseType())) { errorLabel.setVisible(true); errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text")); } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java index efcb4439b0..f2c1d7d82f 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java @@ -34,7 +34,7 @@ import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import java.util.logging.Level; import org.sleuthkit.autopsy.casemodule.Case.CaseType; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; +import org.sleuthkit.autopsy.coreutils.PathValidator; /** * Add input wizard subpanel for adding local files / dirs to the case */ @@ -115,7 +115,7 @@ import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; CaseType currentCaseType = Case.getCurrentCase().getCaseType(); for (String currentPath : pathsList) { - if (!MultiUserPathValidator.isValid(currentPath, currentCaseType)) { + if (!PathValidator.isValid(currentPath, currentCaseType)) { errorLabel.setVisible(true); errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text")); return; diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java index 4fb29e7d1b..1ae4d3c406 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java @@ -29,7 +29,7 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.sleuthkit.autopsy.casemodule.Case.CaseType; import org.sleuthkit.autopsy.core.UserPreferences; -import org.sleuthkit.autopsy.coreutils.MultiUserPathValidator; +import org.sleuthkit.autopsy.coreutils.PathValidator; import org.sleuthkit.datamodel.CaseDbConnectionInfo; import org.sleuthkit.datamodel.TskData.DbType; @@ -391,7 +391,7 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { return false; // no need for error message as the module sets path to "" at startup } - if (!MultiUserPathValidator.isValid(path, getCaseType())) { + if (!PathValidator.isValid(path, getCaseType())) { errorLabel.setVisible(true); errorLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnCDriveError.text")); return false; diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/MultiUserPathValidator.java b/Core/src/org/sleuthkit/autopsy/coreutils/PathValidator.java similarity index 92% rename from Core/src/org/sleuthkit/autopsy/coreutils/MultiUserPathValidator.java rename to Core/src/org/sleuthkit/autopsy/coreutils/PathValidator.java index 3bc4b3f4f7..b4d842fd88 100644 --- a/Core/src/org/sleuthkit/autopsy/coreutils/MultiUserPathValidator.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/PathValidator.java @@ -24,9 +24,9 @@ import java.util.regex.Pattern; import org.sleuthkit.autopsy.casemodule.Case; /** - * Validates absolute path to a data source depending on case type. + * Validates absolute path (e.g. to a data source or case output folder) depending on case type. */ -public final class MultiUserPathValidator { +public final class PathValidator { private static final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$"); public static boolean isValid(String path, Case.CaseType caseType) { From b67eda618f3bc3133c0b8819eaf9bef1b0f68a5f Mon Sep 17 00:00:00 2001 From: APriestman Date: Wed, 27 May 2015 14:16:35 -0400 Subject: [PATCH 61/79] Add checks for null after calls to getAbstractFileById --- .../autopsy/modules/iOS/CallLogAnalyzer.java | 5 ++ .../autopsy/modules/iOS/ContactAnalyzer.java | 5 ++ .../modules/iOS/TextMessageAnalyzer.java | 5 ++ .../autopsy/report/ReportGenerator.java | 41 +++++++++----- .../sleuthkit/autopsy/report/ReportKML.java | 14 ++--- .../timeline/events/db/EventsRepository.java | 53 ++++++++++--------- .../timeline/events/type/MiscTypes.java | 7 ++- .../timeline/explorernodes/EventRootNode.java | 17 +++--- 8 files changed, 98 insertions(+), 49 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/iOS/CallLogAnalyzer.java b/Core/src/org/sleuthkit/autopsy/modules/iOS/CallLogAnalyzer.java index a3d8cc44ba..dcd80a55d4 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/iOS/CallLogAnalyzer.java +++ b/Core/src/org/sleuthkit/autopsy/modules/iOS/CallLogAnalyzer.java @@ -85,6 +85,11 @@ class CallLogAnalyzer { SleuthkitCase skCase = currentCase.getSleuthkitCase(); try { AbstractFile f = skCase.getAbstractFileById(fId); + if(f == null){ + logger.log(Level.SEVERE, "Error getting abstract file " + fId); //NON-NLS + return; + } + try { resultSet = statement.executeQuery( "SELECT number,date,duration,type, name FROM calls ORDER BY date DESC;"); //NON-NLS diff --git a/Core/src/org/sleuthkit/autopsy/modules/iOS/ContactAnalyzer.java b/Core/src/org/sleuthkit/autopsy/modules/iOS/ContactAnalyzer.java index becafbafc0..0adde2c129 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/iOS/ContactAnalyzer.java +++ b/Core/src/org/sleuthkit/autopsy/modules/iOS/ContactAnalyzer.java @@ -101,6 +101,11 @@ class ContactAnalyzer { SleuthkitCase skCase = currentCase.getSleuthkitCase(); try { AbstractFile f = skCase.getAbstractFileById(fId); + if(f == null){ + logger.log(Level.SEVERE, "Error getting abstract file " + fId); //NON-NLS + return; + } + try { // get display_name, mimetype(email or phone number) and data1 (phonenumber or email address depending on mimetype) //sorted by name, so phonenumber/email would be consecutive for a person if they exist. diff --git a/Core/src/org/sleuthkit/autopsy/modules/iOS/TextMessageAnalyzer.java b/Core/src/org/sleuthkit/autopsy/modules/iOS/TextMessageAnalyzer.java index 04d67b78f7..def68b8734 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/iOS/TextMessageAnalyzer.java +++ b/Core/src/org/sleuthkit/autopsy/modules/iOS/TextMessageAnalyzer.java @@ -85,6 +85,11 @@ class TextMessageAnalyzer { SleuthkitCase skCase = currentCase.getSleuthkitCase(); try { AbstractFile f = skCase.getAbstractFileById(fId); + if(f == null){ + logger.log(Level.SEVERE, "Error getting abstract file " + fId); //NON-NLS + return; + } + try { resultSet = statement.executeQuery( "Select address,date,type,subject,body FROM sms;"); //NON-NLS diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java b/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java index 51c074c1db..c808d0d78d 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java @@ -806,7 +806,10 @@ import org.sleuthkit.datamodel.TskData; logger.log(Level.WARNING, "Error while getting content from a blackboard artifact to report on.", ex); //NON-NLS return; } - checkIfFileIsImage(file); + + if(file != null){ + checkIfFileIsImage(file); + } } /** @@ -978,8 +981,11 @@ import org.sleuthkit.datamodel.TskData; String list = resultSet.getString("list"); //NON-NLS String uniquePath = ""; - try { - uniquePath = skCase.getAbstractFileById(objId).getUniquePath(); + try { + AbstractFile f = skCase.getAbstractFileById(objId); + if(f != null){ + uniquePath = skCase.getAbstractFileById(objId).getUniquePath(); + } } catch (TskCoreException ex) { errorList.add( NbBundle.getMessage(this.getClass(), "ReportGenerator.errList.failedGetAbstractFileByID")); @@ -1109,7 +1115,10 @@ import org.sleuthkit.datamodel.TskData; String uniquePath = ""; try { - uniquePath = skCase.getAbstractFileById(objId).getUniquePath(); + AbstractFile f = skCase.getAbstractFileById(objId); + if(f != null){ + uniquePath = skCase.getAbstractFileById(objId).getUniquePath(); + } } catch (TskCoreException ex) { errorList.add( NbBundle.getMessage(this.getClass(), "ReportGenerator.errList.failedGetAbstractFileFromID")); @@ -1772,15 +1781,23 @@ import org.sleuthkit.datamodel.TskData; break; case TSK_EXT_MISMATCH_DETECTED: AbstractFile file = skCase.getAbstractFileById(getObjectID()); - orderedRowData.add(file.getName()); - orderedRowData.add(file.getNameExtension()); - List attrs = file.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); - if (!attrs.isEmpty()) { - orderedRowData.add(attrs.get(0).getValueString()); + if(file != null){ + orderedRowData.add(file.getName()); + orderedRowData.add(file.getNameExtension()); + List attrs = file.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); + if (!attrs.isEmpty()) { + orderedRowData.add(attrs.get(0).getValueString()); + } else { + orderedRowData.add(""); + } + orderedRowData.add(file.getUniquePath()); } else { - orderedRowData.add(""); - } - orderedRowData.add(file.getUniquePath()); + // Make empty rows to make sure the formatting is correct + orderedRowData.add(null); + orderedRowData.add(null); + orderedRowData.add(null); + orderedRowData.add(null); + } break; case TSK_OS_INFO: orderedRowData.add(mappedAttributes.get(ATTRIBUTE_TYPE.TSK_PROCESSOR_ARCHITECTURE.getTypeID())); diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportKML.java b/Core/src/org/sleuthkit/autopsy/report/ReportKML.java index fac72da35b..061329bf4a 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportKML.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportKML.java @@ -131,12 +131,14 @@ class ReportKML implements GeneralReportModule { if (lon != 0 && lat != 0) { aFile = artifact.getSleuthkitCase().getAbstractFileById(artifact.getObjectID()); - extractedToPath = reportPath + aFile.getName(); - geoPath = extractedToPath; - f = new File(extractedToPath); - f.createNewFile(); - copyFileUsingStream(aFile, f); - imageName = aFile.getName(); + if(aFile != null){ + extractedToPath = reportPath + aFile.getName(); + geoPath = extractedToPath; + f = new File(extractedToPath); + f.createNewFile(); + copyFileUsingStream(aFile, f); + imageName = aFile.getName(); + } out.write(String.valueOf(lat)); out.write(";"); out.write(String.valueOf(lon)); diff --git a/Core/src/org/sleuthkit/autopsy/timeline/events/db/EventsRepository.java b/Core/src/org/sleuthkit/autopsy/timeline/events/db/EventsRepository.java index 52af156e35..19708c0438 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/events/db/EventsRepository.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/events/db/EventsRepository.java @@ -243,32 +243,37 @@ public class EventsRepository { } else { try { AbstractFile f = skCase.getAbstractFileById(fID); - //TODO: This is broken for logical files? fix -jm - //TODO: logical files don't necessarily have valid timestamps, so ... -jm - final String uniquePath = f.getUniquePath(); - final String parentPath = f.getParentPath(); - String datasourceName = StringUtils.substringBefore(StringUtils.stripStart(uniquePath, "/"), parentPath); - String rootFolder = StringUtils.substringBetween(parentPath, "/", "/"); - String shortDesc = datasourceName + "/" + StringUtils.defaultIfBlank(rootFolder, ""); - String medD = datasourceName + parentPath; + + if(f != null){ + //TODO: This is broken for logical files? fix -jm + //TODO: logical files don't necessarily have valid timestamps, so ... -jm + final String uniquePath = f.getUniquePath(); + final String parentPath = f.getParentPath(); + String datasourceName = StringUtils.substringBefore(StringUtils.stripStart(uniquePath, "/"), parentPath); + String rootFolder = StringUtils.substringBetween(parentPath, "/", "/"); + String shortDesc = datasourceName + "/" + StringUtils.defaultIfBlank(rootFolder, ""); + String medD = datasourceName + parentPath; - //insert it into the db if time is > 0 => time is legitimate (drops logical files) - if (f.getAtime() > 0) { - eventDB.insertEvent(f.getAtime(), FileSystemTypes.FILE_ACCESSED, fID, null, uniquePath, medD, shortDesc, f.getKnown(), trans); - } - if (f.getMtime() > 0) { - eventDB.insertEvent(f.getMtime(), FileSystemTypes.FILE_MODIFIED, fID, null, uniquePath, medD, shortDesc, f.getKnown(), trans); - } - if (f.getCtime() > 0) { - eventDB.insertEvent(f.getCtime(), FileSystemTypes.FILE_CHANGED, fID, null, uniquePath, medD, shortDesc, f.getKnown(), trans); - } - if (f.getCrtime() > 0) { - eventDB.insertEvent(f.getCrtime(), FileSystemTypes.FILE_CREATED, fID, null, uniquePath, medD, shortDesc, f.getKnown(), trans); - } + //insert it into the db if time is > 0 => time is legitimate (drops logical files) + if (f.getAtime() > 0) { + eventDB.insertEvent(f.getAtime(), FileSystemTypes.FILE_ACCESSED, fID, null, uniquePath, medD, shortDesc, f.getKnown(), trans); + } + if (f.getMtime() > 0) { + eventDB.insertEvent(f.getMtime(), FileSystemTypes.FILE_MODIFIED, fID, null, uniquePath, medD, shortDesc, f.getKnown(), trans); + } + if (f.getCtime() > 0) { + eventDB.insertEvent(f.getCtime(), FileSystemTypes.FILE_CHANGED, fID, null, uniquePath, medD, shortDesc, f.getKnown(), trans); + } + if (f.getCrtime() > 0) { + eventDB.insertEvent(f.getCrtime(), FileSystemTypes.FILE_CREATED, fID, null, uniquePath, medD, shortDesc, f.getKnown(), trans); + } - process(Arrays.asList(new ProgressWindow.ProgressUpdate(i, numFiles, - NbBundle.getMessage(this.getClass(), - "EventsRepository.progressWindow.msg.populateMacEventsFiles2"), f.getName()))); + process(Arrays.asList(new ProgressWindow.ProgressUpdate(i, numFiles, + NbBundle.getMessage(this.getClass(), + "EventsRepository.progressWindow.msg.populateMacEventsFiles2"), f.getName()))); + } else { + LOGGER.log(Level.WARNING, "failed to look up data for file : " + fID); // NON-NLS + } } catch (TskCoreException tskCoreException) { LOGGER.log(Level.WARNING, "failed to insert mac event for file : " + fID, tskCoreException); // NON-NLS } diff --git a/Core/src/org/sleuthkit/autopsy/timeline/events/type/MiscTypes.java b/Core/src/org/sleuthkit/autopsy/timeline/events/type/MiscTypes.java index db097ad884..375f159cd4 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/events/type/MiscTypes.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/events/type/MiscTypes.java @@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils; import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.timeline.zooming.EventTypeZoomLevel; +import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.TskCoreException; @@ -129,7 +130,11 @@ public enum MiscTypes implements EventType, ArtifactEventType { (BlackboardArtifact t, Map u) -> { try { - return t.getSleuthkitCase().getAbstractFileById(t.getObjectID()).getName(); + AbstractFile f = t.getSleuthkitCase().getAbstractFileById(t.getObjectID()); + if(f != null){ + return f.getName(); + } + return " error loading file name"; // NON-NLS } catch (TskCoreException ex) { Exceptions.printStackTrace(ex); return " error loading file name"; // NON-NLS diff --git a/Core/src/org/sleuthkit/autopsy/timeline/explorernodes/EventRootNode.java b/Core/src/org/sleuthkit/autopsy/timeline/explorernodes/EventRootNode.java index 93c7b469be..b56dc46986 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/explorernodes/EventRootNode.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/explorernodes/EventRootNode.java @@ -101,13 +101,18 @@ public class EventRootNode extends DisplayableItemNode { if (eventID >= 0) { final TimeLineEvent eventById = filteredEvents.getEventById(eventID); try { - if (eventById.getType().getSuperType() == BaseTypes.FILE_SYSTEM) { - return new EventNode(eventById, Case.getCurrentCase().getSleuthkitCase().getAbstractFileById(eventById.getFileID())); - } else { - AbstractFile file = Case.getCurrentCase().getSleuthkitCase().getAbstractFileById(eventById.getFileID()); - BlackboardArtifact blackboardArtifact = Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifact(eventById.getArtifactID()); + AbstractFile file = Case.getCurrentCase().getSleuthkitCase().getAbstractFileById(eventById.getFileID()); + if(file != null){ + if (eventById.getType().getSuperType() == BaseTypes.FILE_SYSTEM) { + return new EventNode(eventById, file); + } else { + BlackboardArtifact blackboardArtifact = Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifact(eventById.getArtifactID()); - return new EventNode(eventById, file, blackboardArtifact); + return new EventNode(eventById, file, blackboardArtifact); + } + } else { + LOGGER.log(Level.WARNING, "Failed to lookup sleuthkit object backing TimeLineEvent."); // NON-NLS + return null; } } catch (TskCoreException tskCoreException) { From 571119735770553029265fcca47c24643617a791 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 27 May 2015 14:40:34 -0400 Subject: [PATCH 62/79] Local disk DSP is no longer available for MU cases --- .../AddImageWizardChooseDataSourceVisual.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java index 328d307935..7e2442f789 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java @@ -83,8 +83,11 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { // make a list of core DSPs // ensure that the core DSPs are at the top and in a fixed order - coreDSPTypes.add(ImageDSProcessor.getType()); - coreDSPTypes.add(LocalDiskDSProcessor.getType()); + coreDSPTypes.add(ImageDSProcessor.getType()); + // Local disk processing is not allowed for multi-user cases + if (Case.getCurrentCase().getCaseType() != Case.CaseType.MULTI_USER_CASE){ + coreDSPTypes.add(LocalDiskDSProcessor.getType()); + } coreDSPTypes.add(LocalFilesDSProcessor.getType()); for (String dspType : coreDSPTypes) { @@ -94,7 +97,10 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { // now add any addtional DSPs that haven't already been added for (String dspType : dspTypes) { if (!coreDSPTypes.contains(dspType)) { - typeComboBox.addItem(dspType); + // Local disk processing is not allowed for multi-user cases + if (Case.getCurrentCase().getCaseType() != Case.CaseType.MULTI_USER_CASE || !dspType.contains(LocalDiskDSProcessor.getType())) { + typeComboBox.addItem(dspType); + } } } From 146c0c3b23642f901ca9953806dbcde13d0cec2d Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 27 May 2015 14:50:18 -0400 Subject: [PATCH 63/79] Refactored some code --- .../AddImageWizardChooseDataSourceVisual.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java index 7e2442f789..721320d369 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java @@ -97,10 +97,7 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { // now add any addtional DSPs that haven't already been added for (String dspType : dspTypes) { if (!coreDSPTypes.contains(dspType)) { - // Local disk processing is not allowed for multi-user cases - if (Case.getCurrentCase().getCaseType() != Case.CaseType.MULTI_USER_CASE || !dspType.contains(LocalDiskDSProcessor.getType())) { - typeComboBox.addItem(dspType); - } + addDataSourceProcessorToComboBox(dspType); } } @@ -122,6 +119,13 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { typeComboBox.addActionListener(cbActionListener); typeComboBox.setSelectedIndex(0); } + + private void addDataSourceProcessorToComboBox(String dspType) { + // Local disk processing is not allowed for multi-user cases + if (Case.getCurrentCase().getCaseType() != Case.CaseType.MULTI_USER_CASE || !dspType.contains(LocalDiskDSProcessor.getType())) { + typeComboBox.addItem(dspType); + } + } private void discoverDataSourceProcessors() { From c123bb991ad4031fe03f9af58b3430b87c058e10 Mon Sep 17 00:00:00 2001 From: jmillman Date: Wed, 27 May 2015 15:35:51 -0400 Subject: [PATCH 64/79] Move Image Gallery files to ModuleOutput folder - replace ImageGalleryModule.MODULE_NAME with getter - move drawable.db to ModuleOutput folder - move per case ImageGallery properties to ModuleOutput folder. cleanup PerCaseProperties.java --- .../imagegallery/ImageGalleryController.java | 51 ++++++------- .../imagegallery/ImageGalleryModule.java | 8 ++- .../ImageGalleryOptionsPanel.java | 2 +- .../imagegallery/PerCaseProperties.java | 71 +++++++++---------- 4 files changed, 67 insertions(+), 65 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 1cab3d702c..78471fed0e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013 Basis Technology Corp. + * Copyright 2013-15 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.imagegallery; import java.beans.PropertyChangeEvent; +import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -57,9 +58,9 @@ import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.History; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.autopsy.imagegallery.grouping.GroupViewState; import org.sleuthkit.autopsy.imagegallery.gui.NoGroupsDialog; @@ -155,8 +156,8 @@ public final class ImageGalleryController { public GroupManager getGroupManager() { return groupManager; } - - public DrawableDB getDatabase(){ + + public DrawableDB getDatabase() { return db; } @@ -177,7 +178,7 @@ public final class ImageGalleryController { stale.set(b); }); if (Case.isCaseOpen()) { - new PerCaseProperties(Case.getCurrentCase()).setConfigSetting(ImageGalleryModule.MODULE_NAME, PerCaseProperties.STALE, b.toString()); + new PerCaseProperties(Case.getCurrentCase()).setConfigSetting(ImageGalleryModule.getModuleName(), PerCaseProperties.STALE, b.toString()); } } @@ -198,7 +199,7 @@ public final class ImageGalleryController { }); groupManager.getAnalyzedGroups().addListener((Observable o) -> { - if(Case.isCaseOpen()){ + if (Case.isCaseOpen()) { checkForGroups(); } }); @@ -332,7 +333,7 @@ public final class ImageGalleryController { */ public synchronized void setCase(Case c) { - this.db = DrawableDB.getDrawableDB(c.getCaseDirectory(), this); + this.db = DrawableDB.getDrawableDB(c.getModulesOutputDirAbsPath() + File.separator + ImageGalleryModule.getModuleName(), this); setListeningEnabled(ImageGalleryModule.isEnabledforCase(c)); setStale(ImageGalleryModule.isCaseStale(c)); @@ -514,7 +515,7 @@ public final class ImageGalleryController { try { // @@@ Could probably do something more fancy here and check if we've been canceled every now and then InnerTask it = workQueue.take(); - + if (it.cancelled == false) { it.run(); } @@ -628,16 +629,16 @@ public final class ImageGalleryController { */ @Override public void run() { - try{ + try { DrawableFile drawableFile = DrawableFile.create(getFile(), true, db.isVideoFile(getFile())); db.updateFile(drawableFile); - } catch (NullPointerException | TskCoreException ex){ + } catch (NullPointerException | TskCoreException ex) { // This is one of the places where we get many errors if the case is closed during processing. // We don't want to print out a ton of exceptions if this is the case. - if(Case.isCaseOpen()){ + if (Case.isCaseOpen()) { Logger.getLogger(UpdateFileTask.class.getName()).log(Level.SEVERE, "Error in UpdateFile task"); } - } + } } } @@ -655,16 +656,16 @@ public final class ImageGalleryController { */ @Override public void run() { - try{ - db.removeFile(getFile().getId()); - } catch (NullPointerException ex){ + try { + db.removeFile(getFile().getId()); + } catch (NullPointerException ex) { // This is one of the places where we get many errors if the case is closed during processing. // We don't want to print out a ton of exceptions if this is the case. - if(Case.isCaseOpen()){ + if (Case.isCaseOpen()) { Logger.getLogger(RemoveFileTask.class.getName()).log(Level.SEVERE, "Case was closed out from underneath RemoveFile task"); } } - + } } @@ -771,8 +772,9 @@ public final class ImageGalleryController { * netbeans and ImageGallery progress/status */ class PrePopulateDataSourceFiles extends InnerTask { + private final Content dataSource; - + /** * here we grab by extension but in file_done listener we look at file * type id attributes but fall back on jpeg signatures and extensions to @@ -784,7 +786,7 @@ public final class ImageGalleryController { private ProgressHandle progressHandle = ProgressHandleFactory.createHandle("prepopulating image/video database"); /** - + * * @param dataSourceId Data source object ID */ public PrePopulateDataSourceFiles(Content dataSource) { @@ -806,22 +808,21 @@ public final class ImageGalleryController { final List files; try { List fsObjIds = new ArrayList<>(); - + String fsQuery; if (dataSource instanceof Image) { - Image image = (Image)dataSource; + Image image = (Image) dataSource; for (FileSystem fs : image.getFileSystems()) { fsObjIds.add(fs.getId()); } fsQuery = "(fs_obj_id = " + StringUtils.join(fsObjIds, " or fs_obj_id = ") + ") "; - } - // NOTE: Logical files currently (Apr '15) have a null value for fs_obj_id in DB. + } // NOTE: Logical files currently (Apr '15) have a null value for fs_obj_id in DB. // for them, we will not specify a fs_obj_id, which means we will grab files // from another data source, but the drawable DB is smart enough to de-dupe them. else { fsQuery = "(fs_obj_id IS NULL) "; } - + files = getSleuthKitCase().findAllFilesWhere(fsQuery + " and " + DRAWABLE_QUERY); progressHandle.switchToDeterminate(files.size()); @@ -850,7 +851,7 @@ public final class ImageGalleryController { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "failed to transfer all database contents", ex); } catch (IllegalStateException | NullPointerException ex) { Logger.getLogger(PrePopulateDataSourceFiles.class.getName()).log(Level.WARNING, "Case was closed out from underneath prepopulating database"); - } + } progressHandle.finish(); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java index 91ba34260b..e10ced9774 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013-14 Basis Technology Corp. + * Copyright 2013-15 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -42,7 +42,11 @@ public class ImageGalleryModule { private static final Logger LOGGER = Logger.getLogger(ImageGalleryModule.class.getName()); - static final String MODULE_NAME = ImageGalleryModule.class.getSimpleName(); + private static final String MODULE_NAME = "Image Gallery"; + + public static String getModuleName() { + return MODULE_NAME; + } private static final Set videoExtensions = Sets.newHashSet("aaf", "3gp", "asf", "avi", "m1v", "m2v", "m4v", "mp4", diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryOptionsPanel.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryOptionsPanel.java index b80b95d1c0..e08a45a798 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryOptionsPanel.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryOptionsPanel.java @@ -130,7 +130,7 @@ final class ImageGalleryOptionsPanel extends javax.swing.JPanel { ImageGalleryPreferences.setEnabledByDefault(enabledByDefaultBox.isSelected()); ImageGalleryController.getDefault().setListeningEnabled(enabledForCaseBox.isSelected()); if (Case.isCaseOpen()) { - new PerCaseProperties(Case.getCurrentCase()).setConfigSetting(ImageGalleryModule.MODULE_NAME, PerCaseProperties.ENABLED, Boolean.toString(enabledForCaseBox.isSelected())); + new PerCaseProperties(Case.getCurrentCase()).setConfigSetting(ImageGalleryModule.getModuleName(), PerCaseProperties.ENABLED, Boolean.toString(enabledForCaseBox.isSelected())); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/PerCaseProperties.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/PerCaseProperties.java index 03448b3bd4..c8d1c66410 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/PerCaseProperties.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/PerCaseProperties.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013 Basis Technology Corp. + * Copyright 2013-15 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,11 +18,12 @@ */ package org.sleuthkit.autopsy.imagegallery; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -32,7 +33,7 @@ import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; /** - * Provides access to per case module properties + * Provides access to per-case module properties/settings. */ class PerCaseProperties { @@ -40,13 +41,10 @@ class PerCaseProperties { public static final String STALE = "stale"; - private final Case c; + private final Case theCase; - /** - * the constructor - */ PerCaseProperties(Case c) { - this.c = c; + this.theCase = c; } /** @@ -56,19 +54,21 @@ class PerCaseProperties { * @param moduleName - The name of the config file to make * * @return True if successfully created, false if already exists or an error - * is thrown. + * is thrown. */ public synchronized boolean makeConfigFile(String moduleName) { if (!configExists(moduleName)) { - File propPath = new File(getPropertyPath(moduleName)); - File parent = new File(propPath.getParent()); - if (!parent.exists()) { - parent.mkdirs(); - } + Path propPath = getPropertyPath(moduleName); + Path parent = propPath.getParent(); + Properties props = new Properties(); try { - propPath.createNewFile(); - try (FileOutputStream fos = new FileOutputStream(propPath)) { + if (!Files.exists(parent)) { + Files.createDirectories(parent); + } + Files.createFile(propPath); + + try (OutputStream fos = Files.newOutputStream(propPath)) { props.store(fos, ""); } } catch (IOException e) { @@ -88,8 +88,8 @@ class PerCaseProperties { * @return true if the config exists, false otherwise. */ public synchronized boolean configExists(String moduleName) { - File f = new File(c.getCaseDirectory() + File.separator + moduleName + ".properties"); - return f.exists(); + Path get = Paths.get(theCase.getModulesOutputDirAbsPath(), moduleName, theCase.getName() + ".properties"); + return Files.exists(get); } public synchronized boolean settingExists(String moduleName, String settingName) { @@ -111,16 +111,16 @@ class PerCaseProperties { * @param moduleName - The name of the config file to evaluate * * @return The path of the given config file. Returns null if the config - * file doesn't exist. + * file doesn't exist. */ - private synchronized String getPropertyPath(String moduleName) { - return c.getCaseDirectory() + File.separator + moduleName + ".properties"; //NON-NLS + private synchronized Path getPropertyPath(String moduleName) { + return Paths.get(theCase.getModulesOutputDirAbsPath(), moduleName, theCase.getName() + ".properties"); //NON-NLS } /** * Returns the given properties file's setting as specific by settingName. * - * @param moduleName - The name of the config file to read from. + * @param moduleName - The name of the config file to read from. * @param settingName - The setting name to retrieve. * * @return - the value associated with the setting. @@ -150,7 +150,7 @@ class PerCaseProperties { * @param moduleName - the name of the config file to read from. * * @return - the map of all key:value pairs representing the settings of the - * config. + * config. * * @throws IOException */ @@ -181,8 +181,8 @@ class PerCaseProperties { * Sets the given properties file to the given setting map. * * @param moduleName - The name of the module to be written to. - * @param settings - The mapping of all key:value pairs of settings to add - * to the config. + * @param settings - The mapping of all key:value pairs of settings to add + * to the config. */ public synchronized void setConfigSettings(String moduleName, Map settings) { if (!configExists(moduleName)) { @@ -196,8 +196,7 @@ class PerCaseProperties { props.setProperty(kvp.getKey(), kvp.getValue()); } - File path = new File(getPropertyPath(moduleName)); - try (FileOutputStream fos = new FileOutputStream(path)) { + try (OutputStream fos = Files.newOutputStream(getPropertyPath(moduleName))) { props.store(fos, "Changed config settings(batch)"); //NON-NLS } } catch (IOException e) { @@ -208,9 +207,9 @@ class PerCaseProperties { /** * Sets the given properties file to the given settings. * - * @param moduleName - The name of the module to be written to. + * @param moduleName - The name of the module to be written to. * @param settingName - The name of the setting to be modified. - * @param settingVal - the value to set the setting to. + * @param settingVal - the value to set the setting to. */ public synchronized void setConfigSetting(String moduleName, String settingName, String settingVal) { if (!configExists(moduleName)) { @@ -223,8 +222,7 @@ class PerCaseProperties { props.setProperty(settingName, settingVal); - File path = new File(getPropertyPath(moduleName)); - try (FileOutputStream fos = new FileOutputStream(path)) { + try (OutputStream fos = Files.newOutputStream(getPropertyPath(moduleName))) { props.store(fos, "Changed config settings(single)"); //NON-NLS } } catch (IOException e) { @@ -236,7 +234,7 @@ class PerCaseProperties { * Removes the given key from the given properties file. * * @param moduleName - The name of the properties file to be modified. - * @param key - the name of the key to remove. + * @param key - the name of the key to remove. */ public synchronized void removeProperty(String moduleName, String key) { if (!configExists(moduleName)) { @@ -249,8 +247,7 @@ class PerCaseProperties { Properties props = fetchProperties(moduleName); props.remove(key); - File path = new File(getPropertyPath(moduleName)); - try (FileOutputStream fos = new FileOutputStream(path)) { + try (OutputStream fos = Files.newOutputStream(getPropertyPath(moduleName))) { props.store(fos, "Removed " + key); //NON-NLS } } @@ -274,7 +271,7 @@ class PerCaseProperties { Logger.getLogger(PerCaseProperties.class.getName()).log(Level.INFO, "File did not exist. Created file [" + moduleName + ".properties]"); //NON-NLS NON-NLS } Properties props; - try (InputStream inputStream = new FileInputStream(getPropertyPath(moduleName))) { + try (InputStream inputStream = Files.newInputStream(getPropertyPath(moduleName))) { props = new Properties(); props.load(inputStream); } From e7773e54894c66b3b958d0aa9e7b70a89c29f6ca Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Wed, 27 May 2015 20:16:51 -0400 Subject: [PATCH 65/79] Reduce public API of FileTypeDetector back to what it was --- .../autopsy/modules/exif/Bundle.properties | 2 +- .../exif/ExifParserFileIngestModule.java | 15 ++- .../modules/filetypeid/Bundle.properties | 2 + .../modules/filetypeid/FileTypeDetector.java | 108 ++++++++---------- .../filetypeid/FileTypeIdIngestModule.java | 4 +- .../modules/sevenzip/Bundle.properties | 2 +- .../sevenzip/SevenZipIngestModule.java | 10 +- .../autopsy/keywordsearch/Bundle.properties | 2 +- .../KeywordSearchIngestModule.java | 11 +- 9 files changed, 78 insertions(+), 78 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/exif/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/exif/Bundle.properties index 391cfdac7f..d50338a4b5 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/exif/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/exif/Bundle.properties @@ -6,4 +6,4 @@ OpenIDE-Module-Name=ExifParser OpenIDE-Module-Short-Description=Exif metadata ingest module ExifParserFileIngestModule.moduleName.text=Exif Parser ExifParserFileIngestModule.getDesc.text=Ingests JPEG files and retrieves their EXIF metadata. -ExifParserFileIngestModule.startUp.fileTypeDetectorInitializationException.msg=Error initializing the File Type Detector. \ No newline at end of file +ExifParserFileIngestModule.startUp.fileTypeDetectorInitializationException.msg=Error initializing the file type detector. \ No newline at end of file diff --git a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java index f3f7ea3313..560eeefda3 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2014 Basis Technology Corp. + * Copyright 2011-2015 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -60,7 +60,7 @@ public final class ExifParserFileIngestModule implements FileIngestModule { private static final Logger logger = Logger.getLogger(ExifParserFileIngestModule.class.getName()); private final IngestServices services = IngestServices.getInstance(); - private AtomicInteger filesProcessed = new AtomicInteger(0); + private final AtomicInteger filesProcessed = new AtomicInteger(0); private volatile boolean filesToFire = false; private long jobId; private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter(); @@ -76,12 +76,10 @@ public final class ExifParserFileIngestModule implements FileIngestModule { try { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { - logger.log(Level.SEVERE, NbBundle.getMessage(this.getClass(), "ExifParserFileIngestModule.startUp.fileTypeDetectorInitializationException.msg"), ex); throw new IngestModuleException(NbBundle.getMessage(this.getClass(), "ExifParserFileIngestModule.startUp.fileTypeDetectorInitializationException.msg")); } } - - + @Override public ProcessResult process(AbstractFile content) { //skip unalloc @@ -205,7 +203,12 @@ public final class ExifParserFileIngestModule implements FileIngestModule { * @return true if to be processed */ private boolean parsableFormat(AbstractFile f) { - return fileTypeDetector.getFileType(f).equals("image/jpeg"); + try { + return fileTypeDetector.detect(f).equals("image/jpeg"); + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, "Failed to detect file type", ex); //NON-NLS + return false; + } } @Override diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties index 38dd22806b..baf9fa08c3 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties @@ -44,3 +44,5 @@ FileTypeIdGlobalSettingsPanel.newTypeButton.text=New FileTypeIdGlobalSettingsPanel.jLabel1.text=Custom File Types FileTypeIdGlobalSettingsPanel.jLabel2.text=MIME Types: FileTypeIdGlobalSettingsPanel.jLabel3.text=Autopsy can automatically detect many file types. Add your custom file types here. +FileTypeIdGlobalSettingsPanel.startUp.fileTypeDetectorInitializationException.msg=Error initializing the file type detector. + diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index 3f0b47d7f4..0bfbc0eda2 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -21,11 +21,9 @@ package org.sleuthkit.autopsy.modules.filetypeid; import java.util.ArrayList; import java.util.Map; import java.util.SortedSet; -import java.util.logging.Level; import org.apache.tika.Tika; import org.apache.tika.mime.MediaType; import org.apache.tika.mime.MimeTypes; -import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; @@ -41,7 +39,6 @@ public class FileTypeDetector { private static final int BUFFER_SIZE = 64 * 1024; private final byte buffer[] = new byte[BUFFER_SIZE]; private final Map userDefinedFileTypes; - private static final Logger logger = Logger.getLogger(FileTypeDetector.class.getName()); /** * Constructs an object that detects the type of a file by an inspection of @@ -98,47 +95,6 @@ public class FileTypeDetector { return false; } - /** - * This method returns a string representing the mimetype of the provided - * abstractFile. Blackboard-lookup is performed to check if the mimetype has - * been already detected. If not, mimetype is determined using Apache Tika. - * - * @param abstractFile the file whose mimetype is to be determined. - * @return mimetype of the abstractFile is returned. Empty String returned - * in case of error. - */ - public String getFileType(AbstractFile abstractFile) { - String identifiedFileType = ""; - - // check BB - try { - ArrayList attributes = abstractFile.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); - for (BlackboardAttribute attribute : attributes) { - identifiedFileType = attribute.getValueString(); - break; - } - if (identifiedFileType != null && !identifiedFileType.isEmpty()) { - return identifiedFileType; - } - } catch (TskCoreException ex) { - logger.log(Level.WARNING, "Error performing mimetype blackboard-lookup for " + abstractFile.getName(), ex); - } - - try { - // check UDF and TDF - identifiedFileType = detectAndPostToBlackboard(abstractFile); - if (identifiedFileType != null && !identifiedFileType.isEmpty()) { - return identifiedFileType; - } - } catch (TskCoreException ex) { - logger.log(Level.WARNING, "Error determining the mimetype for " + abstractFile.getName(), ex); // NON-NLS - return ""; // NON-NLS - } - - logger.log(Level.WARNING, "Unable to determine the mimetype for {0}", abstractFile.getName()); // NON-NLS - return ""; // NON-NLS - } - /** * Detect the MIME type of a file, posting it to the blackboard if detection * succeeds. @@ -148,9 +104,11 @@ public class FileTypeDetector { * @throws TskCoreException if there is an error posting to the blackboard. */ public String detectAndPostToBlackboard(AbstractFile file) throws TskCoreException { - - String mimeType; - mimeType = detect(file); + String mimeType = lookupFileType(file); + if (null != mimeType) { + return mimeType; + } + mimeType = detectFileType(file); if (null != mimeType) { /** * Add the file type attribute to the general info artifact. Note @@ -169,10 +127,42 @@ public class FileTypeDetector { * Detect the MIME type of a file. * * @param file The file to test. - * @return The MIME type name id detection was successful, null otherwise. + * @return The MIME type name if detection was successful, null otherwise. */ public String detect(AbstractFile file) throws TskCoreException { - // Consistently mark unallocated and unused space as file type application/octet-stream + String mimeType = lookupFileType(file); + if (null != mimeType) { + return mimeType; + } + return detectFileType(file); + } + + /** + * Look up the MIME type of a file on the blackboard. + * + * @param file The file to test. + * @return The MIME type name if look up was successful, null otherwise. + */ + private String lookupFileType(AbstractFile file) throws TskCoreException { + String fileType = null; + ArrayList attributes = file.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); + for (BlackboardAttribute attribute : attributes) { + /** + * There should be at most TSK_FILE_TYPE_SIG attribute. + */ + fileType = attribute.getValueString(); + break; + } + return fileType; + } + + /** + * Detect the MIME type of a file. + * + * @param file The file to test. + * @return The MIME type name if detection was successful, null otherwise. + */ + private String detectFileType(AbstractFile file) throws TskCoreException { if ((file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) || (file.isFile() == false)) { @@ -224,17 +214,17 @@ public class FileTypeDetector { if (fileType.matches(file)) { if (fileType.alertOnMatch()) { BlackboardArtifact artifact; - artifact = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT); - BlackboardAttribute setNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID(), FileTypeIdModuleFactory.getModuleName(), fileType.getFilesSetName()); - artifact.addAttribute(setNameAttribute); + artifact = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT); + BlackboardAttribute setNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID(), FileTypeIdModuleFactory.getModuleName(), fileType.getFilesSetName()); + artifact.addAttribute(setNameAttribute); - /** - * Use the MIME type as the category, i.e., the rule - * that determined this file belongs to the interesting - * files set. - */ - BlackboardAttribute ruleNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY.getTypeID(), FileTypeIdModuleFactory.getModuleName(), fileType.getMimeType()); - artifact.addAttribute(ruleNameAttribute); + /** + * Use the MIME type as the category, i.e., the rule that + * determined this file belongs to the interesting files + * set. + */ + BlackboardAttribute ruleNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY.getTypeID(), FileTypeIdModuleFactory.getModuleName(), fileType.getMimeType()); + artifact.addAttribute(ruleNameAttribute); } return fileType.getMimeType(); } diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java index 6625c7c616..9c684c4af8 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java @@ -82,9 +82,7 @@ public class FileTypeIdIngestModule implements FileIngestModule { try { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { - String errorMessage = "Failed to create file type detector"; //NON-NLS - logger.log(Level.SEVERE, errorMessage, ex); - throw new IngestModuleException(errorMessage); + throw new IngestModuleException(NbBundle.getMessage(this.getClass(), "FileTypeIdIngestModule.startUp.fileTypeDetectorInitializationException.msg")); } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/Bundle.properties index badd35146a..8f93fde59b 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/Bundle.properties @@ -29,4 +29,4 @@ SevenZipIngestModule.unpack.encrFileDetected.msg=Encrypted files in archive dete SevenZipIngestModule.unpack.encrFileDetected.details=Some files in archive\: {0} are encrypted. {1} extractor was unable to extract all files from this archive. SevenZipIngestModule.UnpackStream.write.exception.msg=Error writing unpacked file to\: {0} SevenZipIngestModule.UnpackedTree.exception.msg=Error adding a derived file to db\:{0} -SevenZipIngestModule.startUp.fileTypeDetectorInitializationException.msg=Error initializing the File Type Detector. +SevenZipIngestModule.startUp.fileTypeDetectorInitializationException.msg=Error initializing the file type detector. diff --git a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java index 59553ae89f..a315a1f608 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java @@ -103,7 +103,6 @@ public final class SevenZipIngestModule implements FileIngestModule { try { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { - logger.log(Level.SEVERE, NbBundle.getMessage(this.getClass(), "SevenZipIngestModule.startUp.fileTypeDetectorInitializationException.msg"), ex); throw new IngestModuleException(NbBundle.getMessage(this.getClass(), "SevenZipIngestModule.startUp.fileTypeDetectorInitializationException.msg")); } @@ -288,7 +287,7 @@ public final class SevenZipIngestModule implements FileIngestModule { } if (detectedFormat == null) { - logger.log(Level.WARNING, "Could not detect format for file: " + archiveFile); //NON-NLS + logger.log(Level.WARNING, "Could not detect format for file: {0}", archiveFile); //NON-NLS // if we don't have attribute info then use file extension String extension = archiveFile.getNameExtension(); @@ -661,7 +660,12 @@ public final class SevenZipIngestModule implements FileIngestModule { * @return true if zip file, false otherwise */ private boolean isZipFileHeader(AbstractFile file) { - return fileTypeDetector.getFileType(file).equals("application/zip"); //NON-NLS + try { + return fileTypeDetector.detect(file).equals("application/zip"); //NON-NLS + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, "Failed to detect file type", ex); //NON-NLS + return false; + } } /** diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties index 7e784739a7..70a2e74a7c 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties @@ -283,4 +283,4 @@ KeywordSearchModuleFactory.createFileIngestModule.exception.msg=Expected setting SearchRunner.Searcher.done.err.msg=Error performing keyword search KeywordSearchGlobalSearchSettingsPanel.timeRadioButton5.toolTipText=Fastest overall, but no results until the end KeywordSearchGlobalSearchSettingsPanel.timeRadioButton5.text=No periodic searches -KeywordSearchIngestModule.startUp.fileTypeDetectorInitializationException.msg=Error initializing the File Type Detector. +KeywordSearchIngestModule.startUp.fileTypeDetectorInitializationException.msg=Error initializing the file type detector. diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index 5a4931574c..ebe407ee6c 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; +import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; @@ -37,6 +38,7 @@ import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.autopsy.keywordsearch.Ingester.IngesterException; import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector; import org.sleuthkit.datamodel.AbstractFile; +import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskData; import org.sleuthkit.datamodel.TskData.FileKnown; @@ -132,7 +134,6 @@ public final class KeywordSearchIngestModule implements FileIngestModule { try { fileTypeDetector = new FileTypeDetector(); } catch (FileTypeDetector.FileTypeDetectorInitException ex) { - logger.log(Level.SEVERE, NbBundle.getMessage(this.getClass(), "KeywordSearchIngestModule.startUp.fileTypeDetectorInitializationException.msg"), ex); throw new IngestModuleException(NbBundle.getMessage(this.getClass(), "KeywordSearchIngestModule.startUp.fileTypeDetectorInitializationException.msg")); } ingester = Server.getIngester(); @@ -475,9 +476,11 @@ public final class KeywordSearchIngestModule implements FileIngestModule { return; } - String detectedFormat = fileTypeDetector.getFileType(aFile); - if (detectedFormat == null) { - logger.log(Level.WARNING, "Could not detect format using fileTypeDetector for file: {0}", aFile); //NON-NLS + String detectedFormat; + try { + detectedFormat = fileTypeDetector.detectAndPostToBlackboard(aFile); + } catch (TskCoreException ex) { + logger.log(Level.SEVERE, String.format("Could not detect format using fileTypeDetector for file: %s", aFile), ex); //NON-NLS return; } From 81c0eaa21c1a7a6e8953ee1a14edeee75abe248e Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Wed, 27 May 2015 20:35:53 -0400 Subject: [PATCH 66/79] Improve comments in FileTypeDetector.java --- .../autopsy/modules/filetypeid/FileTypeDetector.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index 0bfbc0eda2..b851d590d5 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -101,7 +101,8 @@ public class FileTypeDetector { * * @param file The file to test. * @return The MIME type name id detection was successful, null otherwise. - * @throws TskCoreException if there is an error posting to the blackboard. + * @throws TskCoreException if there is an error posting to or reading from + * the blackboard. */ public String detectAndPostToBlackboard(AbstractFile file) throws TskCoreException { String mimeType = lookupFileType(file); @@ -128,6 +129,8 @@ public class FileTypeDetector { * * @param file The file to test. * @return The MIME type name if detection was successful, null otherwise. + * @throws TskCoreException if there is an error reading from the + * blackboard. */ public String detect(AbstractFile file) throws TskCoreException { String mimeType = lookupFileType(file); @@ -142,13 +145,15 @@ public class FileTypeDetector { * * @param file The file to test. * @return The MIME type name if look up was successful, null otherwise. + * @throws TskCoreException if there is an error reading from the + * blackboard. */ private String lookupFileType(AbstractFile file) throws TskCoreException { String fileType = null; ArrayList attributes = file.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); for (BlackboardAttribute attribute : attributes) { /** - * There should be at most TSK_FILE_TYPE_SIG attribute. + * There should be at most one TSK_FILE_TYPE_SIG attribute. */ fileType = attribute.getValueString(); break; @@ -161,6 +166,7 @@ public class FileTypeDetector { * * @param file The file to test. * @return The MIME type name if detection was successful, null otherwise. + * @throws TskCoreException if there is a case database error. */ private String detectFileType(AbstractFile file) throws TskCoreException { if ((file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) @@ -208,6 +214,7 @@ public class FileTypeDetector { * * @param file The file to test. * @return The file type name string or null, if no match is detected. + * @throws TskCoreException if there is a case database error. */ private String detectUserDefinedType(AbstractFile file) throws TskCoreException { for (FileType fileType : userDefinedFileTypes.values()) { From 23d383ac002bf053a26bb5e5f78d4929ae8f0f83 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Wed, 27 May 2015 20:42:04 -0400 Subject: [PATCH 67/79] Minor fixes for file type detection code in KWS and file type modules --- .../org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties | 1 + .../autopsy/keywordsearch/KeywordSearchIngestModule.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties index baf9fa08c3..cca8104c38 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/Bundle.properties @@ -45,4 +45,5 @@ FileTypeIdGlobalSettingsPanel.jLabel1.text=Custom File Types FileTypeIdGlobalSettingsPanel.jLabel2.text=MIME Types: FileTypeIdGlobalSettingsPanel.jLabel3.text=Autopsy can automatically detect many file types. Add your custom file types here. FileTypeIdGlobalSettingsPanel.startUp.fileTypeDetectorInitializationException.msg=Error initializing the file type detector. +FileTypeIdIngestModule.startUp.fileTypeDetectorInitializationException.msg=Error initializing the file type detector. diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index ebe407ee6c..4d322f7d0f 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; -import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; From 9ca7cd79c32f0a388c84da1dc7925829931e7776 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Thu, 28 May 2015 09:56:29 -0400 Subject: [PATCH 68/79] Modified new case action to be disableable --- .../sleuthkit/autopsy/casemodule/CaseNewAction.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java b/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java index 3303f4889c..9ed4e59d14 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java @@ -56,16 +56,5 @@ public final class CaseNewAction extends CallableSystemAction implements CaseNew @Override public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; - } - - /** - * 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); - } + } } From ee48f3850d96360dc2ab5271971e458f43a4d9a0 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Thu, 28 May 2015 10:09:18 -0400 Subject: [PATCH 69/79] Changes from review feedback --- .../AddImageWizardChooseDataSourceVisual.java | 14 ++++------ .../autopsy/casemodule/LocalDiskPanel.java | 28 +------------------ .../casemodule/NewCaseVisualPanel1.java | 14 ++-------- .../casemodule/NewCaseWizardPanel1.java | 1 - 4 files changed, 9 insertions(+), 48 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java index 721320d369..4476083f1d 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourceVisual.java @@ -87,7 +87,10 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { // Local disk processing is not allowed for multi-user cases if (Case.getCurrentCase().getCaseType() != Case.CaseType.MULTI_USER_CASE){ coreDSPTypes.add(LocalDiskDSProcessor.getType()); - } + } else { + // remove LocalDiskDSProcessor from list of DSPs + datasourceProcessorsMap.remove(LocalDiskDSProcessor.getType()); + } coreDSPTypes.add(LocalFilesDSProcessor.getType()); for (String dspType : coreDSPTypes) { @@ -97,7 +100,7 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { // now add any addtional DSPs that haven't already been added for (String dspType : dspTypes) { if (!coreDSPTypes.contains(dspType)) { - addDataSourceProcessorToComboBox(dspType); + typeComboBox.addItem(dspType); } } @@ -119,13 +122,6 @@ final class AddImageWizardChooseDataSourceVisual extends JPanel { typeComboBox.addActionListener(cbActionListener); typeComboBox.setSelectedIndex(0); } - - private void addDataSourceProcessorToComboBox(String dspType) { - // Local disk processing is not allowed for multi-user cases - if (Case.getCurrentCase().getCaseType() != Case.CaseType.MULTI_USER_CASE || !dspType.contains(LocalDiskDSProcessor.getType())) { - typeComboBox.addItem(dspType); - } - } private void discoverDataSourceProcessors() { diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java index 7e03c59268..3cf6b40bc6 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java @@ -45,7 +45,6 @@ import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor; import org.sleuthkit.autopsy.coreutils.LocalDisk; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; -import org.sleuthkit.autopsy.coreutils.PathValidator; import org.sleuthkit.autopsy.coreutils.PlatformUtil; /** @@ -65,8 +64,6 @@ final class LocalDiskPanel extends JPanel { private LocalDiskModel model; private boolean enableNext = false; - - private final int prePendedStringLength = 4; // "Local Disk" panel pre-pends "\\.\" in front of all drive letter and drive names /** * Creates new form LocalDiskPanel @@ -227,32 +224,9 @@ final class LocalDiskPanel extends JPanel { * @return true */ //@Override - public boolean validatePanel() { - - // display warning if there is one (but don't disable "next" button) - warnIfPathIsInvalid(getContentPaths()); - + public boolean validatePanel() { return enableNext; } - - /** - * Validates path to selected data source and displays warning if it is invalid. - * @param path Absolute path to the selected data source - */ - private void warnIfPathIsInvalid(String path){ - String newPath = path; - if (path.length() > prePendedStringLength) { - // "Local Disk" panel pre-pends "\\.\" in front of all drive letter and drive names. - // Path validators expect a "standard" path as input, i.e. one that starts with a drive letter. - newPath = path.substring(prePendedStringLength, path.length()); - } - - errorLabel.setVisible(false); - if (!PathValidator.isValid(newPath, Case.getCurrentCase().getCaseType())) { - errorLabel.setVisible(true); - errorLabel.setText(NbBundle.getMessage(this.getClass(), "DataSourceOnCDriveError.text")); - } - } //@Override public void reset() { diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java index 1ae4d3c406..0ca9173fee 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseVisualPanel1.java @@ -375,27 +375,19 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener { } // display warning if there is one (but don't disable "next" button) - isImagePathValid(parentDir); + warnIfPathIsInvalid(parentDir); } /** - * Validates path to selected case output folder. + * Validates path to selected case output folder. Displays warning if path is invalid. * * @param path Absolute path to the selected case folder - * @return true if path is valid, false otherwise. */ - private boolean isImagePathValid(String path) { + private void warnIfPathIsInvalid(String path) { errorLabel.setVisible(false); - - if (path.isEmpty()) { - return false; // no need for error message as the module sets path to "" at startup - } - if (!PathValidator.isValid(path, getCaseType())) { errorLabel.setVisible(true); errorLabel.setText(NbBundle.getMessage(this.getClass(), "NewCaseVisualPanel1.CaseFolderOnCDriveError.text")); - return false; } - return true; } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardPanel1.java b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardPanel1.java index 92bad320dd..ccdb48b951 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardPanel1.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardPanel1.java @@ -35,7 +35,6 @@ import org.openide.WizardDescriptor; import org.openide.WizardValidationException; import org.openide.util.HelpCtx; import org.sleuthkit.autopsy.casemodule.Case.CaseType; -import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.coreutils.ModuleSettings; /** From 1744a0c5955e2eb0553bb364617c5148fbe326de Mon Sep 17 00:00:00 2001 From: jmillman Date: Thu, 28 May 2015 10:12:01 -0400 Subject: [PATCH 70/79] reduce visibility of members of ImageGalleryModule --- .../autopsy/imagegallery/ImageGalleryModule.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java index e10ced9774..603d23a0f9 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java @@ -44,7 +44,7 @@ public class ImageGalleryModule { private static final String MODULE_NAME = "Image Gallery"; - public static String getModuleName() { + static String getModuleName() { return MODULE_NAME; } @@ -64,7 +64,7 @@ public class ImageGalleryModule { /** mime types of files we can display */ private static final Set supportedMimes = Sets.union(imageMimes, videoMimes); - public static Set getSupportedMimes() { + static Set getSupportedMimes() { return Collections.unmodifiableSet(supportedMimes); } @@ -103,8 +103,8 @@ public class ImageGalleryModule { } } - public static Set getAllSupportedExtensions() { - return supportedExtensions; + static Set getAllSupportedExtensions() { + return Collections.unmodifiableSet(supportedExtensions); } /** is the given file suported by image analyzer: ie, does it have a @@ -115,7 +115,7 @@ public class ImageGalleryModule { * * @return true if this file is supported or false if not */ - public static Boolean isSupported(AbstractFile file) { + static Boolean isSupported(AbstractFile file) { //if there were no file type attributes, or we failed to read it, fall back on extension and jpeg header return Optional.ofNullable(hasSupportedMimeType(file)).orElseGet(() -> { return supportedExtensions.contains(getFileExtension(file)) @@ -131,7 +131,7 @@ public class ImageGalleryModule { * TSK_GEN_INFO that is in the supported list. False if there was an * unsupported attribute, null if no attributes were found */ - public static Boolean hasSupportedMimeType(AbstractFile file) { + static Boolean hasSupportedMimeType(AbstractFile file) { try { ArrayList fileSignatureAttrs = file.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); if (fileSignatureAttrs.isEmpty() == false) { @@ -174,7 +174,7 @@ public class ImageGalleryModule { * @return true if the given {@link AbstractFile} is 'supported' and not * 'known', else false */ - static public boolean isSupportedAndNotKnown(AbstractFile abstractFile) { + public static boolean isSupportedAndNotKnown(AbstractFile abstractFile) { return (abstractFile.getKnown() != TskData.FileKnown.KNOWN) && ImageGalleryModule.isSupported(abstractFile); } } From ffa0b3ae8aa2b1837b49c9af65a21c383c966984 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 28 May 2015 11:12:11 -0400 Subject: [PATCH 71/79] Make FileTypeDetector.lookupFileType() more robust --- .../autopsy/modules/filetypeid/FileTypeDetector.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index b851d590d5..f9ec030602 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -153,10 +153,13 @@ public class FileTypeDetector { ArrayList attributes = file.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); for (BlackboardAttribute attribute : attributes) { /** - * There should be at most one TSK_FILE_TYPE_SIG attribute. + * There should be at most one TSK_FILE_TYPE_SIG attribute... */ - fileType = attribute.getValueString(); - break; + String postedFileType = attribute.getValueString(); + if (null != postedFileType && !postedFileType.isEmpty()) { + fileType = postedFileType; + break; + } } return fileType; } From 1a0b083b7a15598a8c787482f21882247d9bb1fc Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 28 May 2015 13:47:07 -0400 Subject: [PATCH 72/79] Fix bug injected into FileTypeDetector.detectFileType() --- .../sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index f9ec030602..02da263a23 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -173,8 +173,7 @@ public class FileTypeDetector { */ private String detectFileType(AbstractFile file) throws TskCoreException { if ((file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) - || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) - || (file.isFile() == false)) { + || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) { return MimeTypes.OCTET_STREAM; } From bbd475d1b7e9553710670a1f1d3abbb03a82d152 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 28 May 2015 13:52:26 -0400 Subject: [PATCH 73/79] Fix bug injected into FileTypeDetector.detectFileType() --- .../sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index f9ec030602..02da263a23 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -173,8 +173,7 @@ public class FileTypeDetector { */ private String detectFileType(AbstractFile file) throws TskCoreException { if ((file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) - || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) - || (file.isFile() == false)) { + || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) { return MimeTypes.OCTET_STREAM; } From 41bf4df1cc705db914419a716731cbab62918393 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Thu, 28 May 2015 14:34:08 -0400 Subject: [PATCH 74/79] Making sure new case action is not always enabled --- Core/src/org/sleuthkit/autopsy/core/layer.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/core/layer.xml b/Core/src/org/sleuthkit/autopsy/core/layer.xml index c8f37f5318..8bd8328eca 100644 --- a/Core/src/org/sleuthkit/autopsy/core/layer.xml +++ b/Core/src/org/sleuthkit/autopsy/core/layer.xml @@ -44,7 +44,6 @@ - From 0c0a7b3c13391d9d8f1cded82863970e3091aade Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Thu, 28 May 2015 17:14:08 -0400 Subject: [PATCH 75/79] Finished implementation --- Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java b/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java index 9ed4e59d14..1b89f6f432 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/CaseNewAction.java @@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.casemodule; import java.awt.event.ActionEvent; import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; import org.openide.util.actions.CallableSystemAction; import org.openide.util.actions.SystemAction; import org.openide.util.lookup.ServiceProvider; @@ -50,7 +51,7 @@ public final class CaseNewAction extends CallableSystemAction implements CaseNew @Override public String getName() { - return "New Case"; + return NbBundle.getMessage(CaseNewAction.class, "CTL_CaseNewAction"); } @Override From 4508777129cfa79ad702e801ad5a03e433a78441 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 28 May 2015 17:52:56 -0400 Subject: [PATCH 76/79] Re-broaden the FileTypeDetector API --- .../exif/ExifParserFileIngestModule.java | 2 +- .../modules/filetypeid/FileTypeDetector.java | 82 ++++++++----------- .../filetypeid/FileTypeIdIngestModule.java | 2 +- .../sevenzip/SevenZipIngestModule.java | 2 +- .../KeywordSearchIngestModule.java | 2 +- 5 files changed, 37 insertions(+), 53 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java index 560eeefda3..013247c086 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/exif/ExifParserFileIngestModule.java @@ -204,7 +204,7 @@ public final class ExifParserFileIngestModule implements FileIngestModule { */ private boolean parsableFormat(AbstractFile f) { try { - return fileTypeDetector.detect(f).equals("image/jpeg"); + return fileTypeDetector.getFileType(f).equals("image/jpeg"); } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Failed to detect file type", ex); //NON-NLS return false; diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index 02da263a23..44f9414cdd 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -96,20 +96,40 @@ public class FileTypeDetector { } /** - * Detect the MIME type of a file, posting it to the blackboard if detection - * succeeds. + * Look up the MIME type of a file using the blackboard. If it is not already + * posted, detect the type of the file, posting it to the blackboard if + * detection succeeds. * * @param file The file to test. * @return The MIME type name id detection was successful, null otherwise. - * @throws TskCoreException if there is an error posting to or reading from - * the blackboard. + * @throws TskCoreException + */ + public String getFileType(AbstractFile file) throws TskCoreException { + String fileType; + ArrayList attributes = file.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); + for (BlackboardAttribute attribute : attributes) { + /** + * Get the first TSK_FILE_TYPE_SIG attribute. + */ + fileType = attribute.getValueString(); + if (null != fileType && !fileType.isEmpty()) { + return fileType; + } + } + return detectAndPostToBlackboard(file); + } + + /** + * Detect the MIME type of a file, posting it to the blackboard if detection + * succeeds. Note that this method should currently be called at most once + * per file. + * + * @param file The file to test. + * @return The MIME type name id detection was successful, null otherwise. + * @throws TskCoreException */ public String detectAndPostToBlackboard(AbstractFile file) throws TskCoreException { - String mimeType = lookupFileType(file); - if (null != mimeType) { - return mimeType; - } - mimeType = detectFileType(file); + String mimeType = detect(file); if (null != mimeType) { /** * Add the file type attribute to the general info artifact. Note @@ -129,49 +149,13 @@ public class FileTypeDetector { * * @param file The file to test. * @return The MIME type name if detection was successful, null otherwise. - * @throws TskCoreException if there is an error reading from the - * blackboard. + * @throws TskCoreException */ public String detect(AbstractFile file) throws TskCoreException { - String mimeType = lookupFileType(file); - if (null != mimeType) { - return mimeType; + if (!file.isFile() || file.getSize() <= 0) { + return null; } - return detectFileType(file); - } - /** - * Look up the MIME type of a file on the blackboard. - * - * @param file The file to test. - * @return The MIME type name if look up was successful, null otherwise. - * @throws TskCoreException if there is an error reading from the - * blackboard. - */ - private String lookupFileType(AbstractFile file) throws TskCoreException { - String fileType = null; - ArrayList attributes = file.getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_FILE_TYPE_SIG); - for (BlackboardAttribute attribute : attributes) { - /** - * There should be at most one TSK_FILE_TYPE_SIG attribute... - */ - String postedFileType = attribute.getValueString(); - if (null != postedFileType && !postedFileType.isEmpty()) { - fileType = postedFileType; - break; - } - } - return fileType; - } - - /** - * Detect the MIME type of a file. - * - * @param file The file to test. - * @return The MIME type name if detection was successful, null otherwise. - * @throws TskCoreException if there is a case database error. - */ - private String detectFileType(AbstractFile file) throws TskCoreException { if ((file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) { return MimeTypes.OCTET_STREAM; @@ -216,7 +200,7 @@ public class FileTypeDetector { * * @param file The file to test. * @return The file type name string or null, if no match is detected. - * @throws TskCoreException if there is a case database error. + * @throws TskCoreException */ private String detectUserDefinedType(AbstractFile file) throws TskCoreException { for (FileType fileType : userDefinedFileTypes.values()) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java index 9c684c4af8..0be2445ed7 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeIdIngestModule.java @@ -106,7 +106,7 @@ public class FileTypeIdIngestModule implements FileIngestModule { */ try { long startTime = System.currentTimeMillis(); - fileTypeDetector.detectAndPostToBlackboard(file); + fileTypeDetector.getFileType(file); addToTotals(jobId, (System.currentTimeMillis() - startTime)); return ProcessResult.OK; } catch (Exception e) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java index a315a1f608..78136ff56f 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/sevenzip/SevenZipIngestModule.java @@ -661,7 +661,7 @@ public final class SevenZipIngestModule implements FileIngestModule { */ private boolean isZipFileHeader(AbstractFile file) { try { - return fileTypeDetector.detect(file).equals("application/zip"); //NON-NLS + return fileTypeDetector.getFileType(file).equals("application/zip"); //NON-NLS } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Failed to detect file type", ex); //NON-NLS return false; diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index 4d322f7d0f..a8dc0b849e 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -477,7 +477,7 @@ public final class KeywordSearchIngestModule implements FileIngestModule { String detectedFormat; try { - detectedFormat = fileTypeDetector.detectAndPostToBlackboard(aFile); + detectedFormat = fileTypeDetector.getFileType(aFile); } catch (TskCoreException ex) { logger.log(Level.SEVERE, String.format("Could not detect format using fileTypeDetector for file: %s", aFile), ex); //NON-NLS return; From c6e92d876709751f1299c80e724cc84dfec7b8a1 Mon Sep 17 00:00:00 2001 From: sidheshenator Date: Fri, 29 May 2015 12:17:44 -0400 Subject: [PATCH 77/79] non-files, 0-sized, unalloc, unused blocks marked as octet stream --- .../autopsy/modules/filetypeid/FileTypeDetector.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java index 44f9414cdd..cd87737537 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java +++ b/Core/src/org/sleuthkit/autopsy/modules/filetypeid/FileTypeDetector.java @@ -101,7 +101,7 @@ public class FileTypeDetector { * detection succeeds. * * @param file The file to test. - * @return The MIME type name id detection was successful, null otherwise. + * @return The MIME type name if detection was successful, null otherwise. * @throws TskCoreException */ public String getFileType(AbstractFile file) throws TskCoreException { @@ -152,11 +152,11 @@ public class FileTypeDetector { * @throws TskCoreException */ public String detect(AbstractFile file) throws TskCoreException { - if (!file.isFile() || file.getSize() <= 0) { - return null; - } - - if ((file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) + // consistently mark non-regular files (refer TskData.TSK_FS_META_TYPE_ENUM), + // 0 sized files, unallocated, and unused blocks (refer TskData.TSK_DB_FILES_TYPE_ENUM) + // as octet-stream. + if (!file.isFile() || file.getSize() <= 0 + || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS) || (file.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) { return MimeTypes.OCTET_STREAM; } From 20ef8d397f15cc3c47f871fc364c55f5bac2f6a1 Mon Sep 17 00:00:00 2001 From: Eamonn Saunders Date: Fri, 29 May 2015 14:05:09 -0400 Subject: [PATCH 78/79] Return empty lists instead of null to prevent null pointer exception happening in Collections.sort() --- .../directorytree/ExtractUnallocAction.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java index 1b1b284d34..297a4fce05 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java @@ -178,7 +178,7 @@ import org.sleuthkit.datamodel.VolumeSystem; } catch (TskCoreException tce) { logger.log(Level.WARNING, "Couldn't get a list of Unallocated Files, failed at sending out the visitor ", tce); //NON-NLS } - return null; + return Collections.emptyList(); } /** @@ -372,7 +372,7 @@ import org.sleuthkit.datamodel.VolumeSystem; * return the single instance of unallocated space. * * @param lf the LayoutFile the visitor encountered - * @return A list of size 1, returns null if it fails + * @return A list of size 1 */ @Override public List visit(final org.sleuthkit.datamodel.LayoutFile lf) { @@ -389,7 +389,7 @@ import org.sleuthkit.datamodel.VolumeSystem; * * @param fs the FileSystem the visitor encountered * @return A list containing the layout files from - * subsequent Visits(), returns null if it fails + * subsequent Visits(), or an empty list */ @Override public List visit(FileSystem fs) { @@ -402,7 +402,7 @@ import org.sleuthkit.datamodel.VolumeSystem; } catch (TskCoreException tce) { logger.log(Level.WARNING, "Couldn't get a list of Unallocated Files, failed at visiting FileSystem " + fs.getId(), tce); //NON-NLS } - return null; + return Collections.emptyList(); } /** @@ -410,12 +410,12 @@ import org.sleuthkit.datamodel.VolumeSystem; * * @param vd VirtualDirectory the visitor encountered * @return A list containing all the LayoutFile in ld, - * returns null if it fails + * or an empty list. */ @Override public List visit(VirtualDirectory vd) { try { - List lflst = new ArrayList(); + List lflst = new ArrayList<>(); for (Content layout : vd.getChildren()) { lflst.add((LayoutFile) layout); } @@ -423,7 +423,7 @@ import org.sleuthkit.datamodel.VolumeSystem; } catch (TskCoreException tce) { logger.log(Level.WARNING, "Could not get list of Layout Files, failed at visiting Layout Directory", tce); //NON-NLS } - return null; + return Collections.emptyList(); } /** @@ -432,7 +432,7 @@ import org.sleuthkit.datamodel.VolumeSystem; * * @param dir the directory this visitor encountered * @return A list containing LayoutFiles encountered during - * subsequent Visits(), returns null if it fails + * subsequent Visits(), or an empty list. */ @Override public List visit(Directory dir) { @@ -445,12 +445,12 @@ import org.sleuthkit.datamodel.VolumeSystem; } catch (TskCoreException tce) { logger.log(Level.WARNING, "Couldn't get a list of Unallocated Files, failed at visiting Directory " + dir.getId(), tce); //NON-NLS } - return null; + return Collections.emptyList(); } @Override protected List defaultVisit(Content cntnt) { - return null; + return Collections.emptyList(); } } From 06abb7cc1c0a7eacc4dd52f8650e76619419b8ec Mon Sep 17 00:00:00 2001 From: Eamonn Saunders Date: Fri, 29 May 2015 14:08:31 -0400 Subject: [PATCH 79/79] Missed a comment change in last checkin. --- .../sleuthkit/autopsy/directorytree/ExtractUnallocAction.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java index 297a4fce05..dc580d41f8 100644 --- a/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/ExtractUnallocAction.java @@ -165,8 +165,7 @@ import org.sleuthkit.datamodel.VolumeSystem; * Gets all the unallocated files in a given Content. * * @param c Content to get Unallocated Files from - * @return A list if it didn't crash List may be empty. Returns - * null on failure. + * @return A list if it didn't crash List may be empty. */ private List getUnallocFiles(Content c) { UnallocVisitor uv = new UnallocVisitor();