19 package org.sleuthkit.autopsy.discovery.search;
21 import com.google.common.cache.CacheLoader;
22 import java.awt.Image;
23 import java.util.List;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collections;
30 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_CACHE;
31 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_WEB_DOWNLOAD;
33 import org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
39 import org.openide.util.ImageUtilities;
51 private static final String
UNSUPPORTED_IMAGE =
"org/sleuthkit/autopsy/images/image-extraction-not-supported.png";
52 private static final List<String>
SUPPORTED_EXTENSIONS = Arrays.asList(
"jpg",
"svg",
"png",
"webp",
"ico",
"gif");
54 "image/gif",
"image/jpeg",
"image/png",
"image/webp",
55 "image/svg+xml",
"image/vnd.microsoft.icon",
"image/x-icon");
57 private static final List<String>
ICO_MIMETYPES = Arrays.asList(
"image/vnd.microsoft.icon",
"image/x-icon");
80 final SleuthkitCase caseDb = thumbnailRequest.getSleuthkitCase();
82 caseDb, thumbnailRequest.getDomain(), TSK_WEB_DOWNLOAD);
83 final List<BlackboardArtifact> webDownloads = artifactsCache.
get(webDownloadsRequest);
85 Collections.sort(webDownloadPictures, (file1, file2) -> {
89 return Long.compare(file1.getSize(), file2.getSize());
90 }
else if (
isIco(file1)) {
92 }
else if (
isIco(file2)) {
95 return Long.compare(file1.getCrtime(), file2.getCrtime());
99 for (
int i = webDownloadPictures.size() - 1; i >= 0; i--) {
100 if(Thread.currentThread().isInterrupted()) {
101 throw new InterruptedException();
104 final AbstractFile mostRecent = webDownloadPictures.get(i);
108 return candidateThumbnail;
112 caseDb, thumbnailRequest.getDomain(), TSK_WEB_CACHE);
113 final List<BlackboardArtifact> webCacheArtifacts = artifactsCache.
get(webCacheRequest);
115 Collections.sort(webCachePictures, (file1, file2) -> {
119 return Long.compare(file1.getSize(), file2.getSize());
120 }
else if (
isIco(file1)) {
122 }
else if (
isIco(file2)) {
125 return Long.compare(file1.getSize(), file2.getSize());
128 for (
int i = webCachePictures.size() - 1; i >= 0; i--) {
129 if(Thread.currentThread().isInterrupted()) {
130 throw new InterruptedException();
133 final AbstractFile largest = webCachePictures.get(i);
136 return candidateThumbnail;
139 return ImageUtilities.loadImage(UNSUPPORTED_IMAGE,
false);
153 private List<AbstractFile>
getCandidatesFromWebDownloads(SleuthkitCase caseDb, List<BlackboardArtifact> artifacts)
throws TskCoreException, InterruptedException {
154 final List<AbstractFile> candidates =
new ArrayList<>();
155 for (BlackboardArtifact artifact : artifacts) {
156 if(Thread.currentThread().isInterrupted()) {
157 throw new InterruptedException();
159 final Content sourceContent = caseDb.getContentById(artifact.getObjectID());
165 private boolean isIco(AbstractFile file) {
166 return ICO_EXTENSION.equals(file.getNameExtension())
167 || ICO_MIMETYPES.contains(file.getMIMEType());
179 private List<AbstractFile>
getCandidatesFromWebCache(SleuthkitCase caseDb, List<BlackboardArtifact> artifacts)
throws TskCoreException, InterruptedException {
180 final BlackboardAttribute.Type TSK_PATH_ID =
new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_PATH_ID);
181 final List<AbstractFile> candidates =
new ArrayList<>();
182 for (BlackboardArtifact artifact : artifacts) {
183 if(Thread.currentThread().isInterrupted()) {
184 throw new InterruptedException();
186 final BlackboardAttribute tskPathId = artifact.getAttribute(TSK_PATH_ID);
187 if (tskPathId != null) {
188 final Content sourceContent = caseDb.getContentById(tskPathId.getValueLong());
202 if ((sourceContent instanceof AbstractFile) && !(sourceContent instanceof DataSource)) {
203 final AbstractFile file = (AbstractFile) sourceContent;
204 if (SUPPORTED_EXTENSIONS.contains(file.getNameExtension())
205 || SUPPORTED_MIMETYPES.contains(file.getMIMEType())) {
void addIfSupported(List< AbstractFile > files, Content sourceContent)
List< BlackboardArtifact > get(DomainSearchArtifactsRequest request)
DomainSearchThumbnailLoader()
static final List< String > SUPPORTED_EXTENSIONS
static final List< String > ICO_MIMETYPES
static final String ICO_EXTENSION
Image load(DomainSearchThumbnailRequest thumbnailRequest)
static Image getDefaultThumbnail()
final DomainSearchArtifactsCache artifactsCache
List< AbstractFile > getCandidatesFromWebDownloads(SleuthkitCase caseDb, List< BlackboardArtifact > artifacts)
List< AbstractFile > getCandidatesFromWebCache(SleuthkitCase caseDb, List< BlackboardArtifact > artifacts)
static BufferedImage getThumbnail(Content content, int iconSize)
static final List< String > SUPPORTED_MIMETYPES
static final String UNSUPPORTED_IMAGE
boolean isIco(AbstractFile file)