Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
BodyFileReport.java
Go to the documentation of this file.
1  /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2012-2018 Basis Technology Corp.
6  *
7  * Copyright 2012 42six Solutions.
8  * Contact: aebadirad <at> 42six <dot> com
9  * Project Contact/Architect: carrier <at> sleuthkit <dot> org
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.sleuthkit.autopsy.report.modules.bodyfile;
24 
26 import java.io.BufferedWriter;
27 import java.io.FileWriter;
28 import java.io.IOException;
29 import java.util.List;
30 import java.util.logging.Level;
31 import javax.swing.JPanel;
32 
33 import org.openide.util.NbBundle;
40 import org.sleuthkit.datamodel.*;
41 
47 class BodyFileReport implements GeneralReportModule {
48 
49  private static final Logger logger = Logger.getLogger(BodyFileReport.class.getName());
50  private static BodyFileReport instance = null;
51 
52  private Case currentCase;
53  private SleuthkitCase skCase;
54 
55  private String reportPath;
56 
57  // Hidden constructor for the report
58  private BodyFileReport() {
59  }
60 
61  // Get the default implementation of this report
62  public static synchronized BodyFileReport getDefault() {
63  if (instance == null) {
64  instance = new BodyFileReport();
65  }
66  return instance;
67  }
68 
75  @Override
76  @SuppressWarnings("deprecation")
77  public void generateReport(String baseReportDir, ReportProgressPanel progressPanel) {
78  // Start the progress bar and setup the report
79  try {
80  currentCase = Case.getCurrentCaseThrows();
81  } catch (NoCurrentCaseException ex) {
82  logger.log(Level.SEVERE, "Exception while getting open case.", ex);
83  return;
84  }
85  progressPanel.setIndeterminate(false);
86  progressPanel.start();
87  progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportBodyFile.progress.querying"));
88  reportPath = baseReportDir + getRelativeFilePath(); //NON-NLS
89 
90  skCase = currentCase.getSleuthkitCase();
91 
92  // Run query to get all files
93  try {
94  // exclude non-fs files/dirs and . and .. files
95  final String query = "type = " + TskData.TSK_DB_FILES_TYPE_ENUM.FS.getFileType() //NON-NLS
96  + " AND name != '.' AND name != '..'"; //NON-NLS
97 
98  progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportBodyFile.progress.loading"));
99  List<AbstractFile> fs = skCase.findAllFilesWhere(query);
100 
101  // Check if ingest has finished
102  String ingestwarning = "";
104  ingestwarning = NbBundle.getMessage(this.getClass(), "ReportBodyFile.ingestWarning.text");
105  }
106 
107  int size = fs.size();
108  progressPanel.setMaximumProgress(size / 100);
109 
110  BufferedWriter out = null;
111  try {
112  // MD5|name|inode|mode_as_string|UID|GID|size|atime|mtime|ctime|crtime
113  out = new BufferedWriter(new FileWriter(reportPath, true));
114  out.write(ingestwarning);
115  // Loop files and write info to report
116  int count = 0;
117  for (AbstractFile file : fs) {
118  if (progressPanel.getStatus() == ReportStatus.CANCELED) {
119  break;
120  }
121  if (count++ == 100) {
122  progressPanel.increment();
123  progressPanel.updateStatusLabel(
124  NbBundle.getMessage(this.getClass(), "ReportBodyFile.progress.processing",
125  file.getName()));
126  count = 0;
127  }
128 
129  if (file.getMd5Hash() != null) {
130  out.write(file.getMd5Hash());
131  }
132  out.write("|");
133  if (file.getUniquePath() != null) {
134  out.write(file.getUniquePath());
135  }
136  out.write("|");
137  out.write(Long.toString(file.getMetaAddr()));
138  out.write("|");
139  String modeString = file.getModesAsString();
140  if (modeString != null) {
141  out.write(modeString);
142  }
143  out.write("|");
144  out.write(Long.toString(file.getUid()));
145  out.write("|");
146  out.write(Long.toString(file.getGid()));
147  out.write("|");
148  out.write(Long.toString(file.getSize()));
149  out.write("|");
150  out.write(Long.toString(file.getAtime()));
151  out.write("|");
152  out.write(Long.toString(file.getMtime()));
153  out.write("|");
154  out.write(Long.toString(file.getCtime()));
155  out.write("|");
156  out.write(Long.toString(file.getCrtime()));
157  out.write("\n");
158  }
159  } catch (IOException ex) {
160  logger.log(Level.WARNING, "Could not write the temp body file report.", ex); //NON-NLS
161  } finally {
162  try {
163  if (out != null) {
164  out.flush();
165  out.close();
166  Case.getCurrentCaseThrows().addReport(reportPath,
167  NbBundle.getMessage(this.getClass(),
168  "ReportBodyFile.generateReport.srcModuleName.text"), "");
169 
170  }
171  } catch (IOException ex) {
172  logger.log(Level.WARNING, "Could not flush and close the BufferedWriter.", ex); //NON-NLS
173  } catch (TskCoreException | NoCurrentCaseException ex) {
174  String errorMessage = String.format("Error adding %s to case as a report", reportPath); //NON-NLS
175  logger.log(Level.SEVERE, errorMessage, ex);
176  }
177  }
178  progressPanel.complete(ReportStatus.COMPLETE);
179  } catch (TskCoreException ex) {
180  logger.log(Level.WARNING, "Failed to get the unique path.", ex); //NON-NLS
181  }
182  }
183 
184  @Override
185  public String getName() {
186  String name = NbBundle.getMessage(this.getClass(), "ReportBodyFile.getName.text");
187  return name;
188  }
189 
190  @Override
191  public String getRelativeFilePath() {
192  return NbBundle.getMessage(this.getClass(), "ReportBodyFile.getFilePath.text");
193  }
194 
195  @Override
196  public String getDescription() {
197  String desc = NbBundle.getMessage(this.getClass(), "ReportBodyFile.getDesc.text");
198  return desc;
199  }
200 
201  @Override
202  public JPanel getConfigurationPanel() {
203  return null; // No configuration panel
204  }
205 }
static synchronized IngestManager getInstance()
void addReport(String localPath, String srcModuleName, String reportName)
Definition: Case.java:1630
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.