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.WeakListeners;
43 import org.openide.util.lookup.Lookups;
50 import static org.
sleuthkit.datamodel.BlackboardArtifact.Type.TSK_HASHSET_HIT;
51 import org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
53 import org.
sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
63 private static final String
HASHSET_HITS = BlackboardArtifact.Type.TSK_HASHSET_HIT.getTypeName();
64 private static final String
DISPLAY_NAME = BlackboardArtifact.Type.TSK_HASHSET_HIT.getDisplayName();
91 this.filteringDSObjId = objId;
97 return visitor.
visit(
this);
114 List<String> getSetNames() {
117 names =
new ArrayList<>(hashSetHitsMap.keySet());
119 Collections.sort(names);
123 Set<Long> getArtifactIds(String hashSetName) {
125 return hashSetHitsMap.get(hashSetName);
129 @SuppressWarnings(
"deprecation")
130 final
void update() {
132 hashSetHitsMap.clear();
135 if (skCase == null) {
139 int setNameId = ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID();
140 int artId = TSK_HASHSET_HIT.getTypeID();
141 String query =
"SELECT value_text,blackboard_artifacts.artifact_obj_id,attribute_type_id "
142 +
"FROM blackboard_attributes,blackboard_artifacts WHERE "
143 +
"attribute_type_id=" + setNameId
144 +
" AND blackboard_attributes.artifact_id=blackboard_artifacts.artifact_id"
145 +
" AND blackboard_artifacts.artifact_type_id=" + artId;
146 if (filteringDSObjId > 0) {
147 query +=
" AND blackboard_artifacts.data_source_obj_id = " +
filteringDSObjId;
150 try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
151 ResultSet resultSet = dbQuery.getResultSet();
153 while (resultSet.next()) {
154 String setName = resultSet.getString(
"value_text");
155 long artifactObjId = resultSet.getLong(
"artifact_obj_id");
156 if (!hashSetHitsMap.containsKey(setName)) {
157 hashSetHitsMap.put(setName,
new HashSet<>());
159 hashSetHitsMap.get(setName).add(artifactObjId);
162 }
catch (TskCoreException | SQLException ex) {
163 logger.log(Level.WARNING,
"SQL Exception occurred: ", ex);
178 Lookups.singleton(DISPLAY_NAME),
183 super.setName(HASHSET_HITS);
184 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/hashset_hits.png");
194 return visitor.
visit(
this);
199 Sheet sheet = super.createSheet();
200 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
201 if (sheetSet == null) {
202 sheetSet = Sheet.createPropertiesSet();
206 sheetSet.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.name"),
207 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.displayName"),
208 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.desc"),
216 return getClass().getName();
230 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
232 public void propertyChange(PropertyChangeEvent evt) {
233 String eventType = evt.getPropertyName();
250 hashsetResults.update();
267 hashsetResults.update();
275 if (evt.getNewValue() == null) {
283 private final PropertyChangeListener
weakPcl = WeakListeners.propertyChange(pcl, null);
290 hashsetResults.update();
291 hashsetResults.addObserver(
this);
300 hashsetResults.deleteObserver(
this);
305 list.addAll(hashsetResults.getSetNames());
315 public void update(Observable o, Object arg) {
328 super(Children.create(
new HitFactory(hashSetName),
true), Lookups.singleton(hashSetName));
329 super.setName(hashSetName);
332 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/hashset_hits.png");
333 hashsetResults.addObserver(
this);
340 super.setDisplayName(hashSetName +
" (" + hashsetResults.getArtifactIds(hashSetName).size() +
")");
350 Sheet sheet = super.createSheet();
351 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
352 if (sheetSet == null) {
353 sheetSet = Sheet.createPropertiesSet();
357 sheetSet.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.name"),
358 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.displayName"),
359 NbBundle.getMessage(
this.getClass(),
"HashsetHits.createSheet.name.desc"),
367 return visitor.
visit(
this);
371 public void update(Observable o, Object arg) {
381 return getClass().getName();
391 private final Map<Long, AnalysisResult>
artifactHits =
new HashMap<>();
400 hashsetResults.addObserver(
this);
405 hashsetResults.deleteObserver(
this);
414 public void update(Observable o, Object arg) {
420 if (skCase != null) {
422 hashsetResults.getArtifactIds(hashsetName).forEach((
id) -> {
424 if (!artifactHits.containsKey(
id)) {
425 AnalysisResult art = skCase.getBlackboard().getAnalysisResultById(
id);
429 artifactHits.put(
id, art);
431 }
catch (TskCoreException ex) {
432 logger.log(Level.SEVERE,
"TSK Exception occurred", ex);
435 return new ArrayList<>(artifactHits.values());
437 return Collections.emptyList();
BlackboardArtifact.Type getBlackboardArtifactType()
void removeIngestModuleEventListener(final PropertyChangeListener listener)
final long filteringDSObjId
static synchronized IngestManager getInstance()
HashsetNameNode(String hashSetName)
List< AnalysisResult > makeKeys()
static final String DISPLAY_NAME
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
void update(Observable o, Object arg)
HashsetHits(SleuthkitCase skCase)
void removeIngestJobEventListener(final PropertyChangeListener listener)
Node createNodeForKey(AnalysisResult key)
final long filteringDSObjId
final PropertyChangeListener weakPcl
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
T visit(DataSourceFilesNode in)
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 Map< Long, AnalysisResult > artifactHits
final HashsetResults hashsetResults
HashsetHits(SleuthkitCase skCase, long objId)