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

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.