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