Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
VirtualDirectoryNode.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.datamodel;
20 
21 import java.awt.event.ActionEvent;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.LinkedHashMap;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.logging.Level;
30 import javax.swing.AbstractAction;
31 import javax.swing.Action;
32 import org.openide.nodes.Sheet;
33 import org.openide.util.NbBundle;
34 import org.openide.util.NbBundle.Messages;
42 import org.sleuthkit.datamodel.Content;
43 import org.sleuthkit.datamodel.SleuthkitCase;
44 import org.sleuthkit.datamodel.TskCoreException;
45 import org.sleuthkit.datamodel.TskData;
46 import org.sleuthkit.datamodel.VirtualDirectory;
47 
51 public class VirtualDirectoryNode extends AbstractAbstractFileNode<VirtualDirectory> {
52 
53  private static Logger logger = Logger.getLogger(VirtualDirectoryNode.class.getName());
54  //prefix for special VirtualDirectory root nodes grouping local files
55  public final static String LOGICAL_FILE_SET_PREFIX = "LogicalFileSet"; //NON-NLS
56 
57  public static String nameForLayoutFile(VirtualDirectory ld) {
58  return ld.getName();
59  }
60 
61  public VirtualDirectoryNode(VirtualDirectory ld) {
62  super(ld);
63 
64  this.setDisplayName(nameForLayoutFile(ld));
65 
66  String name = ld.getName();
67 
68  //set icon for name, special case for some built-ins
69  if (name.equals(VirtualDirectory.NAME_UNALLOC)) {
70  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/folder-icon-deleted.png"); //NON-NLS
71  } else if (ld.isDataSource()) {
72  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/fileset-icon-16.png"); //NON-NLS
73  } else if (name.equals(VirtualDirectory.NAME_CARVED)) {
74  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/Folder-icon.png"); //TODO NON-NLS
75  } else {
76  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/Folder-icon.png"); //NON-NLS
77  }
78 
79  }
80 
88  @Override
89  @NbBundle.Messages({"VirtualDirectoryNode.action.runIngestMods.text=Run Ingest Modules"})
90  public Action[] getActions(boolean popup) {
91  List<Action> actions = new ArrayList<>();
92  for (Action a : super.getActions(true)) {
93  actions.add(a);
94  }
95 
96  actions.add(new NewWindowViewAction(
97  NbBundle.getMessage(this.getClass(), "VirtualDirectoryNode.getActions.viewInNewWin.text"), this));
98  actions.add(null); // creates a menu separator
99  actions.add(ExtractAction.getInstance());
100  actions.add(null); // creates a menu separator
101  actions.add(new FileSearchAction(
102  Bundle.ImageNode_getActions_openFileSearchByAttr_text()));
103  actions.add(new AbstractAction(
104  Bundle.VirtualDirectoryNode_action_runIngestMods_text()) {
105  @Override
106  public void actionPerformed(ActionEvent e) {
107  final RunIngestModulesDialog ingestDialog = new RunIngestModulesDialog(Collections.<Content>singletonList(content));
108  ingestDialog.display();
109  }
110  });
111  actions.addAll(ContextMenuExtensionPoint.getActions());
112  return actions.toArray(new Action[0]);
113  }
114 
115  @Override
116  @Messages({"VirtualDirectoryNode.createSheet.size.name=Size (Bytes)",
117  "VirtualDirectoryNode.createSheet.size.displayName=Size (Bytes)",
118  "VirtualDirectoryNode.createSheet.size.desc=Size of the data source in bytes.",
119  "VirtualDirectoryNode.createSheet.type.name=Type",
120  "VirtualDirectoryNode.createSheet.type.displayName=Type",
121  "VirtualDirectoryNode.createSheet.type.desc=Type of the image.",
122  "VirtualDirectoryNode.createSheet.type.text=Logical File Set",
123  "VirtualDirectoryNode.createSheet.timezone.name=Timezone",
124  "VirtualDirectoryNode.createSheet.timezone.displayName=Timezone",
125  "VirtualDirectoryNode.createSheet.timezone.desc=Timezone of the image",
126  "VirtualDirectoryNode.createSheet.deviceId.name=Device ID",
127  "VirtualDirectoryNode.createSheet.deviceId.displayName=Device ID",
128  "VirtualDirectoryNode.createSheet.deviceId.desc=Device ID of the image"})
129  protected Sheet createSheet() {
130  Sheet s = super.createSheet();
131  Sheet.Set ss = s.get(Sheet.PROPERTIES);
132  if (ss == null) {
133  ss = Sheet.createPropertiesSet();
134  s.put(ss);
135  }
136 
137  ss.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "VirtualDirectoryNode.createSheet.name.name"),
138  NbBundle.getMessage(this.getClass(),
139  "VirtualDirectoryNode.createSheet.name.displayName"),
140  NbBundle.getMessage(this.getClass(), "VirtualDirectoryNode.createSheet.name.desc"),
141  getName()));
142 
143  if (!this.content.isDataSource()) {
144  Map<String, Object> map = new LinkedHashMap<>();
145  fillPropertyMap(map, content);
146 
147  final String NO_DESCR = NbBundle.getMessage(this.getClass(), "VirtualDirectoryNode.createSheet.noDesc");
148  for (Map.Entry<String, Object> entry : map.entrySet()) {
149  ss.put(new NodeProperty<>(entry.getKey(), entry.getKey(), NO_DESCR, entry.getValue()));
150  }
151  } else {
152  ss.put(new NodeProperty<>(Bundle.VirtualDirectoryNode_createSheet_type_name(),
153  Bundle.VirtualDirectoryNode_createSheet_type_displayName(),
154  Bundle.VirtualDirectoryNode_createSheet_type_desc(),
155  Bundle.VirtualDirectoryNode_createSheet_type_text()));
156  ss.put(new NodeProperty<>(Bundle.VirtualDirectoryNode_createSheet_size_name(),
157  Bundle.VirtualDirectoryNode_createSheet_size_displayName(),
158  Bundle.VirtualDirectoryNode_createSheet_size_desc(),
159  this.content.getSize()));
160  try (SleuthkitCase.CaseDbQuery query = Case.getCurrentCase().getSleuthkitCase().executeQuery("SELECT time_zone FROM data_source_info WHERE obj_id = " + this.content.getId())) {
161  ResultSet timeZoneSet = query.getResultSet();
162  if (timeZoneSet.next()) {
163  ss.put(new NodeProperty<>(Bundle.VirtualDirectoryNode_createSheet_timezone_name(),
164  Bundle.VirtualDirectoryNode_createSheet_timezone_displayName(),
165  Bundle.VirtualDirectoryNode_createSheet_timezone_desc(),
166  timeZoneSet.getString("time_zone")));
167  }
168  } catch (SQLException | TskCoreException ex) {
169  logger.log(Level.SEVERE, "Failed to get time zone for the following image: " + this.content.getId(), ex);
170  }
171  try (SleuthkitCase.CaseDbQuery query = Case.getCurrentCase().getSleuthkitCase().executeQuery("SELECT device_id FROM data_source_info WHERE obj_id = " + this.content.getId());) {
172  ResultSet deviceIdSet = query.getResultSet();
173  if (deviceIdSet.next()) {
174  ss.put(new NodeProperty<>(Bundle.VirtualDirectoryNode_createSheet_deviceId_name(),
175  Bundle.VirtualDirectoryNode_createSheet_deviceId_displayName(),
176  Bundle.VirtualDirectoryNode_createSheet_deviceId_desc(),
177  deviceIdSet.getString("device_id")));
178  }
179  } catch (SQLException | TskCoreException ex) {
180  logger.log(Level.SEVERE, "Failed to get device id for the following image: " + this.content.getId(), ex);
181  }
182 
183  }
184 
185  return s;
186  }
187 
188  @Override
189  public <T> T accept(ContentNodeVisitor<T> v) {
190  return v.visit(this);
191  }
192 
193  @Override
194  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
195  return v.visit(this);
196  }
197 
198  @Override
199  public boolean isLeafTypeNode() {
200  return true;
201  }
202 
210  public static String metaFlagToString(short metaFlag) {
211 
212  String result = "";
213 
214  short allocFlag = TskData.TSK_FS_META_FLAG_ENUM.ALLOC.getValue();
215  short unallocFlag = TskData.TSK_FS_META_FLAG_ENUM.UNALLOC.getValue();
216 
217  if ((metaFlag & allocFlag) == allocFlag) {
218  result = TskData.TSK_FS_META_FLAG_ENUM.ALLOC.toString();
219  }
220  if ((metaFlag & unallocFlag) == unallocFlag) {
221  result = TskData.TSK_FS_META_FLAG_ENUM.UNALLOC.toString();
222  }
223 
224  return result;
225  }
226 
227  /*
228  * TODO (AUT-1849): Correct or remove peristent column reordering code
229  *
230  * Added to support this feature.
231  */
232 // @Override
233 // public String getItemType() {
234 // return "VirtualDirectory"; //NON-NLS
235 // }
236 }
static void fillPropertyMap(Map< String, Object > map, AbstractFile content)
static synchronized ExtractAction getInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

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