Autopsy  4.19.3
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;
36 import org.sleuthkit.datamodel.Content;
37 import org.sleuthkit.datamodel.TskCoreException;
38 
43 /*
44  * THis is commented out so that it is not displayed in the real UI, it is
45  * compiled each time to ensure that it is compliant with the API.
46  */
47 // @ServiceProvider(service = DataContentViewer.class)
48 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
49 class SampleContentViewer extends javax.swing.JPanel implements DataContentViewer {
50 
54  public SampleContentViewer() {
55  initComponents();
56  }
57 
63  @SuppressWarnings("unchecked")
64  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
65  private void initComponents() {
66 
67  jLabel1 = new javax.swing.JLabel();
68 
69  org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(SampleContentViewer.class, "SampleContentViewer.jLabel1.text")); // NOI18N
70 
71  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
72  this.setLayout(layout);
73  layout.setHorizontalGroup(
74  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
75  .addGroup(layout.createSequentialGroup()
76  .addContainerGap()
77  .addComponent(jLabel1)
78  .addContainerGap(339, Short.MAX_VALUE))
79  );
80  layout.setVerticalGroup(
81  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
82  .addGroup(layout.createSequentialGroup()
83  .addGap(19, 19, 19)
84  .addComponent(jLabel1)
85  .addContainerGap(266, Short.MAX_VALUE))
86  );
87  }// </editor-fold>//GEN-END:initComponents
88  // Variables declaration - do not modify//GEN-BEGIN:variables
89  private javax.swing.JLabel jLabel1;
90  // End of variables declaration//GEN-END:variables
91 
92  @Override
93  public void setNode(Node selectedNode) {
94  try {
95  // reset
96  if (selectedNode == null) {
97  setText("");
98  return;
99  }
100 
101  Content content = selectedNode.getLookup().lookup(Content.class);
102  if (content == null) {
103  // non-content object passed in
104  setText("");
105  return;
106  }
107 
108  setText("Doing Analysis");
109  byte buffer[] = new byte[1024];
110  int len = content.read(buffer, 0, 1024);
111  int count = 0;
112  for (int i = 0; i < len; i++) {
113  if (buffer[i] == 0x00) {
114  count++;
115  }
116  }
117  setText(count + " out of " + len + " bytes were 0x00");
118  } catch (TskCoreException ex) {
119  setText("Error reading file: " + ex.getLocalizedMessage());
120  }
121  }
122 
123  // set the text in the lable in the JPanel
124  private void setText(String str) {
125  jLabel1.setText(str);
126  }
127 
128  @Override
129  public String getTitle() {
130  return "Sample";
131  }
132 
133  @Override
134  public String getToolTip() {
135  return "Useless module";
136  }
137 
138  @Override
139  public DataContentViewer createInstance() {
140  return new SampleContentViewer();
141  }
142 
143  @Override
144  public Component getComponent() {
145  // we can do this because this class extends JPanel
146  return this;
147  }
148 
149  @Override
150  public void resetComponent() {
151  setText("");
152  }
153 
154  @Override
155  public boolean isSupported(Node node) {
156  // get a Content datamodel object out of the node
157  Content content = node.getLookup().lookup(Content.class);
158  if (content == null) {
159  return false;
160  }
161 
162  // we only want files that are 1024 bytes or larger (for no good reason)
163  if (content.getSize() < 1024) {
164  return false;
165  }
166  return true;
167  }
168 
169  @Override
170  public int isPreferred(Node node) {
171  // we return 1 since this module will operate on nearly all files
172  return ViewerPriority.viewerPriority.LevelOne.getFlag();
173  }
174 }

Copyright © 2012-2022 Basis Technology. Generated on: Sat Nov 26 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.