Autopsy  4.13.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AbstractSingleEntityParser.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 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.autopsy.datasourceprocessors.xry;
20 
21 import java.io.IOException;
22 import java.nio.file.Path;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.logging.Level;
27 import org.sleuthkit.datamodel.Content;
28 import org.sleuthkit.datamodel.TskCoreException;
29 
34 abstract class AbstractSingleEntityParser implements XRYFileParser {
35 
36  private static final Logger logger = Logger.getLogger(AbstractSingleEntityParser.class.getName());
37 
38  protected static final String PARSER_NAME = "XRY DSP";
39 
40  @Override
41  public void parse(XRYFileReader reader, Content parent) throws IOException, TskCoreException {
42  Path reportPath = reader.getReportPath();
43  logger.log(Level.INFO, String.format("[XRY DSP] Processing report at [ %s ]", reportPath.toString()));
44 
45  while (reader.hasNextEntity()) {
46  String xryEntity = reader.nextEntity();
47  String[] xryLines = xryEntity.split("\n");
48 
49  List<XRYKeyValuePair> keyValuePairs = new ArrayList<>();
50 
51  //First line of the entity is the title, the entity will always be non-empty.
52  logger.log(Level.INFO, String.format("[XRY DSP] Processing [ %s ]", xryLines[0]));
53 
54  String namespace = "";
55  //Process each line, searching for a key value pair or a namespace.
56  for (int i = 1; i < xryLines.length; i++) {
57  String xryLine = xryLines[i];
58 
59  String candidateNamespace = xryLine.trim();
60  //Check if the line is a namespace, which gives context to the keys
61  //that follow.
62  if (isNamespace(candidateNamespace)) {
63  namespace = candidateNamespace;
64  continue;
65  }
66 
67  //Check if this line resembles a Key Value pair.
68  if(!XRYKeyValuePair.isPair(xryLine)) {
69  logger.log(Level.WARNING, String.format("[XRY DSP] Expected a key value "
70  + "pair on this line (in brackets) [ %s ], but one was not detected.",
71  xryLine));
72  continue;
73  }
74 
75  XRYKeyValuePair pair = XRYKeyValuePair.from(xryLine, namespace);
76 
77  //Verify the implementation recognizes the key.
78  if (!canProcess(pair)) {
79  logger.log(Level.WARNING, String.format("[XRY DSP] The following key, "
80  + "value pair (in brackets) [ %s ] was not recognized. Discarding...",
81  pair));
82  continue;
83  }
84 
85  //Empty values are meaningless for blackboard attributes.
86  if (pair.getValue().isEmpty()) {
87  logger.log(Level.WARNING, String.format("[XRY DSP] The following key value pair"
88  + "(in brackets) [ %s ] was recognized, but the value was empty. Discarding...",
89  pair));
90  continue;
91  }
92 
93  keyValuePairs.add(pair);
94  }
95 
96  if(!keyValuePairs.isEmpty()) {
97  makeArtifact(keyValuePairs, parent);
98  }
99  }
100  }
101 
106  abstract boolean canProcess(XRYKeyValuePair pair);
107 
123  abstract boolean isNamespace(String nameSpace);
124 
128  abstract void makeArtifact(List<XRYKeyValuePair> keyValuePairs, Content parent) throws TskCoreException;
129 
130 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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.