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

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