19 package org.sleuthkit.autopsy.datasourcesummary.datamodel;
22 import java.nio.file.Paths;
23 import java.text.DateFormat;
24 import java.text.SimpleDateFormat;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.HashSet;
29 import java.util.List;
30 import java.util.Locale;
32 import java.util.Objects;
34 import java.util.stream.Collectors;
35 import org.apache.commons.lang.StringUtils;
44 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
51 private final static BlackboardAttribute.Type
DATETIME_ACCESSED_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED);
52 private final static BlackboardAttribute.Type
DOMAIN_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN);
53 private final static BlackboardAttribute.Type
PATH_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH);
54 private final static BlackboardAttribute.Type
DATETIME_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME);
55 private final static BlackboardAttribute.Type
ASSOCATED_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT);
56 private final static BlackboardAttribute.Type
EMAIL_FROM_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM);
57 private final static BlackboardAttribute.Type
MSG_DATEIME_SENT_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT);
58 private final static BlackboardArtifact.Type
ASSOCATED_OBJ_ART =
new BlackboardArtifact.Type(ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT);
60 private static final DateFormat
DATETIME_FORMAT =
new SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss", Locale.getDefault());
63 ARTIFACT_TYPE.TSK_RECENT_OBJECT.getTypeID(),
64 ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID(),
65 ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getTypeID(),
66 ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID(),
67 ARTIFACT_TYPE.TSK_MESSAGE.getTypeID()
85 if (provider == null) {
86 throw new IllegalArgumentException(
"Unable to construct RecentFileSummary object. SleuthkitCaseProvider cannot be null");
105 private <T extends RecentFileDetails> List<T> getSortedLimited(List<T> fileDetails,
int limit) {
106 Map<String, T> fileDetailsMap = fileDetails.stream()
107 .filter(details -> details != null)
108 .collect(Collectors.toMap(
109 d -> d.getPath().toUpperCase(),
111 (d1, d2) -> Long.compare(d1.getDateAsLong(), d2.getDateAsLong()) > 0 ? d1 : d2));
113 return fileDetailsMap.values().stream()
114 .sorted((a, b) -> -Long.compare(a.getDateAsLong(), b.getDateAsLong()))
116 .collect(Collectors.toList());
127 String path = DataSourceInfoUtilities.getStringOrNull(artifact,
PATH_ATT);
128 Long lastOpened = DataSourceInfoUtilities.getLongOrNull(artifact,
DATETIME_ATT);
130 if (StringUtils.isBlank(path) || lastOpened == null || lastOpened == 0) {
152 if (dataSource == null) {
153 return Collections.emptyList();
158 List<RecentFileDetails> details = provider.
get().getBlackboard()
159 .getArtifacts(ARTIFACT_TYPE.TSK_RECENT_OBJECT.getTypeID(), dataSource.getId()).stream()
161 .filter(d -> d != null)
162 .collect(Collectors.toList());
164 return getSortedLimited(details, maxCount);
176 String domain = DataSourceInfoUtilities.getStringOrNull(artifact,
DOMAIN_ATT);
177 String path = DataSourceInfoUtilities.getStringOrNull(artifact,
PATH_ATT);
179 if (StringUtils.isBlank(path) || accessedTime == null || accessedTime == 0) {
193 throw new IllegalArgumentException(
"Invalid count: value must be greater than 0.");
211 public List<RecentDownloadDetails>
getRecentDownloads(DataSource dataSource,
int maxCount)
throws TskCoreException, SleuthkitCaseProviderException {
212 if (dataSource == null) {
213 return Collections.emptyList();
218 List<RecentDownloadDetails> details = provider.
get().getBlackboard()
219 .getArtifacts(ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID(), dataSource.getId()).stream()
221 .filter(d -> d != null)
222 .collect(Collectors.toList());
224 return getSortedLimited(details, maxCount);
239 public List<RecentAttachmentDetails>
getRecentAttachments(DataSource dataSource,
int maxCount)
throws SleuthkitCaseProviderException, TskCoreException {
240 if (dataSource == null) {
241 return Collections.emptyList();
246 SleuthkitCase skCase = provider.
get();
248 List<BlackboardArtifact> associatedArtifacts = skCase.getBlackboard()
251 List<RecentAttachmentDetails> details =
new ArrayList<>();
252 for (BlackboardArtifact artifact : associatedArtifacts) {
255 if (thisDetails != null) {
256 details.add(thisDetails);
260 return getSortedLimited(details, maxCount);
274 BlackboardAttribute attribute = artifact.getAttribute(
ASSOCATED_ATT);
275 if (attribute == null) {
280 BlackboardArtifact messageArtifact = skCase.getBlackboardArtifact(attribute.getValueLong());
286 Content content = artifact.getParent();
287 if (!(content instanceof AbstractFile)) {
291 AbstractFile abstractFile = (AbstractFile) content;
294 String path = Paths.get(abstractFile.getParentPath(), abstractFile.getName()).toString();
295 String sender = DataSourceInfoUtilities.getStringOrNull(messageArtifact,
EMAIL_FROM_ATT);
298 if (date == null || date == 0 || StringUtils.isBlank(path)) {
314 final int artifactTypeID = nodeArtifact.getArtifactTypeID();
315 return artifactTypeID == ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
316 || artifactTypeID == ARTIFACT_TYPE.TSK_MESSAGE.getTypeID();
349 return DATETIME_FORMAT.format(date * 1000);
357 Long getDateAsLong() {
394 super(artifact, path, date);
427 super(artifact, path, date);
446 RecentAttachmentDetails compareObj = (RecentAttachmentDetails) obj;
448 return compareObj.
getSender().equals(this.sender)
450 && compareObj.getDateAsLong().equals(this.getDateAsLong());
456 hash = 73 * hash + Objects.hashCode(this.sender);
SleuthkitCaseProvider DEFAULT
Set< Integer > getArtifactTypeIdsForRefresh()
List< RecentFileDetails > getRecentlyOpenedDocuments(DataSource dataSource, int maxCount)
static final Set< Integer > ARTIFACT_UPDATE_TYPE_IDS
RecentDownloadDetails getRecentDownload(BlackboardArtifact artifact)
BlackboardArtifact getArtifact()
static final DateFormat DATETIME_FORMAT
List< RecentDownloadDetails > getRecentDownloads(DataSource dataSource, int maxCount)
static final BlackboardAttribute.Type DOMAIN_ATT
final BlackboardArtifact artifact
static final BlackboardArtifact.Type ASSOCATED_OBJ_ART
RecentAttachmentDetails getRecentAttachment(BlackboardArtifact artifact, SleuthkitCase skCase)
List< RecentAttachmentDetails > getRecentAttachments(DataSource dataSource, int maxCount)
RecentFilesSummary(SleuthkitCaseProvider provider)
RecentFileDetails getRecentlyOpenedDocument(BlackboardArtifact artifact)
boolean isMessageArtifact(BlackboardArtifact nodeArtifact)
static final BlackboardAttribute.Type ASSOCATED_ATT
static final BlackboardAttribute.Type DATETIME_ATT
final SleuthkitCaseProvider provider
static final BlackboardAttribute.Type MSG_DATEIME_SENT_ATT
void throwOnNonPositiveCount(int count)
boolean equals(Object obj)
static final BlackboardAttribute.Type DATETIME_ACCESSED_ATT
static final BlackboardAttribute.Type PATH_ATT
static final BlackboardAttribute.Type EMAIL_FROM_ATT