Sleuth Kit Java Bindings (JNI)  4.2
Java bindings for using The Sleuth Kit
BlackboardArtifact.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
3  *
4  * Copyright 2011-2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.datamodel;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.ResourceBundle;
25 
32 public class BlackboardArtifact implements SleuthkitVisitableItem {
33 
34  private static final ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle");
35 
42  /* It is very important that this list be kept up to
43  * date and in sync with the C++ code. Do not add
44  * anything here unless you also add it there.
45  * See framework/Services/TskBlackboard.* */
46  public enum ARTIFACT_TYPE implements SleuthkitVisitableItem {
47 
48  TSK_GEN_INFO(1, "TSK_GEN_INFO", //NON-NLS
49  bundle.getString("BlackboardArtifact.tskGenInfo.text")),
50  TSK_WEB_BOOKMARK(2, "TSK_WEB_BOOKMARK", //NON-NLS
51  bundle.getString("BlackboardArtifact.tskWebBookmark.text")),
52  TSK_WEB_COOKIE(3, "TSK_WEB_COOKIE", //NON-NLS
53  bundle.getString("BlackboardArtifact.tskWebCookie.text")),
54  TSK_WEB_HISTORY(4, "TSK_WEB_HISTORY", //NON-NLS
55  bundle.getString("BlackboardArtifact.tskWebHistory.text")),
56  TSK_WEB_DOWNLOAD(5, "TSK_WEB_DOWNLOAD", //NON-NLS
57  bundle.getString("BlackboardArtifact.tskWebDownload.text")),
58  TSK_RECENT_OBJECT(6, "TSK_RECENT_OBJ", //NON-NLS
59  bundle.getString("BlackboardArtifact.tsk.recentObject.text")),
60  TSK_GPS_TRACKPOINT(7, "TSK_GPS_TRACKPOINT", //NON-NLS
61  bundle.getString("BlackboardArtifact.tskGpsTrackpoint.text")),
62  TSK_INSTALLED_PROG(8, "TSK_INSTALLED_PROG", //NON-NLS
63  bundle.getString("BlackboardArtifact.tskInstalledProg.text")),
64  TSK_KEYWORD_HIT(9, "TSK_KEYWORD_HIT", //NON-NLS
65  bundle.getString("BlackboardArtifact.tskKeywordHits.text")),
66  TSK_HASHSET_HIT(10, "TSK_HASHSET_HIT", //NON-NLS
67  bundle.getString("BlackboardArtifact.tskHashsetHit.text")),
68  TSK_DEVICE_ATTACHED(11, "TSK_DEVICE_ATTACHED", //NON-NLS
69  bundle.getString("BlackboardArtifact.tskDeviceAttached.text")),
70  TSK_INTERESTING_FILE_HIT(12, "TSK_INTERESTING_FILE_HIT", //NON-NLS
71  bundle.getString("BlackboardArtifact.tskInterestingFileHit.text")),
72  TSK_EMAIL_MSG(13, "TSK_EMAIL_MSG", //NON-NLS
73  bundle.getString("BlackboardArtifact.tskEmailMsg.text")),
74  TSK_EXTRACTED_TEXT(14, "TSK_EXTRACTED_TEXT", //NON-NLS
75  bundle.getString("BlackboardArtifact.tskExtractedText.text")),
76  TSK_WEB_SEARCH_QUERY(15, "TSK_WEB_SEARCH_QUERY", //NON-NLS
77  bundle.getString("BlackboardArtifact.tskWebSearchQuery.text")),
78  TSK_METADATA_EXIF(16, "TSK_METADATA_EXIF", //NON-NLS
79  bundle.getString("BlackboardArtifact.tskMetadataExif.text")),
80  @Deprecated
81  // tags are now added via a special table, not blackboard
82  TSK_TAG_FILE(17, "TSK_TAG_FILE", //NON-NLS
83  bundle.getString("BlackboardArtifact.tagFile.text")),
84  @Deprecated
85  // tags are now added via a special table, not blackboard
86  TSK_TAG_ARTIFACT(18, "TSK_TAG_ARTIFACT", //NON-NLS
87  bundle.getString("BlackboardArtifact.tskTagArtifact.text")),
88  TSK_OS_INFO(19, "TSK_OS_INFO", //NON-NLS
89  bundle.getString("BlackboardArtifact.tskOsInfo.text")),
90  TSK_OS_ACCOUNT(20, "TSK_OS_ACCOUNT", //NON-NLS
91  bundle.getString("BlackboardArtifact.tskOsAccount.text")),
92  TSK_SERVICE_ACCOUNT(21, "TSK_SERVICE_ACCOUNT", //NON-NLS
93  bundle.getString("BlackboardArtifact.tskServiceAccount.text")),
94  @Deprecated
95  // use Case.addReport in Autopsy
96  TSK_TOOL_OUTPUT(22, "TSK_TOOL_OUTPUT", //NON-NLS
97  bundle.getString("BlackboardArtifact.tskToolOutput.text")),
98  TSK_CONTACT(23, "TSK_CONTACT", //NON-NLS
99  bundle.getString("BlackboardArtifact.tskContact.text")),
100  TSK_MESSAGE(24, "TSK_MESSAGE", //NON-NLS
101  bundle.getString("BlackboardArtifact.tskMessage.text")),
102  TSK_CALLLOG(25, "TSK_CALLLOG", //NON-NLS
103  bundle.getString("BlackboardArtifact.tskCalllog.text")),
104  TSK_CALENDAR_ENTRY(26, "TSK_CALENDAR_ENTRY", //NON-NLS
105  bundle.getString("BlackboardArtifact.tskCalendarEntry.text")),
106  TSK_SPEED_DIAL_ENTRY(27, "TSK_SPEED_DIAL_ENTRY", //NON-NLS
107  bundle.getString("BlackboardArtifact.tskSpeedDialEntry.text")),
108  TSK_BLUETOOTH_PAIRING(28, "TSK_BLUETOOTH_PAIRING", //NON-NLS
109  bundle.getString("BlackboardArtifact.tskBluetoothPairing.text")),
110  TSK_GPS_BOOKMARK(29, "TSK_GPS_BOOKMARK", //NON-NLS
111  bundle.getString("BlackboardArtifact.tskGpsBookmark.text")), // GPS Bookmarks
112  TSK_GPS_LAST_KNOWN_LOCATION(30, "TSK_GPS_LAST_KNOWN_LOCATION", //NON-NLS
113  bundle.getString("BlackboardArtifact.tskGpsLastKnownLocation.text")), // GPS Last known location
114  TSK_GPS_SEARCH(31, "TSK_GPS_SEARCH", //NON-NLS
115  bundle.getString("BlackboardArtifact.tskGpsSearch.text")), // GPS Searches
116  TSK_PROG_RUN(32, "TSK_PROG_RUN", //NON-NLS
117  bundle.getString("BlackboardArtifact.tskProgRun.text")),
118  TSK_ENCRYPTION_DETECTED(33, "TSK_ENCRYPTION_DETECTED", //NON-NLS
119  bundle.getString("BlackboardArtifact.tskEncryptionDetected.text")),
120  TSK_EXT_MISMATCH_DETECTED(34, "TSK_EXT_MISMATCH_DETECTED", //NON-NLS
121  bundle.getString("BlackboardArtifact.tskExtMismatchDetected.text")),
122  TSK_INTERESTING_ARTIFACT_HIT(35, "TSK_INTERESTING_ARTIFACT_HIT", //NON-NLS
123  bundle.getString("BlackboardArtifact.tskInterestingArtifactHit.text")), // Any artifact that should be called out
124  TSK_GPS_ROUTE(36, "TSK_GPS_ROUTE", //NON-NLS
125  bundle.getString("BlackboardArtifact.tskGpsRoute.text")), // Route based on GPS coordinates
126  TSK_REMOTE_DRIVE(37, "TSK_REMOTE_DRIVE", //NON-NLS
127  bundle.getString("BlackboardArtifact.tskRemoteDrive.text")),
128  TSK_FACE_DETECTED(38, "TSK_FACE_DETECTED", //NON-NLS
129  bundle.getString("BlackboardArtifact.tskFaceDetected.text"));
130 
131  /* SEE ABOVE -- KEEP C++ CODE IN SYNC */
132  private final String label;
133  private final int typeID;
134  private final String displayName;
135 
136  private ARTIFACT_TYPE(int typeID, String label, String displayName) {
137  this.typeID = typeID;
138  this.label = label;
139  this.displayName = displayName;
140  }
141 
147  public String getLabel() {
148  return this.label;
149  }
150 
156  public int getTypeID() {
157  return this.typeID;
158  }
159 
166  static public ARTIFACT_TYPE fromLabel(String label) {
167  for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
168  if (v.label.equals(label)) {
169  return v;
170  }
171  }
172  throw new IllegalArgumentException("No ARTIFACT_TYPE matching type: " + label);
173  }
174 
181  static public ARTIFACT_TYPE fromID(int ID) {
182  for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
183  if (v.typeID == ID) {
184  return v;
185  }
186  }
187  throw new IllegalArgumentException("No ARTIFACT_TYPE matching type: " + ID);
188  }
189 
195  public String getDisplayName() {
196  return this.displayName;
197  }
198 
199  @Override
200  public <T> T accept(SleuthkitItemVisitor<T> v) {
201  return v.visit(this);
202  }
203  }
204  private final long artifactID;
205  private final long objID;
206  private final int artifactTypeID;
207  private final String artifactTypeName;
208  private final String displayName;
210  private final List<BlackboardAttribute> attrsCache = new ArrayList<BlackboardAttribute>();
211  private boolean loadedCacheFromDb = false; // true once we've gone to the DB to fill in the attrsCache. Until it is set, it may not be complete.
212 
224  protected BlackboardArtifact(SleuthkitCase sleuthkitCase, long artifactID, long objID, int artifactTypeID, String artifactTypeName, String displayName) {
225  this.sleuthkitCase = sleuthkitCase;
226  this.artifactID = artifactID;
227  this.objID = objID;
228  this.artifactTypeID = artifactTypeID;
229  this.artifactTypeName = artifactTypeName;
230  this.displayName = displayName;
231  }
232 
245  BlackboardArtifact(SleuthkitCase sleuthkitCase, long artifactID, long objID, int artifactTypeID, String artifactTypeName, String displayName, boolean isNew) {
246  this.sleuthkitCase = sleuthkitCase;
247  this.artifactID = artifactID;
248  this.objID = objID;
249  this.artifactTypeID = artifactTypeID;
250  this.artifactTypeName = artifactTypeName;
251  this.displayName = displayName;
252 
253  // If the artifact is new, we don't need to waste a database call later to load the attributes
254  if (isNew) {
255  this.loadedCacheFromDb = true;
256  }
257  }
258 
264  public long getArtifactID() {
265  return this.artifactID;
266  }
267 
273  public long getObjectID() {
274  return this.objID;
275  }
276 
282  public int getArtifactTypeID() {
283  return this.artifactTypeID;
284  }
285 
291  public String getArtifactTypeName() {
292  return this.artifactTypeName;
293  }
294 
300  public String getDisplayName() {
301  return this.displayName;
302  }
303 
312  attr.setArtifactID(artifactID);
313  attr.setCase(sleuthkitCase);
314  sleuthkitCase.addBlackboardAttribute(attr, this.artifactTypeID);
315  attrsCache.add(attr);
316  }
317 
326  public void addAttributes(Collection<BlackboardAttribute> attributes) throws TskCoreException {
327  if (attributes.isEmpty()) {
328  return;
329  }
330 
331  for (BlackboardAttribute attr : attributes) {
332  attr.setArtifactID(artifactID);
333  attr.setCase(sleuthkitCase);
334  }
335  sleuthkitCase.addBlackboardAttributes(attributes, this.artifactTypeID);
336  attrsCache.addAll(attributes);
337  }
338 
346  public List<BlackboardAttribute> getAttributes() throws TskCoreException {
347  if (loadedCacheFromDb == false) {
348  List<BlackboardAttribute> attrs = sleuthkitCase.getBlackboardAttributes(this);
349  attrsCache.clear();
350  attrsCache.addAll(attrs);
351  loadedCacheFromDb = true;
352  }
353  return attrsCache;
354  }
355 
365  public List<BlackboardAttribute> getAttributes(final BlackboardAttribute.ATTRIBUTE_TYPE attributeType) throws TskCoreException {
366  if (loadedCacheFromDb == false) {
367  List<BlackboardAttribute> attrs = sleuthkitCase.getBlackboardAttributes(this);
368  attrsCache.clear();
369  attrsCache.addAll(attrs);
370  loadedCacheFromDb = true;
371  }
372  ArrayList<BlackboardAttribute> filteredAttributes = new ArrayList<BlackboardAttribute>();
373  for (BlackboardAttribute attr : attrsCache) {
374  if (attr.getAttributeTypeID() == attributeType.getTypeID()) {
375  filteredAttributes.add(attr);
376  }
377  }
378  return filteredAttributes;
379  }
380 
389  @Override
390  public <T> T accept(SleuthkitItemVisitor<T> v) {
391  return v.visit(this);
392  }
393 
400  return sleuthkitCase;
401  }
402 
403  @Override
404  public boolean equals(Object obj) {
405  if (obj == null) {
406  return false;
407  }
408  if (getClass() != obj.getClass()) {
409  return false;
410  }
411  final BlackboardArtifact other = (BlackboardArtifact) obj;
412  if (this.artifactID != other.artifactID) {
413  return false;
414  }
415  return true;
416  }
417 
418  @Override
419  public int hashCode() {
420  int hash = 7;
421  hash = 41 * hash + (int) (this.artifactID ^ (this.artifactID >>> 32));
422  return hash;
423  }
424 
425  @Override
426  public String toString() {
427  return "BlackboardArtifact{" + "artifactID=" + artifactID + ", objID=" + objID + ", artifactTypeID=" + artifactTypeID + ", artifactTypeName=" + artifactTypeName + ", displayName=" + displayName + ", Case=" + sleuthkitCase + '}'; //NON-NLS
428  }
429 }
ArrayList< BlackboardAttribute > getBlackboardAttributes(final BlackboardArtifact artifact)
void addBlackboardAttributes(Collection< BlackboardAttribute > attributes, int artifactTypeId)
void addAttributes(Collection< BlackboardAttribute > attributes)
void addBlackboardAttribute(BlackboardAttribute attr, int artifactTypeId)
public< T > T accept(SleuthkitItemVisitor< T > v)
List< BlackboardAttribute > getAttributes(final BlackboardAttribute.ATTRIBUTE_TYPE attributeType)
void addAttribute(BlackboardAttribute attr)
BlackboardArtifact(SleuthkitCase sleuthkitCase, long artifactID, long objID, int artifactTypeID, String artifactTypeName, String displayName)
final List< BlackboardAttribute > attrsCache
ARTIFACT_TYPE(int typeID, String label, String displayName)

Copyright © 2011-2015 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.