23 package org.sleuthkit.autopsy.recentactivity;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.logging.Level;
29 import org.apache.commons.io.FilenameUtils;
30 import org.openide.util.NbBundle;
32 import java.util.Collection;
33 import java.util.HashMap;
34 import org.openide.util.NbBundle.Messages;
42 import org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
53 class RecentDocumentsByLnk
extends Extract {
55 private static final Logger logger = Logger.getLogger(RecentDocumentsByLnk.class.getName());
56 private Content dataSource;
57 private final IngestJobContext context;
60 "Progress_Message_Extract_Resent_Docs=Recent Documents",
61 "RecentDocumentsByLnk_displayName=Recent Documents by Link Analyzer"
63 RecentDocumentsByLnk(IngestJobContext context) {
64 super(Bundle.RecentDocumentsByLnk_displayName(), context);
65 this.context = context;
75 private void getRecentDocuments() {
78 List<AbstractFile> recentFiles;
80 recentFiles = fileManager.
findFiles(dataSource,
"%.lnk",
"Recent");
81 }
catch (TskCoreException ex) {
82 logger.log(Level.WARNING,
"Error searching for .lnk files.");
84 NbBundle.getMessage(
this.getClass(),
"RecentDocumentsByLnk.getRecDoc.errMsg.errGetLnkFiles",
85 this.getDisplayName()));
89 if (recentFiles.isEmpty()) {
90 logger.log(Level.INFO,
"Didn't find any recent files.");
95 List<BlackboardArtifact> bbartifacts =
new ArrayList<>();
96 HashMap<String, String> recentFileMap =
new HashMap<>();
97 for (AbstractFile recentFile : recentFiles) {
98 if (context.dataSourceIngestIsCancelled()) {
102 if (recentFile.getSize() == 0) {
106 JLnkParser lnkParser =
new JLnkParser(
new ReadContentInputStream(recentFile), (
int) recentFile.getSize());
108 lnk = lnkParser.parse();
109 }
catch (JLnkParserException e) {
111 boolean unalloc = recentFile.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.UNALLOC)
112 || recentFile.isDirNameFlagSet(TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC);
113 if (unalloc ==
false) {
114 logger.log(Level.WARNING,
"Error lnk parsing the file to get recent files {0}", recentFile);
119 Collection<BlackboardAttribute> bbattributes =
new ArrayList<>();
120 String path = lnk.getBestPath();
121 if (recentFileMap.get(path + File.separator + recentFile.getName()) == null) {
122 recentFileMap.put(path + File.separator + recentFile.getName(), recentFile.getName());
123 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_PATH,
124 NbBundle.getMessage(
this.getClass(),
125 "RecentDocumentsByLnk.parentModuleName.noSpace"),
127 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_PATH_ID,
128 NbBundle.getMessage(
this.getClass(),
129 "RecentDocumentsByLnk.parentModuleName.noSpace"),
130 Util.findID(dataSource, path)));
131 bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED,
132 NbBundle.getMessage(
this.getClass(),
133 "RecentDocumentsByLnk.parentModuleName.noSpace"),
134 recentFile.getCrtime()));
136 BlackboardArtifact bba = createArtifactWithAttributes(BlackboardArtifact.Type.TSK_RECENT_OBJECT, recentFile, bbattributes);
138 bbartifacts.add(bba);
139 bba = createAssociatedArtifact(path, bba);
141 bbartifacts.add(bba);
144 }
catch (TskCoreException ex) {
145 logger.log(Level.SEVERE, String.format(
"Failed to create TSK_RECENT_OBJECT artifact for file %d", recentFile.getId()), ex);
150 if (!context.dataSourceIngestIsCancelled()) {
151 postArtifacts(bbartifacts);
165 private BlackboardArtifact createAssociatedArtifact(String filePathName, BlackboardArtifact bba) {
166 String normalizePathName = FilenameUtils.normalize(filePathName,
true);
167 String fileName = FilenameUtils.getName(normalizePathName);
168 String filePath = FilenameUtils.getPath(normalizePathName);
169 List<AbstractFile> sourceFiles;
170 if (filePath == null) {
174 sourceFiles = currentCase.getSleuthkitCase().getFileManager().findFilesExactNameExactPath(dataSource, fileName, filePath);
175 for (AbstractFile sourceFile : sourceFiles) {
176 if (sourceFile.getParentPath().endsWith(filePath)) {
177 return createAssociatedArtifact(sourceFile, bba);
180 }
catch (TskCoreException ex) {
181 logger.log(Level.WARNING, String.format(
"Error finding actual file %s. file may not exist", filePathName), ex);
188 public void process(Content dataSource, DataSourceIngestModuleProgress progressBar) {
189 this.dataSource = dataSource;
192 progressBar.progress(Bundle.Progress_Message_Extract_Resent_Docs());
193 this.getRecentDocuments();
List< AbstractFile > findFiles(String fileName)