Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportBodyFile.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;
24 
25 import java.io.BufferedWriter;
26 import java.io.FileWriter;
27 import java.io.IOException;
28 import java.util.List;
29 import java.util.logging.Level;
30 import javax.swing.JPanel;
31 
32 import org.openide.util.NbBundle;
38 import org.sleuthkit.datamodel.*;
39 
45 class ReportBodyFile implements GeneralReportModule {
46 
47  private static final Logger logger = Logger.getLogger(ReportBodyFile.class.getName());
48  private static ReportBodyFile instance = null;
49 
50  private Case currentCase;
51  private SleuthkitCase skCase;
52 
53  private String reportPath;
54 
55  // Hidden constructor for the report
56  private ReportBodyFile() {
57  }
58 
59  // Get the default implementation of this report
60  public static synchronized ReportBodyFile getDefault() {
61  if (instance == null) {
62  instance = new ReportBodyFile();
63  }
64  return instance;
65  }
66 
73  @Override
74  @SuppressWarnings("deprecation")
75  public void generateReport(String baseReportDir, ReportProgressPanel progressPanel) {
76  // Start the progress bar and setup the report
77  try {
78  currentCase = Case.getCurrentCaseThrows();
79  } catch (NoCurrentCaseException ex) {
80  logger.log(Level.SEVERE, "Exception while getting open case.", ex);
81  return;
82  }
83  progressPanel.setIndeterminate(false);
84  progressPanel.start();
85  progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportBodyFile.progress.querying"));
86  reportPath = baseReportDir + getRelativeFilePath(); //NON-NLS
87 
88  skCase = currentCase.getSleuthkitCase();
89 
90  // Run query to get all files
91  try {
92  // exclude non-fs files/dirs and . and .. files
93  final String query = "type = " + TskData.TSK_DB_FILES_TYPE_ENUM.FS.getFileType() //NON-NLS
94  + " AND name != '.' AND name != '..'"; //NON-NLS
95 
96  progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportBodyFile.progress.loading"));
97  List<AbstractFile> fs = skCase.findAllFilesWhere(query);
98 
99  // Check if ingest has finished
100  String ingestwarning = "";
101  if (IngestManager.getInstance().isIngestRunning()) {
102  ingestwarning = NbBundle.getMessage(this.getClass(), "ReportBodyFile.ingestWarning.text");
103  }
104 
105  int size = fs.size();
106  progressPanel.setMaximumProgress(size / 100);
107 
108  BufferedWriter out = null;
109  try {
110  // MD5|name|inode|mode_as_string|UID|GID|size|atime|mtime|ctime|crtime
111  out = new BufferedWriter(new FileWriter(reportPath, true));
112  out.write(ingestwarning);
113  // Loop files and write info to report
114  int count = 0;
115  for (AbstractFile file : fs) {
116  if (progressPanel.getStatus() == ReportStatus.CANCELED) {
117  break;
118  }
119  if (count++ == 100) {
120  progressPanel.increment();
121  progressPanel.updateStatusLabel(
122  NbBundle.getMessage(this.getClass(), "ReportBodyFile.progress.processing",
123  file.getName()));
124  count = 0;
125  }
126 
127  if (file.getMd5Hash() != null) {
128  out.write(file.getMd5Hash());
129  }
130  out.write("|");
131  if (file.getUniquePath() != null) {
132  out.write(file.getUniquePath());
133  }
134  out.write("|");
135  out.write(Long.toString(file.getMetaAddr()));
136  out.write("|");
137  String modeString = file.getModesAsString();
138  if (modeString != null) {
139  out.write(modeString);
140  }
141  out.write("|");
142  out.write(Long.toString(file.getUid()));
143  out.write("|");
144  out.write(Long.toString(file.getGid()));
145  out.write("|");
146  out.write(Long.toString(file.getSize()));
147  out.write("|");
148  out.write(Long.toString(file.getAtime()));
149  out.write("|");
150  out.write(Long.toString(file.getMtime()));
151  out.write("|");
152  out.write(Long.toString(file.getCtime()));
153  out.write("|");
154  out.write(Long.toString(file.getCrtime()));
155  out.write("\n");
156  }
157  } catch (IOException ex) {
158  logger.log(Level.WARNING, "Could not write the temp body file report.", ex); //NON-NLS
159  } finally {
160  try {
161  if (out != null) {
162  out.flush();
163  out.close();
164  Case.getCurrentCaseThrows().addReport(reportPath,
165  NbBundle.getMessage(this.getClass(),
166  "ReportBodyFile.generateReport.srcModuleName.text"), "");
167 
168  }
169  } catch (IOException ex) {
170  logger.log(Level.WARNING, "Could not flush and close the BufferedWriter.", ex); //NON-NLS
171  } catch (TskCoreException | NoCurrentCaseException ex) {
172  String errorMessage = String.format("Error adding %s to case as a report", reportPath); //NON-NLS
173  logger.log(Level.SEVERE, errorMessage, ex);
174  }
175  }
176  progressPanel.complete(ReportStatus.COMPLETE);
177  } catch (TskCoreException ex) {
178  logger.log(Level.WARNING, "Failed to get the unique path.", ex); //NON-NLS
179  }
180  }
181 
182  @Override
183  public String getName() {
184  String name = NbBundle.getMessage(this.getClass(), "ReportBodyFile.getName.text");
185  return name;
186  }
187 
188  @Override
189  public String getRelativeFilePath() {
190  return NbBundle.getMessage(this.getClass(), "ReportBodyFile.getFilePath.text");
191  }
192 
193  @Override
194  public String getDescription() {
195  String desc = NbBundle.getMessage(this.getClass(), "ReportBodyFile.getDesc.text");
196  return desc;
197  }
198 
199  @Override
200  public JPanel getConfigurationPanel() {
201  return null; // No configuration panel
202  }
203 }

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