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;
 
   41 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
 
   43 import org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
 
   54 class RecentDocumentsByLnk 
extends Extract {
 
   56     private static final Logger logger = Logger.getLogger(RecentDocumentsByLnk.class.getName());
 
   57     private Content dataSource;
 
   58     private IngestJobContext context;
 
   61         "Progress_Message_Extract_Resent_Docs=Recent Documents",
 
   71     private void getRecentDocuments() {
 
   74         List<AbstractFile> recentFiles;
 
   76             recentFiles = fileManager.
findFiles(dataSource, 
"%.lnk", 
"Recent"); 
 
   77         } 
catch (TskCoreException ex) {
 
   78             logger.log(Level.WARNING, 
"Error searching for .lnk files."); 
 
   80                     NbBundle.getMessage(
this.getClass(), 
"RecentDocumentsByLnk.getRecDoc.errMsg.errGetLnkFiles",
 
   85         if (recentFiles.isEmpty()) {
 
   86             logger.log(Level.INFO, 
"Didn't find any recent files."); 
 
   91         List<BlackboardArtifact> bbartifacts = 
new ArrayList<>();
 
   92         HashMap<String, String> recentFileMap = 
new HashMap<>();
 
   93         for (AbstractFile recentFile : recentFiles) {
 
   94             if (context.dataSourceIngestIsCancelled()) {
 
   98             if (recentFile.getSize() == 0) {
 
  102             JLnkParser lnkParser = 
new JLnkParser(
new ReadContentInputStream(recentFile), (
int) recentFile.getSize());
 
  104                 lnk = lnkParser.parse();
 
  105             } 
catch (JLnkParserException e) {
 
  107                 boolean unalloc = recentFile.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.UNALLOC)
 
  108                         || recentFile.isDirNameFlagSet(TskData.TSK_FS_NAME_FLAG_ENUM.UNALLOC);
 
  109                 if (unalloc == 
false) {
 
  110                     logger.log(Level.WARNING, 
"Error lnk parsing the file to get recent files {0}", recentFile); 
 
  115             Collection<BlackboardAttribute> bbattributes = 
new ArrayList<>();
 
  116             String path = lnk.getBestPath();
 
  117             if (recentFileMap.get(path + File.separator + recentFile.getName()) == null) {
 
  118                 recentFileMap.put(path + File.separator + recentFile.getName(), recentFile.getName());
 
  119             bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_PATH,
 
  120                     NbBundle.getMessage(
this.getClass(),
 
  121                             "RecentDocumentsByLnk.parentModuleName.noSpace"),
 
  123             bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_PATH_ID,
 
  124                     NbBundle.getMessage(
this.getClass(),
 
  125                             "RecentDocumentsByLnk.parentModuleName.noSpace"),
 
  126                     Util.findID(dataSource, path)));
 
  127             bbattributes.add(
new BlackboardAttribute(ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED,
 
  128                     NbBundle.getMessage(
this.getClass(),
 
  129                             "RecentDocumentsByLnk.parentModuleName.noSpace"),
 
  130                     recentFile.getCrtime()));
 
  132                 BlackboardArtifact bba = createArtifactWithAttributes(ARTIFACT_TYPE.TSK_RECENT_OBJECT, recentFile, bbattributes);
 
  134                     bbartifacts.add(bba);
 
  135                     bba = createAssociatedArtifact(path, bba);
 
  137                         bbartifacts.add(bba);
 
  140             } 
catch(TskCoreException ex) {
 
  141                logger.log(Level.SEVERE, String.format(
"Failed to create TSK_RECENT_OBJECT artifact for file %d", recentFile.getId()), ex); 
 
  146         if (!context.dataSourceIngestIsCancelled()) {
 
  147             postArtifacts(bbartifacts);
 
  160     private BlackboardArtifact createAssociatedArtifact(String filePathName, BlackboardArtifact bba) {
 
  161         String normalizePathName = FilenameUtils.normalize(filePathName, 
true);
 
  162         String fileName = FilenameUtils.getName(normalizePathName);
 
  163         String filePath = FilenameUtils.getPath(normalizePathName);
 
  164         List<AbstractFile> sourceFiles;
 
  166             sourceFiles = currentCase.getSleuthkitCase().getFileManager().findFilesExactNameExactPath(dataSource, fileName, filePath);
 
  167             for (AbstractFile sourceFile : sourceFiles) {
 
  168                 if (sourceFile.getParentPath().endsWith(filePath)) {
 
  169                     return createAssociatedArtifact(sourceFile, bba);
 
  172         } 
catch (TskCoreException ex) {
 
  173             logger.log(Level.WARNING, String.format(
"Error finding actual file %s. file may not exist", filePathName), ex); 
 
  180     public void process(Content dataSource, IngestJobContext context, DataSourceIngestModuleProgress progressBar) {
 
  181         this.dataSource = dataSource;
 
  182         this.context = context;
 
  185         progressBar.progress(Bundle.Progress_Message_Extract_Resent_Docs());
 
  186         this.getRecentDocuments();
 
List< AbstractFile > findFiles(String fileName)