19 package org.sleuthkit.autopsy.datasourcesummary.datamodel;
21 import java.nio.file.Paths;
22 import java.text.DateFormat;
23 import java.text.SimpleDateFormat;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
27 import java.util.Locale;
29 import java.util.Objects;
30 import java.util.stream.Collectors;
31 import org.apache.commons.lang.StringUtils;
40 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
47 private final static BlackboardAttribute.Type
DATETIME_ACCESSED_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED);
48 private final static BlackboardAttribute.Type
DOMAIN_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN);
49 private final static BlackboardAttribute.Type
PATH_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH);
50 private final static BlackboardAttribute.Type
ASSOCATED_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT);
51 private final static BlackboardAttribute.Type
EMAIL_FROM_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM);
52 private final static BlackboardAttribute.Type
MSG_DATEIME_SENT_ATT =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT);
53 private final static BlackboardArtifact.Type
ASSOCATED_OBJ_ART =
new BlackboardArtifact.Type(ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT);
55 private static final DateFormat
DATETIME_FORMAT =
new SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss", Locale.getDefault());
72 if (provider == null) {
73 throw new IllegalArgumentException(
"Unable to construct RecentFileSummary object. SleuthkitCaseProvider cannot be null");
87 private static <T extends RecentFileDetails> List<T>
getSortedLimited(List<T> fileDetails,
int limit) {
88 Map<String, T> fileDetailsMap = fileDetails.stream()
89 .filter(details -> details != null)
90 .collect(Collectors.toMap(
91 d -> d.getPath().toUpperCase(),
93 (d1, d2) -> Long.compare(d1.getDateAsLong(), d2.getDateAsLong()) > 0 ? d1 : d2));
95 return fileDetailsMap.values().stream()
96 .sorted((a, b) -> -Long.compare(a.getDateAsLong(), b.getDateAsLong()))
98 .collect(Collectors.toList());
112 if (StringUtils.isBlank(path) || lastOpened == null || lastOpened == 0) {
134 if (dataSource == null) {
135 return Collections.emptyList();
140 List<RecentFileDetails> details = provider.
get().getBlackboard()
141 .getArtifacts(ARTIFACT_TYPE.TSK_RECENT_OBJECT.getTypeID(), dataSource.getId()).stream()
143 .filter(d -> d != null)
144 .collect(Collectors.toList());
161 if (StringUtils.isBlank(path) || accessedTime == null || accessedTime == 0) {
175 throw new IllegalArgumentException(
"Invalid count: value must be greater than 0.");
193 public List<RecentDownloadDetails>
getRecentDownloads(DataSource dataSource,
int maxCount)
throws TskCoreException, SleuthkitCaseProviderException {
194 if (dataSource == null) {
195 return Collections.emptyList();
200 List<RecentDownloadDetails> details = provider.
get().getBlackboard()
201 .getArtifacts(ARTIFACT_TYPE.TSK_WEB_DOWNLOAD.getTypeID(), dataSource.getId()).stream()
203 .filter(d -> d != null)
204 .collect(Collectors.toList());
221 public List<RecentAttachmentDetails>
getRecentAttachments(DataSource dataSource,
int maxCount)
throws SleuthkitCaseProviderException, TskCoreException {
222 if (dataSource == null) {
223 return Collections.emptyList();
228 SleuthkitCase skCase = provider.
get();
230 List<BlackboardArtifact> associatedArtifacts = skCase.getBlackboard()
233 List<RecentAttachmentDetails> details =
new ArrayList<>();
234 for (BlackboardArtifact artifact : associatedArtifacts) {
237 if (thisDetails != null) {
238 details.add(thisDetails);
256 BlackboardAttribute attribute = artifact.getAttribute(
ASSOCATED_ATT);
257 if (attribute == null) {
262 BlackboardArtifact messageArtifact = skCase.getBlackboardArtifact(attribute.getValueLong());
268 Content content = artifact.getParent();
269 if (!(content instanceof AbstractFile)) {
273 AbstractFile abstractFile = (AbstractFile) content;
276 String path = Paths.get(abstractFile.getParentPath(), abstractFile.getName()).toString();
280 if (date == null || date == 0 || StringUtils.isBlank(path)) {
296 final int artifactTypeID = nodeArtifact.getArtifactTypeID();
297 return artifactTypeID == ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()
298 || artifactTypeID == ARTIFACT_TYPE.TSK_MESSAGE.getTypeID();
331 return DATETIME_FORMAT.format(date * 1000);
376 super(artifact, path, date);
409 super(artifact, path, date);
428 RecentAttachmentDetails compareObj = (RecentAttachmentDetails) obj;
430 return compareObj.
getSender().equals(this.sender)
438 hash = 73 * hash + Objects.hashCode(this.sender);
static boolean isMessageArtifact(BlackboardArtifact nodeArtifact)
static RecentDownloadDetails getRecentDownload(BlackboardArtifact artifact)
SleuthkitCaseProvider DEFAULT
List< RecentFileDetails > getRecentlyOpenedDocuments(DataSource dataSource, int maxCount)
static< TextendsRecentFileDetails > List< T > getSortedLimited(List< T > fileDetails, int limit)
static void throwOnNonPositiveCount(int count)
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
List< RecentAttachmentDetails > getRecentAttachments(DataSource dataSource, int maxCount)
RecentFilesSummary(SleuthkitCaseProvider provider)
static RecentAttachmentDetails getRecentAttachment(BlackboardArtifact artifact, SleuthkitCase skCase)
static final BlackboardAttribute.Type ASSOCATED_ATT
static Long getLongOrNull(BlackboardArtifact artifact, Type attributeType)
final SleuthkitCaseProvider provider
static final BlackboardAttribute.Type MSG_DATEIME_SENT_ATT
boolean equals(Object obj)
static final BlackboardAttribute.Type DATETIME_ACCESSED_ATT
static RecentFileDetails getRecentlyOpenedDocument(BlackboardArtifact artifact)
static String getStringOrNull(BlackboardArtifact artifact, Type attributeType)
static final BlackboardAttribute.Type PATH_ATT
static final BlackboardAttribute.Type EMAIL_FROM_ATT