diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 562fc8b605..9c8b009ecd 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -38,8 +38,10 @@ import org.apache.commons.io.FilenameUtils; import org.netbeans.api.progress.ProgressHandle; import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; +import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance; import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet; import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; @@ -52,6 +54,7 @@ import org.sleuthkit.datamodel.HashEntry; import org.sleuthkit.datamodel.HashHitInfo; import org.sleuthkit.datamodel.SleuthkitJNI; import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.datamodel.TskData; /** * This class implements a singleton that manages the set of hash databases used @@ -1279,9 +1282,7 @@ public class HashDbManager implements PropertyChangeListener { */ @Override public boolean isUpdateable() throws TskCoreException { - return false; - // TEMP this will change as soon as adding to the database is supported - // return (! readOnly); + return (! readOnly); } /** @@ -1309,7 +1310,26 @@ public class HashDbManager implements PropertyChangeListener { */ @Override public void addHashes(Content content, String comment) throws TskCoreException { - + // This only works for AbstractFiles and MD5 hashes at present. + assert content instanceof AbstractFile; + if (content instanceof AbstractFile) { + AbstractFile file = (AbstractFile) content; + if (null != file.getMd5Hash()) { + TskData.FileKnown type; + if(knownFilesType.equals(HashDb.KnownFilesType.KNOWN_BAD)){ + type = TskData.FileKnown.BAD; + } else { + type = TskData.FileKnown.KNOWN; + } + EamGlobalFileInstance fileInstance = new EamGlobalFileInstance(centralRepoIndex, file.getMd5Hash(), + type, comment); + try{ + EamDb.getInstance().addReferenceInstance(fileInstance,EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID)); + } catch (EamDbException ex){ + throw new TskCoreException("Error adding hashes to " + getDisplayName(), ex); + } + } + } } /** @@ -1321,7 +1341,23 @@ public class HashDbManager implements PropertyChangeListener { */ @Override public void addHashes(List hashes) throws TskCoreException { + Set globalFileInstances = new HashSet<>(); + for(HashEntry hashEntry:hashes){ + TskData.FileKnown type; + if(knownFilesType.equals(HashDb.KnownFilesType.KNOWN_BAD)){ + type = TskData.FileKnown.BAD; + } else { + type = TskData.FileKnown.KNOWN; + } + globalFileInstances.add(new EamGlobalFileInstance(centralRepoIndex, hashEntry.getMd5Hash(), type, hashEntry.getComment())); + } + try{ + EamDb.getInstance().bulkInsertReferenceTypeEntries(globalFileInstances, + EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID)); + } catch (EamDbException ex){ + throw new TskCoreException("Error adding hashes", ex); + } } /**