23 package org.sleuthkit.autopsy.report;
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;
32 import org.openide.util.NbBundle;
45 class ReportBodyFile
implements GeneralReportModule {
47 private static final Logger logger = Logger.getLogger(ReportBodyFile.class.getName());
48 private static ReportBodyFile instance = null;
50 private Case currentCase;
51 private SleuthkitCase skCase;
53 private String reportPath;
56 private ReportBodyFile() {
60 public static synchronized ReportBodyFile getDefault() {
61 if (instance == null) {
62 instance =
new ReportBodyFile();
74 @SuppressWarnings(
"deprecation")
75 public
void generateReport(String baseReportDir, ReportProgressPanel progressPanel) {
78 currentCase = Case.getCurrentCaseThrows();
79 }
catch (NoCurrentCaseException ex) {
80 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
83 progressPanel.setIndeterminate(
false);
84 progressPanel.start();
85 progressPanel.updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportBodyFile.progress.querying"));
86 reportPath = baseReportDir + getRelativeFilePath();
88 skCase = currentCase.getSleuthkitCase();
93 final String query =
"type = " + TskData.TSK_DB_FILES_TYPE_ENUM.FS.getFileType()
94 +
" AND name != '.' AND name != '..'";
96 progressPanel.updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportBodyFile.progress.loading"));
97 List<AbstractFile> fs = skCase.findAllFilesWhere(query);
100 String ingestwarning =
"";
101 if (IngestManager.getInstance().isIngestRunning()) {
102 ingestwarning = NbBundle.getMessage(this.getClass(),
"ReportBodyFile.ingestWarning.text");
105 int size = fs.size();
106 progressPanel.setMaximumProgress(size / 100);
108 BufferedWriter out = null;
111 out =
new BufferedWriter(
new FileWriter(reportPath,
true));
112 out.write(ingestwarning);
115 for (AbstractFile file : fs) {
116 if (progressPanel.getStatus() == ReportStatus.CANCELED) {
119 if (count++ == 100) {
120 progressPanel.increment();
121 progressPanel.updateStatusLabel(
122 NbBundle.getMessage(
this.getClass(),
"ReportBodyFile.progress.processing",
127 if (file.getMd5Hash() != null) {
128 out.write(file.getMd5Hash());
131 if (file.getUniquePath() != null) {
132 out.write(file.getUniquePath());
135 out.write(Long.toString(file.getMetaAddr()));
137 String modeString = file.getModesAsString();
138 if (modeString != null) {
139 out.write(modeString);
142 out.write(Long.toString(file.getUid()));
144 out.write(Long.toString(file.getGid()));
146 out.write(Long.toString(file.getSize()));
148 out.write(Long.toString(file.getAtime()));
150 out.write(Long.toString(file.getMtime()));
152 out.write(Long.toString(file.getCtime()));
154 out.write(Long.toString(file.getCrtime()));
157 }
catch (IOException ex) {
158 logger.log(Level.WARNING,
"Could not write the temp body file report.", ex);
164 Case.getCurrentCaseThrows().addReport(reportPath,
165 NbBundle.getMessage(
this.getClass(),
166 "ReportBodyFile.generateReport.srcModuleName.text"),
"");
169 }
catch (IOException ex) {
170 logger.log(Level.WARNING,
"Could not flush and close the BufferedWriter.", ex);
171 }
catch (TskCoreException | NoCurrentCaseException ex) {
172 String errorMessage = String.format(
"Error adding %s to case as a report", reportPath);
173 logger.log(Level.SEVERE, errorMessage, ex);
176 progressPanel.complete(ReportStatus.COMPLETE);
177 }
catch (TskCoreException ex) {
178 logger.log(Level.WARNING,
"Failed to get the unique path.", ex);
183 public String getName() {
184 String name = NbBundle.getMessage(this.getClass(),
"ReportBodyFile.getName.text");
189 public String getRelativeFilePath() {
190 return NbBundle.getMessage(this.getClass(),
"ReportBodyFile.getFilePath.text");
194 public String getDescription() {
195 String desc = NbBundle.getMessage(this.getClass(),
"ReportBodyFile.getDesc.text");
200 public JPanel getConfigurationPanel() {