Autopsy  4.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-2016 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.TimeZone;
23 import java.util.logging.Level;
24 
25 import org.openide.util.NbBundle;
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 import org.sleuthkit.datamodel.TskException;
32 
39 public class ArtifactStringContent implements StringContent {
40 
41  BlackboardArtifact artifact;
42  private String stringContent = "";
43  static final Logger logger = Logger.getLogger(ArtifactStringContent.class.getName());
44  private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
45 
46  public ArtifactStringContent(BlackboardArtifact art) {
47  artifact = art;
48  }
49 
50  @Override
51  @SuppressWarnings("deprecation")
52  public String getString() {
53  if (stringContent.isEmpty()) {
54  try {
55  StringBuilder buffer = new StringBuilder();
56  buffer.append("<html>\n"); //NON-NLS
57  buffer.append("<body>\n"); //NON-NLS
58 
59  // artifact name header
60  buffer.append("<h4>"); //NON-NLS
61  buffer.append(artifact.getDisplayName());
62  buffer.append("</h4>\n"); //NON-NLS
63 
64  // start table for attributes
65  buffer.append("<table border='0'>"); //NON-NLS
66  buffer.append("<tr>"); //NON-NLS
67  buffer.append("</tr>\n"); //NON-NLS
68 
69  // cycle through each attribute and display in a row in the table.
70  for (BlackboardAttribute attr : artifact.getAttributes()) {
71 
72  // name column
73  buffer.append("<tr><td>"); //NON-NLS
74  buffer.append(attr.getAttributeType().getDisplayName());
75  buffer.append("</td>"); //NON-NLS
76 
77  // value column
78  buffer.append("<td>"); //NON-NLS
79  switch (attr.getAttributeType().getValueType()) {
80  case STRING:
81  String str = attr.getValueString();
82  str = str.replaceAll(" ", "&nbsp;"); //NON-NLS
83  str = str.replaceAll("<", "&lt;"); //NON-NLS
84  str = str.replaceAll(">", "&gt;"); //NON-NLS
85  str = str.replaceAll("(\r\n|\n)", "<br />"); //NON-NLS
86  buffer.append(str);
87  break;
88  case INTEGER:
89  case LONG:
90  case DOUBLE:
91  case BYTE:
92  buffer.append(attr.getDisplayString());
93  break;
94  case DATETIME:
95  long epoch = attr.getValueLong();
96  String time = "0000-00-00 00:00:00";
97  if (epoch != 0) {
98  dateFormatter.setTimeZone(getTimeZone(artifact));
99  time = dateFormatter.format(new java.util.Date(epoch * 1000));
100  }
101  buffer.append(time);
102  break;
103  }
104  if (!"".equals(attr.getContext())) {
105  buffer.append(" (");
106  buffer.append(attr.getContext());
107  buffer.append(")");
108  }
109  buffer.append("</td>"); //NON-NLS
110  buffer.append("</tr>\n"); //NON-NLS
111  }
112 
113  final Content content = getAssociatedContent(artifact);
114 
115  String path = "";
116  try {
117  path = content.getUniquePath();
118  } catch (TskCoreException ex) {
119  logger.log(Level.SEVERE, "Exception while calling Content.getUniquePath() on {0} : {1}", new Object[]{content, ex.getLocalizedMessage()}); //NON-NLS
120  }
121 
122  //add file path
123  buffer.append("<tr>"); //NON-NLS
124  buffer.append("<td>"); //NON-NLS
125  buffer.append(NbBundle.getMessage(this.getClass(), "ArtifactStringContent.getStr.srcFilePath.text"));
126  buffer.append("</td>"); //NON-NLS
127  buffer.append("<td>"); //NON-NLS
128  buffer.append(path);
129  buffer.append("</td>"); //NON-NLS
130  buffer.append("</tr>\n"); //NON-NLS
131 
132  // add artifact ID (useful for debugging)
133  buffer.append("<tr><td>"); //NON-NLS
134  buffer.append(NbBundle.getMessage(this.getClass(), "ArtifactStringContent.getStr.artifactId.text"));
135  buffer.append("</td><td>"); //NON-NLS
136  buffer.append(artifact.getArtifactID());
137  buffer.append("</td>"); //NON-NLS
138  buffer.append("</tr>\n"); //NON-NLS
139 
140  buffer.append("</table>"); //NON-NLS
141  buffer.append("</html>\n"); //NON-NLS
142 
143  stringContent = buffer.toString();
144  } catch (TskException ex) {
145  stringContent = NbBundle.getMessage(this.getClass(), "ArtifactStringContent.getStr.err");
146  }
147  }
148 
149  return stringContent;
150  }
151 
152  private static Content getAssociatedContent(BlackboardArtifact artifact) {
153  try {
154  return artifact.getSleuthkitCase().getContentById(artifact.getObjectID());
155  } catch (TskException ex) {
156  logger.log(Level.WARNING, "Getting file failed", ex); //NON-NLS
157  }
158  throw new IllegalArgumentException(NbBundle.getMessage(ArtifactStringContent.class, "ArtifactStringContent.exception.msg"));
159  }
160 
161  private static TimeZone getTimeZone(BlackboardArtifact artifact) {
163 
164  }
165 }
static Content getAssociatedContent(BlackboardArtifact artifact)
static TimeZone getTimeZone(BlackboardArtifact artifact)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jan 2 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.