22 package org.sleuthkit.autopsy.rejview;
24 import com.williballenthin.rejistry.HexDump;
25 import com.williballenthin.rejistry.RegistryParseException;
26 import com.williballenthin.rejistry.ValueData;
27 import java.io.UnsupportedEncodingException;
28 import java.nio.ByteBuffer;
29 import java.util.Iterator;
30 import org.openide.util.NbBundle.Messages;
37 final class RegeditExeValueFormatter {
39 private static final int MAX_STRING_LENGTH = 48;
40 private static final int MAX_BUFFER_SIZE = 16;
41 private static final String OVER_MAX_LENGTH_ENDING =
"...";
43 @Messages({
"RegeditExeValueFormatter.valueNotSet.text=(value not set)"})
44 static String format(ValueData val)
throws UnsupportedEncodingException, RegistryParseException {
45 StringBuilder sb =
new StringBuilder();
47 switch (val.getValueType()) {
51 String valString = val.getAsString();
52 if (valString.length() == 0) {
53 sb.append(Bundle.RegeditExeValueFormatter_valueNotSet_text());
57 if (sb.length() > MAX_STRING_LENGTH) {
58 sb.setLength(MAX_STRING_LENGTH - OVER_MAX_LENGTH_ENDING.length());
59 sb.append(OVER_MAX_LENGTH_ENDING);
64 Iterator<String> it = val.getAsStringList().iterator();
65 while (it.hasNext()) {
71 if (sb.length() > MAX_STRING_LENGTH) {
72 sb.setLength(MAX_STRING_LENGTH - OVER_MAX_LENGTH_ENDING.length());
73 sb.append(OVER_MAX_LENGTH_ENDING);
78 case REG_BIG_ENDIAN: {
79 sb.append(String.format(
"0x%08x (%d)", val.getAsNumber(), val.getAsNumber()));
83 sb.append(String.format(
"0x%016x (%d)", val.getAsNumber(), val.getAsNumber()));
87 ByteBuffer valData = val.getAsRawData();
88 valData.position(0x0);
89 for (
int i = 0; i < Math.min(MAX_BUFFER_SIZE, valData.limit()); i++) {
90 byte b = valData.get();
91 sb.append(HexDump.toHexString(b));
92 if (i != MAX_BUFFER_SIZE - 1) {
96 if (valData.limit() > MAX_BUFFER_SIZE) {
97 sb.append(OVER_MAX_LENGTH_ENDING);
102 return sb.toString();
105 private RegeditExeValueFormatter() {