19 package org.sleuthkit.autopsy.datamodel;
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.sql.ResultSet;
24 import java.sql.SQLException;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.EnumSet;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.LinkedHashMap;
31 import java.util.List;
33 import java.util.Observable;
34 import java.util.Observer;
36 import java.util.logging.Level;
37 import org.openide.nodes.ChildFactory;
38 import org.openide.nodes.Children;
39 import org.openide.nodes.Node;
40 import org.openide.nodes.Sheet;
41 import org.openide.util.NbBundle;
42 import org.openide.util.lookup.Lookups;
49 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
50 import org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
52 import org.
sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
60 private static final String
HASHSET_HITS = BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getLabel();
61 private static final String
DISPLAY_NAME = BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getDisplayName();
88 this.filteringDSObjId = objId;
94 return visitor.
visit(
this);
111 List<String> getSetNames() {
114 names =
new ArrayList<>(hashSetHitsMap.keySet());
116 Collections.sort(names);
120 Set<Long> getArtifactIds(String hashSetName) {
122 return hashSetHitsMap.get(hashSetName);
126 @SuppressWarnings(
"deprecation")
127 final
void update() {
129 hashSetHitsMap.clear();
132 if (skCase == null) {
136 int setNameId = ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID();
137 int artId = ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID();
138 String query =
"SELECT value_text,blackboard_attributes.artifact_id,attribute_type_id "
139 +
"FROM blackboard_attributes,blackboard_artifacts WHERE "
140 +
"attribute_type_id=" + setNameId
141 +
" AND blackboard_attributes.artifact_id=blackboard_artifacts.artifact_id"
142 +
" AND blackboard_artifacts.artifact_type_id=" + artId;
143 if (filteringDSObjId > 0) {
144 query +=
" AND blackboard_artifacts.data_source_obj_id = " +
filteringDSObjId;
147 try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
148 ResultSet resultSet = dbQuery.getResultSet();
150 while (resultSet.next()) {
151 String setName = resultSet.getString(
"value_text");
152 long artifactId = resultSet.getLong(
"artifact_id");
153 if (!hashSetHitsMap.containsKey(setName)) {
154 hashSetHitsMap.put(setName,
new HashSet<>());
156 hashSetHitsMap.get(setName).add(artifactId);
159 }
catch (TskCoreException | SQLException ex) {
160 logger.log(Level.WARNING,
"SQL Exception occurred: ", ex);
174 super(Children.create(
new HashsetNameFactory(),
true), Lookups.singleton(DISPLAY_NAME));
175 super.setName(HASHSET_HITS);
176 super.setDisplayName(DISPLAY_NAME);
177 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/hashset_hits.png");
187 return visitor.
visit(
this);
192 Sheet sheet = super.createSheet();
193 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
194 if (sheetSet == null) {
195 sheetSet = Sheet.createPropertiesSet();
199 sheetSet.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.name"),
200 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.displayName"),
201 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.desc"),
209 return getClass().getName();
223 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
225 public void propertyChange(PropertyChangeEvent evt) {
226 String eventType = evt.getPropertyName();
242 if (null != eventData && eventData.
getBlackboardArtifactType().getTypeID() == ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID()) {
243 hashsetResults.update();
260 hashsetResults.update();
268 if (evt.getNewValue() == null) {
281 hashsetResults.update();
282 hashsetResults.addObserver(
this);
290 hashsetResults.deleteObserver(
this);
295 list.addAll(hashsetResults.getSetNames());
305 public void update(Observable o, Object arg) {
318 super(Children.create(
new HitFactory(hashSetName),
true), Lookups.singleton(hashSetName));
319 super.setName(hashSetName);
322 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/hashset_hits.png");
323 hashsetResults.addObserver(
this);
330 super.setDisplayName(hashSetName +
" (" + hashsetResults.getArtifactIds(hashSetName).size() +
")");
340 Sheet sheet = super.createSheet();
341 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
342 if (sheetSet == null) {
343 sheetSet = Sheet.createPropertiesSet();
347 sheetSet.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.name"),
348 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.displayName"),
349 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.desc"),
357 return visitor.
visit(
this);
361 public void update(Observable o, Object arg) {
371 return getClass().getName();
381 private final Map<Long, BlackboardArtifact>
artifactHits =
new HashMap<>();
390 hashsetResults.addObserver(
this);
395 hashsetResults.deleteObserver(
this);
404 public void update(Observable o, Object arg) {
410 if (skCase != null) {
412 hashsetResults.getArtifactIds(hashsetName).forEach((
id) -> {
414 if (!artifactHits.containsKey(
id)) {
415 BlackboardArtifact art = skCase.getBlackboardArtifact(
id);
416 artifactHits.put(
id, art);
418 }
catch (TskCoreException ex) {
419 logger.log(Level.SEVERE,
"TSK Exception occurred", ex);
422 return new ArrayList<>(artifactHits.values());
424 return Collections.emptyList();
BlackboardArtifact.Type getBlackboardArtifactType()
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
HashsetNameNode(String hashSetName)
static final String DISPLAY_NAME
final Map< Long, BlackboardArtifact > artifactHits
static final Set< IngestManager.IngestModuleEvent > INGEST_MODULE_EVENTS_OF_INTEREST
HitFactory(String hashsetName)
boolean createKeys(List< String > list)
Node createNodeForKey(String key)
static final String HASHSET_HITS
static final Logger logger
T visit(DataSourcesNode in)
void update(Observable o, Object arg)
HashsetHits(SleuthkitCase skCase)
void removeIngestJobEventListener(final PropertyChangeListener listener)
final long filteringDSObjId
List< BlackboardArtifact > makeKeys()
void addIngestJobEventListener(final PropertyChangeListener listener)
static final Set< IngestManager.IngestJobEvent > INGEST_JOB_EVENTS_OF_INTEREST
final Map< String, Set< Long > > hashSetHitsMap
void update(Observable o, Object arg)
final PropertyChangeListener pcl
Node createNodeForKey(BlackboardArtifact key)
void addIngestModuleEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
void update(Observable o, Object arg)
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
final HashsetResults hashsetResults
HashsetHits(SleuthkitCase skCase, long objId)