Autopsy  4.8.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CentralRepoCommonAttributeInstance.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.commonfilesearch;
21 
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Optional;
28 import java.util.logging.Level;
34 import org.sleuthkit.datamodel.AbstractFile;
35 import org.sleuthkit.datamodel.DataSource;
36 import org.sleuthkit.datamodel.SleuthkitCase;
37 import org.sleuthkit.datamodel.TskCoreException;
38 
45 
46  private static final Logger LOGGER = Logger.getLogger(CentralRepoCommonAttributeInstance.class.getName());
47  private final Integer crFileId;
50 
52  super();
53  this.crFileId = attrInstId;
55  }
56 
57  @Override
59  return this.correlationType;
60  }
61 
62  void setCurrentAttributeInst(CorrelationAttributeInstance attribute) {
63  this.currentAttribute = attribute;
64  }
65 
66  @Override
67  AbstractFile getAbstractFile() {
68 
69  Case currentCase;
70  if (this.currentAttribute != null) {
71 
72  final CorrelationAttributeInstance currentAttributeInstance = this.currentAttribute;
73 
74  try {
75  String currentFullPath = currentAttributeInstance.getFilePath();
76  currentCase = Case.getCurrentCaseThrows();
77 
78  // Only attempt to make the abstract file if the attribute is from the current case
79  if (currentCase.getName().equals(currentAttributeInstance.getCorrelationCase().getCaseUUID())) {
80 
81  SleuthkitCase tskDb = currentCase.getSleuthkitCase();
82 
83  // Find the correct data source
84  Optional<DataSource> dataSource = tskDb.getDataSources().stream()
85  .filter(p -> p.getDeviceId().equals(currentAttribute.getCorrelationDataSource().getDeviceID()))
86  .findFirst();
87  if (! dataSource.isPresent()) {
88  LOGGER.log(Level.WARNING, String.format("Unable to find data source with device ID %s in the current case", currentAttribute.getCorrelationDataSource().getDeviceID()));
89  return null;
90  }
91 
92  File fileFromPath = new File(currentFullPath);
93  String fileName = fileFromPath.getName();
94 
95  // Create the parent path. Make sure not to add a separator if there is already one there.
96  String parentPath = fileFromPath.getParent();
97  if (! parentPath.endsWith(File.separator)) {
98  parentPath = parentPath + File.separator;
99  }
100  parentPath = parentPath.replace("\\", "/");
101 
102  final String whereClause = String.format("lower(name) = '%s' AND md5 = '%s' AND lower(parent_path) = '%s' AND data_source_obj_id = %s", fileName, currentAttribute.getCorrelationValue(), parentPath, dataSource.get().getId());
103  List<AbstractFile> potentialAbstractFiles = tskDb.findAllFilesWhere(whereClause);
104 
105  if (potentialAbstractFiles.isEmpty()) {
106  return null;
107  } else if (potentialAbstractFiles.size() > 1) {
108  LOGGER.log(Level.WARNING, String.format("Unable to find an exact match for AbstractFile for record with filePath: %s. May have returned the wrong file.", new Object[]{currentFullPath}));
109  return potentialAbstractFiles.get(0);
110  } else {
111  return potentialAbstractFiles.get(0);
112  }
113  } else {
114  return null;
115  }
116  } catch (TskCoreException | NoCurrentCaseException ex) {
117  LOGGER.log(Level.SEVERE, String.format("Unable to find AbstractFile for record with filePath: %s. Node not created.", new Object[]{currentAttributeInstance.getFilePath()}), ex);
118  return null;
119  }
120 
121  }
122  return null;
123  }
124 
125  @Override
127 
128  // @@@ We should be doing more of this work in teh generateKeys method. We want to do as little as possible in generateNodes
129  InterCaseSearchResultsProcessor eamDbAttrInst = new InterCaseSearchResultsProcessor(correlationType);
130  CorrelationAttributeInstance corrAttr = eamDbAttrInst.findSingleCorrelationAttribute(crFileId);
131  List<DisplayableItemNode> attrInstNodeList = new ArrayList<>(0);
132  String currCaseDbName = Case.getCurrentCase().getDisplayName();
133 
134  try {
135  this.setCurrentAttributeInst(corrAttr);
136 
137  AbstractFile abstractFileForAttributeInstance = this.getAbstractFile();
138  DisplayableItemNode generatedInstNode = AbstractCommonAttributeInstance.createNode(corrAttr, abstractFileForAttributeInstance, currCaseDbName);
139  attrInstNodeList.add(generatedInstNode);
140 
141  } catch (TskCoreException ex) {
142  LOGGER.log(Level.SEVERE, String.format("Unable to get DataSource for record with md5: %s. Node not created.", new Object[]{corrAttr.getCorrelationValue()}), ex);
143  }
144 
145  return attrInstNodeList.toArray(new DisplayableItemNode[attrInstNodeList.size()]);
146  }
147 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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