From 2c7eb4ce88fdd2926dfcef02aa0b6283cb64fdce Mon Sep 17 00:00:00 2001 From: Jeff Wallace Date: Fri, 13 Dec 2013 16:22:55 -0500 Subject: [PATCH] Link to content in HTML reports for blackboard artifact tags that refer to image files. --- .../autopsy/report/ReportGenerator.java | 35 +----- .../sleuthkit/autopsy/report/ReportHTML.java | 106 +++++++++--------- 2 files changed, 58 insertions(+), 83 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java b/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java index a3df4bd8b3..f95c002134 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportGenerator.java @@ -588,14 +588,10 @@ public class ReportGenerator { // We add a thumbnail if the artifact is associated with an // image file. row = new ArrayList<>(Arrays.asList(tag.getArtifact().getArtifactTypeName(), tag.getName().getDisplayName(), tag.getComment(), tag.getContent().getName())); - if (module instanceof ReportHTML == false) { - module.addRow(row); - } else if ((thumbFile = getImageContent(tag.getArtifact())) != null) { - ((ReportHTML) module).addRow(row, thumbFile); + if (module instanceof ReportHTML) { + ((ReportHTML) module).addRowWithTaggedContentHyperlink(row, tag); } else { - // Add an extra cell so the row extends the proper amount of columns - row.add(""); - module.addRow(row); + module.addRow(row); } } } @@ -621,31 +617,6 @@ public class ReportGenerator { iter.remove(); } } - } - - /** - * Get a thumbnail of the content associated with the artifact if the - * content is an image. - * - * Returns null if the content is not an image. - * - * @param artifact - * @return - */ - private File getImageContent(BlackboardArtifact artifact) { - Content c; - try { - c = artifact.getSleuthkitCase().getContentById(artifact.getObjectID()); - } catch (TskException ex) { - logger.log(Level.WARNING, "Getting file failed", ex); - return null; - } - - if (c == null || ImageUtils.thumbnailSupported(c) == false) { - return null; - } - - return ImageUtils.getIconFile(c, ImageUtils.ICON_SIZE_SMALL); } } diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java b/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java index b9c4448543..f678729622 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportHTML.java @@ -39,9 +39,9 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.logging.Level; -import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; import org.sleuthkit.autopsy.casemodule.Case; +import org.openide.filesystems.FileUtil; import org.sleuthkit.autopsy.coreutils.ImageUtils; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.datamodel.ContentUtils.ExtractFscContentVisitor; @@ -52,6 +52,7 @@ import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE; +import org.sleuthkit.datamodel.BlackboardArtifactTag; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM; @@ -502,41 +503,6 @@ public class ReportHTML implements TableReportModule { logger.log(Level.SEVERE, "Output writer is null. Page was not initialized before writing.", ex); } } - - /** - * Adds a row with a thumbnail image as the last column. - * - * @param row - * @param thumbFile - */ - public void addRow(List row, File thumbFile) { - try { - File to = new File(thumbsPath); - FileUtil.copyFile(FileUtil.toFileObject(thumbFile), FileUtil.toFileObject(to), thumbFile.getName(), ""); - } catch (IOException ex) { - logger.log(Level.SEVERE, "Failed to write thumb file to report directory."); - } - StringBuilder builder = new StringBuilder(); - builder.append("\t\n"); - for (String cell : row) { - builder.append("\t\t").append(cell).append("\n"); - } - - builder.append("\t\t\n") - .append("\t\n"); - rowCount++; - - try { - out.write(builder.toString()); - } catch (IOException ex) { - logger.log(Level.SEVERE, "Failed to write row to out.", ex); - } catch (NullPointerException ex) { - logger.log(Level.SEVERE, "Output writer is null. Page was not initialized before writing.", ex); - } - } /** * Saves a local copy of a tagged file and adds a row with a hyper link to @@ -548,14 +514,59 @@ public class ReportHTML implements TableReportModule { */ public void addRowWithTaggedContentHyperlink(List row, ContentTag contentTag) { // Only handling AbstractFiles at present. + String tagName = contentTag.getName().getDisplayName(); AbstractFile file; if (contentTag.getContent() instanceof AbstractFile) { file = (AbstractFile)contentTag.getContent(); + StringBuilder linkContent = new StringBuilder(); + if (ImageUtils.thumbnailSupported(file)) { + linkContent.append(""); + } else { + linkContent.append("View File"); + } + addRowWithTaggedContentHyperlink(row, file, tagName, linkContent.toString()); } - else { + } + + /** + * Saves a local copy of a tagged file and adds a row with a hyper link to + * the file. The hyper link will be a thumbnail if the Content associated + * with the given BlackboardArtifactTag is an image. + * + * @param row Values for each data cell in the row. + * @param artifactTag An artifact tag to use to make the hyper link. + */ + public void addRowWithTaggedContentHyperlink(List row, BlackboardArtifactTag artifactTag) { + String tagName = artifactTag.getName().getDisplayName(); + AbstractFile file; + try { + file = Case.getCurrentCase().getSleuthkitCase().getAbstractFileById(artifactTag.getArtifact().getObjectID()); + } catch (TskCoreException ex) { + logger.log(Level.WARNING, "Error while getting content from a blackboard artifact to report on.", ex); return; } + // Only include content for images + if (ImageUtils.thumbnailSupported(file)) { + StringBuilder linkContent = new StringBuilder(); + linkContent.append(""); + addRowWithTaggedContentHyperlink(row, file, tagName, linkContent.toString()); + } else { + row.add(""); + this.addRow(row); + } + } + + /** + * Saves a local copy of a tagged file and adds a row with a hyper link to + * the file. The content of the hyperlink is provided in linkHTMLContent. + * + * @param row Values for each data cell in the row + * @param file The file to link to in the report. + * @param tagName the name of the tag that the content was flagged by + * @param linkHTMLContent the html that will be the body of the link + */ + private void addRowWithTaggedContentHyperlink(List row, AbstractFile file, String tagName, String linkHTMLContent) { // Don't make a local copy of the file if it is a directory or unallocated space. if (file.isDir() || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS || @@ -564,51 +575,44 @@ public class ReportHTML implements TableReportModule { return; } - // Make a folder for the local file with the same name as the tag. + // Make a folder for the local file with the same tagName as the tag. StringBuilder localFilePath = new StringBuilder(); localFilePath.append(path); - localFilePath.append(contentTag.getName().getDisplayName()); + localFilePath.append(tagName); File localFileFolder = new File(localFilePath.toString()); if (!localFileFolder.exists()) { localFileFolder.mkdirs(); } - // Construct a file name for the local file that incorporates the file id to ensure uniqueness. + // Construct a file tagName for the local file that incorporates the file id to ensure uniqueness. String fileName = file.getName(); String objectIdSuffix = "_" + file.getId(); int lastDotIndex = fileName.lastIndexOf("."); if (lastDotIndex != -1 && lastDotIndex != 0) { - // The file name has a conventional extension. Insert the object id before the '.' of the extension. + // The file tagName has a conventional extension. Insert the object id before the '.' of the extension. fileName = fileName.substring(0, lastDotIndex) + objectIdSuffix + fileName.substring(lastDotIndex, fileName.length()); } else { // The file has no extension or the only '.' in the file is an initial '.', as in a hidden file. - // Add the object id to the end of the file name. + // Add the object id to the end of the file tagName. fileName += objectIdSuffix; } localFilePath.append(File.separator); localFilePath.append(fileName); // If the local file doesn't already exist, create it now. - // The existence check is necessary because it is possible to apply multiple tags with the same name to a file. + // The existence check is necessary because it is possible to apply multiple tags with the same tagName to a file. File localFile = new File(localFilePath.toString()); if (!localFile.exists()) { ExtractFscContentVisitor.extract(file, localFile, null, null); } - - StringBuilder linkContent = new StringBuilder(); - if (ImageUtils.thumbnailSupported(file)) { - linkContent.append(""); - } else { - linkContent.append("View File"); - } // Add the hyperlink to the row. A column header for it was created in startTable(). StringBuilder localFileLink = new StringBuilder(); localFileLink.append(""); - localFileLink.append(linkContent); + localFileLink.append(linkHTMLContent); localFileLink.append(""); row.add(localFileLink.toString());