Sleuth Kit Java Bindings (JNI)  4.6.0
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-2017 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.io.UnsupportedEncodingException;
23 import java.text.MessageFormat;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Objects;
31 import java.util.ResourceBundle;
32 import java.util.Set;
36 
46 public class BlackboardArtifact implements Content {
47 
48  private static final ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle");
49  private final long artifactId;
50  private final long sourceObjId; // refers to objID of parent/source object
51  private final long artifactObjId; // objId of the artifact in tsk_objects. TBD: replace artifactID with this
52  private final long dataSourceObjId; // objId of the data source in tsk_objects.
53  private final int artifactTypeId;
54  private final String artifactTypeName;
55  private final String displayName;
56  private ReviewStatus reviewStatus;
57  private final SleuthkitCase sleuthkitCase;
58  private final List<BlackboardAttribute> attrsCache = new ArrayList<BlackboardAttribute>();
59  private boolean loadedCacheFromDb = false;
60  private Content parent;
61  private String uniquePath;
62 
63  private byte[] contentBytes = null;
64 
65  private volatile boolean checkedHasChildren;
66  private volatile boolean hasChildren;
67  private volatile int childrenCount;
68 
89  BlackboardArtifact(SleuthkitCase sleuthkitCase, long artifactID, long sourceObjId, long artifactObjId, long dataSourceObjId, int artifactTypeID, String artifactTypeName, String displayName, ReviewStatus reviewStatus) {
90 
91  this.sleuthkitCase = sleuthkitCase;
92  this.artifactId = artifactID;
93  this.sourceObjId = sourceObjId;
94  this.artifactObjId = artifactObjId;
95  this.artifactTypeId = artifactTypeID;
96  this.dataSourceObjId = dataSourceObjId;
97  this.artifactTypeName = artifactTypeName;
98  this.displayName = displayName;
99  this.reviewStatus = reviewStatus;
100 
101  this.checkedHasChildren = false;
102  this.hasChildren = false;
103  this.childrenCount = -1;
104 
105  }
106 
126  BlackboardArtifact(SleuthkitCase sleuthkitCase, long artifactID, long sourceObjId, long artifactObjID, long dataSourceObjID, int artifactTypeID, String artifactTypeName, String displayName, ReviewStatus reviewStatus, boolean isNew) {
127  this(sleuthkitCase, artifactID, sourceObjId, artifactObjID, dataSourceObjID, artifactTypeID, artifactTypeName, displayName, reviewStatus);
128  if (isNew) {
129  /*
130  * If this object represents a newly created artifact, then its
131  * collection of attributes has already been populated and there is
132  * no need to fetch them form the case database.
133  */
134  this.loadedCacheFromDb = true;
135  }
136  }
137 
145  return sleuthkitCase;
146  }
147 
153  public long getArtifactID() {
154  return this.artifactId;
155  }
156 
163  public long getObjectID() {
164  return this.sourceObjId;
165  }
166 
172  long getDataSourceObjectID() {
173  return this.dataSourceObjId;
174  }
175 
181  public int getArtifactTypeID() {
182  return this.artifactTypeId;
183  }
184 
190  public String getArtifactTypeName() {
191  return this.artifactTypeName;
192  }
193 
199  public String getDisplayName() {
200  return this.displayName;
201  }
202 
210  public String getShortDescription() throws TskCoreException {
211  BlackboardAttribute attr = null;
212  StringBuilder shortDescription = new StringBuilder("");
213  switch (ARTIFACT_TYPE.fromID(artifactTypeId)) {
214  case TSK_WEB_BOOKMARK: //web_bookmark, web_cookie, web_download, and web_history are the same attribute for now
215  case TSK_WEB_COOKIE:
216  case TSK_WEB_DOWNLOAD:
217  case TSK_WEB_HISTORY:
219  break;
220  case TSK_KEYWORD_HIT:
222  break;
223  case TSK_DEVICE_ATTACHED:
225  break;
226  case TSK_CONTACT: //contact, message, and calllog are the same attributes for now
227  case TSK_MESSAGE:
228  case TSK_CALLLOG:
229  //get the first of these attributes which exists and is non null
230  final ATTRIBUTE_TYPE[] typesThatCanHaveName = {ATTRIBUTE_TYPE.TSK_NAME,
241  ATTRIBUTE_TYPE.TSK_EMAIL_OFFICE}; //in the order we want to use them
242  for (ATTRIBUTE_TYPE t : typesThatCanHaveName) {
243  attr = getAttribute(new BlackboardAttribute.Type(t));
244  if (attr != null && !attr.getDisplayString().isEmpty()) {
245  break;
246  }
247  }
248  break;
249  default:
250  break;
251  }
252  if (attr != null) {
253  shortDescription.append(attr.getAttributeType().getDisplayName()).append(": ").append(attr.getDisplayString());
254  } else {
255  shortDescription.append(getDisplayName());
256  }
257  //get the first of these date attributes which exists and is non null
258  final ATTRIBUTE_TYPE[] typesThatCanHaveDate = {ATTRIBUTE_TYPE.TSK_DATETIME,
265  ATTRIBUTE_TYPE.TSK_DATETIME_END}; //in the order we want to use them
266  BlackboardAttribute date;
267  for (ATTRIBUTE_TYPE t : typesThatCanHaveDate) {
268  date = getAttribute(new BlackboardAttribute.Type(t));
269  if (date != null && !date.getDisplayString().isEmpty()) {
270  shortDescription.append(" ");
271  shortDescription.append(MessageFormat.format(bundle.getString("BlackboardArtifact.shortDescriptionDate.text"), date.getDisplayString())); //NON-NLS
272  break;
273  }
274  }
275  return shortDescription.toString();
276  }
277 
285  return reviewStatus;
286  }
287 
296  public void setReviewStatus(ReviewStatus newStatus) throws TskCoreException {
297  getSleuthkitCase().setReviewStatus(this, newStatus);
298  reviewStatus = newStatus;
299  }
300 
312  public void addAttribute(BlackboardAttribute attribute) throws TskCoreException {
313  attribute.setArtifactId(artifactId);
314  attribute.setCaseDatabase(getSleuthkitCase());
315  getSleuthkitCase().addBlackboardAttribute(attribute, this.artifactTypeId);
316  attrsCache.add(attribute);
317  }
318 
327  public List<BlackboardAttribute> getAttributes() throws TskCoreException {
328  ArrayList<BlackboardAttribute> attributes;
329  if (false == loadedCacheFromDb) {
330  attributes = getSleuthkitCase().getBlackboardAttributes(this);
331  attrsCache.clear();
332  attrsCache.addAll(attributes);
333  loadedCacheFromDb = true;
334  } else {
335  attributes = new ArrayList<BlackboardAttribute>(attrsCache);
336  }
337  return attributes;
338  }
339 
355  List<BlackboardAttribute> attributes = this.getAttributes();
356  for (BlackboardAttribute attribute : attributes) {
357  if (attribute.getAttributeType().equals(attributeType)) {
358  return attribute;
359  }
360  }
361  return null;
362  }
363 
373  public void addAttributes(Collection<BlackboardAttribute> attributes) throws TskCoreException {
374  if (attributes.isEmpty()) {
375  return;
376  }
377  for (BlackboardAttribute attribute : attributes) {
378  attribute.setArtifactId(artifactId);
379  attribute.setCaseDatabase(getSleuthkitCase());
380  }
381  getSleuthkitCase().addBlackboardAttributes(attributes, artifactTypeId);
382  attrsCache.addAll(attributes);
383  }
384 
391  @Override
392  public synchronized String getUniquePath() throws TskCoreException {
393 
394  // Return the path of the parrent file
395  if (uniquePath == null) {
396  uniquePath = "";
397  Content myParent = getParent();
398  if (myParent != null) {
399  uniquePath = myParent.getUniquePath();
400  }
401  }
402  return uniquePath;
403  }
404 
405  @Override
406  public synchronized Content getParent() throws TskCoreException {
407  if (parent == null) {
408  ObjectInfo parentInfo;
409  try {
410  parentInfo = getSleuthkitCase().getParentInfo(this);
411  } catch (TskCoreException ex) {
412  // there is not parent; not an error if we've got a data source
413  return null;
414  }
415  parent = getSleuthkitCase().getContentById(parentInfo.getId());
416  }
417  return parent;
418  }
419 
427  @Override
428  public ArrayList<BlackboardArtifact> getAllArtifacts() throws TskCoreException {
429  // Currently we don't have any artifacts derived from an artifact.
430  return new ArrayList<BlackboardArtifact>();
431  }
432 
443  @Override
444  public ArrayList<BlackboardArtifact> getArtifacts(String artifactTypeName) throws TskCoreException {
445  // Currently we don't have any artifacts derived from an artifact.
446  return new ArrayList<BlackboardArtifact>();
447  }
448 
459  @Override
460  public ArrayList<BlackboardArtifact> getArtifacts(int artifactTypeID) throws TskCoreException {
461  // Currently we don't have any artifacts derived from an artifact.
462  return new ArrayList<BlackboardArtifact>();
463  }
464 
474  @Override
475  public ArrayList<BlackboardArtifact> getArtifacts(BlackboardArtifact.ARTIFACT_TYPE type) throws TskCoreException {
476  // Currently we don't have any artifacts derived from an artifact.
477  return new ArrayList<BlackboardArtifact>();
478  }
479 
487  @Override
488  public long getAllArtifactsCount() throws TskCoreException {
489  // Currently we don't have any artifacts derived from an artifact.
490  return 0;
491  }
492 
503  @Override
504  public long getArtifactsCount(String artifactTypeName) throws TskCoreException {
505  // Currently we don't have any artifacts derived from an artifact.
506  return 0;
507  }
508 
519  @Override
520  public long getArtifactsCount(int artifactTypeID) throws TskCoreException {
521  // Currently we don't have any artifacts derived from an artifact.
522  return 0;
523  }
524 
535  @Override
537  // Currently we don't have any artifacts derived from an artifact.
538  return 0;
539  }
540 
549  @Override
551  // Currently we don't have any artifacts derived from an artifact.
552  return null;
553  }
554 
568  @Override
570  // Currently we don't have any artifacts derived from an artifact.
571  if (create) {
572  throw new TskCoreException("Artifacts of artifacts are not supported.");
573  }
574 
575  return null;
576  }
577 
588  @Override
589  public ArrayList<BlackboardAttribute> getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE attr_type) throws TskCoreException {
590  // Currently we don't have any artifacts derived from an artifact.
591  return new ArrayList<BlackboardAttribute>();
592  }
593 
601  @Override
602  public Set<String> getHashSetNames() throws TskCoreException {
603  // Currently we don't have any artifacts derived from an artifact.
604  return new HashSet<String>();
605  }
606 
618  @Override
619  public BlackboardArtifact newArtifact(int artifactTypeID) throws TskCoreException {
620  throw new TskCoreException("Cannot create artifact of an artifact. Not supported.");
621  }
622 
633  @Override
635  throw new TskCoreException("Cannot create artifact of an artifact. Not supported.");
636  }
637 
646  @Override
647  public <T> T accept(ContentVisitor<T> v) {
648  return v.visit(this);
649  }
650 
658  @Override
659  public boolean equals(Object object) {
660  if (object == null) {
661  return false;
662  }
663  if (getClass() != object.getClass()) {
664  return false;
665  }
666  final BlackboardArtifact other = (BlackboardArtifact) object;
667  return artifactId == other.getArtifactID();
668  }
669 
675  @Override
676  public int hashCode() {
677  int hash = 7;
678  hash = 41 * hash + (int) (this.artifactId ^ (this.artifactId >>> 32));
679  return hash;
680  }
681 
687  @Override
688  public String toString() {
689  return "BlackboardArtifact{" + "artifactID=" + artifactId + ", objID=" + getObjectID() + ", artifactObjID=" + artifactObjId + ", artifactTypeID=" + artifactTypeId + ", artifactTypeName=" + artifactTypeName + ", displayName=" + displayName + ", Case=" + getSleuthkitCase() + '}'; //NON-NLS
690  }
691 
702  @Override
703  public <T> T accept(SleuthkitItemVisitor<T> visitor) {
704  return visitor.visit(this);
705  }
706 
713  @Override
714  public long getSize() {
715 
716  if (contentBytes == null) {
717  try {
718  loadArtifactContent();
719  } catch (TskCoreException ex) {
720  return 0;
721  }
722  }
723 
724  return contentBytes.length;
725  }
726 
730  @Override
731  public void close() {
732  contentBytes = null;
733  }
734 
748  @Override
749  public final int read(byte[] buf, long offset, long len) throws TskCoreException {
750 
751  if (contentBytes == null) {
752  loadArtifactContent();
753  }
754 
755  if (0 == contentBytes.length) {
756  return 0;
757  }
758 
759  // Copy bytes
760  long readLen = Math.min(contentBytes.length - offset, len);
761  System.arraycopy(contentBytes, 0, buf, 0, (int) readLen);
762 
763  return (int) readLen;
764  }
765 
766  @Override
767  public String getName() {
768  return this.displayName + getArtifactID();
769  }
770 
771  @Override
773  Content myParent = getParent();
774  if (myParent == null) {
775  return null;
776  }
777 
778  return myParent.getDataSource();
779  }
780 
787  private void loadArtifactContent() throws TskCoreException {
788  StringBuilder artifactContents = new StringBuilder();
789 
790  Content dataSource = null;
791  try {
792  dataSource = getDataSource();
793  } catch (TskCoreException ex) {
794  throw new TskCoreException("Unable to get datasource for artifact: " + this.toString(), ex);
795  }
796  if (dataSource == null) {
797  throw new TskCoreException("Datasource was null for artifact: " + this.toString());
798  }
799 
800  try {
801  for (BlackboardAttribute attribute : getAttributes()) {
802  artifactContents.append(attribute.getAttributeType().getDisplayName());
803  artifactContents.append(" : ");
804  artifactContents.append(attribute.getDisplayString());
805  artifactContents.append(System.lineSeparator());
806  }
807  } catch (TskCoreException ex) {
808  throw new TskCoreException("Unable to get attributes for artifact: " + this.toString(), ex);
809  }
810 
811  try {
812  contentBytes = artifactContents.toString().getBytes("UTF-8");
813  } catch (UnsupportedEncodingException ex) {
814  throw new TskCoreException("Failed to convert artifact string to bytes for artifact: " + this.toString(), ex);
815  }
816 
817  }
818 
822  public static final class Type implements Serializable {
823 
824  private static final long serialVersionUID = 1L;
825  private final String typeName;
826  private final int typeID;
827  private final String displayName;
828 
836  public Type(int typeID, String typeName, String displayName) {
837  this.typeID = typeID;
838  this.typeName = typeName;
839  this.displayName = displayName;
840  }
841 
847  public Type(ARTIFACT_TYPE type) {
848  this(type.getTypeID(), type.getLabel(), type.getDisplayName());
849  }
850 
856  public String getTypeName() {
857  return this.typeName;
858  }
859 
865  public int getTypeID() {
866  return this.typeID;
867  }
868 
874  public String getDisplayName() {
875  return this.displayName;
876  }
877 
885  @Override
886  public boolean equals(Object that) {
887  if (this == that) {
888  return true;
889  } else if (!(that instanceof Type)) {
890  return false;
891  } else {
892  return ((Type) that).sameType(this);
893  }
894  }
895 
903  private boolean sameType(Type that) {
904  return this.typeName.equals(that.getTypeName())
905  && this.displayName.equals(that.getDisplayName())
906  && this.typeID == that.getTypeID();
907  }
908 
914  @Override
915  public int hashCode() {
916  int hash = 11;
917  hash = 83 * hash + Objects.hashCode(this.typeID);
918  hash = 83 * hash + Objects.hashCode(this.displayName);
919  hash = 83 * hash + Objects.hashCode(this.typeName);
920  return hash;
921  }
922  }
923 
929  public enum ARTIFACT_TYPE implements SleuthkitVisitableItem {
930 
934  TSK_GEN_INFO(1, "TSK_GEN_INFO", //NON-NLS
935  bundle.getString("BlackboardArtifact.tskGenInfo.text")),
939  TSK_WEB_BOOKMARK(2, "TSK_WEB_BOOKMARK", //NON-NLS
940  bundle.getString("BlackboardArtifact.tskWebBookmark.text")),
944  TSK_WEB_COOKIE(3, "TSK_WEB_COOKIE",
945  bundle.getString("BlackboardArtifact.tskWebCookie.text")), //NON-NLS
949  TSK_WEB_HISTORY(4, "TSK_WEB_HISTORY", //NON-NLS
950  bundle.getString("BlackboardArtifact.tskWebHistory.text")),
954  TSK_WEB_DOWNLOAD(5, "TSK_WEB_DOWNLOAD", //NON-NLS
955  bundle.getString("BlackboardArtifact.tskWebDownload.text")),
959  TSK_RECENT_OBJECT(6, "TSK_RECENT_OBJ", //NON-NLS
960  bundle.getString("BlackboardArtifact.tsk.recentObject.text")),
964  TSK_GPS_TRACKPOINT(7, "TSK_GPS_TRACKPOINT", //NON-NLS
965  bundle.getString("BlackboardArtifact.tskGpsTrackpoint.text")),
969  TSK_INSTALLED_PROG(8, "TSK_INSTALLED_PROG", //NON-NLS
970  bundle.getString("BlackboardArtifact.tskInstalledProg.text")),
974  TSK_KEYWORD_HIT(9, "TSK_KEYWORD_HIT",
975  bundle.getString("BlackboardArtifact.tskKeywordHits.text")),
979  TSK_HASHSET_HIT(10, "TSK_HASHSET_HIT", //NON-NLS
980  bundle.getString("BlackboardArtifact.tskHashsetHit.text")),
984  TSK_DEVICE_ATTACHED(11, "TSK_DEVICE_ATTACHED", //NON-NLS
985  bundle.getString("BlackboardArtifact.tskDeviceAttached.text")),
990  TSK_INTERESTING_FILE_HIT(12, "TSK_INTERESTING_FILE_HIT", //NON-NLS
991  bundle.getString("BlackboardArtifact.tskInterestingFileHit.text")),
992 
995  TSK_EMAIL_MSG(13, "TSK_EMAIL_MSG", //NON-NLS
996  bundle.getString("BlackboardArtifact.tskEmailMsg.text")),
1000  TSK_EXTRACTED_TEXT(14, "TSK_EXTRACTED_TEXT", //NON-NLS
1001  bundle.getString("BlackboardArtifact.tskExtractedText.text")),
1005  TSK_WEB_SEARCH_QUERY(15, "TSK_WEB_SEARCH_QUERY", //NON-NLS
1006  bundle.getString("BlackboardArtifact.tskWebSearchQuery.text")),
1010  TSK_METADATA_EXIF(16, "TSK_METADATA_EXIF", //NON-NLS
1011  bundle.getString("BlackboardArtifact.tskMetadataExif.text")),
1017  @Deprecated
1018  TSK_TAG_FILE(17, "TSK_TAG_FILE", //NON-NLS
1019  bundle.getString("BlackboardArtifact.tagFile.text")),
1025  @Deprecated
1026  TSK_TAG_ARTIFACT(18, "TSK_TAG_ARTIFACT", //NON-NLS
1027  bundle.getString("BlackboardArtifact.tskTagArtifact.text")),
1031  TSK_OS_INFO(19, "TSK_OS_INFO", //NON-NLS
1032  bundle.getString("BlackboardArtifact.tskOsInfo.text")),
1036  TSK_OS_ACCOUNT(20, "TSK_OS_ACCOUNT", //NON-NLS
1037  bundle.getString("BlackboardArtifact.tskOsAccount.text")),
1041  TSK_SERVICE_ACCOUNT(21, "TSK_SERVICE_ACCOUNT", //NON-NLS
1042  bundle.getString("BlackboardArtifact.tskServiceAccount.text")),
1048  @Deprecated
1049  TSK_TOOL_OUTPUT(22, "TSK_TOOL_OUTPUT", //NON-NLS
1050  bundle.getString("BlackboardArtifact.tskToolOutput.text")),
1055  TSK_CONTACT(23, "TSK_CONTACT", //NON-NLS
1056  bundle.getString("BlackboardArtifact.tskContact.text")),
1061  TSK_MESSAGE(24, "TSK_MESSAGE", //NON-NLS
1062  bundle.getString("BlackboardArtifact.tskMessage.text")),
1066  TSK_CALLLOG(25, "TSK_CALLLOG", //NON-NLS
1067  bundle.getString("BlackboardArtifact.tskCalllog.text")),
1071  TSK_CALENDAR_ENTRY(26, "TSK_CALENDAR_ENTRY", //NON-NLS
1072  bundle.getString("BlackboardArtifact.tskCalendarEntry.text")),
1076  TSK_SPEED_DIAL_ENTRY(27, "TSK_SPEED_DIAL_ENTRY", //NON-NLS
1077  bundle.getString("BlackboardArtifact.tskSpeedDialEntry.text")),
1081  TSK_BLUETOOTH_PAIRING(28, "TSK_BLUETOOTH_PAIRING", //NON-NLS
1082  bundle.getString("BlackboardArtifact.tskBluetoothPairing.text")),
1086  TSK_GPS_BOOKMARK(29, "TSK_GPS_BOOKMARK", //NON-NLS
1087  bundle.getString("BlackboardArtifact.tskGpsBookmark.text")),
1091  TSK_GPS_LAST_KNOWN_LOCATION(30, "TSK_GPS_LAST_KNOWN_LOCATION", //NON-NLS
1092  bundle.getString("BlackboardArtifact.tskGpsLastKnownLocation.text")),
1096  TSK_GPS_SEARCH(31, "TSK_GPS_SEARCH", //NON-NLS
1097  bundle.getString("BlackboardArtifact.tskGpsSearch.text")),
1101  TSK_PROG_RUN(32, "TSK_PROG_RUN", //NON-NLS
1102  bundle.getString("BlackboardArtifact.tskProgRun.text")),
1106  TSK_ENCRYPTION_DETECTED(33, "TSK_ENCRYPTION_DETECTED", //NON-NLS
1107  bundle.getString("BlackboardArtifact.tskEncryptionDetected.text")),
1111  TSK_EXT_MISMATCH_DETECTED(34, "TSK_EXT_MISMATCH_DETECTED", //NON-NLS
1112  bundle.getString("BlackboardArtifact.tskExtMismatchDetected.text")),
1117  TSK_INTERESTING_ARTIFACT_HIT(35, "TSK_INTERESTING_ARTIFACT_HIT", //NON-NLS
1118  bundle.getString("BlackboardArtifact.tskInterestingArtifactHit.text")),
1122  TSK_GPS_ROUTE(36, "TSK_GPS_ROUTE", //NON-NLS
1123  bundle.getString("BlackboardArtifact.tskGpsRoute.text")),
1127  TSK_REMOTE_DRIVE(37, "TSK_REMOTE_DRIVE", //NON-NLS
1128  bundle.getString("BlackboardArtifact.tskRemoteDrive.text")),
1132  TSK_FACE_DETECTED(38, "TSK_FACE_DETECTED", //NON-NLS
1133  bundle.getString("BlackboardArtifact.tskFaceDetected.text")),
1137  TSK_ACCOUNT(39, "TSK_ACCOUNT", //NON-NLS
1138  bundle.getString("BlackboardArtifact.tskAccount.text")),
1142  TSK_ENCRYPTION_SUSPECTED(40, "TSK_ENCRYPTION_SUSPECTED", //NON-NLS
1143  bundle.getString("BlackboardArtifact.tskEncryptionSuspected.text"));
1144 
1145  private final String label;
1146  private final int typeId;
1147  private final String displayName;
1148 
1156  private ARTIFACT_TYPE(int typeId, String label, String displayName) {
1157  this.typeId = typeId;
1158  this.label = label;
1159  this.displayName = displayName;
1160  }
1161 
1167  public int getTypeID() {
1168  return this.typeId;
1169  }
1170 
1176  public String getLabel() {
1177  return this.label;
1178  }
1179 
1188  static public ARTIFACT_TYPE fromLabel(String label) {
1189  for (ARTIFACT_TYPE value : ARTIFACT_TYPE.values()) {
1190  if (value.getLabel().equals(label)) {
1191  return value;
1192  }
1193  }
1194  throw new IllegalArgumentException("No ARTIFACT_TYPE matching type: " + label);
1195  }
1196 
1205  static public ARTIFACT_TYPE fromID(int id) {
1206  for (ARTIFACT_TYPE value : ARTIFACT_TYPE.values()) {
1207  if (value.getTypeID() == id) {
1208  return value;
1209  }
1210  }
1211  throw new IllegalArgumentException("No ARTIFACT_TYPE matching type: " + id);
1212  }
1213 
1219  public String getDisplayName() {
1220  return displayName;
1221  }
1222 
1234  @Override
1235  public <T> T accept(SleuthkitItemVisitor<T> visitor) {
1236  return visitor.visit(this);
1237  }
1238 
1239  }
1240 
1244  public enum ReviewStatus {
1245 
1246  APPROVED(1, "APPROVED", "ReviewStatus.Approved"), //approved by human user
1247  REJECTED(2, "REJECTED", "ReviewStatus.Rejected"), //rejected by humna user
1248  UNDECIDED(3, "UNDECIDED", "ReviewStatus.Undecided"); // not yet reviewed by human user
1249 
1250  private final Integer id;
1251  private final String name;
1252  private final String displayName;
1253  private final static Map<Integer, ReviewStatus> idToStatus = new HashMap<Integer, ReviewStatus>();
1254 
1255  static {
1256  for (ReviewStatus status : values()) {
1257  idToStatus.put(status.getID(), status);
1258  }
1259  }
1260 
1269  private ReviewStatus(Integer id, String name, String displayNameKey) {
1270  this.id = id;
1271  this.name = name;
1272  this.displayName = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle").getString(displayNameKey);
1273  }
1274 
1282  public static ReviewStatus withID(int id) {
1283  return idToStatus.get(id);
1284  }
1285 
1291  public Integer getID() {
1292  return id;
1293  }
1294 
1300  String getName() {
1301  return name;
1302  }
1303 
1309  public String getDisplayName() {
1310  return displayName;
1311  }
1312  }
1313 
1335  @Deprecated
1336  protected BlackboardArtifact(SleuthkitCase sleuthkitCase, long artifactID, long objID, long artifactObjID, long dataSourceObjId, int artifactTypeID, String artifactTypeName, String displayName) {
1337  this(sleuthkitCase, artifactID, objID, artifactObjID, dataSourceObjId, artifactTypeID, artifactTypeName, displayName, ReviewStatus.UNDECIDED);
1338  }
1339 
1354  @Deprecated
1355  public List<BlackboardAttribute> getAttributes(final BlackboardAttribute.ATTRIBUTE_TYPE attributeType) throws TskCoreException {
1356  if (loadedCacheFromDb == false) {
1357  List<BlackboardAttribute> attrs = getSleuthkitCase().getBlackboardAttributes(this);
1358  attrsCache.clear();
1359  attrsCache.addAll(attrs);
1360  loadedCacheFromDb = true;
1361  }
1362  ArrayList<BlackboardAttribute> filteredAttributes = new ArrayList<BlackboardAttribute>();
1363  for (BlackboardAttribute attr : attrsCache) {
1364  if (attr.getAttributeType().getTypeID() == attributeType.getTypeID()) {
1365  filteredAttributes.add(attr);
1366  }
1367  }
1368  return filteredAttributes;
1369  }
1370 
1371  @Override
1372  public long getId() {
1373  return this.artifactObjId;
1374  }
1375 
1384  @Override
1385  public List<Long> getChildrenIds() throws TskCoreException {
1386  List<Long> childrenIDs = new ArrayList<Long>();
1387  childrenIDs.addAll(getSleuthkitCase().getAbstractFileChildrenIds(this));
1388  childrenIDs.addAll(getSleuthkitCase().getBlackboardArtifactChildrenIds(this));
1389 
1390  return childrenIDs;
1391  }
1392 
1393  @Override
1394  public int getChildrenCount() throws TskCoreException {
1395  if (childrenCount != -1) {
1396  return childrenCount;
1397  }
1398 
1399  childrenCount = this.getSleuthkitCase().getContentChildrenCount(this);
1400 
1401  hasChildren = childrenCount > 0;
1402  checkedHasChildren = true;
1403 
1404  return childrenCount;
1405  }
1406 
1407  @Override
1408  public boolean hasChildren() throws TskCoreException {
1409  if (checkedHasChildren == true) {
1410  return hasChildren;
1411  }
1412 
1413  childrenCount = this.getSleuthkitCase().getContentChildrenCount(this);
1414 
1415  hasChildren = childrenCount > 0;
1416  checkedHasChildren = true;
1417 
1418  return hasChildren;
1419  }
1420 
1429  @Override
1430  public List<Content> getChildren() throws TskCoreException {
1431  List<Content> children = new ArrayList<Content>();
1432  children.addAll(getSleuthkitCase().getAbstractFileChildren(this));
1433  children.addAll(getSleuthkitCase().getBlackboardArtifactChildren(this));
1434 
1435  return children;
1436  }
1437 }
ArrayList< BlackboardArtifact > getArtifacts(int artifactTypeID)
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)
List< BlackboardAttribute > getAttributes(final BlackboardAttribute.ATTRIBUTE_TYPE attributeType)
final int read(byte[] buf, long offset, long len)
void addAttribute(BlackboardAttribute attribute)
ArrayList< BlackboardArtifact > getArtifacts(BlackboardArtifact.ARTIFACT_TYPE type)
public< T > T accept(SleuthkitItemVisitor< T > visitor)
BlackboardArtifact newArtifact(int artifactTypeID)
BlackboardAttribute getAttribute(BlackboardAttribute.Type attributeType)
long getArtifactsCount(String artifactTypeName)
BlackboardArtifact getGenInfoArtifact(boolean create)
ArrayList< BlackboardArtifact > getArtifacts(String artifactTypeName)
BlackboardArtifact(SleuthkitCase sleuthkitCase, long artifactID, long objID, long artifactObjID, long dataSourceObjId, int artifactTypeID, String artifactTypeName, String displayName)
ArrayList< BlackboardArtifact > getAllArtifacts()
long getArtifactsCount(BlackboardArtifact.ARTIFACT_TYPE type)
ArrayList< BlackboardAttribute > getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE attr_type)
BlackboardArtifact newArtifact(BlackboardArtifact.ARTIFACT_TYPE type)
void setReviewStatus(BlackboardArtifact artifact, BlackboardArtifact.ReviewStatus newStatus)

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