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

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