Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
Extract.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2012-2014 Basis Technology Corp.
6  *
7  * Copyright 2012 42six Solutions.
8  * Contact: aebadirad <at> 42six <dot> com
9  * Project Contact/Architect: carrier <at> sleuthkit <dot> org
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.sleuthkit.autopsy.recentactivity;
24 
26 import java.sql.ResultSet;
27 import java.sql.ResultSetMetaData;
28 import java.sql.SQLException;
29 import java.util.*;
30 import java.util.logging.Level;
31 
32 import org.openide.util.NbBundle;
37 import org.sleuthkit.datamodel.*;
38 
39 abstract class Extract {
40 
41  protected Case currentCase = Case.getCurrentCase();
42  protected SleuthkitCase tskCase = currentCase.getSleuthkitCase();
43  private final Logger logger = Logger.getLogger(this.getClass().getName());
44  private final ArrayList<String> errorMessages = new ArrayList<>();
45  String moduleName = "";
46  boolean dataFound = false;
47 
48  Extract() {
49  }
50 
51  void init() throws IngestModuleException {
52  }
53 
54  abstract void process(Content dataSource, IngestJobContext context);
55 
56  void complete() {
57  }
58 
59 
65  List<String> getErrorMessages() {
66  return errorMessages;
67  }
68 
74  protected void addErrorMessage(String message) {
75  errorMessages.add(message);
76  }
77 
88  protected void addArtifact(BlackboardArtifact.ARTIFACT_TYPE type, AbstractFile content, Collection<BlackboardAttribute> bbattributes) {
89  try {
90  BlackboardArtifact bbart = content.newArtifact(type);
91  bbart.addAttributes(bbattributes);
92  } catch (TskException ex) {
93  logger.log(Level.SEVERE, "Error while trying to add an artifact", ex); //NON-NLS
94  }
95  }
96 
107  protected List<HashMap<String, Object>> dbConnect(String path, String query) {
108  ResultSet temprs;
109  List<HashMap<String, Object>> list;
110  String connectionString = "jdbc:sqlite:" + path; //NON-NLS
111  try {
112  SQLiteDBConnect tempdbconnect = new SQLiteDBConnect("org.sqlite.JDBC", connectionString); //NON-NLS
113  temprs = tempdbconnect.executeQry(query);
114  list = this.resultSetToArrayList(temprs);
115  tempdbconnect.closeConnection();
116  } catch (SQLException ex) {
117  logger.log(Level.SEVERE, "Error while trying to read into a sqlite db." + connectionString, ex); //NON-NLS
118  errorMessages.add(NbBundle.getMessage(this.getClass(), "Extract.dbConn.errMsg.failedToQueryDb", getName()));
119  return Collections.<HashMap<String,Object>>emptyList();
120  }
121  return list;
122  }
123 
130  private List<HashMap<String, Object>> resultSetToArrayList(ResultSet rs) throws SQLException {
131  ResultSetMetaData md = rs.getMetaData();
132  int columns = md.getColumnCount();
133  List<HashMap<String, Object>> list = new ArrayList<>(50);
134  while (rs.next()) {
135  HashMap<String, Object> row = new HashMap<>(columns);
136  for (int i = 1; i <= columns; ++i) {
137  if (rs.getObject(i) == null) {
138  row.put(md.getColumnName(i), "");
139  } else {
140  row.put(md.getColumnName(i), rs.getObject(i));
141  }
142  }
143  list.add(row);
144  }
145 
146  return list;
147  }
148 
154  protected String getName() {
155  return moduleName;
156  }
157 
158  public boolean foundData() {
159  return dataFound;
160  }
161 }
void addAttributes(Collection< BlackboardAttribute > attributes)
BlackboardArtifact newArtifact(int artifactTypeID)

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.