Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
Metadata.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.contentviewers;
20 
21 import java.awt.Component;
22 import org.openide.nodes.Node;
23 import org.openide.util.NbBundle;
24 import org.openide.util.NbBundle.Messages;
25 import org.openide.util.lookup.ServiceProvider;
28 import org.sleuthkit.datamodel.AbstractFile;
29 import org.sleuthkit.datamodel.Image;
30 import org.sleuthkit.datamodel.FsContent;
31 import org.sleuthkit.datamodel.TskCoreException;
32 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
33 
39 @ServiceProvider(service = DataContentViewer.class, position = 6)
40 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
41 public class Metadata extends javax.swing.JPanel implements DataContentViewer {
42 
46  public Metadata() {
47  initComponents();
48  customizeComponents();
49  }
50 
56  @SuppressWarnings("unchecked")
57  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
58  private void initComponents() {
59 
60  jPopupMenu1 = new javax.swing.JPopupMenu();
61  jScrollPane2 = new javax.swing.JScrollPane();
62  jTextPane1 = new javax.swing.JTextPane();
63 
64  setPreferredSize(new java.awt.Dimension(100, 52));
65 
66  jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
67  jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
68  jScrollPane2.setPreferredSize(new java.awt.Dimension(610, 52));
69 
70  jTextPane1.setEditable(false);
71  jTextPane1.setPreferredSize(new java.awt.Dimension(600, 52));
72  jScrollPane2.setViewportView(jTextPane1);
73 
74  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
75  this.setLayout(layout);
76  layout.setHorizontalGroup(
77  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
78  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
79  );
80  layout.setVerticalGroup(
81  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
82  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
83  );
84  }// </editor-fold>//GEN-END:initComponents
85  // Variables declaration - do not modify//GEN-BEGIN:variables
86  private javax.swing.JPopupMenu jPopupMenu1;
87  private javax.swing.JScrollPane jScrollPane2;
88  private javax.swing.JTextPane jTextPane1;
89  // End of variables declaration//GEN-END:variables
90 
91  private void customizeComponents() {
92  /*
93  * jTextPane1.setComponentPopupMenu(rightClickMenu); ActionListener
94  * actList = new ActionListener(){ @Override public void
95  * actionPerformed(ActionEvent e){ JMenuItem jmi = (JMenuItem)
96  * e.getSource(); if(jmi.equals(copyMenuItem)) outputViewPane.copy();
97  * else if(jmi.equals(selectAllMenuItem)) outputViewPane.selectAll(); }
98  * }; copyMenuItem.addActionListener(actList);
99  * selectAllMenuItem.addActionListener(actList);
100  */
101 
103  }
104 
105  private void setText(String str) {
106  jTextPane1.setText("<html><body>" + str + "</body></html>"); //NON-NLS
107  }
108 
109  private void startTable(StringBuilder sb) {
110  sb.append("<table>"); //NON-NLS
111  }
112 
113  private void endTable(StringBuilder sb) {
114  sb.append("</table>"); //NON-NLS
115  }
116 
117  private void addRow(StringBuilder sb, String key, String value) {
118  sb.append("<tr><td valign=\"top\">"); //NON-NLS
119  sb.append(key);
120  sb.append("</td><td>"); //NON-NLS
121  sb.append(value);
122  sb.append("</td></tr>"); //NON-NLS
123  }
124 
125  @Messages({
126  "Metadata.tableRowTitle.mimeType=MIME Type",
127  "Metadata.nodeText.truncated=(results truncated)",
128  "Metadata.tableRowTitle.sha1=SHA1",
129  "Metadata.tableRowTitle.sha256=SHA256",
130  "Metadata.tableRowTitle.imageType=Type",
131  "Metadata.tableRowTitle.sectorSize=Sector Size",
132  "Metadata.tableRowTitle.timezone=Time Zone",
133  "Metadata.tableRowTitle.deviceId=Device ID"})
134  @Override
135  public void setNode(Node node) {
136  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
137  Image image = node.getLookup().lookup((Image.class));
138  if (file == null && image == null) {
139  setText(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.nonFilePassedIn"));
140  return;
141  }
142 
143  StringBuilder sb = new StringBuilder();
144  startTable(sb);
145 
146  if (file != null) {
147  try {
148  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getUniquePath());
149  } catch (TskCoreException ex) {
150  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getParentPath() + "/" + file.getName());
151  }
152 
153  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.type"), file.getType().getName());
154  addRow(sb, Bundle.Metadata_tableRowTitle_mimeType(), file.getMIMEType());
155  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.size"), Long.toString(file.getSize()));
156  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.fileNameAlloc"), file.getDirFlagAsString());
157  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.metadataAlloc"), file.getMetaFlagsAsString());
158  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.modified"), ContentUtils.getStringTime(file.getMtime(), file));
159  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.accessed"), ContentUtils.getStringTime(file.getAtime(), file));
160  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.created"), ContentUtils.getStringTime(file.getCrtime(), file));
161  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.changed"), ContentUtils.getStringTime(file.getCtime(), file));
162 
163 
164  String md5 = file.getMd5Hash();
165  if (md5 == null) {
166  md5 = NbBundle.getMessage(this.getClass(), "Metadata.tableRowContent.md5notCalc");
167  }
168  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.md5"), md5);
169  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.hashLookupResults"), file.getKnown().toString());
170 
171  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.internalid"), Long.toString(file.getId()));
172  if (file.getType().compareTo(TSK_DB_FILES_TYPE_ENUM.LOCAL) == 0) {
173  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.localPath"), file.getLocalAbsPath());
174  }
175 
176  endTable(sb);
177 
178  /*
179  * If we have a file system file, grab the more detailed metadata text
180  * too
181  */
182  try {
183  if (file instanceof FsContent) {
184  FsContent fsFile = (FsContent) file;
185 
186  sb.append("<hr /><pre>\n"); //NON-NLS
187  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.text"));
188  sb.append(" <br /><br />"); // NON-NLS
189  for (String str : fsFile.getMetaDataText()) {
190  sb.append(str).append("<br />"); //NON-NLS
191 
192  /*
193  * Very long results can cause the UI to hang before displaying,
194  * so truncate the results if necessary.
195  */
196  if(sb.length() > 50000){
197  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.truncated"));
198  break;
199  }
200  }
201  sb.append("</pre>\n"); //NON-NLS
202  }
203  } catch (TskCoreException ex) {
204  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.exceptionNotice.text")).append(ex.getLocalizedMessage());
205  }
206  } else {
207  try {
208  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), image.getUniquePath());
209  } catch (TskCoreException ex) {
210  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), image.getName());
211  }
212  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.imageType"), image.getType().getName());
213  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.size"), Long.toString(image.getSize()));
214 
215  try {
216  String md5 = image.getMd5();
217  if (md5 == null || md5.isEmpty()) {
218  md5 = NbBundle.getMessage(this.getClass(), "Metadata.tableRowContent.md5notCalc");
219  }
220  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.md5"), md5);
221 
222  String sha1 = image.getSha1();
223  if (sha1 == null || sha1.isEmpty()) {
224  sha1 = NbBundle.getMessage(this.getClass(), "Metadata.tableRowContent.md5notCalc");
225  }
226  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.sha1"), sha1);
227 
228  String sha256 = image.getSha256();
229  if (sha256 == null || sha256.isEmpty()) {
230  sha256 = NbBundle.getMessage(this.getClass(), "Metadata.tableRowContent.md5notCalc");
231  }
232  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.sha256"), sha256);
233  } catch (TskCoreException ex) {
234  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.exceptionNotice.text")).append(ex.getLocalizedMessage());
235  }
236  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.sectorSize"), Long.toString(image.getSsize()));
237  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.timezone"), image.getTimeZone());
238  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.deviceId"), image.getDeviceId());
239  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.internalid"), Long.toString(image.getId()));
240 
241  // Add all the data source paths to the "Local Path" value cell.
242  String[] imagePaths = image.getPaths();
243  StringBuilder pathValues = new StringBuilder("<div>");
244  pathValues.append(imagePaths[0]);
245  pathValues.append("</div>");
246  for (int i=1; i < imagePaths.length; i++) {
247  pathValues.append("<div>");
248  pathValues.append(imagePaths[i]);
249  pathValues.append("</div>");
250  }
251  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.localPath"), pathValues.toString());
252  }
253 
254  setText(sb.toString());
255  jTextPane1.setCaretPosition(0);
256  this.setCursor(null);
257  }
258 
259  @Override
260  public String getTitle() {
261  return NbBundle.getMessage(this.getClass(), "Metadata.title");
262  }
263 
264  @Override
265  public String getToolTip() {
266  return NbBundle.getMessage(this.getClass(), "Metadata.toolTip");
267  }
268 
269  @Override
270  public DataContentViewer createInstance() {
271  return new Metadata();
272  }
273 
274  @Override
275  public Component getComponent() {
276  return this;
277  }
278 
279  @Override
280  public void resetComponent() {
281  setText("");
282  }
283 
284  @Override
285  public boolean isSupported(Node node) {
286  Image image = node.getLookup().lookup(Image.class);
287  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
288  return (file != null) || (image != null);
289  }
290 
291  @Override
292  public int isPreferred(Node node) {
293  return 1;
294  }
295 }
static String getStringTime(long epochSeconds, TimeZone tzone)
void addRow(StringBuilder sb, String key, String value)
Definition: Metadata.java:117
static void configureTextPaneAsHtml(JTextPane pane)
Definition: Utilities.java:32

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.