Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExplorerNodeActionVisitor.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.directorytree;
20 
21 import org.openide.util.NbBundle;
23 import java.awt.Toolkit;
24 import java.awt.Dimension;
25 import java.awt.Font;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.Collections;
31 import java.util.List;
32 import java.util.logging.Level;
33 import javax.swing.AbstractAction;
34 import javax.swing.Action;
35 import javax.swing.JDialog;
36 import javax.swing.JFrame;
37 import javax.swing.JLabel;
38 import javax.swing.JTable;
39 import javax.swing.table.DefaultTableModel;
42 import org.sleuthkit.datamodel.Content;
43 import org.sleuthkit.datamodel.ContentVisitor;
44 import org.sleuthkit.datamodel.DerivedFile;
45 import org.sleuthkit.datamodel.Directory;
46 import org.sleuthkit.datamodel.FileSystem;
47 import org.sleuthkit.datamodel.Image;
48 import org.sleuthkit.datamodel.LocalFile;
49 import org.sleuthkit.datamodel.VirtualDirectory;
50 import org.sleuthkit.datamodel.Volume;
51 
52 public class ExplorerNodeActionVisitor extends ContentVisitor.Default<List<? extends Action>> {
53 
55 
56  public static List<Action> getActions(Content c) {
57  List<Action> actions = new ArrayList<>();
58 
59  actions.addAll(c.accept(instance));
60  //TODO: fix this
61  /*
62  * while (c.isOnto()) { try { List<? extends Content> children =
63  * c.getChildren(); if (!children.isEmpty()) { c =
64  * c.getChildren().get(0); } else { return actions; } } catch
65  * (TskException ex) {
66  * Log.get(ExplorerNodeActionVisitor.class).log(Level.WARNING, "Error
67  * getting show detail actions.", ex); return actions; }
68  * actions.addAll(c.accept(instance));
69  }
70  */
71  return actions;
72  }
73 
75  }
76 
77  @Override
78  public List<? extends Action> visit(final Image img) {
79  List<Action> lst = new ArrayList<>();
80  lst.add(new ImageDetails(
81  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.imgDetails.title"), img));
82  //TODO lst.add(new ExtractAction("Extract Image", img));
83  lst.add(new ExtractUnallocAction(
84  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.extUnallocToSingleFiles"), img));
85  return lst;
86  }
87 
88  @Override
89  public List<? extends Action> visit(final FileSystem fs) {
90  return Collections.singletonList(new FileSystemDetails(
91  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.fileSystemDetails.title"), fs));
92  }
93 
94  @Override
95  public List<? extends Action> visit(final Volume vol) {
96  List<AbstractAction> lst = new ArrayList<>();
97  lst.add(new VolumeDetails(
98  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.volumeDetails.title"), vol));
99  lst.add(new ExtractUnallocAction(
100  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.extUnallocToSingleFile"), vol));
101  return lst;
102  }
103 
104  @Override
105  public List<? extends Action> visit(final Directory d) {
106  List<Action> actions = new ArrayList<>();
107  actions.add(AddContentTagAction.getInstance());
108  actions.addAll(ContextMenuExtensionPoint.getActions());
109  return actions;
110  }
111 
112  @Override
113  public List<? extends Action> visit(final VirtualDirectory d) {
114  List<Action> actions = new ArrayList<>();
115  actions.add(ExtractAction.getInstance());
116  actions.addAll(ContextMenuExtensionPoint.getActions());
117  return actions;
118  }
119 
120  @Override
121  public List<? extends Action> visit(final DerivedFile d) {
122  List<Action> actions = new ArrayList<>();
123  actions.add(ExtractAction.getInstance());
124  actions.add(AddContentTagAction.getInstance());
125  actions.addAll(ContextMenuExtensionPoint.getActions());
126  return actions;
127  }
128 
129  @Override
130  public List<? extends Action> visit(final LocalFile d) {
131  List<Action> actions = new ArrayList<>();
132  actions.add(ExtractAction.getInstance());
133  actions.add(AddContentTagAction.getInstance());
134  actions.addAll(ContextMenuExtensionPoint.getActions());
135  return actions;
136  }
137 
138  @Override
139  public List<? extends Action> visit(final org.sleuthkit.datamodel.File d) {
140  List<Action> actions = new ArrayList<>();
141  actions.add(ExtractAction.getInstance());
142  actions.add(AddContentTagAction.getInstance());
143  actions.addAll(ContextMenuExtensionPoint.getActions());
144  return actions;
145  }
146 
147  @Override
148  protected List<? extends Action> defaultVisit(Content di) {
149  return Collections.<Action>emptyList();
150  }
151 
152  //Below here are classes regarding node-specific actions
156  private class VolumeDetails extends AbstractAction {
157 
158  private final String title;
159  private final Volume vol;
160 
161  VolumeDetails(String title, Volume vol) {
162  super(title);
163  this.title = title;
164  this.vol = vol;
165  }
166 
167  @Override
168  public void actionPerformed(ActionEvent e) {
169  final JFrame frame = new JFrame(title);
170  final JDialog popUpWindow = new JDialog(frame, title, true); // to make the popUp Window to be modal
171 
172  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
173 
174  // set the popUp window / JFrame
175  popUpWindow.setSize(800, 400);
176 
177  int w = popUpWindow.getSize().width;
178  int h = popUpWindow.getSize().height;
179 
180  // set the location of the popUp Window on the center of the screen
181  popUpWindow.setLocation((screenDimension.width - w) / 2, (screenDimension.height - h) / 2);
182 
183  VolumeDetailsPanel volumeDetailPanel = new VolumeDetailsPanel();
184  Boolean counter = false;
185 
186  volumeDetailPanel.setVolumeIDValue(Long.toString(vol.getAddr()));
187  volumeDetailPanel.setStartValue(Long.toString(vol.getStart()));
188  volumeDetailPanel.setLengthValue(Long.toString(vol.getLength()));
189  volumeDetailPanel.setDescValue(vol.getDescription());
190  volumeDetailPanel.setFlagsValue(vol.getFlagsAsString());
191  counter = true;
192 
193  if (counter) {
194  // add the volume detail panel to the popUp window
195  popUpWindow.add(volumeDetailPanel);
196  } else {
197  // error handler if no volume matches
198  JLabel error = new JLabel(
199  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.volDetail.noVolMatchErr"));
200  error.setFont(error.getFont().deriveFont(Font.BOLD, 24));
201  popUpWindow.add(error);
202  }
203 
204  // add the command to close the window to the button on the Volume Detail Panel
205  volumeDetailPanel.setOKButtonActionListener(new ActionListener() {
206  @Override
207  public void actionPerformed(ActionEvent e) {
208  popUpWindow.dispose();
209  }
210  });
211  popUpWindow.pack();
212  popUpWindow.setResizable(false);
213  popUpWindow.setVisible(true);
214 
215  }
216  }
217 
221  private class ImageDetails extends AbstractAction {
222 
223  final String title;
224  final Image img;
225 
226  ImageDetails(String title, Image img) {
227  super(title);
228  this.title = title;
229  this.img = img;
230  }
231 
232  @Override
233  public void actionPerformed(ActionEvent e) {
234  final JFrame frame = new JFrame(title);
235  final JDialog popUpWindow = new JDialog(frame, title, true); // to make the popUp Window to be modal
236  // if we select the Image Details menu
237 
238  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
239 
240  // set the popUp window / JFrame
241  popUpWindow.setSize(750, 400);
242 
243  int w = popUpWindow.getSize().width;
244  int h = popUpWindow.getSize().height;
245 
246  // set the location of the popUp Window on the center of the screen
247  popUpWindow.setLocation((screenDimension.width - w) / 2, (screenDimension.height - h) / 2);
248 
249  ImageDetailsPanel imgDetailPanel = new ImageDetailsPanel();
250  Boolean counter = false;
251 
252  imgDetailPanel.setImgNameValue(img.getName());
253  imgDetailPanel.setImgTypeValue(img.getType().getName());
254  imgDetailPanel.setImgSectorSizeValue(Long.toString(img.getSsize()));
255  imgDetailPanel.setImgTotalSizeValue(Long.toString(img.getSize()));
256  String hash = img.getMd5();
257  // don't show the hash if there isn't one
258  imgDetailPanel.setVisibleHashInfo(hash != null);
259  imgDetailPanel.setImgHashValue(hash);
260 
261  counter = true;
262 
263  if (counter) {
264  // add the volume detail panel to the popUp window
265  popUpWindow.add(imgDetailPanel);
266  } else {
267  // error handler if no volume matches
268  JLabel error = new JLabel(
269  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.imgDetail.noVolMatchesErr"));
270  error.setFont(error.getFont().deriveFont(Font.BOLD, 24));
271  popUpWindow.add(error);
272  }
273 
274  // add the command to close the window to the button on the Volume Detail Panel
275  imgDetailPanel.setOKButtonActionListener(new ActionListener() {
276  @Override
277  public void actionPerformed(ActionEvent e) {
278  popUpWindow.dispose();
279  }
280  });
281 
282  popUpWindow.pack();
283  popUpWindow.setResizable(false);
284  popUpWindow.setVisible(true);
285  }
286  }
287 
291  private class FileSystemDetails extends AbstractAction {
292 
293  private final FileSystem fs;
294  private final String title;
295 
296  FileSystemDetails(String title, FileSystem fs) {
297  super(title);
298  this.title = title;
299  this.fs = fs;
300  }
301 
302  @Override
303  public void actionPerformed(ActionEvent e) {
304  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
305 
306  final JFrame frame = new JFrame(title);
307  final JDialog popUpWindow = new JDialog(frame, title, true); // to make the popUp Window to be modal
308 
309  // set the popUp window / JFrame
310  popUpWindow.setSize(1000, 500);
311 
312  int w = popUpWindow.getSize().width;
313  int h = popUpWindow.getSize().height;
314 
315  // set the location of the popUp Window on the center of the screen
316  popUpWindow.setLocation((screenDimension.width - w) / 2, (screenDimension.height - h) / 2);
317 
318  String[] columnNames = new String[]{
319  "fs_id", //NON-NLS
320  "img_offset", //NON-NLS
321  "par_id", //NON-NLS
322  "fs_type", //NON-NLS
323  "block_size", //NON-NLS
324  "block_count", //NON-NLS
325  "root_inum", //NON-NLS
326  "first_inum", //NON-NLS
327  "last_inum" //NON-NLS
328  };
329 
330  Object[][] rowValues = new Object[1][9];
331 
332  Content parent = null;
333  try {
334  parent = fs.getParent();
335  } catch (Exception ex) {
336  throw new RuntimeException(
337  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.exception.probGetParent.text",
338  FileSystem.class.getName(), fs), ex);
339  }
340  long id = -1;
341  if (parent != null) {
342  id = parent.getId();
343  }
344 
345  Arrays.fill(rowValues, 0, 1, new Object[]{
346  fs.getId(),
347  fs.getImageOffset(),
348  id,
349  fs.getFsType(),
350  fs.getBlock_size(),
351  fs.getBlock_count(),
352  fs.getRoot_inum(),
353  fs.getFirst_inum(),
354  fs.getLastInum()
355  });
356 
357  JTable table = new JTable(new DefaultTableModel(rowValues, columnNames));
358 
359  FileSystemDetailsPanel fsdPanel = new FileSystemDetailsPanel();
360 
361  // add the command to close the window to the button on the Volume Detail Panel
362  fsdPanel.setOKButtonActionListener(new ActionListener() {
363  @Override
364  public void actionPerformed(ActionEvent e) {
365  popUpWindow.dispose();
366  }
367  });
368 
369  try {
370  fsdPanel.setFileSystemTypeValue(table.getValueAt(0, 3).toString());
371  fsdPanel.setImageOffsetValue(table.getValueAt(0, 1).toString());
372  fsdPanel.setVolumeIDValue(table.getValueAt(0, 2).toString()); //TODO: fix this to parent id, not vol id
373  fsdPanel.setBlockSizeValue(table.getValueAt(0, 4).toString());
374  fsdPanel.setBlockCountValue(table.getValueAt(0, 5).toString());
375  fsdPanel.setRootInumValue(table.getValueAt(0, 6).toString());
376  fsdPanel.setFirstInumValue(table.getValueAt(0, 7).toString());
377  fsdPanel.setLastInumValue(table.getValueAt(0, 8).toString());
378 
379  popUpWindow.add(fsdPanel);
380  } catch (Exception ex) {
381  Logger.getLogger(ExplorerNodeActionVisitor.class.getName()).log(Level.WARNING, "Error setting up File System Details panel.", ex); //NON-NLS
382  }
383 
384  popUpWindow.pack();
385  popUpWindow.setResizable(false);
386  popUpWindow.setVisible(true);
387 
388  }
389  }
390 }
static synchronized ExtractAction getInstance()
List<?extends Action > visit(final org.sleuthkit.datamodel.File d)
synchronized static Logger getLogger(String name)
Definition: Logger.java:166
static synchronized AddContentTagAction getInstance()

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.