Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
SampleContentViewer.java
Go to the documentation of this file.
1 /*
2  * Sample module in the public domain. Feel free to use this as a template
3  * for your modules.
4  *
5  * Contact: Brian Carrier [carrier <at> sleuthkit [dot] org]
6  *
7  * This is free and unencumbered software released into the public domain.
8  *
9  * Anyone is free to copy, modify, publish, use, compile, sell, or
10  * distribute this software, either in source code form or as a compiled
11  * binary, for any purpose, commercial or non-commercial, and by any
12  * means.
13  *
14  * In jurisdictions that recognize copyright laws, the author or authors
15  * of this software dedicate any and all copyright interest in the
16  * software to the public domain. We make this dedication for the benefit
17  * of the public at large and to the detriment of our heirs and
18  * successors. We intend this dedication to be an overt act of
19  * relinquishment in perpetuity of all present and future rights to this
20  * software under copyright law.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  */
30 package org.sleuthkit.autopsy.examples;
31 
32 import java.awt.Component;
33 import org.openide.nodes.Node;
35 import org.sleuthkit.datamodel.Content;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
42 /*
43  * THis is commented out so that it is not displayed in the real UI, it is
44  * compiled each time to ensure that it is compliant with the API.
45  */
46 // @ServiceProvider(service = DataContentViewer.class)
47 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
48 class SampleContentViewer extends javax.swing.JPanel implements DataContentViewer {
49 
53  public SampleContentViewer() {
54  initComponents();
55  }
56 
62  @SuppressWarnings("unchecked")
63  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
64  private void initComponents() {
65 
66  jLabel1 = new javax.swing.JLabel();
67 
68  org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(SampleContentViewer.class, "SampleContentViewer.jLabel1.text")); // NOI18N
69 
70  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
71  this.setLayout(layout);
72  layout.setHorizontalGroup(
73  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
74  .addGroup(layout.createSequentialGroup()
75  .addContainerGap()
76  .addComponent(jLabel1)
77  .addContainerGap(339, Short.MAX_VALUE))
78  );
79  layout.setVerticalGroup(
80  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
81  .addGroup(layout.createSequentialGroup()
82  .addGap(19, 19, 19)
83  .addComponent(jLabel1)
84  .addContainerGap(266, Short.MAX_VALUE))
85  );
86  }// </editor-fold>//GEN-END:initComponents
87  // Variables declaration - do not modify//GEN-BEGIN:variables
88  private javax.swing.JLabel jLabel1;
89  // End of variables declaration//GEN-END:variables
90 
91  @Override
92  public void setNode(Node selectedNode) {
93  try {
94  // reset
95  if (selectedNode == null) {
96  setText("");
97  return;
98  }
99 
100  Content content = selectedNode.getLookup().lookup(Content.class);
101  if (content == null) {
102  // non-content object passed in
103  setText("");
104  return;
105  }
106 
107  setText("Doing Analysis");
108  byte buffer[] = new byte[1024];
109  int len = content.read(buffer, 0, 1024);
110  int count = 0;
111  for (int i = 0; i < len; i++) {
112  if (buffer[i] == 0x00) {
113  count++;
114  }
115  }
116  setText(count + " out of " + len + " bytes were 0x00");
117  } catch (TskCoreException ex) {
118  setText("Error reading file: " + ex.getLocalizedMessage());
119  }
120  }
121 
122  // set the text in the lable in the JPanel
123  private void setText(String str) {
124  jLabel1.setText(str);
125  }
126 
127  @Override
128  public String getTitle() {
129  return "Sample";
130  }
131 
132  @Override
133  public String getToolTip() {
134  return "Useless module";
135  }
136 
137  @Override
138  public DataContentViewer createInstance() {
139  return new SampleContentViewer();
140  }
141 
142  @Override
143  public Component getComponent() {
144  // we can do this because this class extends JPanel
145  return this;
146  }
147 
148  @Override
149  public void resetComponent() {
150  setText("");
151  }
152 
153  @Override
154  public boolean isSupported(Node node) {
155  // get a Content datamodel object out of the node
156  Content content = node.getLookup().lookup(Content.class);
157  if (content == null) {
158  return false;
159  }
160 
161  // we only want files that are 1024 bytes or larger (for no good reason)
162  if (content.getSize() < 1024) {
163  return false;
164  }
165  return true;
166  }
167 
168  @Override
169  public int isPreferred(Node node) {
170  // we return 1 since this module will operate on nearly all files
171  return 1;
172  }
173 }

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.