From cfa50f4345a4db4bfb2ee4d8b4c276e014f79c9d Mon Sep 17 00:00:00 2001 From: Brian Carrier Date: Thu, 23 Jan 2014 16:07:19 -0500 Subject: [PATCH] reporting uses new extension code, displays full path and tag names, can be moved around (relative paths) --- .../autopsy/coreutils/ImageUtils.java | 10 ++--- .../autopsy/report/ReportGenerator.java | 12 ++++- .../sleuthkit/autopsy/report/ReportHTML.java | 45 +++++++++++++++---- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java index f53834c3b0..f1fa3714ee 100755 --- a/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/ImageUtils.java @@ -93,16 +93,12 @@ public class ImageUtils { logger.log(Level.WARNING, "Error while getting file signature from blackboard.", ex); } - final String fName = f.getName(); - final int dotIdx = fName.lastIndexOf('.'); + final String extension = f.getNameExtension(); // if we have an extension, check it - if ((dotIdx != -1) && (dotIdx != (fName.length() - 1))) { - - final String ext = fName.substring(dotIdx + 1).toLowerCase(); - + if (extension.equals("") == false) { // Note: thumbnail generator only supports JPG, GIF, and PNG for now - if (SUPP_EXTENSIONS.contains(ext)) { + if (SUPP_EXTENSIONS.contains(extension)) { return true; } } diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java b/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java index 6bcb210bfc..63a0fd2747 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java @@ -46,6 +46,7 @@ import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.SwingWorker; import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.EscapeUtil; import org.sleuthkit.autopsy.coreutils.ImageUtils; @@ -87,7 +88,7 @@ public class ReportGenerator { static final String REPORTS_DIR = "Reports"; ReportGenerator(Map tableModuleStates, Map generalModuleStates, Map fileListModuleStates) { - // Create the root reports directory path of the form: /Reports/ / + // Create the root reports directory path of the form: /Reports/ / DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy-HH-mm-ss"); Date date = new Date(); String dateNoTime = dateFormat.format(date); @@ -542,7 +543,14 @@ public class ReportGenerator { continue; } - ArrayList rowData = new ArrayList<>(Arrays.asList(tag.getContent().getName(), tag.getName().getDisplayName(), tag.getComment())); + String fileName; + try { + fileName = tag.getContent().getUniquePath(); + } catch (TskCoreException ex) { + fileName = tag.getContent().getName(); + } + + ArrayList rowData = new ArrayList<>(Arrays.asList(fileName, tag.getName().getDisplayName(), tag.getComment())); for (TableReportModule module : tableModules) { // @@@ This casting is a tricky little workaround to allow the HTML report module to slip in a content hyperlink. if (module instanceof ReportHTML) { diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java b/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java index faa9c0612c..2cccef4c35 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java @@ -44,6 +44,8 @@ import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; import org.openide.filesystems.FileUtil; +import org.sleuthkit.autopsy.casemodule.services.Services; +import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.ImageUtils; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.datamodel.ContentUtils.ExtractFscContentVisitor; @@ -538,7 +540,7 @@ public class ReportHTML implements TableReportModule { // Add the hyperlink to the row. A column header for it was created in startTable(). StringBuilder localFileLink = new StringBuilder(); - localFileLink.append("View File"); row.add(localFileLink.toString()); @@ -605,15 +607,39 @@ public class ReportHTML implements TableReportModule { continue; } String contentPath = saveContent(file, "thumbs_fullsize"); + String nameInImage; + try { + nameInImage = file.getUniquePath(); + } catch (TskCoreException ex) { + nameInImage = file.getName(); + } StringBuilder linkToThumbnail = new StringBuilder(); - linkToThumbnail.append(""); - linkToThumbnail.append(""); + linkToThumbnail.append(""); linkToThumbnail.append("
"); linkToThumbnail.append(file.getName()).append("
"); - // @@@ Add tags here + + Services services = currentCase.getServices(); + TagsManager tagsManager = services.getTagsManager(); + try { + List tags = tagsManager.getContentTagsByContent(content); + if (tags.size() > 0) { + linkToThumbnail.append("Tags: " ); + } + for (int i = 0; i < tags.size(); i++) { + ContentTag tag = tags.get(i); + linkToThumbnail.append(tag.getName().getDisplayName()); + if (i != tags.size() - 1) { + linkToThumbnail.append(", "); + } + } + } catch (TskCoreException ex) { + logger.log(Level.WARNING, "Could not find get tags for file.", ex); + } + currentRow.add(linkToThumbnail.toString()); totalCount++; @@ -649,7 +675,7 @@ public class ReportHTML implements TableReportModule { * Save a local copy of the given file in the reports folder. * @param file File to save * @param dirName Custom top-level folder to use to store the files in (tag name, etc.) - * @return Path to where file was stored + * @return Path to where file was stored (relative to root of HTML folder) */ public String saveContent(AbstractFile file, String dirName) { // clean up the dir name passed in @@ -657,8 +683,9 @@ public class ReportHTML implements TableReportModule { dirName2 = dirName2.replace("\\", "_"); // Make a folder for the local file with the same tagName as the tag. - StringBuilder localFilePath = new StringBuilder(); - localFilePath.append(path); + StringBuilder localFilePath = new StringBuilder(); // full path + + localFilePath.append(path); localFilePath.append(dirName2); File localFileFolder = new File(localFilePath.toString()); if (!localFileFolder.exists()) { @@ -687,7 +714,9 @@ public class ReportHTML implements TableReportModule { if (!localFile.exists()) { ExtractFscContentVisitor.extract(file, localFile, null, null); } - return localFilePath.toString(); + + // get the relative path + return localFilePath.toString().substring(path.length()); } /**