Autopsy  4.6.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-2018 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;
33 
38 @NbBundle.Messages({
39  "CannotCreateOutputFolder=Unable to create output folder.",
40  "CannotRunFileTypeDetection=Unable to run file type detection.",
41  "UnableToInitializeLibraries=Unable to initialize 7Zip libraries.",
42  "EmbeddedFileExtractorIngestModule.NoOpenCase.errMsg=No open case available.",
43  "EmbeddedFileExtractorIngestModule.UnableToGetMSOfficeExtractor.errMsg=Unable to get MSOfficeEmbeddedContentExtractor."
44 })
46 
47  static final String[] SUPPORTED_EXTENSIONS = {"zip", "rar", "arj", "7z", "7zip", "gzip", "gz", "bzip2", "tar", "tgz",}; // "iso"}; NON-NLS
48  private String moduleDirRelative;
49  private String moduleDirAbsolute;
50  private MSOfficeEmbeddedContentExtractor officeExtractor;
51  private SevenZipExtractor archiveExtractor;
53 
59  }
60 
61  @Override
62  public void startUp(IngestJobContext context) throws IngestModuleException {
63  /*
64  * Construct absolute and relative paths to the output directory. The
65  * relative path is relative to the case folder, and will be used in the
66  * case database for extracted (derived) file paths. The absolute path
67  * is used to write the extracted (derived) files to local storage.
68  */
69  try {
70  final Case currentCase = Case.getOpenCase();
71  moduleDirRelative = Paths.get(currentCase.getModuleOutputDirectoryRelativePath(), EmbeddedFileExtractorModuleFactory.getModuleName()).toString();
72  moduleDirAbsolute = Paths.get(currentCase.getModuleDirectory(), EmbeddedFileExtractorModuleFactory.getModuleName()).toString();
73  } catch (NoCurrentCaseException ex) {
74  throw new IngestModuleException(Bundle.EmbeddedFileExtractorIngestModule_NoOpenCase_errMsg(), ex);
75  }
76  /*
77  * Create the output directory.
78  */
79  File extractionDirectory = new File(moduleDirAbsolute);
80  if (!extractionDirectory.exists()) {
81  try {
82  extractionDirectory.mkdirs();
83  } catch (SecurityException ex) {
84  throw new IngestModuleException(Bundle.CannotCreateOutputFolder(), ex);
85  }
86  }
87 
88  /*
89  * Construct a file type detector.
90  */
91  try {
92  fileTypeDetector = new FileTypeDetector();
94  throw new IngestModuleException(Bundle.CannotRunFileTypeDetection(), ex);
95  }
96 
97  /*
98  * Construct a 7Zip file extractor for processing archive files.
99  */
100  try {
101  this.archiveExtractor = new SevenZipExtractor(context, fileTypeDetector, moduleDirRelative, moduleDirAbsolute);
102  } catch (SevenZipNativeInitializationException ex) {
103  throw new IngestModuleException(Bundle.UnableToInitializeLibraries(), ex);
104  }
105 
106  /*
107  * Construct an embedded content extractor for processing Microsoft
108  * Office documents.
109  */
110  try {
111  this.officeExtractor = new MSOfficeEmbeddedContentExtractor(context, fileTypeDetector, moduleDirRelative, moduleDirAbsolute);
112  } catch (NoCurrentCaseException ex) {
113  throw new IngestModuleException(Bundle.EmbeddedFileExtractorIngestModule_UnableToGetMSOfficeExtractor_errMsg(), ex);
114  }
115  }
116 
117  @Override
118  public ProcessResult process(AbstractFile abstractFile) {
119  /*
120  * Skip unallocated space files.
121  */
122  if ((abstractFile.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS))
123  || (abstractFile.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK))) {
124  return ProcessResult.OK;
125  }
126 
127  /*
128  * Skip known files.
129  */
130  if (abstractFile.getKnown().equals(TskData.FileKnown.KNOWN)) {
131  return ProcessResult.OK;
132  }
133 
134  /*
135  * Skip directories, etc.
136  */
137  if (!abstractFile.isFile()) {
138  return ProcessResult.OK;
139  }
140 
141  /*
142  * Attempt embedded file extraction for the file if it is a supported
143  * type/format.
144  */
145  if (archiveExtractor.isSevenZipExtractionSupported(abstractFile)) {
146  archiveExtractor.unpack(abstractFile);
147  } else if (officeExtractor.isContentExtractionSupported(abstractFile)) {
148  officeExtractor.extractEmbeddedContent(abstractFile);
149  }
150  return ProcessResult.OK;
151  }
152 
161  static String getUniqueName(AbstractFile file) {
162  return file.getName() + "_" + file.getId();
163  }
164 
165 }

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