Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
Md5Node.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2018 Basis Technology Corp.
6  * Contact: carrier <at> sleuthkit <dot> org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 package org.sleuthkit.autopsy.datamodel;
21 
22 import java.util.LinkedHashMap;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.logging.Level;
26 import org.openide.nodes.ChildFactory;
27 import org.openide.nodes.Children;
28 import org.openide.nodes.Node;
29 import org.openide.nodes.Sheet;
30 import org.openide.util.NbBundle;
31 import org.openide.util.lookup.Lookups;
37 import org.sleuthkit.datamodel.AbstractFile;
38 import org.sleuthkit.datamodel.SleuthkitCase;
39 import org.sleuthkit.datamodel.TskCoreException;
40 
47 public class Md5Node extends DisplayableItemNode {
48 
49  private static final Logger LOGGER = Logger.getLogger(Md5Node.class.getName());
50 
51  private final String md5Hash;
52  private final int commonFileCount;
53  private final String dataSources;
54 
55  public Md5Node(Md5Metadata data) {
56  super(Children.create(
57  new FileInstanceNodeFactory(data), true),
58  Lookups.singleton(data.getMd5()));
59 
60  this.commonFileCount = data.size();
61  this.dataSources = String.join(", ", data.getDataSources());
62  this.md5Hash = data.getMd5();
63 
64  this.setDisplayName(this.md5Hash);
65  }
66 
67  int getCommonFileCount() {
68  return this.commonFileCount;
69  }
70 
71  String getDataSources() {
72  return this.dataSources;
73  }
74 
75  public String getMd5() {
76  return this.md5Hash;
77  }
78 
79  @Override
80  protected Sheet createSheet() {
81  Sheet sheet = new Sheet();
82  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
83  if (sheetSet == null) {
84  sheetSet = Sheet.createPropertiesSet();
85  sheet.put(sheetSet);
86  }
87 
88  Map<String, Object> map = new LinkedHashMap<>();
89  fillPropertyMap(map, this);
90 
91  final String NO_DESCR = Bundle.AbstractFsContentNode_noDesc_text();
93  final String propString = propType.toString();
94  sheetSet.put(new NodeProperty<>(propString, propString, NO_DESCR, map.get(propString)));
95  }
96 
97  return sheet;
98  }
99 
107  static private void fillPropertyMap(Map<String, Object> map, Md5Node node) {
108  map.put(CommonFileParentPropertyType.File.toString(), node.getMd5());
109  map.put(CommonFileParentPropertyType.InstanceCount.toString(), node.getCommonFileCount());
110  map.put(CommonFileParentPropertyType.DataSource.toString(), node.getDataSources());
111  }
112 
113  @Override
114  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
115  return visitor.visit(this);
116  }
117 
118  @Override
119  public boolean isLeafTypeNode() {
120  return false;
121  }
122 
123  @Override
124  public String getItemType() {
125  return getClass().getName();
126  }
127 
131  static class FileInstanceNodeFactory extends ChildFactory<FileInstanceMetadata> {
132 
133  private final Md5Metadata descendants;
134 
135  FileInstanceNodeFactory(Md5Metadata descendants) {
136  this.descendants = descendants;
137  }
138 
139  @Override
140  protected Node createNodeForKey(FileInstanceMetadata file) {
141  try {
142  Case currentCase = Case.getOpenCase();
143  SleuthkitCase tskDb = currentCase.getSleuthkitCase();
144  AbstractFile abstractFile = tskDb.findAllFilesWhere(String.format("obj_id in (%s)", file.getObjectId())).get(0);
145 
146  return new FileInstanceNode(abstractFile, file.getDataSourceName());
147  } catch (NoCurrentCaseException ex) {
148  LOGGER.log(Level.SEVERE, String.format("Unable to create node for file with obj_id: %s.", new Object[]{file.getObjectId()}), ex);
149  } catch (TskCoreException ex) {
150  LOGGER.log(Level.SEVERE, String.format("Unable to create node for file with obj_id: %s.", new Object[]{file.getObjectId()}), ex);
151  }
152  return null;
153  }
154 
155  @Override
156  protected boolean createKeys(List<FileInstanceMetadata> list) {
157  list.addAll(this.descendants.getMetadata());
158  return true;
159  }
160  }
161 
162  @NbBundle.Messages({
163  "CommonFileParentPropertyType.fileColLbl=File",
164  "CommonFileParentPropertyType.instanceColLbl=Instance Count",
165  "CommonFileParentPropertyType.dataSourceColLbl=Data Source"})
167 
168  File(Bundle.CommonFileParentPropertyType_fileColLbl()),
169  InstanceCount(Bundle.CommonFileParentPropertyType_instanceColLbl()),
170  DataSource(Bundle.CommonFileParentPropertyType_dataSourceColLbl());
171 
172  final private String displayString;
173 
174  private CommonFileParentPropertyType(String displayString) {
175  this.displayString = displayString;
176  }
177 
178  @Override
179  public String toString() {
180  return displayString;
181  }
182  }
183 }
static void fillPropertyMap(Map< String, Object > map, Md5Node node)
Definition: Md5Node.java:107
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
Collection< FileInstanceMetadata > getMetadata()

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