Sleuth Kit Java Bindings (JNI)  4.6
Java bindings for using The Sleuth Kit
TimelineEventTypes.java
Go to the documentation of this file.
1 /*
2  * Sleuth Kit Data Model
3  *
4  * Copyright 2018-2019 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.datamodel;
20 
21 import com.google.common.net.InternetDomainName;
22 import java.net.URI;
23 import java.net.URISyntaxException;
24 import java.util.stream.Collectors;
25 import java.util.stream.Stream;
26 import org.apache.commons.lang3.StringUtils;
27 
32 class TimelineEventTypes {
33 
34  private TimelineEventTypes() {
35  }
36 
42  final static class EmptyExtractor implements TimelineEventArtifactTypeImpl.TSKCoreCheckedFunction<BlackboardArtifact, String> {
43 
44  @Override
45  public String apply(BlackboardArtifact ignored) throws TskCoreException {
46  return "";
47  }
48  }
49 
50  static class URLArtifactEventType extends TimelineEventArtifactTypeSingleDescription {
51 
52  URLArtifactEventType(int typeID, String displayName, TimelineEventType superType, BlackboardArtifact.Type artifactType, BlackboardAttribute.Type timeAttribute, BlackboardAttribute.Type descriptionAttribute) {
53  super(typeID, displayName, superType, artifactType, timeAttribute, descriptionAttribute);
54  }
55 
56  TimelineEventDescription parseDescription(String fullDescriptionRaw, String medDescriptionRaw, String shortDescriptionRaw) {
64  String fullDescription = fullDescriptionRaw;
65  try {
66  URI uri = new URI(fullDescription);
67  String host = uri.getHost();
68  if (host == null) {
69  host = StringUtils.strip(fullDescription, "./");
70 
71  }
72  String shortDescription;
73  if (InternetDomainName.isValid(host)) {
74  InternetDomainName domain = InternetDomainName.from(host);
75  shortDescription = (domain.isUnderPublicSuffix())
76  ? domain.topPrivateDomain().toString()
77  : domain.toString();
78  } else {
79  shortDescription = host;
80  }
81 
82  String mediumDescription = new URI(uri.getScheme(), uri.getUserInfo(), host, uri.getPort(), uri.getPath(), null, null).toString();
83 
84  return new TimelineEventDescription(fullDescription, mediumDescription, shortDescription);
85  } catch (URISyntaxException ex) {
86  //There was an error parsing the description as a URL, just ignore the description levels.
87  return new TimelineEventDescription(fullDescription);
88  }
89  }
90  }
91 
92  static class FilePathEventType extends TimelineEventTypeImpl {
93 
94  FilePathEventType(long typeID, String displayName, TimelineEventType.HierarchyLevel eventTypeZoomLevel, TimelineEventType superType) {
95  super(typeID, displayName, eventTypeZoomLevel, superType);
96  }
97 
98  TimelineEventDescription parseDescription(String fullDescription, String medDescription, String shortDescription) {
99  return parseFilePathDescription(fullDescription);
100  }
101 
102  }
103 
104  static class FilePathArtifactEventType extends TimelineEventArtifactTypeSingleDescription {
105 
106  FilePathArtifactEventType(int typeID, String displayName, TimelineEventType superType, BlackboardArtifact.Type artifactType, BlackboardAttribute.Type timeAttribute, BlackboardAttribute.Type descriptionAttribute) {
107  super(typeID, displayName, superType, artifactType, timeAttribute, descriptionAttribute);
108  }
109 
110  TimelineEventDescription parseDescription(String fullDescriptionRaw, String medDescriptionRaw, String shortDescriptionRaw) {
111  return parseFilePathDescription(fullDescriptionRaw);
112  }
113  }
114 
123  static TimelineEventDescription parseFilePathDescription(String fullDescription) {
124 
125  String[] split = fullDescription.split("/");
126  String mediumDescription = Stream.of(split)
127  .filter(StringUtils::isNotBlank)
128  .limit(Math.max(1, split.length - 2))
129  .collect(Collectors.joining("/", "/", ""))
130  .replaceAll("//", "/");
131 
132  String shortDescription = Stream.of(split)
133  .filter(StringUtils::isNotBlank)
134  .limit(1)
135  .collect(Collectors.joining("/", "/", ""))
136  .replaceAll("//", "/");
137  return new TimelineEventDescription(fullDescription, mediumDescription, shortDescription);
138 
139  }
140 
141 }

Copyright © 2011-2018 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.