19 package org.sleuthkit.autopsy.report.modules.caseuco;
21 import com.fasterxml.jackson.annotation.JsonAnyGetter;
22 import com.fasterxml.jackson.annotation.JsonInclude;
23 import com.fasterxml.jackson.annotation.JsonProperty;
24 import java.io.IOException;
25 import java.nio.file.Path;
26 import java.util.SimpleTimeZone;
27 import java.util.TimeZone;
33 import com.fasterxml.jackson.core.JsonEncoding;
34 import com.fasterxml.jackson.core.JsonFactory;
35 import com.fasterxml.jackson.core.JsonGenerator;
36 import com.fasterxml.jackson.core.util.DefaultIndenter;
37 import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
38 import com.fasterxml.jackson.databind.ObjectMapper;
39 import com.google.common.base.Strings;
40 import java.util.ArrayList;
41 import java.util.LinkedHashMap;
42 import java.util.List;
99 this.reportPath = directory.resolve(reportName +
"." + EXTENSION);
101 JsonFactory jsonGeneratorFactory =
new JsonFactory();
102 reportGenerator = jsonGeneratorFactory.createGenerator(reportPath.toFile(), JsonEncoding.UTF8);
104 reportGenerator.setPrettyPrinter(
new DefaultPrettyPrinter()
105 .withObjectIndenter(
new DefaultIndenter(
" ",
"\n")));
107 ObjectMapper mapper =
new ObjectMapper();
108 mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
109 mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
111 reportGenerator.setCodec(mapper);
113 reportGenerator.writeStartObject();
114 reportGenerator.writeFieldName(
"@graph");
115 reportGenerator.writeStartArray();
118 this.timeZone =
new SimpleTimeZone(0,
"GMT");
131 public void addFile(AbstractFile file, Content parentDataSource)
throws IOException, TskCoreException {
132 addFile(file, parentDataSource, null);
148 public void addFile(AbstractFile file, Content parentDataSource, Path localPath)
throws IOException, TskCoreException {
166 fileTrace.
addBundle(contentDataPropertyBundle);
168 if(localPath != null) {
172 urlPropertyBundle.
addProperty(
"fullValue", localPath.toString());
175 contentDataPropertyBundle.
addProperty(
"dataPayloadReferenceUrl", urlTraceId);
176 reportGenerator.writeObject(urlTrace);
188 pathRelationPropertyBundle.
addProperty(
"path", file.getUniquePath());
189 relationship.
addBundle(pathRelationPropertyBundle);
192 reportGenerator.writeObject(fileTrace);
193 reportGenerator.writeObject(relationship);
197 return "url-" + content.getId();
208 relationship.
addProperty(
"kindOfRelationship",
"contained-within");
221 filePropertyBundle.
addProperty(
"createdTime", createdTime);
222 filePropertyBundle.
addProperty(
"accessedTime", accessedTime);
223 filePropertyBundle.
addProperty(
"modifiedTime", modifiedTime);
224 if (!Strings.isNullOrEmpty(file.getNameExtension())) {
225 filePropertyBundle.
addProperty(
"extension", file.getNameExtension());
227 filePropertyBundle.
addProperty(
"fileName", file.getName());
228 filePropertyBundle.
addProperty(
"filePath", file.getUniquePath());
229 filePropertyBundle.
addProperty(
"isDirectory", file.isDir());
230 filePropertyBundle.
addProperty(
"sizeInBytes", Long.toString(file.getSize()));
231 return filePropertyBundle;
239 if (!Strings.isNullOrEmpty(file.getMIMEType())) {
240 contentDataPropertyBundle.
addProperty(
"mimeType", file.getMIMEType());
242 if (!Strings.isNullOrEmpty(file.getMd5Hash())) {
243 List<CASEPropertyBundle> hashPropertyBundles =
new ArrayList<>();
245 md5HashPropertyBundle.addProperty(
"hashMethod",
"MD5");
246 md5HashPropertyBundle.addProperty(
"hashValue", file.getMd5Hash());
247 hashPropertyBundles.add(md5HashPropertyBundle);
248 contentDataPropertyBundle.
addProperty(
"hash", hashPropertyBundles);
250 contentDataPropertyBundle.
addProperty(
"sizeInBytes", Long.toString(file.getSize()));
251 return contentDataPropertyBundle;
258 return "file-" + file.getId();
265 return "relationship-" + content.getId();
278 public void addDataSource(Content dataSource,
Case parentCase)
throws IOException, TskCoreException {
286 filePropertyBundle.
addProperty(
"filePath", dataSourcePath);
287 dataSourceTrace.
addBundle(filePropertyBundle);
289 if (dataSource.getSize() > 0) {
291 contentDataPropertyBundle.
addProperty(
"sizeInBytes", Long.toString(dataSource.getSize()));
292 dataSourceTrace.
addBundle(contentDataPropertyBundle);
299 dataSourceTraceId, caseTraceId);
302 pathRelationBundle.
addProperty(
"path", dataSourcePath);
303 relationship.
addBundle(pathRelationBundle);
306 reportGenerator.writeObject(dataSourceTrace);
307 reportGenerator.writeObject(relationship);
311 String dataSourcePath =
"";
312 if (dataSource instanceof Image) {
313 String[] paths = ((Image) dataSource).getPaths();
314 if (paths.length > 0) {
317 dataSourcePath = paths[0];
320 dataSourcePath = dataSource.getName();
322 dataSourcePath = dataSourcePath.replaceAll(
"\\\\",
"/");
323 return dataSourcePath;
333 return "data-source-" + dataSource.getId();
344 SleuthkitCase skCase = caseObj.getSleuthkitCase();
346 String caseDirPath = skCase.getDbDirPath();
352 caseDirPath = caseDirPath.replaceAll(
"\\\\",
"/");
356 filePropertyBundle.
addProperty(
"filePath", caseDirPath +
"/" + skCase.getDatabaseName());
357 filePropertyBundle.
addProperty(
"isDirectory",
false);
359 filePropertyBundle.
addProperty(
"filePath", caseDirPath);
360 filePropertyBundle.
addProperty(
"isDirectory",
true);
364 reportGenerator.writeObject(caseTrace);
374 return "case-" + caseObj.
getName();
389 reportGenerator.writeEndArray();
390 reportGenerator.writeEndObject();
391 reportGenerator.close();
402 private final String
id;
412 properties =
new LinkedHashMap<>();
413 propertyBundle =
new ArrayList<>();
421 @JsonProperty(
"@type")
431 @JsonProperty(
"propertyBundle")
437 properties.put(key, val);
441 propertyBundle.add(bundle);
453 properties =
new LinkedHashMap<>();
463 properties.put(key, val);
String getRelationshipId(Content content)
List< CASEPropertyBundle > getPropertyBundle()
void addCase(Case caseObj)
CASEPropertyBundle(String type)
static final String EXTENSION
String getDataSourcePath(Content dataSource)
Map< String, Object > getProperties()
CASENode createRelationshipNode(String relationshipID, String sourceID, String targetID)
Map< String, Object > getProperties()
void addDataSource(Content dataSource, Case parentCase)
String getCaseTraceId(Case caseObj)
final Map< String, Object > properties
CASENode(String id, String type)
void addBundle(CASEPropertyBundle bundle)
static String getStringTimeISO8601(long epochSeconds, TimeZone tzone)
CASEPropertyBundle createFileBundle(AbstractFile file)
CASEPropertyBundle createContentDataBundle(AbstractFile file)
CaseUcoReportGenerator(Path directory, String reportName)
final JsonGenerator reportGenerator
final List< CASEPropertyBundle > propertyBundle
void addFile(AbstractFile file, Content parentDataSource)
String getDataSourceTraceId(Content dataSource)
String getFileTraceId(AbstractFile file)
final Map< String, Object > properties
void addProperty(String key, Object val)
void addProperty(String key, Object val)
String getURLTraceId(Content content)
void addFile(AbstractFile file, Content parentDataSource, Path localPath)