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

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.