Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AnalysisSummary.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.datasourcesummary.datamodel;
20 
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29 import java.util.function.Function;
30 import java.util.stream.Collectors;
31 import org.apache.commons.lang3.StringUtils;
32 import org.apache.commons.lang3.tuple.Pair;
34 import org.sleuthkit.datamodel.BlackboardArtifact;
35 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
36 import org.sleuthkit.datamodel.BlackboardAttribute;
37 import org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
38 import org.sleuthkit.datamodel.DataSource;
39 import org.sleuthkit.datamodel.SleuthkitCase;
40 import org.sleuthkit.datamodel.TskCoreException;
41 
46 
47  private static final BlackboardAttribute.Type TYPE_SET_NAME = new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_SET_NAME);
48 
49  private static final Set<String> EXCLUDED_KEYWORD_SEARCH_ITEMS = new HashSet<>();
50 
51  private static final Set<Integer> ARTIFACT_UPDATE_TYPE_IDS = new HashSet<>(Arrays.asList(
52  ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT.getTypeID(),
53  ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT.getTypeID(),
54  ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID(),
55  ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()
56  ));
57 
59 
63  public AnalysisSummary() {
65  }
66 
73  this.provider = provider;
74  }
75 
76  @Override
77  public Set<Integer> getArtifactTypeIdsForRefresh() {
79  }
80 
91  public List<Pair<String, Long>> getHashsetCounts(DataSource dataSource) throws SleuthkitCaseProviderException, TskCoreException {
92  return getCountsData(dataSource, TYPE_SET_NAME, ARTIFACT_TYPE.TSK_HASHSET_HIT);
93  }
94 
105  public List<Pair<String, Long>> getKeywordCounts(DataSource dataSource) throws SleuthkitCaseProviderException, TskCoreException {
106  return getCountsData(dataSource, TYPE_SET_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT).stream()
107  // make sure we have a valid set and that that set does not belong to the set of excluded items
108  .filter((pair) -> pair != null && pair.getKey() != null && !EXCLUDED_KEYWORD_SEARCH_ITEMS.contains(pair.getKey().toUpperCase().trim()))
109  .collect(Collectors.toList());
110  }
111 
124  public List<Pair<String, Long>> getInterestingItemCounts(DataSource dataSource) throws SleuthkitCaseProviderException, TskCoreException {
125  return getCountsData(dataSource, TYPE_SET_NAME, ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT, ARTIFACT_TYPE.TSK_INTERESTING_ARTIFACT_HIT);
126  }
127 
142  private List<Pair<String, Long>> getCountsData(DataSource dataSource, BlackboardAttribute.Type keyType, ARTIFACT_TYPE... artifactTypes)
143  throws SleuthkitCaseProviderException, TskCoreException {
144 
145  if (dataSource == null) {
146  return Collections.emptyList();
147  }
148 
149  List<BlackboardArtifact> artifacts = new ArrayList<>();
150  SleuthkitCase skCase = provider.get();
151 
152  // get all artifacts in one list for each artifact type
153  for (ARTIFACT_TYPE type : artifactTypes) {
154  artifacts.addAll(skCase.getBlackboard().getArtifacts(type.getTypeID(), dataSource.getId()));
155  }
156 
157  // group those based on the value of the attribute type that should serve as a key
158  Map<String, Long> countedKeys = artifacts.stream()
159  .map((art) -> {
160  String key = DataSourceInfoUtilities.getStringOrNull(art, keyType);
161  return (StringUtils.isBlank(key)) ? null : key;
162  })
163  .filter((key) -> key != null)
164  .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
165 
166  // sort from max to min counts
167  return countedKeys.entrySet().stream()
168  .map((e) -> Pair.of(e.getKey(), e.getValue()))
169  .sorted((a, b) -> -a.getValue().compareTo(b.getValue()))
170  .collect(Collectors.toList());
171  }
172 }
List< Pair< String, Long > > getInterestingItemCounts(DataSource dataSource)
List< Pair< String, Long > > getCountsData(DataSource dataSource, BlackboardAttribute.Type keyType, ARTIFACT_TYPE...artifactTypes)
List< Pair< String, Long > > getHashsetCounts(DataSource dataSource)
List< Pair< String, Long > > getKeywordCounts(DataSource dataSource)

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.