Sleuth Kit Java Bindings (JNI)  4.3
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-2016 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.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Objects;
28 import java.util.ResourceBundle;
29 
36 public class BlackboardArtifact implements SleuthkitVisitableItem {
37 
38  private static final ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle");
39 
43  public static final class Type implements Serializable {
44 
45  private static final long serialVersionUID = 1L;
46  private final String typeName;
47  private final int typeID;
48  private final String displayName;
49 
57  public Type(int typeID, String typeName, String displayName) {
58  this.typeID = typeID;
59  this.typeName = typeName;
60  this.displayName = displayName;
61  }
62 
68  public Type(ARTIFACT_TYPE type) {
69  this.typeID = type.getTypeID();
70  this.typeName = type.getLabel();
71  this.displayName = type.getDisplayName();
72  }
73 
79  public String getTypeName() {
80  return this.typeName;
81  }
82 
88  public int getTypeID() {
89  return this.typeID;
90  }
91 
97  public String getDisplayName() {
98  return this.displayName;
99  }
100 
101  @Override
102  public boolean equals(Object that) {
103  if (this == that) {
104  return true;
105  } else if (!(that instanceof Type)) {
106  return false;
107  } else {
108  return ((Type) that).sameType(this);
109  }
110  }
111 
119  private boolean sameType(Type that) {
120  return this.typeName.equals(that.getTypeName())
121  && this.displayName.equals(that.getDisplayName())
122  && this.typeID == that.getTypeID();
123  }
124 
125  @Override
126  public int hashCode() {
127  int hash = 11;
128  hash = 83 * hash + Objects.hashCode(this.typeID);
129  hash = 83 * hash + Objects.hashCode(this.displayName);
130  hash = 83 * hash + Objects.hashCode(this.typeName);
131  return hash;
132  }
133  }
134 
140  public enum ARTIFACT_TYPE implements SleuthkitVisitableItem {
141 
142  TSK_GEN_INFO(1, "TSK_GEN_INFO", //NON-NLS
143  bundle.getString("BlackboardArtifact.tskGenInfo.text")),
144  TSK_WEB_BOOKMARK(2, "TSK_WEB_BOOKMARK", //NON-NLS
145  bundle.getString("BlackboardArtifact.tskWebBookmark.text")),
146  TSK_WEB_COOKIE(3, "TSK_WEB_COOKIE", //NON-NLS
147  bundle.getString("BlackboardArtifact.tskWebCookie.text")),
148  TSK_WEB_HISTORY(4, "TSK_WEB_HISTORY", //NON-NLS
149  bundle.getString("BlackboardArtifact.tskWebHistory.text")),
150  TSK_WEB_DOWNLOAD(5, "TSK_WEB_DOWNLOAD", //NON-NLS
151  bundle.getString("BlackboardArtifact.tskWebDownload.text")),
152  TSK_RECENT_OBJECT(6, "TSK_RECENT_OBJ", //NON-NLS
153  bundle.getString("BlackboardArtifact.tsk.recentObject.text")),
154  TSK_GPS_TRACKPOINT(7, "TSK_GPS_TRACKPOINT", //NON-NLS
155  bundle.getString("BlackboardArtifact.tskGpsTrackpoint.text")),
156  TSK_INSTALLED_PROG(8, "TSK_INSTALLED_PROG", //NON-NLS
157  bundle.getString("BlackboardArtifact.tskInstalledProg.text")),
158  TSK_KEYWORD_HIT(9, "TSK_KEYWORD_HIT", //NON-NLS
159  bundle.getString("BlackboardArtifact.tskKeywordHits.text")),
160  TSK_HASHSET_HIT(10, "TSK_HASHSET_HIT", //NON-NLS
161  bundle.getString("BlackboardArtifact.tskHashsetHit.text")),
162  TSK_DEVICE_ATTACHED(11, "TSK_DEVICE_ATTACHED", //NON-NLS
163  bundle.getString("BlackboardArtifact.tskDeviceAttached.text")),
164  TSK_INTERESTING_FILE_HIT(12, "TSK_INTERESTING_FILE_HIT", //NON-NLS
165  bundle.getString("BlackboardArtifact.tskInterestingFileHit.text")),
166  TSK_EMAIL_MSG(13, "TSK_EMAIL_MSG", //NON-NLS
167  bundle.getString("BlackboardArtifact.tskEmailMsg.text")),
168  TSK_EXTRACTED_TEXT(14, "TSK_EXTRACTED_TEXT", //NON-NLS
169  bundle.getString("BlackboardArtifact.tskExtractedText.text")),
170  TSK_WEB_SEARCH_QUERY(15, "TSK_WEB_SEARCH_QUERY", //NON-NLS
171  bundle.getString("BlackboardArtifact.tskWebSearchQuery.text")),
172  TSK_METADATA_EXIF(16, "TSK_METADATA_EXIF", //NON-NLS
173  bundle.getString("BlackboardArtifact.tskMetadataExif.text")),
174  @Deprecated
175  // tags are now added via a special table, not blackboard
176  TSK_TAG_FILE(17, "TSK_TAG_FILE", //NON-NLS
177  bundle.getString("BlackboardArtifact.tagFile.text")),
178  @Deprecated
179  // tags are now added via a special table, not blackboard
180  TSK_TAG_ARTIFACT(18, "TSK_TAG_ARTIFACT", //NON-NLS
181  bundle.getString("BlackboardArtifact.tskTagArtifact.text")),
182  TSK_OS_INFO(19, "TSK_OS_INFO", //NON-NLS
183  bundle.getString("BlackboardArtifact.tskOsInfo.text")),
184  TSK_OS_ACCOUNT(20, "TSK_OS_ACCOUNT", //NON-NLS
185  bundle.getString("BlackboardArtifact.tskOsAccount.text")),
186  TSK_SERVICE_ACCOUNT(21, "TSK_SERVICE_ACCOUNT", //NON-NLS
187  bundle.getString("BlackboardArtifact.tskServiceAccount.text")),
188  @Deprecated
189  // use Case.addReport in Autopsy
190  TSK_TOOL_OUTPUT(22, "TSK_TOOL_OUTPUT", //NON-NLS
191  bundle.getString("BlackboardArtifact.tskToolOutput.text")),
192  TSK_CONTACT(23, "TSK_CONTACT", //NON-NLS
193  bundle.getString("BlackboardArtifact.tskContact.text")),
194  TSK_MESSAGE(24, "TSK_MESSAGE", //NON-NLS
195  bundle.getString("BlackboardArtifact.tskMessage.text")),
196  TSK_CALLLOG(25, "TSK_CALLLOG", //NON-NLS
197  bundle.getString("BlackboardArtifact.tskCalllog.text")),
198  TSK_CALENDAR_ENTRY(26, "TSK_CALENDAR_ENTRY", //NON-NLS
199  bundle.getString("BlackboardArtifact.tskCalendarEntry.text")),
200  TSK_SPEED_DIAL_ENTRY(27, "TSK_SPEED_DIAL_ENTRY", //NON-NLS
201  bundle.getString("BlackboardArtifact.tskSpeedDialEntry.text")),
202  TSK_BLUETOOTH_PAIRING(28, "TSK_BLUETOOTH_PAIRING", //NON-NLS
203  bundle.getString("BlackboardArtifact.tskBluetoothPairing.text")),
204  TSK_GPS_BOOKMARK(29, "TSK_GPS_BOOKMARK", //NON-NLS
205  bundle.getString("BlackboardArtifact.tskGpsBookmark.text")), // GPS Bookmarks
206  TSK_GPS_LAST_KNOWN_LOCATION(30, "TSK_GPS_LAST_KNOWN_LOCATION", //NON-NLS
207  bundle.getString("BlackboardArtifact.tskGpsLastKnownLocation.text")), // GPS Last known location
208  TSK_GPS_SEARCH(31, "TSK_GPS_SEARCH", //NON-NLS
209  bundle.getString("BlackboardArtifact.tskGpsSearch.text")), // GPS Searches
210  TSK_PROG_RUN(32, "TSK_PROG_RUN", //NON-NLS
211  bundle.getString("BlackboardArtifact.tskProgRun.text")),
212  TSK_ENCRYPTION_DETECTED(33, "TSK_ENCRYPTION_DETECTED", //NON-NLS
213  bundle.getString("BlackboardArtifact.tskEncryptionDetected.text")),
214  TSK_EXT_MISMATCH_DETECTED(34, "TSK_EXT_MISMATCH_DETECTED", //NON-NLS
215  bundle.getString("BlackboardArtifact.tskExtMismatchDetected.text")),
216  TSK_INTERESTING_ARTIFACT_HIT(35, "TSK_INTERESTING_ARTIFACT_HIT", //NON-NLS
217  bundle.getString("BlackboardArtifact.tskInterestingArtifactHit.text")), // Any artifact that should be called out
218  TSK_GPS_ROUTE(36, "TSK_GPS_ROUTE", //NON-NLS
219  bundle.getString("BlackboardArtifact.tskGpsRoute.text")), // Route based on GPS coordinates
220  TSK_REMOTE_DRIVE(37, "TSK_REMOTE_DRIVE", //NON-NLS
221  bundle.getString("BlackboardArtifact.tskRemoteDrive.text")),
222  TSK_FACE_DETECTED(38, "TSK_FACE_DETECTED", //NON-NLS
223  bundle.getString("BlackboardArtifact.tskFaceDetected.text")),
224  TSK_ACCOUNT(39, "TSK_ACCOUNT", //NON-NLS
225  bundle.getString("BlackboardArtifact.tskAccount.text"));
226 
227  /*
228  * SEE ABOVE -- KEEP C++ CODE IN SYNC
229  */
230  private final String label;
231  private final int typeID;
232  private final String displayName;
233 
234  private ARTIFACT_TYPE(int typeID, String label, String displayName) {
235  this.typeID = typeID;
236  this.label = label;
237  this.displayName = displayName;
238  }
239 
245  public String getLabel() {
246  return this.label;
247  }
248 
254  public int getTypeID() {
255  return this.typeID;
256  }
257 
266  static public ARTIFACT_TYPE fromLabel(String label) {
267  for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
268  if (v.label.equals(label)) {
269  return v;
270  }
271  }
272  throw new IllegalArgumentException("No ARTIFACT_TYPE matching type: " + label);
273  }
274 
282  static public ARTIFACT_TYPE fromID(int ID) {
283  for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
284  if (v.typeID == ID) {
285  return v;
286  }
287  }
288  throw new IllegalArgumentException("No ARTIFACT_TYPE matching type: " + ID);
289  }
290 
296  public String getDisplayName() {
297  return this.displayName;
298  }
299 
300  @Override
301  public <T> T accept(SleuthkitItemVisitor<T> v) {
302  return v.visit(this);
303  }
304  }
305  private final long artifactID;
306  private final long objID;
307  private final int artifactTypeID;
308  private final String artifactTypeName;
309  private final String displayName;
310  private final ReviewStatus reviewStatus;
312  private final List<BlackboardAttribute> attrsCache = new ArrayList<BlackboardAttribute>();
313  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.
314 
327  BlackboardArtifact(SleuthkitCase sleuthkitCase, long artifactID, long objID, int artifactTypeID, String artifactTypeName, String displayName, ReviewStatus reviewStatus) {
328  this.sleuthkitCase = sleuthkitCase;
329  this.artifactID = artifactID;
330  this.objID = objID;
331  this.artifactTypeID = artifactTypeID;
332  this.artifactTypeName = artifactTypeName;
333  this.displayName = displayName;
334  this.reviewStatus = reviewStatus;
335  }
336 
350  BlackboardArtifact(SleuthkitCase sleuthkitCase, long artifactID, long objID, int artifactTypeID, String artifactTypeName, String displayName, ReviewStatus reviewStatus, boolean isNew) {
352  // If the artifact is new, we don't need to waste a database call later to load the attributes
353  if (isNew) {
354  this.loadedCacheFromDb = true;
355  }
356  }
357 
359  return reviewStatus;
360  }
361 
367  public long getArtifactID() {
368  return this.artifactID;
369  }
370 
376  public long getObjectID() {
377  return this.objID;
378  }
379 
385  public int getArtifactTypeID() {
386  return this.artifactTypeID;
387  }
388 
394  public String getArtifactTypeName() {
395  return this.artifactTypeName;
396  }
397 
403  public String getDisplayName() {
404  return this.displayName;
405  }
406 
416  attr.setArtifactId(artifactID);
417  attr.setCaseDatabase(sleuthkitCase);
418  sleuthkitCase.addBlackboardAttribute(attr, this.artifactTypeID);
419  attrsCache.add(attr);
420  }
421 
431  public void addAttributes(Collection<BlackboardAttribute> attributes) throws TskCoreException {
432  if (attributes.isEmpty()) {
433  return;
434  }
435 
436  for (BlackboardAttribute attr : attributes) {
437  attr.setArtifactId(artifactID);
438  attr.setCaseDatabase(sleuthkitCase);
439  }
440  sleuthkitCase.addBlackboardAttributes(attributes, this.artifactTypeID);
441  attrsCache.addAll(attributes);
442  }
443 
452  public List<BlackboardAttribute> getAttributes() throws TskCoreException {
453  if (loadedCacheFromDb == false) {
454  List<BlackboardAttribute> attrs = sleuthkitCase.getBlackboardAttributes(this);
455  attrsCache.clear();
456  attrsCache.addAll(attrs);
457  loadedCacheFromDb = true;
458  }
459  return attrsCache;
460  }
461 
475  @Deprecated
476  public List<BlackboardAttribute> getAttributes(final BlackboardAttribute.ATTRIBUTE_TYPE attributeType) throws TskCoreException {
477  if (loadedCacheFromDb == false) {
478  List<BlackboardAttribute> attrs = sleuthkitCase.getBlackboardAttributes(this);
479  attrsCache.clear();
480  attrsCache.addAll(attrs);
481  loadedCacheFromDb = true;
482  }
483  ArrayList<BlackboardAttribute> filteredAttributes = new ArrayList<BlackboardAttribute>();
484  for (BlackboardAttribute attr : attrsCache) {
485  if (attr.getAttributeType().getTypeID() == attributeType.getTypeID()) {
486  filteredAttributes.add(attr);
487  }
488  }
489  return filteredAttributes;
490  }
491 
504  List<BlackboardAttribute> attributes = this.getAttributes();
505  for (BlackboardAttribute attribute : attributes) {
506  if (attribute.getAttributeType().equals(attributeType)) {
507  return attribute;
508  }
509  }
510  return null;
511  }
512 
522  @Override
523  public <T> T accept(SleuthkitItemVisitor<T> v) {
524  return v.visit(this);
525  }
526 
533  return sleuthkitCase;
534  }
535 
536  @Override
537  public boolean equals(Object obj) {
538  if (obj == null) {
539  return false;
540  }
541  if (getClass() != obj.getClass()) {
542  return false;
543  }
544  final BlackboardArtifact other = (BlackboardArtifact) obj;
545  if (this.artifactID != other.artifactID) {
546  return false;
547  }
548  return true;
549  }
550 
551  @Override
552  public int hashCode() {
553  int hash = 7;
554  hash = 41 * hash + (int) (this.artifactID ^ (this.artifactID >>> 32));
555  return hash;
556  }
557 
558  @Override
559  public String toString() {
560  return "BlackboardArtifact{" + "artifactID=" + artifactID + ", objID=" + objID + ", artifactTypeID=" + artifactTypeID + ", artifactTypeName=" + artifactTypeName + ", displayName=" + displayName + ", Case=" + sleuthkitCase + '}'; //NON-NLS
561  }
562 
566  public enum ReviewStatus {
567 
568  APPROVED(1, "APPROVED", "ReviewStatus.Approved"), //approved by human user
569  REJECTED(2, "REJECTED", "ReviewStatus.Rejected"), //rejected by humna user
570  UNDECIDED(3, "UNDECIDED", "ReviewStatus.Undecided"); // not yet reviewed by human user
571 
572  private final Integer id;
573  private final String name;
574  private final String displayName;
575 
576  private final static Map<Integer, ReviewStatus> idToStatus = new HashMap<Integer, ReviewStatus>();
577 
578  static {
579  for (ReviewStatus status : values()) {
580  idToStatus.put(status.getID(), status);
581  };
582  }
583 
584  private ReviewStatus(Integer id, String name, String displayNameKey) {
585  this.id = id;
586  this.name = name;
587  this.displayName = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle").getString(displayNameKey);
588  }
589 
597  public static ReviewStatus withID(int id) {
598  return idToStatus.get(id);
599  }
600 
606  public Integer getID() {
607  return id;
608  }
609 
615  String getName() {
616  return name;
617  }
618 
624  public String getDisplayName() {
625  return displayName;
626  }
627  }
628 
644  @Deprecated
645  protected BlackboardArtifact(SleuthkitCase sleuthkitCase, long artifactID, long objID, int artifactTypeID, String artifactTypeName, String displayName) {
647  }
648 }
ArrayList< BlackboardAttribute > getBlackboardAttributes(final BlackboardArtifact artifact)
void addBlackboardAttributes(Collection< BlackboardAttribute > attributes, int artifactTypeId)
Type(int typeID, String typeName, String displayName)
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)
BlackboardAttribute getAttribute(BlackboardAttribute.Type attributeType)
ReviewStatus(Integer id, String name, String displayNameKey)
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.