code review comments

This commit is contained in:
Karl Mortensen 2016-06-02 15:24:04 -04:00
parent 189f73d008
commit 5ebe410215

View File

@ -177,6 +177,8 @@ class ReportKML implements GeneralReportModule {
document.addContent(gpsSearchesFolder); document.addContent(gpsSearchesFolder);
document.addContent(gpsTrackpointsFolder); document.addContent(gpsTrackpointsFolder);
ReportProgressPanel.ReportStatus result = ReportProgressPanel.ReportStatus.COMPLETE;
/** /**
* In the following code, nulls are okay, and are handled when we go to * In the following code, nulls are okay, and are handled when we go to
* write out the KML feature. Nulls are expected to be returned from any * write out the KML feature. Nulls are expected to be returned from any
@ -186,9 +188,15 @@ class ReportKML implements GeneralReportModule {
* as anyone could write a module that adds additional attributes to an * as anyone could write a module that adds additional attributes to an
* artifact. * artifact.
* *
* If there are any issues reading the database getting artifacts and
* attributes, or any exceptions thrown during this process, a severe
* error is logged, the report is marked as "Incomplete KML Report", and
* we use a best-effort method to generate KML information on everything
* we can successfully pull out of the database.
*/ */
try { try {
for (BlackboardArtifact artifact : skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_METADATA_EXIF)) { for (BlackboardArtifact artifact : skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_METADATA_EXIF)) {
try {
Long timestamp = getLong(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED); Long timestamp = getLong(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED);
String desc = getDescriptionFromArtifact(artifact, "EXIF Metadata With Locations"); //NON-NLS String desc = getDescriptionFromArtifact(artifact, "EXIF Metadata With Locations"); //NON-NLS
Double lat = getDouble(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE); Double lat = getDouble(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE);
@ -198,27 +206,31 @@ class ReportKML implements GeneralReportModule {
if (lat != null && lat != 0.0 && lon != null && lon != 0.0) { if (lat != null && lat != 0.0 && lon != null && lon != 0.0) {
AbstractFile abstractFile = artifact.getSleuthkitCase().getAbstractFileById(artifact.getObjectID()); AbstractFile abstractFile = artifact.getSleuthkitCase().getAbstractFileById(artifact.getObjectID());
Path path = null; Path path = null;
if (abstractFile != null) {
copyFileUsingStream(abstractFile, Paths.get(baseReportDir, abstractFile.getName()).toFile()); copyFileUsingStream(abstractFile, Paths.get(baseReportDir, abstractFile.getName()).toFile());
try { try {
path = Paths.get(removeLeadingImgAndVol(abstractFile.getUniquePath())); path = Paths.get(removeLeadingImgAndVol(abstractFile.getUniquePath()));
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
path = Paths.get(abstractFile.getParentPath(), abstractFile.getName()); path = Paths.get(abstractFile.getParentPath(), abstractFile.getName());
} }
}
String formattedCoordinates = String.format("%.2f, %.2f", lat, lon); String formattedCoordinates = String.format("%.2f, %.2f", lat, lon);
if (path == null) { if (path == null) {
path = Paths.get(abstractFile.getName()); path = Paths.get(abstractFile.getName());
} }
gpsExifMetadataFolder.addContent(makePlacemarkWithPicture(abstractFile.getName(), FeatureColor.RED, desc, timestamp, point, path, formattedCoordinates)); gpsExifMetadataFolder.addContent(makePlacemarkWithPicture(abstractFile.getName(), FeatureColor.RED, desc, timestamp, point, path, formattedCoordinates));
} }
} catch (Exception ex) {
logger.log(Level.SEVERE, "Could not extract photo information.", ex); //NON-NLS
result = ReportProgressPanel.ReportStatus.ERROR;
} }
} catch (TskCoreException | IOException ex) { }
} catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Could not extract photos with EXIF metadata.", ex); //NON-NLS logger.log(Level.SEVERE, "Could not extract photos with EXIF metadata.", ex); //NON-NLS
result = ReportProgressPanel.ReportStatus.ERROR;
} }
try { try {
for (BlackboardArtifact artifact : skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_BOOKMARK)) { for (BlackboardArtifact artifact : skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_BOOKMARK)) {
try {
Long timestamp = getLong(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME); Long timestamp = getLong(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME);
String desc = getDescriptionFromArtifact(artifact, "GPS Bookmark"); //NON-NLS String desc = getDescriptionFromArtifact(artifact, "GPS Bookmark"); //NON-NLS
Double lat = getDouble(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE); Double lat = getDouble(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE);
@ -227,13 +239,19 @@ class ReportKML implements GeneralReportModule {
String bookmarkName = getString(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME); String bookmarkName = getString(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME);
String formattedCoordinates = String.format("%.2f, %.2f", lat, lon); String formattedCoordinates = String.format("%.2f, %.2f", lat, lon);
gpsBookmarksFolder.addContent(makePlacemark(bookmarkName, FeatureColor.BLUE, desc, timestamp, point, formattedCoordinates)); gpsBookmarksFolder.addContent(makePlacemark(bookmarkName, FeatureColor.BLUE, desc, timestamp, point, formattedCoordinates));
} catch (Exception ex) {
logger.log(Level.SEVERE, "Could not extract Bookmark information.", ex); //NON-NLS
result = ReportProgressPanel.ReportStatus.ERROR;
}
} }
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Could not get GPS Bookmarks from database.", ex); //NON-NLS logger.log(Level.SEVERE, "Could not get GPS Bookmarks from database.", ex); //NON-NLS
result = ReportProgressPanel.ReportStatus.ERROR;
} }
try { try {
for (BlackboardArtifact artifact : skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_LAST_KNOWN_LOCATION)) { for (BlackboardArtifact artifact : skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_LAST_KNOWN_LOCATION)) {
try {
Long timestamp = getLong(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME); Long timestamp = getLong(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME);
String desc = getDescriptionFromArtifact(artifact, "GPS Last Known Location"); //NON-NLS String desc = getDescriptionFromArtifact(artifact, "GPS Last Known Location"); //NON-NLS
Double lat = getDouble(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE); Double lat = getDouble(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE);
@ -242,13 +260,19 @@ class ReportKML implements GeneralReportModule {
Element point = makePoint(lat, lon, alt); Element point = makePoint(lat, lon, alt);
String formattedCoordinates = String.format("%.2f, %.2f", lat, lon); String formattedCoordinates = String.format("%.2f, %.2f", lat, lon);
gpsLastKnownLocationFolder.addContent(makePlacemark("Last Known Location", FeatureColor.PURPLE, desc, timestamp, point, formattedCoordinates)); //NON-NLS gpsLastKnownLocationFolder.addContent(makePlacemark("Last Known Location", FeatureColor.PURPLE, desc, timestamp, point, formattedCoordinates)); //NON-NLS
} catch (Exception ex) {
logger.log(Level.SEVERE, "Could not extract Last Known Location information.", ex); //NON-NLS
result = ReportProgressPanel.ReportStatus.ERROR;
}
} }
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Could not get GPS Last Known Location from database.", ex); //NON-NLS logger.log(Level.SEVERE, "Could not get GPS Last Known Location from database.", ex); //NON-NLS
result = ReportProgressPanel.ReportStatus.ERROR;
} }
try { try {
for (BlackboardArtifact artifact : skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_ROUTE)) { for (BlackboardArtifact artifact : skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_ROUTE)) {
try {
Long timestamp = getLong(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME); Long timestamp = getLong(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME);
String desc = getDescriptionFromArtifact(artifact, "GPS Route"); String desc = getDescriptionFromArtifact(artifact, "GPS Route");
Double latitudeStart = getDouble(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_START); Double latitudeStart = getDouble(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_START);
@ -269,9 +293,14 @@ class ReportKML implements GeneralReportModule {
formattedCoordinates = String.format("%.2f, %.2f", latitudeEnd, longitudeEnd); formattedCoordinates = String.format("%.2f, %.2f", latitudeEnd, longitudeEnd);
gpsRouteFolder.addContent(makePlacemark("End", FeatureColor.GREEN, desc, timestamp, endingPoint, formattedCoordinates)); //NON-NLS gpsRouteFolder.addContent(makePlacemark("End", FeatureColor.GREEN, desc, timestamp, endingPoint, formattedCoordinates)); //NON-NLS
} catch (Exception ex) {
logger.log(Level.SEVERE, "Could not extract GPS Route information.", ex); //NON-NLS
result = ReportProgressPanel.ReportStatus.ERROR;
}
} }
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Could not get GPS Routes from database.", ex); //NON-NLS logger.log(Level.SEVERE, "Could not get GPS Routes from database.", ex); //NON-NLS
result = ReportProgressPanel.ReportStatus.ERROR;
} }
try { try {
@ -294,10 +323,12 @@ class ReportKML implements GeneralReportModule {
} }
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Could not get GPS Searches from database.", ex); //NON-NLS logger.log(Level.SEVERE, "Could not get GPS Searches from database.", ex); //NON-NLS
result = ReportProgressPanel.ReportStatus.ERROR;
} }
try { try {
for (BlackboardArtifact artifact : skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACKPOINT)) { for (BlackboardArtifact artifact : skCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACKPOINT)) {
try {
Long timestamp = getLong(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME); Long timestamp = getLong(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME);
String desc = getDescriptionFromArtifact(artifact, "GPS Trackpoint"); //NON-NLS String desc = getDescriptionFromArtifact(artifact, "GPS Trackpoint"); //NON-NLS
Double lat = getDouble(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE); Double lat = getDouble(artifact, BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE);
@ -316,24 +347,14 @@ class ReportKML implements GeneralReportModule {
trackName = "GPS Trackpoint"; trackName = "GPS Trackpoint";
} }
gpsTrackpointsFolder.addContent(makePlacemark(trackName, FeatureColor.YELLOW, desc, timestamp, point, formattedCoordinates)); gpsTrackpointsFolder.addContent(makePlacemark(trackName, FeatureColor.YELLOW, desc, timestamp, point, formattedCoordinates));
} catch (Exception ex) {
logger.log(Level.SEVERE, "Could not extract Trackpoint information.", ex); //NON-NLS
result = ReportProgressPanel.ReportStatus.ERROR;
}
} }
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Could not get GPS Trackpoints from database.", ex); //NON-NLS logger.log(Level.SEVERE, "Could not get GPS Trackpoints from database.", ex); //NON-NLS
} result = ReportProgressPanel.ReportStatus.ERROR;
try (FileOutputStream writer = new FileOutputStream(kmlFileFullPath)) {
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
outputter.output(kmlDocument, writer);
Case.getCurrentCase().addReport(kmlFileFullPath,
NbBundle.getMessage(this.getClass(), "ReportKML.genReport.srcModuleName.text"),
NbBundle.getMessage(this.getClass(), "ReportKML.genReport.reportName"));
} catch (IOException ex) {
logger.log(Level.SEVERE, "Could not write the KML file.", ex); //NON-NLS
progressPanel.complete(ReportProgressPanel.ReportStatus.ERROR);
} catch (TskCoreException ex) {
String errorMessage = String.format("Error adding %s to case as a report", kmlFileFullPath); //NON-NLS
logger.log(Level.SEVERE, errorMessage, ex);
progressPanel.complete(ReportProgressPanel.ReportStatus.ERROR);
} }
// Copy the style sheet // Copy the style sheet
@ -343,9 +364,29 @@ class ReportKML implements GeneralReportModule {
FileUtil.copy(input, output); FileUtil.copy(input, output);
} catch (IOException ex) { } catch (IOException ex) {
logger.log(Level.SEVERE, "Error placing KML stylesheet. The .KML file will not function properly.", ex); //NON-NLS logger.log(Level.SEVERE, "Error placing KML stylesheet. The .KML file will not function properly.", ex); //NON-NLS
result = ReportProgressPanel.ReportStatus.ERROR;
} }
progressPanel.complete(ReportProgressPanel.ReportStatus.COMPLETE); try (FileOutputStream writer = new FileOutputStream(kmlFileFullPath)) {
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
outputter.output(kmlDocument, writer);
String prependedStatus = "";
if (result == ReportProgressPanel.ReportStatus.ERROR) {
prependedStatus = "Incomplete ";
}
Case.getCurrentCase().addReport(kmlFileFullPath,
NbBundle.getMessage(this.getClass(), "ReportKML.genReport.srcModuleName.text"),
prependedStatus + NbBundle.getMessage(this.getClass(), "ReportKML.genReport.reportName"));
} catch (IOException ex) {
logger.log(Level.SEVERE, "Could not write the KML file.", ex); //NON-NLS
progressPanel.complete(ReportProgressPanel.ReportStatus.ERROR);
} catch (TskCoreException ex) {
String errorMessage = String.format("Error adding %s to case as a report", kmlFileFullPath); //NON-NLS
logger.log(Level.SEVERE, errorMessage, ex);
result = ReportProgressPanel.ReportStatus.ERROR;
}
progressPanel.complete(result);
} }
/** /**