23 package org.sleuthkit.autopsy.recentactivity;
26 import java.io.IOException;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
29 import java.sql.ResultSet;
30 import java.sql.ResultSetMetaData;
31 import java.sql.SQLException;
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.logging.Level;
38 import org.openide.util.NbBundle.Messages;
57 abstract class Extract {
59 protected Case currentCase;
60 protected SleuthkitCase tskCase;
61 protected Blackboard blackboard;
62 private final Logger logger = Logger.getLogger(this.getClass().getName());
63 private final ArrayList<String> errorMessages =
new ArrayList<>();
64 String moduleName =
"";
65 boolean dataFound =
false;
70 final void init() throws IngestModuleException {
72 currentCase = Case.getCurrentCaseThrows();
73 tskCase = currentCase.getSleuthkitCase();
74 blackboard = tskCase.getBlackboard();
75 }
catch (NoCurrentCaseException ex) {
76 throw new IngestModuleException(Bundle.Extract_indexError_message(), ex);
86 void configExtractor() throws IngestModuleException {
89 abstract void process(Content dataSource, IngestJobContext context, DataSourceIngestModuleProgress progressBar);
99 List<String> getErrorMessages() {
100 return errorMessages;
108 protected void addErrorMessage(String message) {
109 errorMessages.add(message);
124 protected BlackboardArtifact createArtifactWithAttributes(BlackboardArtifact.ARTIFACT_TYPE type, Content content, Collection<BlackboardAttribute> bbattributes) {
126 BlackboardArtifact bbart = content.newArtifact(type);
127 bbart.addAttributes(bbattributes);
129 }
catch (TskException ex) {
130 logger.log(Level.WARNING,
"Error while trying to add an artifact", ex);
140 @Messages({
"Extract.indexError.message=Failed to index artifact for keyword search.",
141 "Extract.noOpenCase.errMsg=No open case available."})
142 void postArtifact(BlackboardArtifact bbart) {
149 blackboard.postArtifact(bbart, getName());
150 }
catch (Blackboard.BlackboardException ex) {
151 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + bbart.getDisplayName(), ex);
160 void postArtifacts(Collection<BlackboardArtifact> artifacts) {
161 if(artifacts == null || artifacts.isEmpty()) {
166 blackboard.postArtifacts(artifacts, getName());
167 }
catch (Blackboard.BlackboardException ex) {
168 logger.log(Level.SEVERE,
"Unable to post blackboard artifacts", ex);
183 protected List<HashMap<String, Object>> dbConnect(String path, String query) {
185 List<HashMap<String, Object>> list;
186 String connectionString =
"jdbc:sqlite:" + path;
187 SQLiteDBConnect tempdbconnect = null;
189 tempdbconnect =
new SQLiteDBConnect(
"org.sqlite.JDBC", connectionString);
190 temprs = tempdbconnect.executeQry(query);
191 list = this.resultSetToArrayList(temprs);
192 }
catch (SQLException ex) {
193 logger.log(Level.WARNING,
"Error while trying to read into a sqlite db." + connectionString, ex);
194 return Collections.<HashMap<String, Object>>emptyList();
197 if (tempdbconnect != null) {
198 tempdbconnect.closeConnection();
211 private List<HashMap<String, Object>> resultSetToArrayList(ResultSet rs)
throws SQLException {
212 ResultSetMetaData md = rs.getMetaData();
213 int columns = md.getColumnCount();
214 List<HashMap<String, Object>> list =
new ArrayList<>(50);
216 HashMap<String, Object> row =
new HashMap<>(columns);
217 for (
int i = 1; i <= columns; ++i) {
218 if (rs.getObject(i) == null) {
219 row.put(md.getColumnName(i),
"");
221 row.put(md.getColumnName(i), rs.getObject(i));
235 protected String getName() {
239 protected String getRAModuleName() {
240 return RecentActivityExtracterModuleFactory.getModuleName();
247 public boolean foundData() {
255 protected void setFoundData(
boolean foundData){
256 dataFound = foundData;
263 protected Case getCurrentCase(){
264 return this.currentCase;
280 protected Collection<BlackboardAttribute> createHistoryAttribute(String url, Long accessTime,
281 String referrer, String title, String programName, String domain, String user)
throws TskCoreException {
283 Collection<BlackboardAttribute> bbattributes =
new ArrayList<>();
284 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL,
285 RecentActivityExtracterModuleFactory.getModuleName(),
286 (url != null) ? url :
""));
288 if (accessTime != null) {
289 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED,
290 RecentActivityExtracterModuleFactory.getModuleName(), accessTime));
293 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_REFERRER,
294 RecentActivityExtracterModuleFactory.getModuleName(),
295 (referrer != null) ? referrer :
""));
297 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE,
298 RecentActivityExtracterModuleFactory.getModuleName(),
299 (title != null) ? title :
""));
301 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME,
302 RecentActivityExtracterModuleFactory.getModuleName(),
303 (programName != null) ? programName :
""));
305 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN,
306 RecentActivityExtracterModuleFactory.getModuleName(),
307 (domain != null) ? domain :
""));
309 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_USER_NAME,
310 RecentActivityExtracterModuleFactory.getModuleName(),
311 (user != null) ? user :
""));
327 protected Collection<BlackboardAttribute> createCookieAttributes(String url,
328 Long creationTime, String name, String value, String programName, String domain) {
330 Collection<BlackboardAttribute> bbattributes =
new ArrayList<>();
331 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL,
332 RecentActivityExtracterModuleFactory.getModuleName(),
333 (url != null) ? url :
""));
335 if (creationTime != null) {
336 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME,
337 RecentActivityExtracterModuleFactory.getModuleName(), creationTime));
340 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME,
341 RecentActivityExtracterModuleFactory.getModuleName(),
342 (name != null) ? name :
""));
344 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_VALUE,
345 RecentActivityExtracterModuleFactory.getModuleName(),
346 (value != null) ? value :
""));
348 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME,
349 RecentActivityExtracterModuleFactory.getModuleName(),
350 (programName != null) ? programName :
""));
352 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN,
353 RecentActivityExtracterModuleFactory.getModuleName(),
354 (domain != null) ? domain :
""));
369 protected Collection<BlackboardAttribute> createBookmarkAttributes(String url, String title, Long creationTime, String programName, String domain) {
370 Collection<BlackboardAttribute> bbattributes =
new ArrayList<>();
372 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL,
373 RecentActivityExtracterModuleFactory.getModuleName(),
374 (url != null) ? url :
""));
376 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE,
377 RecentActivityExtracterModuleFactory.getModuleName(),
378 (title != null) ? title :
""));
380 if (creationTime != null) {
381 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED,
382 RecentActivityExtracterModuleFactory.getModuleName(), creationTime));
385 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME,
386 RecentActivityExtracterModuleFactory.getModuleName(),
387 (programName != null) ? programName :
""));
389 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN,
390 RecentActivityExtracterModuleFactory.getModuleName(),
391 (domain != null) ? domain :
""));
406 protected Collection<BlackboardAttribute> createDownloadAttributes(String path, Long pathID, String url, Long accessTime, String domain, String programName) {
407 Collection<BlackboardAttribute> bbattributes =
new ArrayList<>();
409 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH,
410 RecentActivityExtracterModuleFactory.getModuleName(),
411 (path != null) ? path :
""));
413 if (pathID != null && pathID != -1) {
414 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID,
415 RecentActivityExtracterModuleFactory.getModuleName(),
419 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL,
420 RecentActivityExtracterModuleFactory.getModuleName(),
421 (url != null) ? url :
""));
423 if (accessTime != null) {
424 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_ACCESSED,
425 RecentActivityExtracterModuleFactory.getModuleName(), accessTime));
428 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DOMAIN,
429 RecentActivityExtracterModuleFactory.getModuleName(),
430 (domain != null) ? domain :
""));
432 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME,
433 RecentActivityExtracterModuleFactory.getModuleName(),
434 (programName != null) ? programName :
""));
445 protected Collection<BlackboardAttribute> createDownloadSourceAttributes(String url) {
446 Collection<BlackboardAttribute> bbattributes =
new ArrayList<>();
448 bbattributes.add(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_URL,
449 RecentActivityExtracterModuleFactory.getModuleName(),
450 (url != null) ? url :
""));
464 protected File createTemporaryFile(IngestJobContext context, AbstractFile file)
throws IOException{
465 Path tempFilePath = Paths.get(RAImageIngestModule.getRATempPath(
466 getCurrentCase(), getName()), file.getName() + file.getId() + file.getNameExtension());
467 java.io.File tempFile = tempFilePath.toFile();
470 ContentUtils.writeToFile(file, tempFile, context::dataSourceIngestIsCancelled);
471 }
catch (IOException ex) {
472 throw new IOException(
"Error writingToFile: " + file, ex);