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.List;
32 import java.util.Observable;
33 import java.util.Observer;
35 import java.util.logging.Level;
36 import org.openide.nodes.Children;
37 import org.openide.nodes.Node;
38 import org.openide.nodes.Sheet;
39 import org.openide.util.NbBundle;
40 import org.openide.util.WeakListeners;
41 import org.openide.util.lookup.Lookups;
48 import org.
sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
52 import static org.
sleuthkit.datamodel.BlackboardArtifact.Type.TSK_MALWARE;
86 this.filteringDSObjId = objId;
92 return visitor.
visit(
this);
110 Set<Long> getArtifactIds() {
112 return Collections.unmodifiableSet(malwareHits);
116 @SuppressWarnings(
"deprecation")
117 final
void update() {
122 if (skCase == null) {
126 String query =
"SELECT blackboard_artifacts.artifact_obj_id "
127 +
"FROM blackboard_artifacts,tsk_analysis_results WHERE "
128 +
"blackboard_artifacts.artifact_type_id=" + TSK_MALWARE.getTypeID()
129 +
" AND tsk_analysis_results.artifact_obj_id=blackboard_artifacts.artifact_obj_id"
130 +
" AND (tsk_analysis_results.significance=" + Score.Significance.NOTABLE.getId()
131 +
" OR tsk_analysis_results.significance=" + Score.Significance.LIKELY_NOTABLE.getId() +
" )";
132 if (filteringDSObjId > 0) {
133 query +=
" AND blackboard_artifacts.data_source_obj_id = " +
filteringDSObjId;
136 try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
137 ResultSet resultSet = dbQuery.getResultSet();
139 while (resultSet.next()) {
140 long artifactObjId = resultSet.getLong(
"artifact_obj_id");
141 malwareHits.add(artifactObjId);
144 }
catch (TskCoreException | SQLException ex) {
145 logger.log(Level.WARNING,
"SQL Exception occurred: ", ex);
152 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
154 public void propertyChange(PropertyChangeEvent evt) {
155 String eventType = evt.getPropertyName();
172 malwareResults.update();
189 malwareResults.update();
197 if (evt.getNewValue() == null) {
205 private final PropertyChangeListener
weakPcl = WeakListeners.propertyChange(pcl, null);
226 public void update(Observable o, Object arg) {
237 super(Children.create(
new HitFactory(TSK_MALWARE.getDisplayName()),
true),
238 Lookups.singleton(TSK_MALWARE.getDisplayName()),
239 TSK_MALWARE.getDisplayName(),
243 super.setName(TSK_MALWARE.getTypeName());
245 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/artifact-icon.png");
255 return visitor.
visit(
this);
260 Sheet sheet = super.createSheet();
261 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
262 if (sheetSet == null) {
263 sheetSet = Sheet.createPropertiesSet();
267 sheetSet.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"MalwareHits.createSheet.name.name"),
268 NbBundle.getMessage(
this.getClass(),
"MalwareHits.createSheet.name.displayName"),
269 NbBundle.getMessage(
this.getClass(),
"MalwareHits.createSheet.name.desc"),
277 return getClass().getName();
285 void updateDisplayName() {
286 super.setDisplayName(TSK_MALWARE.getDisplayName() +
" (" + malwareResults.getArtifactIds().size() +
")");
295 private final Map<Long, AnalysisResult>
artifactHits =
new HashMap<>();
303 malwareResults.addObserver(
this);
308 malwareResults.deleteObserver(
this);
317 public void update(Observable o, Object arg) {
323 if (skCase != null) {
325 malwareResults.getArtifactIds().forEach((
id) -> {
327 if (!artifactHits.containsKey(
id)) {
328 AnalysisResult art = skCase.getBlackboard().getAnalysisResultById(
id);
332 artifactHits.put(
id, art);
334 }
catch (TskCoreException ex) {
335 logger.log(Level.SEVERE,
"TSK Exception occurred", ex);
338 return new ArrayList<>(artifactHits.values());
340 return Collections.emptyList();
BlackboardArtifact.Type getBlackboardArtifactType()
void update(Observable o, Object arg)
final PropertyChangeListener pcl
void removeIngestModuleEventListener(final PropertyChangeListener listener)
final long filteringDSObjId
static synchronized IngestManager getInstance()
final PropertyChangeListener weakPcl
final MalwareResults malwareResults
final Map< Long, AnalysisResult > artifactHits
Node createNodeForKey(AnalysisResult key)
void removeIngestJobEventListener(final PropertyChangeListener listener)
List< AnalysisResult > makeKeys()
static final Set< IngestManager.IngestModuleEvent > INGEST_MODULE_EVENTS_OF_INTEREST
static final Logger logger
void addIngestJobEventListener(final PropertyChangeListener listener)
MalwareHits(SleuthkitCase skCase, long objId)
T visit(DataSourceFilesNode in)
HitFactory(String nodeName)
void addIngestModuleEventListener(final PropertyChangeListener listener)
MalwareHits(SleuthkitCase skCase)
static final Set< IngestManager.IngestJobEvent > INGEST_JOB_EVENTS_OF_INTEREST
void update(Observable o, Object arg)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
final Set< Long > malwareHits
final long filteringDSObjId
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)