Autopsy  3.1
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;
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()) {
63  try {
64  List<? extends Content> children = c.getChildren();
65  if (!children.isEmpty()) {
66  c = c.getChildren().get(0);
67  } else {
68  return actions;
69  }
70  } catch (TskException ex) {
71  Log.get(ExplorerNodeActionVisitor.class).log(Level.WARNING, "Error getting show detail actions.", ex);
72  return actions;
73  }
74  actions.addAll(c.accept(instance));
75  }*/
76  return actions;
77  }
78 
80  }
81 
82  @Override
83  public List<? extends Action> visit(final Image img) {
84  List<Action> lst = new ArrayList<>();
85  lst.add(new ImageDetails(
86  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.imgDetails.title"), img));
87  //TODO lst.add(new ExtractAction("Extract Image", img));
88  lst.add(new ExtractUnallocAction(
89  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.extUnallocToSingleFiles"), img));
90  return lst;
91  }
92 
93  @Override
94  public List<? extends Action> visit(final FileSystem fs) {
95  return Collections.singletonList(new FileSystemDetails(
96  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.fileSystemDetails.title"), fs));
97  }
98 
99  @Override
100  public List<? extends Action> visit(final Volume vol) {
101  List<AbstractAction> lst = new ArrayList<>();
102  lst.add(new VolumeDetails(
103  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.volumeDetails.title"), vol));
104  lst.add(new ExtractUnallocAction(
105  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.extUnallocToSingleFile"), vol));
106  return lst;
107  }
108 
109  @Override
110  public List<? extends Action> visit(final Directory d) {
111  List<Action> actions = new ArrayList<>();
112  actions.add(AddContentTagAction.getInstance());
113  actions.addAll(ContextMenuExtensionPoint.getActions());
114  return actions;
115  }
116 
117  @Override
118  public List<? extends Action> visit(final VirtualDirectory d) {
119  List<Action> actions = new ArrayList<>();
120  actions.add(ExtractAction.getInstance());
121  actions.addAll(ContextMenuExtensionPoint.getActions());
122  return actions;
123  }
124 
125  @Override
126  public List<? extends Action> visit(final DerivedFile d) {
127  List<Action> actions = new ArrayList<>();
128  actions.add(ExtractAction.getInstance());
129  actions.add(AddContentTagAction.getInstance());
130  actions.addAll(ContextMenuExtensionPoint.getActions());
131  return actions;
132  }
133 
134  @Override
135  public List<? extends Action> visit(final LocalFile d) {
136  List<Action> actions = new ArrayList<>();
137  actions.add(ExtractAction.getInstance());
138  actions.add(AddContentTagAction.getInstance());
139  actions.addAll(ContextMenuExtensionPoint.getActions());
140  return actions;
141  }
142 
143  @Override
144  public List<? extends Action> visit(final org.sleuthkit.datamodel.File d) {
145  List<Action> actions = new ArrayList<>();
146  actions.add(ExtractAction.getInstance());
147  actions.add(AddContentTagAction.getInstance());
148  actions.addAll(ContextMenuExtensionPoint.getActions());
149  return actions;
150  }
151 
152  @Override
153  protected List<? extends Action> defaultVisit(Content di) {
154  return Collections.<Action>emptyList();
155  }
156 
157  //Below here are classes regarding node-specific actions
161  private class VolumeDetails extends AbstractAction {
162 
163  private final String title;
164  private final Volume vol;
165 
166  VolumeDetails(String title, Volume vol) {
167  super(title);
168  this.title = title;
169  this.vol = vol;
170  }
171 
172  @Override
173  public void actionPerformed(ActionEvent e) {
174  final JFrame frame = new JFrame(title);
175  final JDialog popUpWindow = new JDialog(frame, title, true); // to make the popUp Window to be modal
176 
177  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
178 
179  // set the popUp window / JFrame
180  popUpWindow.setSize(800, 400);
181 
182  int w = popUpWindow.getSize().width;
183  int h = popUpWindow.getSize().height;
184 
185  // set the location of the popUp Window on the center of the screen
186  popUpWindow.setLocation((screenDimension.width - w) / 2, (screenDimension.height - h) / 2);
187 
188  VolumeDetailsPanel volumeDetailPanel = new VolumeDetailsPanel();
189  Boolean counter = false;
190 
191  volumeDetailPanel.setVolumeIDValue(Long.toString(vol.getAddr()));
192  volumeDetailPanel.setStartValue(Long.toString(vol.getStart()));
193  volumeDetailPanel.setLengthValue(Long.toString(vol.getLength()));
194  volumeDetailPanel.setDescValue(vol.getDescription());
195  volumeDetailPanel.setFlagsValue(vol.getFlagsAsString());
196  counter = true;
197 
198  if (counter) {
199  // add the volume detail panel to the popUp window
200  popUpWindow.add(volumeDetailPanel);
201  } else {
202  // error handler if no volume matches
203  JLabel error = new JLabel(
204  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.volDetail.noVolMatchErr"));
205  error.setFont(error.getFont().deriveFont(Font.BOLD, 24));
206  popUpWindow.add(error);
207  }
208 
209  // add the command to close the window to the button on the Volume Detail Panel
210  volumeDetailPanel.setOKButtonActionListener(new ActionListener() {
211  @Override
212  public void actionPerformed(ActionEvent e) {
213  popUpWindow.dispose();
214  }
215  });
216  popUpWindow.pack();
217  popUpWindow.setResizable(false);
218  popUpWindow.setVisible(true);
219 
220  }
221  }
222 
226  private class ImageDetails extends AbstractAction {
227 
228  final String title;
229  final Image img;
230 
231  ImageDetails(String title, Image img) {
232  super(title);
233  this.title = title;
234  this.img = img;
235  }
236 
237  @Override
238  public void actionPerformed(ActionEvent e) {
239  final JFrame frame = new JFrame(title);
240  final JDialog popUpWindow = new JDialog(frame, title, true); // to make the popUp Window to be modal
241  // if we select the Image Details menu
242 
243  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
244 
245  // set the popUp window / JFrame
246  popUpWindow.setSize(750, 400);
247 
248  int w = popUpWindow.getSize().width;
249  int h = popUpWindow.getSize().height;
250 
251  // set the location of the popUp Window on the center of the screen
252  popUpWindow.setLocation((screenDimension.width - w) / 2, (screenDimension.height - h) / 2);
253 
254  ImageDetailsPanel imgDetailPanel = new ImageDetailsPanel();
255  Boolean counter = false;
256 
257  imgDetailPanel.setImgNameValue(img.getName());
258  imgDetailPanel.setImgTypeValue(img.getType().getName());
259  imgDetailPanel.setImgSectorSizeValue(Long.toString(img.getSsize()));
260  imgDetailPanel.setImgTotalSizeValue(Long.toString(img.getSize()));
261  String hash=img.getMd5();
262  // don't show the hash if there isn't one
263  imgDetailPanel.setVisibleHashInfo(hash != null);
264  imgDetailPanel.setImgHashValue(hash);
265 
266 
267  counter = true;
268 
269  if (counter) {
270  // add the volume detail panel to the popUp window
271  popUpWindow.add(imgDetailPanel);
272  } else {
273  // error handler if no volume matches
274  JLabel error = new JLabel(
275  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.imgDetail.noVolMatchesErr"));
276  error.setFont(error.getFont().deriveFont(Font.BOLD, 24));
277  popUpWindow.add(error);
278  }
279 
280  // add the command to close the window to the button on the Volume Detail Panel
281  imgDetailPanel.setOKButtonActionListener(new ActionListener() {
282  @Override
283  public void actionPerformed(ActionEvent e) {
284  popUpWindow.dispose();
285  }
286  });
287 
288 
289  popUpWindow.pack();
290  popUpWindow.setResizable(false);
291  popUpWindow.setVisible(true);
292  }
293  }
294 
298  private class FileSystemDetails extends AbstractAction {
299 
300  private final FileSystem fs;
301  private final String title;
302 
303  FileSystemDetails(String title, FileSystem fs) {
304  super(title);
305  this.title = title;
306  this.fs = fs;
307  }
308 
309  @Override
310  public void actionPerformed(ActionEvent e) {
311  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
312 
313  final JFrame frame = new JFrame(title);
314  final JDialog popUpWindow = new JDialog(frame, title, true); // to make the popUp Window to be modal
315 
316  // set the popUp window / JFrame
317 
318  popUpWindow.setSize(1000, 500);
319 
320  int w = popUpWindow.getSize().width;
321  int h = popUpWindow.getSize().height;
322 
323  // set the location of the popUp Window on the center of the screen
324  popUpWindow.setLocation((screenDimension.width - w) / 2, (screenDimension.height - h) / 2);
325 
326  String[] columnNames = new String[]{
327  "fs_id", //NON-NLS
328  "img_offset", //NON-NLS
329  "par_id", //NON-NLS
330  "fs_type", //NON-NLS
331  "block_size", //NON-NLS
332  "block_count", //NON-NLS
333  "root_inum", //NON-NLS
334  "first_inum", //NON-NLS
335  "last_inum" //NON-NLS
336  };
337 
338  Object[][] rowValues = new Object[1][9];
339 
340  Content parent = null;
341  try {
342  parent = fs.getParent();
343  } catch (Exception ex) {
344  throw new RuntimeException(
345  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.exception.probGetParent.text",
346  FileSystem.class.getName(), fs), ex);
347  }
348  long id = -1;
349  if (parent != null) {
350  id = parent.getId();
351  }
352 
353  Arrays.fill(rowValues, 0, 1, new Object[]{
354  fs.getId(),
355  fs.getImageOffset(),
356  id,
357  fs.getFsType(),
358  fs.getBlock_size(),
359  fs.getBlock_count(),
360  fs.getRoot_inum(),
361  fs.getFirst_inum(),
362  fs.getLastInum()
363  });
364 
365 
366  JTable table = new JTable(new DefaultTableModel(rowValues, columnNames));
367 
368  FileSystemDetailsPanel fsdPanel = new FileSystemDetailsPanel();
369 
370  // add the command to close the window to the button on the Volume Detail Panel
371  fsdPanel.setOKButtonActionListener(new ActionListener() {
372  @Override
373  public void actionPerformed(ActionEvent e) {
374  popUpWindow.dispose();
375  }
376  });
377 
378  try {
379  fsdPanel.setFileSystemTypeValue(table.getValueAt(0, 3).toString());
380  fsdPanel.setImageOffsetValue(table.getValueAt(0, 1).toString());
381  fsdPanel.setVolumeIDValue(table.getValueAt(0, 2).toString()); //TODO: fix this to parent id, not vol id
382  fsdPanel.setBlockSizeValue(table.getValueAt(0, 4).toString());
383  fsdPanel.setBlockCountValue(table.getValueAt(0, 5).toString());
384  fsdPanel.setRootInumValue(table.getValueAt(0, 6).toString());
385  fsdPanel.setFirstInumValue(table.getValueAt(0, 7).toString());
386  fsdPanel.setLastInumValue(table.getValueAt(0, 8).toString());
387 
388  popUpWindow.add(fsdPanel);
389  } catch (Exception ex) {
390  Logger.getLogger(ExplorerNodeActionVisitor.class.getName()).log(Level.WARNING, "Error setting up File System Details panel.", ex); //NON-NLS
391  }
392 
393  popUpWindow.pack();
394  popUpWindow.setResizable(false);
395  popUpWindow.setVisible(true);
396 
397  }
398  }
399 }
TskData.TSK_IMG_TYPE_ENUM getType()
static synchronized ExtractAction getInstance()
List<?extends Action > visit(final org.sleuthkit.datamodel.File d)
TskData.TSK_FS_TYPE_ENUM getFsType()
public< T > T accept(ContentVisitor< T > v)
static Logger getLogger(String name)
Definition: Logger.java:131
static synchronized AddContentTagAction getInstance()

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.