Autopsy  4.13.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CustomArtifactType.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.test;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import javax.xml.bind.DatatypeConverter;
26 import org.sleuthkit.datamodel.Blackboard;
27 import org.sleuthkit.datamodel.BlackboardArtifact;
28 import org.sleuthkit.datamodel.BlackboardAttribute;
29 import org.sleuthkit.datamodel.Content;
30 import org.sleuthkit.datamodel.TskCoreException;
31 
35 final class CustomArtifactType {
36 
37  private static final String MODULE_NAME = CustomArtifactsCreatorIngestModuleFactory.getModuleName();
38  private static final String ADDITIONAL_MODULE_NAME = "Another Module";
39  private static final String ARTIFACT_TYPE_NAME = "CUSTOM_ARTIFACT";
40  private static final String ARTIFACT_DISPLAY_NAME = "Custom Artifact";
41  private static final String INT_ATTR_TYPE_NAME = "CUSTOM_INT_ATTRIBUTE";
42  private static final String INT_ATTR_DISPLAY_NAME = "Custom Integer";
43  private static final String DOUBLE_ATTR_TYPE_NAME = "CUSTOM_DOUBLE_ATTRIBUTE";
44  private static final String DOUBLE_ATTR_DISPLAY_NAME = "Custom Double";
45  private static final String LONG_ATTR_TYPE_NAME = "CUSTOM_LONG_ATTRIBUTE";
46  private static final String LONG_ATTR_DISPLAY_NAME = "Custom Long";
47  private static final String DATETIME_ATTR_TYPE_NAME = "CUSTOM_DATETIME_ATTRIBUTE";
48  private static final String DATETIME_ATTR_DISPLAY_NAME = "Custom Datetime";
49  private static final String BYTES_ATTR_TYPE_NAME = "CUSTOM_BYTES_ATTRIBUTE";
50  private static final String BYTES_ATTR_DISPLAY_NAME = "Custom Bytes";
51  private static final String STRING_ATTR_TYPE_NAME = "CUSTOM_STRING_ATTRIBUTE";
52  private static final String STRING_ATTR_DISPLAY_NAME = "Custom String";
53  private static final String JSON_ATTR_TYPE_NAME = "CUSTOM_JSON_ATTRIBUTE";
54  private static final String JSON_ATTR_DISPLAY_NAME = "Custom Json";
55  private static BlackboardArtifact.Type artifactType;
56  private static BlackboardAttribute.Type intAttrType;
57  private static BlackboardAttribute.Type doubleAttrType;
58  private static BlackboardAttribute.Type longAttributeType;
59  private static BlackboardAttribute.Type dateTimeAttrType;
60  private static BlackboardAttribute.Type bytesAttrType;
61  private static BlackboardAttribute.Type stringAttrType;
62  private static BlackboardAttribute.Type jsonAttrType;
63 
70  static void addToCaseDatabase() throws Blackboard.BlackboardException, NoCurrentCaseException {
71  Blackboard blackboard = Case.getCurrentCaseThrows().getServices().getArtifactsBlackboard();
72  artifactType = blackboard.getOrAddArtifactType(ARTIFACT_TYPE_NAME, ARTIFACT_DISPLAY_NAME);
73  intAttrType = blackboard.getOrAddAttributeType(INT_ATTR_TYPE_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.INTEGER, INT_ATTR_DISPLAY_NAME);
74  doubleAttrType = blackboard.getOrAddAttributeType(DOUBLE_ATTR_TYPE_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DOUBLE, DOUBLE_ATTR_DISPLAY_NAME);
75  longAttributeType = blackboard.getOrAddAttributeType(LONG_ATTR_TYPE_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.LONG, LONG_ATTR_DISPLAY_NAME);
76  dateTimeAttrType = blackboard.getOrAddAttributeType(DATETIME_ATTR_TYPE_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME, DATETIME_ATTR_DISPLAY_NAME);
77  bytesAttrType = blackboard.getOrAddAttributeType(BYTES_ATTR_TYPE_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.BYTE, BYTES_ATTR_DISPLAY_NAME);
78  stringAttrType = blackboard.getOrAddAttributeType(STRING_ATTR_TYPE_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.STRING, STRING_ATTR_DISPLAY_NAME);
79  jsonAttrType = blackboard.getOrAddAttributeType(JSON_ATTR_TYPE_NAME, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.JSON, JSON_ATTR_DISPLAY_NAME);
80  }
81 
91  static BlackboardArtifact createInstance(Content source) throws TskCoreException {
92  BlackboardArtifact artifact = source.newArtifact(artifactType.getTypeID());
93  List<BlackboardAttribute> attributes = new ArrayList<>();
94  attributes.add(new BlackboardAttribute(intAttrType, MODULE_NAME, 0));
95  attributes.add(new BlackboardAttribute(doubleAttrType, MODULE_NAME, 0.0));
96  attributes.add(new BlackboardAttribute(longAttributeType, MODULE_NAME, 0L));
97  attributes.add(new BlackboardAttribute(dateTimeAttrType, MODULE_NAME, 60L));
98  attributes.add(new BlackboardAttribute(bytesAttrType, MODULE_NAME, DatatypeConverter.parseHexBinary("ABCD")));
99  attributes.add(new BlackboardAttribute(stringAttrType, MODULE_NAME, "Zero"));
100  attributes.add(new BlackboardAttribute(jsonAttrType, MODULE_NAME, "{\"fruit\": \"Apple\",\"size\": \"Large\",\"color\": \"Red\"}"));
101  artifact.addAttributes(attributes);
102 
103  /*
104  * Add a second source module to the attributes. Try to do it twice. The
105  * second attempt should have no effect on the data.
106  */
107  for (BlackboardAttribute attr : attributes) {
108  attr.addSource(ADDITIONAL_MODULE_NAME);
109  attr.addSource(ADDITIONAL_MODULE_NAME);
110  }
111 
112  return artifact;
113  }
114 
118  private CustomArtifactType() {
119  }
120 
121 }

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.