Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
RejTreeKeyView.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Copyright 2013 Willi Ballenthin
8  * Contact: willi.ballenthin <at> gmail <dot> com
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 package org.sleuthkit.autopsy.rejview;
23 
24 import com.williballenthin.rejistry.RegistryParseException;
25 import com.williballenthin.rejistry.RegistryValue;
26 import java.awt.BorderLayout;
27 import java.awt.Dimension;
28 import javax.swing.table.TableColumn;
29 import javax.swing.table.TableColumnModel;
30 import java.io.UnsupportedEncodingException;
31 import java.text.SimpleDateFormat;
32 import java.util.Date;
33 import java.util.Iterator;
34 import java.util.logging.Level;
35 import javax.swing.BorderFactory;
36 import javax.swing.JLabel;
37 import javax.swing.JScrollPane;
38 import javax.swing.JTable;
39 import javax.swing.SwingConstants;
40 import org.openide.util.NbBundle.Messages;
42 
46 public final class RejTreeKeyView extends RejTreeNodeView {
47 
48  private static final long serialVersionUID = 1L;
49  private static final Logger logger = Logger.getLogger(RejTreeKeyView.class.getName());
50 
51  @Messages({"RejTreeKeyView.failedToParse.keyName=FAILED TO PARSE KEY NAME",
52  "RejTreeKeyView.columns.name=Name",
53  "RejTreeKeyView.columns.type=Type",
54  "RejTreeKeyView.columns.value=Value",
55  "RejTreeKeyView.metadataBorder.title=Metadata",
56  "RejTreeKeyView.valuesBorder.title=Values",
57  "RejTreeKeyView.template.name=Name:",
58  "RejTreeKeyView.template.numberOfSubkeys=Number of subkeys:",
59  "RejTreeKeyView.template.numberOfValues=Number of values:",
60  "RejTreeKeyView.template.dateTime=Modification Time:"})
62  super(new BorderLayout());
63 
64  /*
65  * param 1 Name
66  * param 2 Number of subkeys
67  * param 3 Number of values
68  * param 4 Date/time
69  */
70  String metadataTemplate = "<html><i>"
71  + Bundle.RejTreeKeyView_template_name()
72  + "</i><b> %1$s</b><br/><i>"
73  + Bundle.RejTreeKeyView_template_numberOfSubkeys()
74  + "</i> %2$d<br/><i>"
75  + Bundle.RejTreeKeyView_template_numberOfValues()
76  + "</i> %3$d<br/><i>"
77  + Bundle.RejTreeKeyView_template_dateTime()
78  + "</i> %4$s</br></html>";
79  String keyName;
80  int numSubkeys;
81  int numValues;
82  String dateTime;
83 
84  try {
85  keyName = node.getKey().getName();
86  } catch (UnsupportedEncodingException ex) {
87  logger.log(Level.WARNING, "Failed to parse key name", ex);
88  keyName = Bundle.RejTreeKeyView_failedToParse_keyName();
89  }
90 
91  try {
92  numSubkeys = node.getKey().getSubkeyList().size();
93  } catch (RegistryParseException ex) {
94  logger.log(Level.WARNING, "Failed to get subkeylist from key", ex);
95  numSubkeys = -1;
96  }
97 
98  try {
99  numValues = node.getKey().getValueList().size();
100  } catch (RegistryParseException ex) {
101  logger.log(Level.WARNING, "Failed to get value list from key", ex);
102  numValues = -1;
103  }
104 
105  Date date = new java.util.Date(node.getKey().getTimestamp().getTimeInMillis());
106  SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
107  sdf.setTimeZone(java.util.TimeZone.getTimeZone("GMT+0"));
108  dateTime = sdf.format(date);
109 
110  JLabel metadataLabel = new JLabel(String.format(metadataTemplate, keyName, numSubkeys, numValues, dateTime), JLabel.LEFT);
111  metadataLabel.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeKeyView_metadataBorder_title()));
112  metadataLabel.setVerticalAlignment(SwingConstants.TOP);
113 
114  String[] columnNames = {Bundle.RejTreeKeyView_columns_name(), Bundle.RejTreeKeyView_columns_type(), Bundle.RejTreeKeyView_columns_value()};
115  Object[][] data = new Object[numValues][3];
116 
117  try {
118  Iterator<RegistryValue> valit = node.getKey().getValueList().iterator();
119  int i = 0;
120  while (valit.hasNext()) {
121  RegistryValue val = valit.next();
122  if (val.getName().length() == 0) {
123  data[i][0] = RejTreeValueNode.DEFAULT_VALUE_NAME;
124  } else {
125  data[i][0] = val.getName();
126  }
127  data[i][1] = val.getValueType().toString();
128  data[i][2] = RegeditExeValueFormatter.format(val.getValue());
129  i++;
130  }
131  } catch (RegistryParseException | UnsupportedEncodingException ex) {
132  logger.log(Level.WARNING, "Error while getting RegistryValues.", ex);
133  //some data may have already been added but not necessarily all of it
134  }
135 
136  JTable table = new JTable(data, columnNames);
137  table.setAutoCreateRowSorter(true);
138  table.setCellSelectionEnabled(false);
139  table.setRowSelectionAllowed(true);
140  table.setIntercellSpacing(new Dimension(10, 1));
141 
142  // inspiration for packing the columns from:
143  // http://jroller.com/santhosh/entry/packing_jtable_columns
144  if (table.getColumnCount() > 0) {
145  int width[] = new int[table.getColumnCount()];
146  int total = 0;
147  for (int j = 0; j < width.length; j++) {
148  TableColumn column = table.getColumnModel().getColumn(j);
149  int w = (int) table.getTableHeader().getDefaultRenderer().getTableCellRendererComponent(table, column.getIdentifier(), false, false, -1, j).getPreferredSize().getWidth();
150 
151  if (table.getRowCount() > 0) {
152  for (int i = 0; i < table.getRowCount(); i++) {
153  int pw = (int) table.getCellRenderer(i, j).getTableCellRendererComponent(table, table.getValueAt(i, j), false, false, i, j).getPreferredSize().getWidth();
154  w = Math.max(w, pw);
155  }
156  }
157  width[j] += w + table.getIntercellSpacing().width;
158  total += w + table.getIntercellSpacing().width;
159  }
160  width[width.length - 1] += table.getVisibleRect().width - total;
161  TableColumnModel columnModel = table.getColumnModel();
162  for (int j = 0; j < width.length; j++) {
163  TableColumn column = columnModel.getColumn(j);
164  table.getTableHeader().setResizingColumn(column);
165  column.setWidth(width[j]);
166  }
167  }
168 
169  JScrollPane valuesPane = new JScrollPane(table);
170  valuesPane.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeKeyView_valuesBorder_title()));
171 
172  this.add(metadataLabel, BorderLayout.NORTH);
173  this.add(valuesPane, BorderLayout.CENTER);
174  }
175 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.