Merge pull request #4322 from dgrove727/4443_ExifDuplicateArtifacts

4443 Don't make duplicate EXIF metadata artifacts
This commit is contained in:
Richard Cordovano 2018-12-04 16:18:14 -05:00 committed by GitHub
commit cb3b075376
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,6 +58,7 @@ import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.Image; import org.sleuthkit.datamodel.Image;
import org.sleuthkit.datamodel.ReadContentInputStream; import org.sleuthkit.datamodel.ReadContentInputStream;
import org.sleuthkit.datamodel.ReadContentInputStream.ReadContentInputStreamException; import org.sleuthkit.datamodel.ReadContentInputStream.ReadContentInputStreamException;
import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.datamodel.TskData; import org.sleuthkit.datamodel.TskData;
import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM; import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
@ -82,6 +83,7 @@ public final class ExifParserFileIngestModule implements FileIngestModule {
private FileTypeDetector fileTypeDetector; private FileTypeDetector fileTypeDetector;
private final HashSet<String> supportedMimeTypes = new HashSet<>(); private final HashSet<String> supportedMimeTypes = new HashSet<>();
private TimeZone timeZone = null; private TimeZone timeZone = null;
private Case currentCase;
private Blackboard blackboard; private Blackboard blackboard;
ExifParserFileIngestModule() { ExifParserFileIngestModule() {
@ -104,7 +106,8 @@ public final class ExifParserFileIngestModule implements FileIngestModule {
@Override @Override
public ProcessResult process(AbstractFile content) { public ProcessResult process(AbstractFile content) {
try { try {
blackboard = Case.getCurrentCaseThrows().getServices().getBlackboard(); currentCase = Case.getCurrentCaseThrows();
blackboard = currentCase.getServices().getBlackboard();
} catch (NoCurrentCaseException ex) { } catch (NoCurrentCaseException ex) {
logger.log(Level.INFO, "Exception while getting open case.", ex); //NON-NLS logger.log(Level.INFO, "Exception while getting open case.", ex); //NON-NLS
return ProcessResult.ERROR; return ProcessResult.ERROR;
@ -142,12 +145,12 @@ public final class ExifParserFileIngestModule implements FileIngestModule {
} }
@Messages({"ExifParserFileIngestModule.indexError.message=Failed to index EXIF Metadata artifact for keyword search."}) @Messages({"ExifParserFileIngestModule.indexError.message=Failed to index EXIF Metadata artifact for keyword search."})
ProcessResult processFile(AbstractFile f) { ProcessResult processFile(AbstractFile file) {
InputStream in = null; InputStream in = null;
BufferedInputStream bin = null; BufferedInputStream bin = null;
try { try {
in = new ReadContentInputStream(f); in = new ReadContentInputStream(file);
bin = new BufferedInputStream(in); bin = new BufferedInputStream(in);
Collection<BlackboardAttribute> attributes = new ArrayList<>(); Collection<BlackboardAttribute> attributes = new ArrayList<>();
@ -160,7 +163,7 @@ public final class ExifParserFileIngestModule implements FileIngestModule {
// set the timeZone for the current datasource. // set the timeZone for the current datasource.
if (timeZone == null) { if (timeZone == null) {
try { try {
Content dataSource = f.getDataSource(); Content dataSource = file.getDataSource();
if ((dataSource != null) && (dataSource instanceof Image)) { if ((dataSource != null) && (dataSource instanceof Image)) {
Image image = (Image) dataSource; Image image = (Image) dataSource;
timeZone = TimeZone.getTimeZone(image.getTimeZone()); timeZone = TimeZone.getTimeZone(image.getTimeZone());
@ -208,18 +211,23 @@ public final class ExifParserFileIngestModule implements FileIngestModule {
// Add the attributes, if there are any, to a new artifact // Add the attributes, if there are any, to a new artifact
if (!attributes.isEmpty()) { if (!attributes.isEmpty()) {
BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_METADATA_EXIF); SleuthkitCase tskCase = currentCase.getSleuthkitCase();
bba.addAttributes(attributes); org.sleuthkit.datamodel.Blackboard tskBlackboard = tskCase.getBlackboard();
// Create artifact if it doesn't already exist.
if (!tskBlackboard.artifactExists(file, BlackboardArtifact.ARTIFACT_TYPE.TSK_METADATA_EXIF, attributes)) {
BlackboardArtifact bba = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_METADATA_EXIF);
bba.addAttributes(attributes);
try { try {
// index the artifact for keyword search // index the artifact for keyword search
blackboard.indexArtifact(bba); blackboard.indexArtifact(bba);
} catch (Blackboard.BlackboardException ex) { } catch (Blackboard.BlackboardException ex) {
logger.log(Level.SEVERE, "Unable to index blackboard artifact " + bba.getArtifactID(), ex); //NON-NLS logger.log(Level.SEVERE, "Unable to index blackboard artifact " + bba.getArtifactID(), ex); //NON-NLS
MessageNotifyUtil.Notify.error( MessageNotifyUtil.Notify.error(
Bundle.ExifParserFileIngestModule_indexError_message(), bba.getDisplayName()); Bundle.ExifParserFileIngestModule_indexError_message(), bba.getDisplayName());
}
filesToFire = true;
} }
filesToFire = true;
} }
return ProcessResult.OK; return ProcessResult.OK;
@ -227,13 +235,13 @@ public final class ExifParserFileIngestModule implements FileIngestModule {
logger.log(Level.WARNING, "Failed to create blackboard artifact for exif metadata ({0}).", ex.getLocalizedMessage()); //NON-NLS logger.log(Level.WARNING, "Failed to create blackboard artifact for exif metadata ({0}).", ex.getLocalizedMessage()); //NON-NLS
return ProcessResult.ERROR; return ProcessResult.ERROR;
} catch (ImageProcessingException ex) { } catch (ImageProcessingException ex) {
logger.log(Level.WARNING, String.format("Failed to process the image file '%s/%s' (id=%d).", f.getParentPath(), f.getName(), f.getId()), ex); logger.log(Level.WARNING, String.format("Failed to process the image file '%s/%s' (id=%d).", file.getParentPath(), file.getName(), file.getId()), ex);
return ProcessResult.ERROR; return ProcessResult.ERROR;
} catch (ReadContentInputStreamException ex) { } catch (ReadContentInputStreamException ex) {
logger.log(Level.WARNING, String.format("Error while trying to read image file '%s/%s' (id=%d).", f.getParentPath(), f.getName(), f.getId()), ex); //NON-NLS logger.log(Level.WARNING, String.format("Error while trying to read image file '%s/%s' (id=%d).", file.getParentPath(), file.getName(), file.getId()), ex); //NON-NLS
return ProcessResult.ERROR; return ProcessResult.ERROR;
} catch (IOException ex) { } catch (IOException ex) {
logger.log(Level.WARNING, String.format("IOException when parsing image file '%s/%s' (id=%d).", f.getParentPath(), f.getName(), f.getId()), ex); //NON-NLS logger.log(Level.WARNING, String.format("IOException when parsing image file '%s/%s' (id=%d).", file.getParentPath(), file.getName(), file.getId()), ex); //NON-NLS
return ProcessResult.ERROR; return ProcessResult.ERROR;
} finally { } finally {
try { try {