Autopsy  4.9.1
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.List;
25 import java.util.Optional;
26 import java.util.logging.Level;
32 import org.sleuthkit.datamodel.AbstractFile;
33 import org.sleuthkit.datamodel.DataSource;
34 import org.sleuthkit.datamodel.SleuthkitCase;
35 import org.sleuthkit.datamodel.TskCoreException;
36 
43 
44  private static final Logger LOGGER = Logger.getLogger(CentralRepoCommonAttributeInstance.class.getName());
45  private final Integer crFileId;
46  private final NODE_TYPE nodeType;
49 
51  super();
52  this.crFileId = attrInstId;
54  this.nodeType = nodeType;
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  SleuthkitCase tskDb = currentCase.getSleuthkitCase();
81 
82  // Find the correct data source
83  Optional<DataSource> dataSource = tskDb.getDataSources().stream()
84  .filter(p -> p.getId() == currentAttribute.getCorrelationDataSource().getDataSourceObjectID())
85  .findFirst();
86  if (!dataSource.isPresent()) {
87  LOGGER.log(Level.WARNING, String.format("Unable to find data source with device ID %s in the current case", currentAttribute.getCorrelationDataSource().getDeviceID()));
88  return null;
89  }
90 
91  File fileFromPath = new File(currentFullPath);
92  String fileName = fileFromPath.getName();
93 
94  // Create the parent path. Make sure not to add a separator if there is already one there.
95  String parentPath = fileFromPath.getParent();
96  if (!parentPath.endsWith(File.separator)) {
97  parentPath += File.separator;
98  }
99  parentPath = parentPath.replace("\\", "/");
100  final String whereClause = String.format("lower(name) = '%s' AND lower(parent_path) = '%s' AND data_source_obj_id = %s", fileName, parentPath, dataSource.get().getId());
101  List<AbstractFile> potentialAbstractFiles = tskDb.findAllFilesWhere(whereClause);
102 
103  if (potentialAbstractFiles.isEmpty()) {
104  return null;
105  } else if (potentialAbstractFiles.size() > 1) {
106  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}));
107  return potentialAbstractFiles.get(0);
108  } else {
109  return potentialAbstractFiles.get(0);
110  }
111  } else {
112  return null;
113  }
114  } catch (TskCoreException | NoCurrentCaseException ex) {
115  LOGGER.log(Level.SEVERE, String.format("Unable to find AbstractFile for record with filePath: %s. Node not created.", new Object[]{currentAttributeInstance.getFilePath()}), ex);
116  return null;
117  }
118 
119  }
120  return null;
121  }
122 
123  @Override
125  // @@@ We should be doing more of this work in teh generateKeys method. We want to do as little as possible in generateNodes
126  List<DisplayableItemNode> attrInstNodeList = new ArrayList<>(0);
127  String currCaseDbName = Case.getCurrentCase().getDisplayName();
128  try {
129  AbstractFile abstractFileForAttributeInstance = this.getAbstractFile();
130  DisplayableItemNode generatedInstNode = AbstractCommonAttributeInstance.createNode(currentAttribute, abstractFileForAttributeInstance, currCaseDbName, nodeType);
131  attrInstNodeList.add(generatedInstNode);
132  } catch (TskCoreException ex) {
133  LOGGER.log(Level.SEVERE, String.format("Unable to get DataSource for record with md5: %s. Node not created.", new Object[]{currentAttribute.getCorrelationValue()}), ex);
134  }
135 
136  return attrInstNodeList.toArray(new DisplayableItemNode[attrInstNodeList.size()]);
137  }
138 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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