mirror of
https://github.com/elisspace/autopsy.git
synced 2026-09-06 02:24:30 +00:00
Link to content in HTML reports for blackboard artifact tags that refer to image files.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String> 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<tr>\n");
|
||||
for (String cell : row) {
|
||||
builder.append("\t\t<td>").append(cell).append("</td>\n");
|
||||
}
|
||||
|
||||
builder.append("\t\t<td><img src=\"")
|
||||
.append(THUMBS_REL_PATH)
|
||||
.append(thumbFile.getName())
|
||||
.append("\"/></td>\n")
|
||||
.append("\t</tr>\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<String> 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("<img src=\"").append(prepareThumbnail(file)).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<String> 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("<img src=\"").append(prepareThumbnail(file)).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<String> 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("<img src=\"").append(prepareThumbnail(file)).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("<a href=\"file:///");
|
||||
localFileLink.append(localFilePath.toString());
|
||||
localFileLink.append("\">");
|
||||
localFileLink.append(linkContent);
|
||||
localFileLink.append(linkHTMLContent);
|
||||
localFileLink.append("</a>");
|
||||
row.add(localFileLink.toString());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user