19 package org.sleuthkit.autopsy.modules.stix;
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.mitre.cybox.common_2.ConditionApplicationEnum;
24 import org.mitre.cybox.common_2.ConditionTypeEnum;
25 import org.mitre.cybox.common_2.StringObjectPropertyType;
35 abstract class EvaluatableObject {
37 private String warnings;
39 protected String spacing;
41 abstract public ObservableResult evaluate();
48 public void setWarnings(String a_warnings) {
49 warnings = a_warnings;
58 public String getWarnings() {
67 public void addWarning(String a_newWarning) {
68 if ((warnings == null) || warnings.isEmpty()) {
69 warnings = a_newWarning;
72 warnings = warnings +
", " + a_newWarning;
87 public List<BlackboardArtifact> findArtifactsBySubstring(StringObjectPropertyType item,
88 BlackboardAttribute.ATTRIBUTE_TYPE attrType) throws TskCoreException {
90 if (item.getValue() == null) {
91 throw new TskCoreException(
"Error: Value field is null");
94 if (item.getCondition() == null) {
95 addWarning(
"Warning: No condition given for " + attrType.getDisplayName() +
" field, using substring comparison");
96 }
else if (item.getCondition() != ConditionTypeEnum.CONTAINS) {
97 addWarning(
"Warning: Ignoring condition " + item.getCondition() +
" for "
98 + attrType.getDisplayName() +
" field and doing substring comparison");
101 List<BlackboardArtifact> hits = null;
103 Case case1 = Case.getCurrentCase();
104 SleuthkitCase sleuthkitCase = case1.getSleuthkitCase();
106 String[] parts = item.getValue().toString().split(
"##comma##");
108 if ((item.getApplyCondition() == null)
109 || (item.getApplyCondition() == ConditionApplicationEnum.ANY)) {
111 for (String part : parts) {
114 hits = sleuthkitCase.getBlackboardArtifacts(
118 hits.addAll(sleuthkitCase.getBlackboardArtifacts(
123 }
else if ((item.getApplyCondition() != null)
124 || (item.getApplyCondition() == ConditionApplicationEnum.ALL)) {
126 boolean firstRound =
true;
127 for (String part : parts) {
129 hits = sleuthkitCase.getBlackboardArtifacts(
133 }
else if (hits != null) {
134 hits.retainAll(sleuthkitCase.getBlackboardArtifacts(
140 return new ArrayList<BlackboardArtifact>();
144 throw new TskCoreException(
"Error: Can not apply NONE condition in search");
146 }
catch (TskCoreException ex) {
147 addWarning(ex.getLocalizedMessage());
163 public static boolean compareStringObject(StringObjectPropertyType stringObj, String strField)
164 throws TskCoreException {
165 if (stringObj.getValue() == null) {
166 throw new TskCoreException(
"Error: Value field is null");
169 String valueStr = stringObj.getValue().toString();
170 ConditionTypeEnum condition = stringObj.getCondition();
171 ConditionApplicationEnum applyCondition = stringObj.getApplyCondition();
173 return compareStringObject(valueStr, condition, applyCondition, strField);
188 public static boolean compareStringObject(String valueStr, ConditionTypeEnum condition,
189 ConditionApplicationEnum applyCondition, String strField)
190 throws TskCoreException {
192 if (valueStr == null) {
193 throw new TskCoreException(
"Error: Value field is null");
196 String[] parts = valueStr.split(
"##comma##");
197 String lowerFieldName = strField.toLowerCase();
199 for (String value : parts) {
200 boolean partialResult;
201 if ((condition == null)
202 || (condition == ConditionTypeEnum.EQUALS)) {
203 partialResult = value.equalsIgnoreCase(strField);
204 }
else if (condition == ConditionTypeEnum.DOES_NOT_EQUAL) {
205 partialResult = !value.equalsIgnoreCase(strField);
206 }
else if (condition == ConditionTypeEnum.CONTAINS) {
207 partialResult = lowerFieldName.contains(value.toLowerCase());
208 }
else if (condition == ConditionTypeEnum.DOES_NOT_CONTAIN) {
209 partialResult = !lowerFieldName.contains(value.toLowerCase());
210 }
else if (condition == ConditionTypeEnum.STARTS_WITH) {
211 partialResult = lowerFieldName.startsWith(value.toLowerCase());
212 }
else if (condition == ConditionTypeEnum.ENDS_WITH) {
213 partialResult = lowerFieldName.endsWith(value.toLowerCase());
215 throw new TskCoreException(
"Could not process condition " + condition.value() +
" on " + value);
219 if (applyCondition == ConditionApplicationEnum.NONE) {
220 if (partialResult ==
true) {
224 }
else if (applyCondition == ConditionApplicationEnum.ALL) {
225 if (partialResult ==
false) {
231 if (partialResult ==
true) {
239 if ((applyCondition == ConditionApplicationEnum.NONE)
240 || (applyCondition == ConditionApplicationEnum.ALL)) {
252 public String getPrintableWarnings() {
253 String warningsToPrint =
"";
254 if ((getWarnings() != null)
255 && (!getWarnings().isEmpty())) {
256 warningsToPrint =
" (" + getWarnings() +
")";
258 return warningsToPrint;