Autopsy  4.5.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EmbeddedFileExtractorIngestModule.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2015 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.embeddedfileextractor;
20 
21 import java.io.File;
22 import java.nio.file.Paths;
23 import org.openide.util.NbBundle;
25 import org.sleuthkit.datamodel.AbstractFile;
26 import org.sleuthkit.datamodel.TskData;
30 import net.sf.sevenzipjbinding.SevenZipNativeInitializationException;
32 
37 @NbBundle.Messages({
38  "CannotCreateOutputFolder=Unable to create output folder.",
39  "CannotRunFileTypeDetection=Unable to run file type detection.",
40  "UnableToInitializeLibraries=Unable to initialize 7Zip libraries."
41 })
43 
44  static final String[] SUPPORTED_EXTENSIONS = {"zip", "rar", "arj", "7z", "7zip", "gzip", "gz", "bzip2", "tar", "tgz",}; // "iso"}; NON-NLS
45  private String moduleDirRelative;
46  private String moduleDirAbsolute;
47  private MSOfficeEmbeddedContentExtractor officeExtractor;
48  private SevenZipExtractor archiveExtractor;
50 
56  }
57 
58  @Override
59  public void startUp(IngestJobContext context) throws IngestModuleException {
60  /*
61  * Construct absolute and relative paths to the output directory. The
62  * relative path is relative to the case folder, and will be used in the
63  * case database for extracted (derived) file paths. The absolute path
64  * is used to write the extracted (derived) files to local storage.
65  */
66  final Case currentCase = Case.getCurrentCase();
67  moduleDirRelative = Paths.get(currentCase.getModuleOutputDirectoryRelativePath(), EmbeddedFileExtractorModuleFactory.getModuleName()).toString();
68  moduleDirAbsolute = Paths.get(currentCase.getModuleDirectory(), EmbeddedFileExtractorModuleFactory.getModuleName()).toString();
69 
70  /*
71  * Create the output directory.
72  */
73  File extractionDirectory = new File(moduleDirAbsolute);
74  if (!extractionDirectory.exists()) {
75  try {
76  extractionDirectory.mkdirs();
77  } catch (SecurityException ex) {
78  throw new IngestModuleException(Bundle.CannotCreateOutputFolder(), ex);
79  }
80  }
81 
82  /*
83  * Construct a file type detector.
84  */
85  try {
86  fileTypeDetector = new FileTypeDetector();
88  throw new IngestModuleException(Bundle.CannotRunFileTypeDetection(), ex);
89  }
90 
91  /*
92  * Construct a 7Zip file extractor for processing archive files.
93  */
94  try {
95  this.archiveExtractor = new SevenZipExtractor(context, fileTypeDetector, moduleDirRelative, moduleDirAbsolute);
96  } catch (SevenZipNativeInitializationException ex) {
97  throw new IngestModuleException(Bundle.UnableToInitializeLibraries(), ex);
98  }
99 
100  /*
101  * Construct an embedded content extractor for processing Microsoft
102  * Office documents.
103  */
104  this.officeExtractor = new MSOfficeEmbeddedContentExtractor(context, fileTypeDetector, moduleDirRelative, moduleDirAbsolute);
105  }
106 
107  @Override
108  public ProcessResult process(AbstractFile abstractFile) {
109  /*
110  * Skip unallocated space files.
111  */
112  if ((abstractFile.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS))
113  || (abstractFile.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK))) {
114  return ProcessResult.OK;
115  }
116 
117  /*
118  * Skip known files.
119  */
120  if (abstractFile.getKnown().equals(TskData.FileKnown.KNOWN)) {
121  return ProcessResult.OK;
122  }
123 
124  /*
125  * Skip directories, etc.
126  */
127  if (!abstractFile.isFile()) {
128  return ProcessResult.OK;
129  }
130 
131  /*
132  * Attempt embedded file extraction for the file if it is a supported
133  * type/format.
134  */
135  if (archiveExtractor.isSevenZipExtractionSupported(abstractFile)) {
136  archiveExtractor.unpack(abstractFile);
137  } else if (officeExtractor.isContentExtractionSupported(abstractFile)) {
138  officeExtractor.extractEmbeddedContent(abstractFile);
139  }
140  return ProcessResult.OK;
141  }
142 
151  static String getUniqueName(AbstractFile file) {
152  return file.getName() + "_" + file.getId();
153  }
154 
155 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Feb 20 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.