Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
RejTreeValueView.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.ValueData;
26 import java.awt.BorderLayout;
27 import java.io.UnsupportedEncodingException;
28 import java.util.logging.Level;
29 import javax.swing.BorderFactory;
30 import javax.swing.JComponent;
31 import javax.swing.JLabel;
32 import javax.swing.JScrollPane;
33 import javax.swing.SwingConstants;
34 import org.openide.util.NbBundle.Messages;
36 
40 public final class RejTreeValueView extends RejTreeNodeView {
41 
42  private static final long serialVersionUID = 1L;
43  private static final Logger logger = Logger.getLogger(RejTreeValueView.class.getName());
44 
45  @Messages({"RejTreeValueView.template.name=Name:",
46  "RejTreeValueView.template.type=Type:",
47  "RejTreeValueView.failedToDecode.valueName=FAILED TO DECODE VALUE NAME",
48  "RejTreeValueView.failedToDecode.valueType=FAILED TO PARSE VALUE TYPE",
49  "RejTreeValueView.failedToParse.value=FAILED TO PARSE VALUE VALUE",
50  "RejTreeValueView.metadataBorder.title=Metadata",
51  "RejTreeValueView.valueBorder.title=Value",})
53  super(new BorderLayout());
54  /*
55  * param 1 Name
56  * param 2 Type
57  */
58  String metadataTemplate = "<html><i>"
59  + Bundle.RejTreeValueView_template_name()
60  + "</i><b> %1$s</b><br/><i>"
61  + Bundle.RejTreeValueView_template_type()
62  + " </i> %2$s</html>";
63  String valueName;
64  String valueType;
65 
66  /*
67  * param 1 Value
68  */
69  String valueTemplate = "<html>%1$s</html>";
70  try {
71  valueName = node.getValue().getName();
72  } catch (UnsupportedEncodingException ex) {
73  logger.log(Level.WARNING, "Failed to get value name", ex);
74  valueName = Bundle.RejTreeValueView_failedToDecode_valueName();
75  }
76 
77  try {
78  valueType = node.getValue().getValueType().toString();
79  } catch (RegistryParseException ex) {
80  logger.log(Level.WARNING, "Failed to get value type", ex);
81  valueType = Bundle.RejTreeValueView_failedToDecode_valueType();
82  }
83 
84  JLabel metadataLabel = new JLabel(String.format(metadataTemplate, valueName, valueType), JLabel.LEFT);
85  metadataLabel.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeValueView_metadataBorder_title()));
86  metadataLabel.setVerticalAlignment(SwingConstants.TOP);
87 
88  // this valueComponent must be set in the follow try/catch block.
89  JComponent valueComponent;
90  try {
91  ValueData data = node.getValue().getValue();
92 
93  // the case statements are a bit repetitive, but i think make more sense than confusingly-nested if/elses
94  switch (data.getValueType()) {
95  case REG_SZ: // empty case - intentional fall-through
96  case REG_EXPAND_SZ: {
97  String valueValue = data.getAsString();
98  JLabel valueLabel = new JLabel(String.format(valueTemplate, valueValue), JLabel.LEFT);
99  valueLabel.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeValueView_valueBorder_title()));
100  valueLabel.setVerticalAlignment(SwingConstants.TOP);
101  valueComponent = valueLabel;
102  break;
103  }
104  case REG_MULTI_SZ: {
105  StringBuilder sb = new StringBuilder();
106  for (String s : data.getAsStringList()) {
107  sb.append(s);
108  sb.append("<br />");
109  }
110  String valueValue = sb.toString();
111  JLabel valueLabel = new JLabel(String.format(valueTemplate, valueValue), JLabel.LEFT);
112  valueLabel.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeValueView_valueBorder_title()));
113  valueLabel.setVerticalAlignment(SwingConstants.TOP);
114  valueComponent = valueLabel;
115  break;
116  }
117  case REG_DWORD: // empty case - intentional fall-through
118  case REG_QWORD: // empty case - intentional fall-through
119  case REG_BIG_ENDIAN: {
120  String valueValue = String.format("0x%x", data.getAsNumber());
121  JLabel valueLabel = new JLabel(String.format(valueTemplate, valueValue), JLabel.LEFT);
122  valueLabel.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeValueView_valueBorder_title()));
123  valueLabel.setVerticalAlignment(SwingConstants.TOP);
124  valueComponent = valueLabel;
125  break;
126  }
127  default: {
128  HexView hexView = new HexView(data.getAsRawData());
129  hexView.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeValueView_valueBorder_title()));
130  valueComponent = hexView;
131  break;
132  }
133  }
134  } catch (RegistryParseException | UnsupportedEncodingException ex) {
135  logger.log(Level.WARNING, "Failure getting or parsing value value", ex);
136  JLabel valueLabel = new JLabel(String.format(valueTemplate, Bundle.RejTreeValueView_failedToParse_value()), JLabel.LEFT);
137  valueLabel.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeValueView_valueBorder_title()));
138  valueLabel.setVerticalAlignment(SwingConstants.TOP);
139  valueComponent = valueLabel;
140  }
141 
142  this.add(metadataLabel, BorderLayout.NORTH);
143  this.add(new JScrollPane(valueComponent), BorderLayout.CENTER);
144  }
145 }
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.