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

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