19 package org.sleuthkit.autopsy.recentactivity;
 
   21 import java.util.ArrayList;
 
   22 import java.util.Collection;
 
   23 import java.util.List;
 
   24 import java.util.logging.Level;
 
   25 import org.apache.commons.io.FilenameUtils;
 
   26 import org.openide.util.NbBundle.Messages;
 
   45 @Messages({
"DataSourceUsageAnalyzer.parentModuleName=Recent Activity"})
 
   46 class DataSourceUsageAnalyzer extends Extract {
 
   48     private static final Logger logger = Logger.getLogger(DataSourceUsageAnalyzer.class.getName());
 
   49     private static final int FAT_EXFAT_FLAGS =  TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_FAT16.getValue() | 
 
   50                                                 TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_FAT32.getValue() | 
 
   51                                                 TskData.TSK_FS_TYPE_ENUM.TSK_FS_TYPE_EXFAT.getValue();
 
   52     private static final long HUNDRED_GB = 100*1024*1024*1024l;
 
   54     private static final String ANDROID_MEDIACARD_ROOT_FILENAMES[] =    
 
   55                                 {
".android_secure", 
"android", 
"audio", 
 
   56                                  "photos", 
"dcim", 
"music", 
"pictures", 
"videos"}; 
 
   57     private Content dataSource;
 
   61         "DataSourceUsageAnalyzer.customVolume.label=OS Drive ({0})",
 
   62         "Progress_Message_Analyze_Usage=Data Sources Usage Analysis",
 
   65     void process(Content dataSource, IngestJobContext context, DataSourceIngestModuleProgress progressBar) {
 
   66         this.dataSource = dataSource;
 
   68             progressBar.progress(Bundle.Progress_Message_Analyze_Usage());
 
   69             createDataSourceUsageArtifacts();
 
   70         } 
catch (TskCoreException ex) {
 
   71             logger.log(Level.WARNING, 
"Failed to check if datasource contained a volume with operating system specific files", ex);
 
   76     private void createDataSourceUsageArtifacts() throws TskCoreException {
 
   78          createOSInfoDataSourceUsageArtifacts();
 
   79          createAndroidMediaCardArtifacts(); 
 
   87     private void createOSInfoDataSourceUsageArtifacts() throws TskCoreException {
 
   88         boolean windowsOsDetected = 
false;
 
   89         List<BlackboardArtifact> osInfoArtifacts = tskCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_OS_INFO);
 
   90         for (BlackboardArtifact osInfoArt : osInfoArtifacts) {
 
   92             if (osInfoArt.getDataSource().getId() == dataSource.getId()) {
 
   93                 BlackboardAttribute progNameAttr = osInfoArt.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME));
 
   94                 if (progNameAttr != null) {
 
   95                     if (progNameAttr.getValueString().isEmpty()) {
 
   97                     } 
else if (progNameAttr.getDisplayString().toLowerCase().contains(
"windows")) { 
 
   98                         windowsOsDetected = 
true;
 
  100                         createDataSourceUsageArtifact(Bundle.DataSourceUsageAnalyzer_customVolume_label(progNameAttr.getDisplayString()));
 
  102                         ExtractOs.OS_TYPE osType = ExtractOs.OS_TYPE.fromOsInfoLabel(progNameAttr.getValueString());
 
  103                         if (osType != null) {
 
  104                             createDataSourceUsageArtifact(osType.getDsUsageLabel());
 
  107                             createDataSourceUsageArtifact(Bundle.DataSourceUsageAnalyzer_customVolume_label(progNameAttr.getDisplayString()));
 
  113         if (!windowsOsDetected) {  
 
  114             checkIfOsSpecificVolume(ExtractOs.OS_TYPE.WINDOWS);
 
  127     private void createDataSourceUsageArtifact(String dataSourceUsageDescription) 
throws TskCoreException {
 
  129         List<BlackboardArtifact> artifacts = tskCase.getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE, dataSource.getId());
 
  130         for (BlackboardArtifact artifact : artifacts) {
 
  131             if (artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION)).getValueString().equals(dataSourceUsageDescription)) {
 
  135         Collection<BlackboardAttribute> bbattributes = 
new ArrayList<>();
 
  136         bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DESCRIPTION,
 
  137                 Bundle.DataSourceUsageAnalyzer_parentModuleName(),
 
  138                 dataSourceUsageDescription)); 
 
  139         addArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_DATA_SOURCE_USAGE, dataSource, bbattributes);
 
  151     private void checkIfOsSpecificVolume(ExtractOs.OS_TYPE osType) throws TskCoreException {
 
  152         FileManager fileManager = currentCase.getServices().getFileManager();
 
  153         for (String filePath : osType.getFilePaths()) {
 
  154             for (AbstractFile file : fileManager.findFiles(dataSource, FilenameUtils.getName(filePath), FilenameUtils.getPath(filePath))) {
 
  155                 if ((file.getParentPath() + file.getName()).equals(filePath)) {
 
  156                     createDataSourceUsageArtifact(osType.getDsUsageLabel());
 
  172         "DataSourceUsage_AndroidMedia=Android Media Card",
 
  173         "DataSourceUsage_FlashDrive=Flash Drive" 
  175     private void createAndroidMediaCardArtifacts() throws TskCoreException {
 
  177         if (dataSource instanceof Image) {
 
  178            Image image = (Image) dataSource;
 
  180                if (image.getSize() > HUNDRED_GB) {
 
  184                List<FileSystem> fileSystems = image.getFileSystems();
 
  185                if (fileSystems.isEmpty() || fileSystems.size() > 1) {
 
  189                FileSystem fileSystem = fileSystems.get(0);
 
  190                if ( fileSystem == null || (fileSystem.getFsType().getValue() & FAT_EXFAT_FLAGS) == 0) {
 
  194                FileManager fileManager = currentCase.getServices().getFileManager();
 
  195                for (String fileName : ANDROID_MEDIACARD_ROOT_FILENAMES ) {
 
  196                     for (AbstractFile file : fileManager.findFiles(dataSource, fileName, 
"/")) { 
 
  197                         if (file.getParentPath().equals(
"/") &&  file.getName().equalsIgnoreCase(fileName)) { 
 
  198                             createDataSourceUsageArtifact(Bundle.DataSourceUsage_AndroidMedia());
 
  205                createDataSourceUsageArtifact(Bundle.DataSourceUsage_FlashDrive());    
 
  207            } 
catch (TskCoreException ex) {
 
  208                logger.log(Level.SEVERE, 
"Exception while checking image: {0} for Andriod media card", image.getName() + ex.getMessage());