19 package org.sleuthkit.datamodel;
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;
30 import java.util.Objects;
31 import java.util.ResourceBundle;
48 private static final ResourceBundle bundle = ResourceBundle.getBundle(
"org.sleuthkit.datamodel.Bundle");
49 private final long artifactId;
50 private final long sourceObjId;
51 private final long artifactObjId;
52 private final long dataSourceObjId;
53 private final int artifactTypeId;
54 private final String artifactTypeName;
55 private final String displayName;
58 private final List<BlackboardAttribute> attrsCache =
new ArrayList<BlackboardAttribute>();
59 private boolean loadedCacheFromDb =
false;
61 private String uniquePath;
63 private byte[] contentBytes = null;
65 private volatile boolean checkedHasChildren;
67 private volatile int childrenCount;
89 BlackboardArtifact(
SleuthkitCase sleuthkitCase,
long artifactID,
long sourceObjId,
long artifactObjId,
long dataSourceObjId,
int artifactTypeID, String artifactTypeName, String displayName,
ReviewStatus reviewStatus) {
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;
101 this.checkedHasChildren =
false;
102 this.hasChildren =
false;
103 this.childrenCount = -1;
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);
134 this.loadedCacheFromDb =
true;
145 return sleuthkitCase;
154 return this.artifactId;
164 return this.sourceObjId;
172 long getDataSourceObjectID() {
173 return this.dataSourceObjId;
182 return this.artifactTypeId;
191 return this.artifactTypeName;
200 return this.displayName;
212 StringBuilder shortDescription =
new StringBuilder(
"");
214 case TSK_WEB_BOOKMARK:
216 case TSK_WEB_DOWNLOAD:
217 case TSK_WEB_HISTORY:
220 case TSK_KEYWORD_HIT:
223 case TSK_DEVICE_ATTACHED:
270 shortDescription.append(
" ");
271 shortDescription.append(MessageFormat.format(bundle.getString(
"BlackboardArtifact.shortDescriptionDate.text"), date.
getDisplayString()));
298 reviewStatus = newStatus;
313 attribute.setArtifactId(artifactId);
316 attrsCache.add(attribute);
328 ArrayList<BlackboardAttribute> attributes;
329 if (
false == loadedCacheFromDb) {
332 attrsCache.addAll(attributes);
333 loadedCacheFromDb =
true;
335 attributes =
new ArrayList<BlackboardAttribute>(attrsCache);
357 if (attribute.getAttributeType().equals(attributeType)) {
374 if (attributes.isEmpty()) {
378 attribute.setArtifactId(artifactId);
382 attrsCache.addAll(attributes);
395 if (uniquePath == null) {
398 if (myParent != null) {
407 if (parent == null) {
408 ObjectInfo parentInfo;
411 }
catch (TskCoreException ex) {
430 return new ArrayList<BlackboardArtifact>();
446 return new ArrayList<BlackboardArtifact>();
462 return new ArrayList<BlackboardArtifact>();
477 return new ArrayList<BlackboardArtifact>();
591 return new ArrayList<BlackboardAttribute>();
604 return new HashSet<String>();
620 throw new TskCoreException(
"Cannot create artifact of an artifact. Not supported.");
635 throw new TskCoreException(
"Cannot create artifact of an artifact. Not supported.");
648 return v.
visit(
this);
660 if (
object == null) {
663 if (getClass() !=
object.getClass()) {
678 hash = 41 * hash + (int) (this.artifactId ^ (this.artifactId >>> 32));
689 return "BlackboardArtifact{" +
"artifactID=" + artifactId +
", objID=" +
getObjectID() +
", artifactObjID=" + artifactObjId +
", artifactTypeID=" + artifactTypeId +
", artifactTypeName=" + artifactTypeName +
", displayName=" + displayName +
", Case=" +
getSleuthkitCase() +
'}';
704 return visitor.
visit(
this);
716 if (contentBytes == null) {
718 loadArtifactContent();
724 return contentBytes.length;
751 if (contentBytes == null) {
752 loadArtifactContent();
755 if (0 == contentBytes.length) {
760 long readLen = Math.min(contentBytes.length - offset, len);
761 System.arraycopy(contentBytes, 0, buf, 0, (
int) readLen);
763 return (
int) readLen;
774 if (myParent == null) {
788 StringBuilder artifactContents =
new StringBuilder();
793 }
catch (TskCoreException ex) {
794 throw new TskCoreException(
"Unable to get datasource for artifact: " + this.
toString(), ex);
796 if (dataSource == null) {
797 throw new TskCoreException(
"Datasource was null for artifact: " + this.
toString());
802 artifactContents.append(attribute.getAttributeType().getDisplayName());
803 artifactContents.append(
" : ");
804 artifactContents.append(attribute.getDisplayString());
805 artifactContents.append(System.lineSeparator());
807 }
catch (TskCoreException ex) {
808 throw new TskCoreException(
"Unable to get attributes for artifact: " + this.
toString(), ex);
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);
822 public static final class Type implements Serializable {
824 private static final long serialVersionUID = 1L;
825 private final String typeName;
826 private final int typeID;
827 private final String displayName;
836 public Type(
int typeID, String typeName, String displayName) {
837 this.typeID = typeID;
838 this.typeName = typeName;
839 this.displayName = displayName;
857 return this.typeName;
875 return this.displayName;
889 }
else if (!(that instanceof
Type)) {
892 return ((Type) that).sameType(
this);
903 private boolean sameType(
Type that) {
917 hash = 83 * hash + Objects.hashCode(this.typeID);
918 hash = 83 * hash + Objects.hashCode(this.displayName);
919 hash = 83 * hash + Objects.hashCode(this.typeName);
934 TSK_GEN_INFO(1,
"TSK_GEN_INFO",
935 bundle.getString(
"BlackboardArtifact.tskGenInfo.text")),
939 TSK_WEB_BOOKMARK(2,
"TSK_WEB_BOOKMARK",
940 bundle.getString(
"BlackboardArtifact.tskWebBookmark.text")),
944 TSK_WEB_COOKIE(3,
"TSK_WEB_COOKIE",
945 bundle.getString(
"BlackboardArtifact.tskWebCookie.text")),
949 TSK_WEB_HISTORY(4,
"TSK_WEB_HISTORY",
950 bundle.getString(
"BlackboardArtifact.tskWebHistory.text")),
954 TSK_WEB_DOWNLOAD(5,
"TSK_WEB_DOWNLOAD",
955 bundle.getString(
"BlackboardArtifact.tskWebDownload.text")),
959 TSK_RECENT_OBJECT(6,
"TSK_RECENT_OBJ",
960 bundle.getString(
"BlackboardArtifact.tsk.recentObject.text")),
964 TSK_GPS_TRACKPOINT(7,
"TSK_GPS_TRACKPOINT",
965 bundle.getString(
"BlackboardArtifact.tskGpsTrackpoint.text")),
969 TSK_INSTALLED_PROG(8,
"TSK_INSTALLED_PROG",
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",
980 bundle.getString(
"BlackboardArtifact.tskHashsetHit.text")),
984 TSK_DEVICE_ATTACHED(11,
"TSK_DEVICE_ATTACHED",
985 bundle.getString(
"BlackboardArtifact.tskDeviceAttached.text")),
990 TSK_INTERESTING_FILE_HIT(12,
"TSK_INTERESTING_FILE_HIT",
991 bundle.getString(
"BlackboardArtifact.tskInterestingFileHit.text")),
995 TSK_EMAIL_MSG(13,
"TSK_EMAIL_MSG",
996 bundle.getString(
"BlackboardArtifact.tskEmailMsg.text")),
1000 TSK_EXTRACTED_TEXT(14,
"TSK_EXTRACTED_TEXT",
1001 bundle.getString(
"BlackboardArtifact.tskExtractedText.text")),
1005 TSK_WEB_SEARCH_QUERY(15,
"TSK_WEB_SEARCH_QUERY",
1006 bundle.getString(
"BlackboardArtifact.tskWebSearchQuery.text")),
1010 TSK_METADATA_EXIF(16,
"TSK_METADATA_EXIF",
1011 bundle.getString(
"BlackboardArtifact.tskMetadataExif.text")),
1018 TSK_TAG_FILE(17,
"TSK_TAG_FILE",
1019 bundle.getString(
"BlackboardArtifact.tagFile.text")),
1026 TSK_TAG_ARTIFACT(18,
"TSK_TAG_ARTIFACT",
1027 bundle.getString(
"BlackboardArtifact.tskTagArtifact.text")),
1031 TSK_OS_INFO(19,
"TSK_OS_INFO",
1032 bundle.getString(
"BlackboardArtifact.tskOsInfo.text")),
1036 TSK_OS_ACCOUNT(20,
"TSK_OS_ACCOUNT",
1037 bundle.getString(
"BlackboardArtifact.tskOsAccount.text")),
1041 TSK_SERVICE_ACCOUNT(21,
"TSK_SERVICE_ACCOUNT",
1042 bundle.getString(
"BlackboardArtifact.tskServiceAccount.text")),
1049 TSK_TOOL_OUTPUT(22,
"TSK_TOOL_OUTPUT",
1050 bundle.getString(
"BlackboardArtifact.tskToolOutput.text")),
1055 TSK_CONTACT(23,
"TSK_CONTACT",
1056 bundle.getString(
"BlackboardArtifact.tskContact.text")),
1061 TSK_MESSAGE(24,
"TSK_MESSAGE",
1062 bundle.getString(
"BlackboardArtifact.tskMessage.text")),
1066 TSK_CALLLOG(25,
"TSK_CALLLOG",
1067 bundle.getString(
"BlackboardArtifact.tskCalllog.text")),
1071 TSK_CALENDAR_ENTRY(26,
"TSK_CALENDAR_ENTRY",
1072 bundle.getString(
"BlackboardArtifact.tskCalendarEntry.text")),
1076 TSK_SPEED_DIAL_ENTRY(27,
"TSK_SPEED_DIAL_ENTRY",
1077 bundle.getString(
"BlackboardArtifact.tskSpeedDialEntry.text")),
1081 TSK_BLUETOOTH_PAIRING(28,
"TSK_BLUETOOTH_PAIRING",
1082 bundle.getString(
"BlackboardArtifact.tskBluetoothPairing.text")),
1086 TSK_GPS_BOOKMARK(29,
"TSK_GPS_BOOKMARK",
1087 bundle.getString(
"BlackboardArtifact.tskGpsBookmark.text")),
1091 TSK_GPS_LAST_KNOWN_LOCATION(30,
"TSK_GPS_LAST_KNOWN_LOCATION",
1092 bundle.getString(
"BlackboardArtifact.tskGpsLastKnownLocation.text")),
1096 TSK_GPS_SEARCH(31,
"TSK_GPS_SEARCH",
1097 bundle.getString(
"BlackboardArtifact.tskGpsSearch.text")),
1101 TSK_PROG_RUN(32,
"TSK_PROG_RUN",
1102 bundle.getString(
"BlackboardArtifact.tskProgRun.text")),
1106 TSK_ENCRYPTION_DETECTED(33,
"TSK_ENCRYPTION_DETECTED",
1107 bundle.getString(
"BlackboardArtifact.tskEncryptionDetected.text")),
1111 TSK_EXT_MISMATCH_DETECTED(34,
"TSK_EXT_MISMATCH_DETECTED",
1112 bundle.getString(
"BlackboardArtifact.tskExtMismatchDetected.text")),
1117 TSK_INTERESTING_ARTIFACT_HIT(35,
"TSK_INTERESTING_ARTIFACT_HIT",
1118 bundle.getString(
"BlackboardArtifact.tskInterestingArtifactHit.text")),
1122 TSK_GPS_ROUTE(36,
"TSK_GPS_ROUTE",
1123 bundle.getString(
"BlackboardArtifact.tskGpsRoute.text")),
1127 TSK_REMOTE_DRIVE(37,
"TSK_REMOTE_DRIVE",
1128 bundle.getString(
"BlackboardArtifact.tskRemoteDrive.text")),
1132 TSK_FACE_DETECTED(38,
"TSK_FACE_DETECTED",
1133 bundle.getString(
"BlackboardArtifact.tskFaceDetected.text")),
1137 TSK_ACCOUNT(39,
"TSK_ACCOUNT",
1138 bundle.getString(
"BlackboardArtifact.tskAccount.text")),
1142 TSK_ENCRYPTION_SUSPECTED(40,
"TSK_ENCRYPTION_SUSPECTED",
1143 bundle.getString(
"BlackboardArtifact.tskEncryptionSuspected.text"));
1145 private final String label;
1146 private final int typeId;
1147 private final String displayName;
1156 private ARTIFACT_TYPE(
int typeId, String label, String displayName) {
1157 this.typeId = typeId;
1159 this.displayName = displayName;
1190 if (value.getLabel().equals(label)) {
1194 throw new IllegalArgumentException(
"No ARTIFACT_TYPE matching type: " + label);
1207 if (value.getTypeID() == id) {
1211 throw new IllegalArgumentException(
"No ARTIFACT_TYPE matching type: " +
id);
1236 return visitor.
visit(
this);
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>();
1257 idToStatus.put(status.getID(), status);
1269 private ReviewStatus(Integer
id, String name, String displayNameKey) {
1272 this.displayName = ResourceBundle.getBundle(
"org.sleuthkit.datamodel.Bundle").getString(displayNameKey);
1283 return idToStatus.get(
id);
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);
1356 if (loadedCacheFromDb ==
false) {
1359 attrsCache.addAll(attrs);
1360 loadedCacheFromDb =
true;
1362 ArrayList<BlackboardAttribute> filteredAttributes =
new ArrayList<BlackboardAttribute>();
1364 if (attr.getAttributeType().getTypeID() == attributeType.getTypeID()) {
1365 filteredAttributes.add(attr);
1368 return filteredAttributes;
1373 return this.artifactObjId;
1386 List<Long> childrenIDs =
new ArrayList<Long>();
1388 childrenIDs.addAll(
getSleuthkitCase().getBlackboardArtifactChildrenIds(
this));
1395 if (childrenCount != -1) {
1396 return childrenCount;
1401 hasChildren = childrenCount > 0;
1402 checkedHasChildren =
true;
1404 return childrenCount;
1409 if (checkedHasChildren ==
true) {
1415 hasChildren = childrenCount > 0;
1416 checkedHasChildren =
true;
1431 List<Content> children =
new ArrayList<Content>();
static ARTIFACT_TYPE fromID(int id)
synchronized String getUniquePath()
long getAllArtifactsCount()
ArrayList< BlackboardArtifact > getArtifacts(int artifactTypeID)
ArrayList< BlackboardAttribute > getBlackboardAttributes(final BlackboardArtifact artifact)
static ARTIFACT_TYPE fromLabel(String label)
void addBlackboardAttributes(Collection< BlackboardAttribute > attributes, int artifactTypeId)
Type(int typeID, String typeName, String displayName)
String getArtifactTypeName()
void addAttributes(Collection< BlackboardAttribute > attributes)
void addBlackboardAttribute(BlackboardAttribute attr, int artifactTypeId)
List< BlackboardAttribute > getAttributes(final BlackboardAttribute.ATTRIBUTE_TYPE attributeType)
long getArtifactsCount(int artifactTypeID)
Content getContentById(long id)
BlackboardArtifact getGenInfoArtifact()
final int read(byte[] buf, long offset, long len)
String getShortDescription()
SleuthkitCase getSleuthkitCase()
void addAttribute(BlackboardAttribute attribute)
boolean equals(Object object)
ReviewStatus getReviewStatus()
ArrayList< BlackboardArtifact > getArtifacts(BlackboardArtifact.ARTIFACT_TYPE type)
Set< String > getHashSetNames()
public< T > T accept(SleuthkitItemVisitor< T > visitor)
String getDisplayString()
BlackboardArtifact newArtifact(int artifactTypeID)
BlackboardAttribute getAttribute(BlackboardAttribute.Type attributeType)
List< Long > getChildrenIds()
long getArtifactsCount(String artifactTypeName)
BlackboardArtifact getGenInfoArtifact(boolean create)
ArrayList< BlackboardArtifact > getArtifacts(String artifactTypeName)
BlackboardAttribute.Type getAttributeType()
List< BlackboardAttribute > getAttributes()
BlackboardArtifact(SleuthkitCase sleuthkitCase, long artifactID, long objID, long artifactObjID, long dataSourceObjId, int artifactTypeID, String artifactTypeName, String displayName)
List< Content > getChildren()
synchronized Content getParent()
boolean equals(Object that)
ArrayList< BlackboardArtifact > getAllArtifacts()
void setReviewStatus(ReviewStatus newStatus)
long getArtifactsCount(BlackboardArtifact.ARTIFACT_TYPE type)
ArrayList< BlackboardAttribute > getGenInfoAttributes(BlackboardAttribute.ATTRIBUTE_TYPE attr_type)
static ReviewStatus withID(int id)
BlackboardArtifact newArtifact(BlackboardArtifact.ARTIFACT_TYPE type)
void setReviewStatus(BlackboardArtifact artifact, BlackboardArtifact.ReviewStatus newStatus)