Autopsy  4.14.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.util.Iterator;
32 import java.util.logging.Level;
33 import javax.swing.BorderFactory;
34 import javax.swing.JLabel;
35 import javax.swing.JScrollPane;
36 import javax.swing.JTable;
37 import javax.swing.SwingConstants;
38 import org.openide.util.NbBundle.Messages;
40 
44 public final class RejTreeKeyView extends RejTreeNodeView {
45 
46  private static final long serialVersionUID = 1L;
47  private static final Logger logger = Logger.getLogger(RejTreeKeyView.class.getName());
48 
49  @Messages({"RejTreeKeyView.failedToParse.keyName=FAILED TO PARSE KEY NAME",
50  "RejTreeKeyView.columns.name=Name",
51  "RejTreeKeyView.columns.type=Type",
52  "RejTreeKeyView.columns.value=Value",
53  "RejTreeKeyView.metadataBorder.title=Metadata",
54  "RejTreeKeyView.valuesBorder.title=Values",
55  "RejTreeKeyView.template.name=Name:",
56  "RejTreeKeyView.template.numberOfSubkeys=Number of subkeys:",
57  "RejTreeKeyView.template.numberOfValues=Number of values:"})
59  super(new BorderLayout());
60 
61  /*
62  * param 1 Name
63  * param 2 Number of subkeys
64  * param 3 Number of values
65  */
66  String metadataTemplate = "<html><i>"
67  + Bundle.RejTreeKeyView_template_name()
68  + "</i><b> %1$s</b><br/><i>"
69  + Bundle.RejTreeKeyView_template_numberOfSubkeys()
70  + "</i> %2$d<br/><i>"
71  + Bundle.RejTreeKeyView_template_numberOfValues()
72  + "</i> %3$d<br/></html>";
73  String keyName;
74  int numSubkeys;
75  int numValues;
76 
77  try {
78  keyName = node.getKey().getName();
79  } catch (UnsupportedEncodingException ex) {
80  logger.log(Level.WARNING, "Failed to parse key name", ex);
81  keyName = Bundle.RejTreeKeyView_failedToParse_keyName();
82  }
83 
84  try {
85  numSubkeys = node.getKey().getSubkeyList().size();
86  } catch (RegistryParseException ex) {
87  logger.log(Level.WARNING, "Failed to get subkeylist from key", ex);
88  numSubkeys = -1;
89  }
90 
91  try {
92  numValues = node.getKey().getValueList().size();
93  } catch (RegistryParseException ex) {
94  logger.log(Level.WARNING, "Failed to get value list from key", ex);
95  numValues = -1;
96  }
97 
98  JLabel metadataLabel = new JLabel(String.format(metadataTemplate, keyName, numSubkeys, numValues), JLabel.LEFT);
99  metadataLabel.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeKeyView_metadataBorder_title()));
100  metadataLabel.setVerticalAlignment(SwingConstants.TOP);
101 
102  String[] columnNames = {Bundle.RejTreeKeyView_columns_name(), Bundle.RejTreeKeyView_columns_type(), Bundle.RejTreeKeyView_columns_value()};
103  Object[][] data = new Object[numValues][3];
104 
105  try {
106  Iterator<RegistryValue> valit = node.getKey().getValueList().iterator();
107  int i = 0;
108  while (valit.hasNext()) {
109  RegistryValue val = valit.next();
110  if (val.getName().length() == 0) {
111  data[i][0] = RejTreeValueNode.DEFAULT_VALUE_NAME;
112  } else {
113  data[i][0] = val.getName();
114  }
115  data[i][1] = val.getValueType().toString();
116  data[i][2] = RegeditExeValueFormatter.format(val.getValue());
117  i++;
118  }
119  } catch (RegistryParseException | UnsupportedEncodingException ex) {
120  logger.log(Level.WARNING, "Error while getting RegistryValues.", ex);
121  //some data may have already been added but not necessarily all of it
122  }
123 
124  JTable table = new JTable(data, columnNames);
125  table.setAutoCreateRowSorter(true);
126  table.setCellSelectionEnabled(false);
127  table.setRowSelectionAllowed(true);
128  table.setIntercellSpacing(new Dimension(10, 1));
129 
130  // inspiration for packing the columns from:
131  // http://jroller.com/santhosh/entry/packing_jtable_columns
132  if (table.getColumnCount() > 0) {
133  int width[] = new int[table.getColumnCount()];
134  int total = 0;
135  for (int j = 0; j < width.length; j++) {
136  TableColumn column = table.getColumnModel().getColumn(j);
137  int w = (int) table.getTableHeader().getDefaultRenderer().getTableCellRendererComponent(table, column.getIdentifier(), false, false, -1, j).getPreferredSize().getWidth();
138 
139  if (table.getRowCount() > 0) {
140  for (int i = 0; i < table.getRowCount(); i++) {
141  int pw = (int) table.getCellRenderer(i, j).getTableCellRendererComponent(table, table.getValueAt(i, j), false, false, i, j).getPreferredSize().getWidth();
142  w = Math.max(w, pw);
143  }
144  }
145  width[j] += w + table.getIntercellSpacing().width;
146  total += w + table.getIntercellSpacing().width;
147  }
148  width[width.length - 1] += table.getVisibleRect().width - total;
149  TableColumnModel columnModel = table.getColumnModel();
150  for (int j = 0; j < width.length; j++) {
151  TableColumn column = columnModel.getColumn(j);
152  table.getTableHeader().setResizingColumn(column);
153  column.setWidth(width[j]);
154  }
155  }
156 
157  JScrollPane valuesPane = new JScrollPane(table);
158  valuesPane.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeKeyView_valuesBorder_title()));
159 
160  this.add(metadataLabel, BorderLayout.NORTH);
161  this.add(valuesPane, BorderLayout.CENTER);
162  }
163 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.