Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ArtifactStringContent.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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.datamodel;
20 
21 import java.text.SimpleDateFormat;
22 import java.util.logging.Level;
23 import org.apache.commons.lang.StringUtils;
24 import org.openide.util.NbBundle;
25 import org.openide.util.NbBundle.Messages;
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 
40 @Deprecated
41 public class ArtifactStringContent implements StringContent {
42 
43  private final static SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
44  private final static Logger logger = Logger.getLogger(ArtifactStringContent.class.getName());
45  private final BlackboardArtifact artifact;
46  private String stringContent = "";
47 
56  public ArtifactStringContent(BlackboardArtifact artifact) {
57  this.artifact = artifact;
58  }
59 
65  @Messages({
66  "ArtifactStringContent.attrsTableHeader.type=Type",
67  "ArtifactStringContent.attrsTableHeader.value=Value",
68  "ArtifactStringContent.attrsTableHeader.sources=Source(s)",
69  "ArtifactStringContent.failedToGetSourcePath.message=Failed to get source file path from case database",
70  "ArtifactStringContent.failedToGetAttributes.message=Failed to get some or all attributes from case database"
71  })
72  @Override
73  public String getString() {
74  if (stringContent.isEmpty()) {
75  /*
76  * Start the document.
77  */
78  StringBuilder buffer = new StringBuilder(1024);
79  buffer.append("<html>\n"); //NON-NLS
80  buffer.append("<body>\n"); //NON-NLS
81 
82  /*
83  * Use the artifact display name as a header.
84  */
85  buffer.append("<h3>"); //NON-NLS
86  buffer.append(artifact.getDisplayName());
87  buffer.append("</h3>\n"); //NON-NLS
88 
89  /*
90  * Put the attributes, source content path and artifact id in a
91  * table.
92  */
93  buffer.append("<table border='1'>"); //NON-NLS
94 
95  // header row
96  buffer.append("<tr>"); //NON-NLS
97  buffer.append("<th><b>"); //NON-NLS
98  buffer.append(Bundle.ArtifactStringContent_attrsTableHeader_type());
99  buffer.append("</b></th>"); //NON-NLS
100  buffer.append("<th><b>"); //NON-NLS
101  buffer.append(Bundle.ArtifactStringContent_attrsTableHeader_value());
102  buffer.append("</b></th>"); //NON-NLS
103  buffer.append("<th><b>"); //NON-NLS
104  buffer.append(Bundle.ArtifactStringContent_attrsTableHeader_sources());
105  buffer.append("</b></th>"); //NON-NLS
106  buffer.append("</tr>\n"); //NON-NLS
107  try {
108  Content content = artifact.getSleuthkitCase().getContentById(artifact.getObjectID());
109 
110  /*
111  * Add rows for each attribute.
112  */
113  for (BlackboardAttribute attr : artifact.getAttributes()) {
114 
115  /*
116  * Attribute value column.
117  */
118  String value = "";
119  switch (attr.getAttributeType().getValueType()) {
120  case STRING:
121  case INTEGER:
122  case LONG:
123  case DOUBLE:
124  case BYTE:
125  case JSON:
126  default:
127  value = attr.getDisplayString();
128  break;
129 
130  // Use Autopsy date formatting settings, not TSK defaults
131  case DATETIME:
132  long epoch = attr.getValueLong();
133  value = "0000-00-00 00:00:00";
134  if (null != content && 0 != epoch) {
135  dateFormatter.setTimeZone(ContentUtils.getTimeZone(content));
136  value = dateFormatter.format(new java.util.Date(epoch * 1000));
137  }
138  break;
139  }
140 
141  /*
142  * Attribute sources column.
143  */
144  String sources = StringUtils.join(attr.getSources(), ", ");
145  buffer.append(makeTableRow(attr.getAttributeType().getDisplayName(), value, sources));
146  }
147 
148  /*
149  * Add a row for the source content path.
150  */
151 
152  String path = "";
153  try {
154  if (null != content) {
155  path = content.getUniquePath();
156  }
157  } catch (TskCoreException ex) {
158  logger.log(Level.SEVERE, String.format("Error getting source content path for artifact (artifact_id=%d, obj_id=%d)", artifact.getArtifactID(), artifact.getObjectID()), ex);
159  path = Bundle.ArtifactStringContent_failedToGetSourcePath_message();
160  }
161 
162  buffer.append(makeTableRow(NbBundle.getMessage(this.getClass(), "ArtifactStringContent.getStr.srcFilePath.text"),
163  path, ""));
164 
165 
166  /*
167  * Add a row for the artifact id.
168  */
169  buffer.append(makeTableRow(NbBundle.getMessage(this.getClass(), "ArtifactStringContent.getStr.artifactId.text"),
170  Long.toString(artifact.getArtifactID()), ""));
171 
172  } catch (TskCoreException ex) {
173  logger.log(Level.SEVERE, String.format("Error getting data for artifact (artifact_id=%d)", artifact.getArtifactID()), ex);
174  buffer.append(makeTableRow(Bundle.ArtifactStringContent_failedToGetAttributes_message(), "", ""));
175  } finally {
176  /*
177  * Finish the document
178  */
179  buffer.append("</table>"); //NON-NLS
180  buffer.append("</html>\n"); //NON-NLS
181  stringContent = buffer.toString();
182  }
183  }
184 
185  return stringContent;
186  }
187 
188  // escape special HTML characters
189  private String escapeHtmlString(String str) {
190  str = str.replaceAll(" ", "&nbsp;"); //NON-NLS
191  str = str.replaceAll("<", "&lt;"); //NON-NLS
192  str = str.replaceAll(">", "&gt;"); //NON-NLS
193  str = str.replaceAll("(\r\n|\n)", "<br />"); //NON-NLS
194  return str;
195  }
196 
204  private String makeTableRow(String type, String value, String source) {
205  String row = "<tr><td>" + escapeHtmlString(type) + "</td><td>" + escapeHtmlString(value) + "</td><td>" + escapeHtmlString(source) + "</td></tr>";
206  return row;
207  }
208 
209 }
String makeTableRow(String type, String value, String source)
static TimeZone getTimeZone(Content content)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.