Autopsy  4.4
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-2014 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.FsContent;
30 import org.sleuthkit.datamodel.TskCoreException;
31 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
32 
38 @ServiceProvider(service = DataContentViewer.class, position = 3)
39 public class Metadata extends javax.swing.JPanel implements DataContentViewer {
40 
44  public Metadata() {
45  initComponents();
46  customizeComponents();
47  }
48 
54  @SuppressWarnings("unchecked")
55  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
56  private void initComponents() {
57 
58  jPopupMenu1 = new javax.swing.JPopupMenu();
59  jScrollPane2 = new javax.swing.JScrollPane();
60  jTextPane1 = new javax.swing.JTextPane();
61 
62  setPreferredSize(new java.awt.Dimension(610, 52));
63 
64  jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
65  jScrollPane2.setPreferredSize(new java.awt.Dimension(610, 52));
66 
67  jTextPane1.setEditable(false);
68  jTextPane1.setPreferredSize(new java.awt.Dimension(600, 52));
69  jScrollPane2.setViewportView(jTextPane1);
70 
71  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
72  this.setLayout(layout);
73  layout.setHorizontalGroup(
74  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
75  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
76  );
77  layout.setVerticalGroup(
78  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
79  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
80  );
81  }// </editor-fold>//GEN-END:initComponents
82  // Variables declaration - do not modify//GEN-BEGIN:variables
83  private javax.swing.JPopupMenu jPopupMenu1;
84  private javax.swing.JScrollPane jScrollPane2;
85  private javax.swing.JTextPane jTextPane1;
86  // End of variables declaration//GEN-END:variables
87 
88  private void customizeComponents() {
89  /*
90  * jTextPane1.setComponentPopupMenu(rightClickMenu); ActionListener
91  * actList = new ActionListener(){ @Override public void
92  * actionPerformed(ActionEvent e){ JMenuItem jmi = (JMenuItem)
93  * e.getSource(); if(jmi.equals(copyMenuItem)) outputViewPane.copy();
94  * else if(jmi.equals(selectAllMenuItem)) outputViewPane.selectAll(); }
95  * }; copyMenuItem.addActionListener(actList);
96  * selectAllMenuItem.addActionListener(actList);
97  */
98 
100  }
101 
102  private void setText(String str) {
103  jTextPane1.setText("<html><body>" + str + "</body></html>"); //NON-NLS
104  }
105 
106  private void startTable(StringBuilder sb) {
107  sb.append("<table>"); //NON-NLS
108  }
109 
110  private void endTable(StringBuilder sb) {
111  sb.append("</table>"); //NON-NLS
112  }
113 
114  private void addRow(StringBuilder sb, String key, String value) {
115  sb.append("<tr><td>"); //NON-NLS
116  sb.append(key);
117  sb.append("</td><td>"); //NON-NLS
118  sb.append(value);
119  sb.append("</td></tr>"); //NON-NLS
120  }
121 
122  @Messages({
123  "Metadata.tableRowTitle.mimeType=MIME Type",
124  "Metadata.nodeText.truncated=(results truncated)"})
125  @Override
126  public void setNode(Node node) {
127  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
128  if (file == null) {
129  setText(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.nonFilePassedIn"));
130  return;
131  }
132 
133  StringBuilder sb = new StringBuilder();
134  startTable(sb);
135 
136  try {
137  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getUniquePath());
138  } catch (TskCoreException ex) {
139  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.name"), file.getParentPath() + "/" + file.getName());
140  }
141 
142  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.type"), file.getType().getName());
143  addRow(sb, Bundle.Metadata_tableRowTitle_mimeType(), file.getMIMEType());
144  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.size"), Long.toString(file.getSize()));
145  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.fileNameAlloc"), file.getDirFlagAsString());
146  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.metadataAlloc"), file.getMetaFlagsAsString());
147  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.modified"), ContentUtils.getStringTime(file.getMtime(), file));
148  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.accessed"), ContentUtils.getStringTime(file.getAtime(), file));
149  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.created"), ContentUtils.getStringTime(file.getCrtime(), file));
150  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.changed"), ContentUtils.getStringTime(file.getCtime(), file));
151 
152 
153  String md5 = file.getMd5Hash();
154  if (md5 == null) {
155  md5 = NbBundle.getMessage(this.getClass(), "Metadata.tableRowContent.md5notCalc");
156  }
157  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.md5"), md5);
158  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.hashLookupResults"), file.getKnown().toString());
159 
160  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.internalid"), Long.toString(file.getId()));
161  if (file.getType().compareTo(TSK_DB_FILES_TYPE_ENUM.LOCAL) == 0) {
162  addRow(sb, NbBundle.getMessage(this.getClass(), "Metadata.tableRowTitle.localPath"), file.getLocalAbsPath());
163  }
164 
165  endTable(sb);
166 
167  /*
168  * If we have a file system file, grab the more detailed metadata text
169  * too
170  */
171  try {
172  if (file instanceof FsContent) {
173  FsContent fsFile = (FsContent) file;
174 
175  sb.append("<hr /><pre>\n"); //NON-NLS
176  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.text"));
177  sb.append(" <br /><br />"); // NON-NLS
178  for (String str : fsFile.getMetaDataText()) {
179  sb.append(str).append("<br />"); //NON-NLS
180 
181  /*
182  * Very long results can cause the UI to hang before displaying,
183  * so truncate the results if necessary.
184  */
185  if(sb.length() > 50000){
186  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.truncated"));
187  break;
188  }
189  }
190  sb.append("</pre>\n"); //NON-NLS
191  }
192  } catch (TskCoreException ex) {
193  sb.append(NbBundle.getMessage(this.getClass(), "Metadata.nodeText.exceptionNotice.text")).append(ex.getLocalizedMessage());
194  }
195 
196  setText(sb.toString());
197  jTextPane1.setCaretPosition(0);
198  this.setCursor(null);
199  }
200 
201  @Override
202  public String getTitle() {
203  return NbBundle.getMessage(this.getClass(), "Metadata.title");
204  }
205 
206  @Override
207  public String getToolTip() {
208  return NbBundle.getMessage(this.getClass(), "Metadata.toolTip");
209  }
210 
211  @Override
212  public DataContentViewer createInstance() {
213  return new Metadata();
214  }
215 
216  @Override
217  public Component getComponent() {
218  return this;
219  }
220 
221  @Override
222  public void resetComponent() {
223  return;
224  }
225 
226  @Override
227  public boolean isSupported(Node node) {
228  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
229  return file != null;
230  }
231 
232  @Override
233  public int isPreferred(Node node) {
234  return 1;
235  }
236 }
static String getStringTime(long epochSeconds, TimeZone tzone)
void addRow(StringBuilder sb, String key, String value)
Definition: Metadata.java:114
static void configureTextPaneAsHtml(JTextPane pane)
Definition: Utilities.java:31

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.