22 package org.sleuthkit.autopsy.contentviewers;
24 import com.williballenthin.rejistry.RegistryHive;
25 import com.williballenthin.rejistry.RegistryHiveBuffer;
26 import com.williballenthin.rejistry.RegistryParseException;
27 import java.awt.BorderLayout;
28 import java.awt.Component;
29 import java.awt.Cursor;
30 import java.nio.ByteBuffer;
31 import java.util.Arrays;
32 import java.util.List;
33 import java.util.logging.Level;
34 import javax.swing.JPanel;
44 class WindowsRegistryViewer
extends JPanel implements FileTypeViewer {
46 private static final long serialVersionUID = 1L;
47 private static final Logger logger = Logger.getLogger(WindowsRegistryViewer.class.getName());
48 private static final String[] SUPPORTED_MIMETYPES =
new String[]{
"application/x.windows-registry"};
50 private static final String LOG_FILE_EXTENSION =
"log";
51 private RejView regview;
52 private AbstractFile lastFile;
54 WindowsRegistryViewer() {
55 super(
new BorderLayout());
58 private void setDataView(Content content) {
59 if (content == null) {
60 this.resetComponent();
64 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
66 if (content.getSize() == 0) {
70 byte[] data =
new byte[(int) content.getSize()];
73 content.read(data, 0x0, content.getSize());
74 }
catch (TskCoreException ex) {
75 logger.log(Level.WARNING,
"Failed to read file content.", ex);
78 ByteBuffer buf = ByteBuffer.wrap(data);
80 RegistryHive h =
new RegistryHiveBuffer(buf);
81 this.regview =
new RejView(h);
82 this.add(this.regview, BorderLayout.CENTER);
88 public Component getComponent() {
93 public void resetComponent() {
95 if (this.regview != null) {
96 this.
remove(this.regview);
103 public boolean isSupported(AbstractFile file) {
107 if (file.getSize() == 0) {
111 if (file.getNameExtension().toLowerCase().startsWith(LOG_FILE_EXTENSION)) {
114 byte[] header =
new byte[0x4000];
117 file.read(header, 0x0, Math.min(0x4000, file.getSize()));
118 }
catch (TskCoreException ex) {
119 logger.log(Level.WARNING,
"Failed to read file content", ex);
122 ByteBuffer buf = ByteBuffer.wrap(header);
124 RegistryHive hive =
new RegistryHiveBuffer(buf);
128 }
catch (RegistryParseException ex) {
129 logger.log(Level.WARNING,
"Failed to get hive header", ex);
135 public List<String> getSupportedMIMETypes() {
136 return Arrays.asList(SUPPORTED_MIMETYPES);
140 public void setFile(AbstractFile file) {
145 if (file.equals(lastFile)) {
149 this.setDataView(file);