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.HashSet;
28 import java.util.LinkedHashMap;
29 import java.util.List;
31 import java.util.Observable;
32 import java.util.Observer;
34 import java.util.logging.Level;
35 import org.openide.nodes.ChildFactory;
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.lookup.Lookups;
63 .getMessage(
KeywordHits.class,
"KeywordHits.simpleLiteralSearch.text");
65 .getMessage(
KeywordHits.class,
"KeywordHits.singleRegexSearch.text");
75 private final Map<String, Map<String, Set<Long>>>
topLevelMap;
78 topLevelMap =
new LinkedHashMap<>();
82 List<String> getListNames() {
83 List <String> names =
new ArrayList<>(topLevelMap.keySet());
90 List<String> getKeywords(String listName) {
91 List <String> keywords =
new ArrayList<>(topLevelMap.get(listName).keySet());
92 Collections.sort(keywords);
96 Set<Long> getArtifactIds(String listName, String keyword) {
97 return topLevelMap.get(listName).get(keyword);
101 void populateMaps(Map<Long, Map<Long, String>> artifactIds) {
105 Map<String, Map<String, Set<Long>>> listsMap =
new LinkedHashMap<>();
108 Map<String, Set<Long>> literalMap =
new LinkedHashMap<>();
111 Map<String, Set<Long>> regexMap =
new LinkedHashMap<>();
114 topLevelMap.put(SIMPLE_LITERAL_SEARCH, literalMap);
115 topLevelMap.put(SIMPLE_REGEX_SEARCH, regexMap);
117 for (Map.Entry<Long, Map<Long, String>> art : artifactIds.entrySet()) {
118 long id = art.getKey();
119 Map<Long, String> attributes = art.getValue();
122 String listName = attributes.get(Long.valueOf(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID()));
123 String word = attributes.get(Long.valueOf(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD.getTypeID()));
124 String reg = attributes.get(Long.valueOf(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_REGEXP.getTypeID()));
127 if (listName != null) {
128 if (listsMap.containsKey(listName) ==
false) {
129 listsMap.put(listName,
new LinkedHashMap<String, Set<Long>>());
132 Map<String, Set<Long>> listMap = listsMap.get(listName);
133 if (listMap.containsKey(word) ==
false) {
134 listMap.put(word,
new HashSet<Long>());
137 listMap.get(word).add(
id);
140 else if (reg != null) {
141 if (regexMap.containsKey(reg) ==
false) {
142 regexMap.put(reg,
new HashSet<Long>());
144 regexMap.get(reg).add(
id);
148 if (literalMap.containsKey(word) ==
false) {
149 literalMap.put(word,
new HashSet<Long>());
151 literalMap.get(word).add(
id);
153 topLevelMap.putAll(listsMap);
159 @SuppressWarnings(
"deprecation")
161 Map<Long, Map<Long, String>> artifactIds =
new LinkedHashMap<>();
163 if (skCase == null) {
171 String query =
"SELECT blackboard_attributes.value_text,blackboard_attributes.artifact_id,"
172 +
"blackboard_attributes.attribute_type_id FROM blackboard_attributes,blackboard_artifacts WHERE "
173 +
"(blackboard_attributes.artifact_id=blackboard_artifacts.artifact_id AND "
174 +
"blackboard_artifacts.artifact_type_id=" + artId
175 +
") AND (attribute_type_id=" + setId +
" OR "
176 +
"attribute_type_id=" + wordId +
" OR "
177 +
"attribute_type_id=" + regexId +
")";
180 ResultSet resultSet = dbQuery.getResultSet();
181 while (resultSet.next()) {
182 String value = resultSet.getString(
"value_text");
183 long artifactId = resultSet.getLong(
"artifact_id");
184 long typeId = resultSet.getLong(
"attribute_type_id");
185 if (!artifactIds.containsKey(artifactId)) {
186 artifactIds.put(artifactId,
new LinkedHashMap<Long, String>());
188 if (!value.equals(
"")) {
189 artifactIds.get(artifactId).put(typeId, value);
193 logger.log(Level.WARNING,
"SQL Exception occurred: ", ex);
196 populateMaps(artifactIds);
201 public <T> T accept(AutopsyItemVisitor<T> v) {
202 return v.visit(
this);
209 super(Children.create(
new ListFactory(),
true), Lookups.singleton(KEYWORD_HITS));
211 super.setDisplayName(KEYWORD_HITS);
212 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/keyword_hits.png");
222 return v.
visit(
this);
227 Sheet s = super.createSheet();
228 Sheet.Set ss = s.get(Sheet.PROPERTIES);
230 ss = Sheet.createPropertiesSet();
234 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.name.name"),
235 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.name.displayName"),
236 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.name.desc"),
243 private class ListFactory extends ChildFactory.Detachable<String> implements Observer {
245 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
247 public void propertyChange(PropertyChangeEvent evt) {
248 String eventType = evt.getPropertyName();
261 if (evt.getNewValue() == null) {
275 keywordResults.addObserver(
this);
283 keywordResults.deleteObserver(
this);
288 list.addAll(keywordResults.getListNames());
298 public void update(Observable o, Object arg) {
307 super(Children.create(
new TermFactory(listName),
true), Lookups.singleton(listName));
308 super.setName(listName);
309 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/keyword_hits.png");
312 keywordResults.addObserver(
this);
316 int totalDescendants = 0;
317 for (String word : keywordResults.getKeywords(listName)) {
318 Set<Long> ids = keywordResults.getArtifactIds(listName, word);
319 totalDescendants += ids.size();
321 super.setDisplayName(listName +
" (" + totalDescendants +
")");
326 Sheet s = super.createSheet();
327 Sheet.Set ss = s.get(Sheet.PROPERTIES);
329 ss = Sheet.createPropertiesSet();
333 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.listName.name"),
334 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.listName.displayName"),
335 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.listName.desc"),
339 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.numChildren.name"),
340 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.numChildren.displayName"),
341 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.numChildren.desc"),
342 keywordResults.getKeywords(listName).size()));
354 return v.
visit(
this);
358 public void update(Observable o, Object arg) {
363 private class TermFactory extends ChildFactory.Detachable<String> implements Observer {
373 keywordResults.addObserver(
this);
378 keywordResults.deleteObserver(
this);
383 list.addAll(keywordResults.getKeywords(setName));
393 public void update(Observable o, Object arg) {
404 super(Children.create(
new HitsFactory (setName, keyword),
true), Lookups.singleton(keyword));
405 super.setName(keyword);
408 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/keyword_hits.png");
410 keywordResults.addObserver(
this);
414 super.setDisplayName(keyword +
" (" + keywordResults.getArtifactIds(setName, keyword).size() +
")");
419 public void update(Observable o, Object arg) {
430 return v.
visit(
this);
435 Sheet s = super.createSheet();
436 Sheet.Set ss = s.get(Sheet.PROPERTIES);
438 ss = Sheet.createPropertiesSet();
442 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.listName.name"),
443 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.listName.displayName"),
444 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.listName.desc"),
447 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.filesWithHits.name"),
448 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.filesWithHits.displayName"),
449 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createSheet.filesWithHits.desc"),
450 keywordResults.getArtifactIds(setName, keyword).size()));
456 public class HitsFactory extends ChildFactory.Detachable<Long> implements Observer {
468 keywordResults.addObserver(
this);
473 keywordResults.deleteObserver(
this);
478 list.addAll(keywordResults.getArtifactIds(setName, keyword));
485 if (skCase == null) {
496 logger.log(Level.SEVERE,
"TskCoreException while constructing BlackboardArtifact Node from KeywordHitsKeywordChildren");
507 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createNodeForKey.modTime.name"),
508 NbBundle.getMessage(
this.getClass(),
509 "KeywordHits.createNodeForKey.modTime.displayName"),
510 NbBundle.getMessage(
this.getClass(),
511 "KeywordHits.createNodeForKey.modTime.desc"),
514 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createNodeForKey.accessTime.name"),
515 NbBundle.getMessage(
this.getClass(),
516 "KeywordHits.createNodeForKey.accessTime.displayName"),
517 NbBundle.getMessage(
this.getClass(),
518 "KeywordHits.createNodeForKey.accessTime.desc"),
521 NbBundle.getMessage(
this.getClass(),
"KeywordHits.createNodeForKey.chgTime.name"),
522 NbBundle.getMessage(
this.getClass(),
523 "KeywordHits.createNodeForKey.chgTime.displayName"),
524 NbBundle.getMessage(
this.getClass(),
525 "KeywordHits.createNodeForKey.chgTime.desc"),
529 logger.log(Level.WARNING,
"TSK Exception occurred", ex);
535 public void update(Observable o, Object arg) {
final PropertyChangeListener pcl
KeywordHits(SleuthkitCase skCase)
static final String KEYWORD_HITS
void removeIngestModuleEventListener(final PropertyChangeListener listener)
void update(Observable o, Object arg)
static String getStringTime(long epochSeconds, TimeZone tzone)
Node createNodeForKey(String key)
static synchronized IngestManager getInstance()
void update(Observable o, Object arg)
final KeywordResults keywordResults
void update(Observable o, Object arg)
static final String SIMPLE_REGEX_SEARCH
TermFactory(String setName)
BlackboardArtifact getBlackboardArtifact(long artifactID)
T visit(DataSourcesNode in)
final Map< String, Map< String, Set< Long > > > topLevelMap
AbstractFile getAbstractFileById(long id)
boolean createKeys(List< String > list)
void removeIngestJobEventListener(final PropertyChangeListener listener)
TermNode(String setName, String keyword)
boolean createKeys(List< String > list)
void update(Observable o, Object arg)
void addIngestJobEventListener(final PropertyChangeListener listener)
Node createNodeForKey(Long artifactId)
Node createNodeForKey(String key)
ListNode(String listName)
boolean createKeys(List< Long > list)
static final Logger logger
static synchronized void removePropertyChangeListener(PropertyChangeListener listener)
void addIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized void addPropertyChangeListener(PropertyChangeListener listener)
static final String SIMPLE_LITERAL_SEARCH
static Logger getLogger(String name)
void update(Observable o, Object arg)
HitsFactory(String setName, String keyword)
CaseDbQuery executeQuery(String query)