19 package org.sleuthkit.autopsy.modules.android;
22 import java.sql.Connection;
23 import java.sql.DatabaseMetaData;
24 import java.sql.DriverManager;
25 import java.sql.ResultSet;
26 import java.sql.SQLException;
27 import java.sql.Statement;
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.logging.Level;
45 class ContactAnalyzer {
47 private static final String moduleName = AndroidModuleFactory.getModuleName();
48 private static final Logger logger = Logger.getLogger(ContactAnalyzer.class.getName());
50 public static void findContacts(Content dataSource, FileManager fileManager) {
52 List<AbstractFile> absFiles;
54 absFiles = fileManager.findFiles(dataSource,
"contacts.db");
55 absFiles.addAll(fileManager.findFiles(dataSource,
"contacts2.db"));
56 if (absFiles.isEmpty()) {
59 for (AbstractFile AF : absFiles) {
61 File jFile =
new File(Case.getCurrentCase().getTempDirectory(), AF.getName());
62 ContentUtils.writeToFile(AF, jFile);
63 findContactsInDB(jFile.toString(), AF);
64 }
catch (Exception e) {
65 logger.log(Level.SEVERE,
"Error parsing Contacts", e);
68 }
catch (TskCoreException e) {
69 logger.log(Level.SEVERE,
"Error finding Contacts", e);
79 private static void findContactsInDB(String databasePath, AbstractFile f) {
80 Connection connection = null;
81 ResultSet resultSet = null;
82 Statement statement = null;
84 if (databasePath == null || databasePath.isEmpty()) {
88 Class.forName(
"org.sqlite.JDBC");
89 connection = DriverManager.getConnection(
"jdbc:sqlite:" + databasePath);
90 statement = connection.createStatement();
91 }
catch (ClassNotFoundException | SQLException e) {
92 logger.log(Level.SEVERE,
"Error opening database", e);
100 Boolean column_found =
false;
101 DatabaseMetaData metadata = connection.getMetaData();
102 ResultSet columnListResultSet = metadata.getColumns(null, null,
"contacts", null);
103 while (columnListResultSet.next()) {
104 if (columnListResultSet.getString(
"COLUMN_NAME").equals(
"name_raw_contact_id")) {
110 resultSet = statement.executeQuery(
111 "SELECT mimetype,data1, name_raw_contact.display_name AS display_name \n"
112 +
"FROM raw_contacts JOIN contacts ON (raw_contacts.contact_id=contacts._id) \n"
113 +
"JOIN raw_contacts AS name_raw_contact ON(name_raw_contact_id=name_raw_contact._id) "
114 +
"LEFT OUTER JOIN data ON (data.raw_contact_id=raw_contacts._id) \n"
115 +
"LEFT OUTER JOIN mimetypes ON (data.mimetype_id=mimetypes._id) \n"
116 +
"WHERE mimetype = 'vnd.android.cursor.item/phone_v2' OR mimetype = 'vnd.android.cursor.item/email_v2'\n"
117 +
"ORDER BY name_raw_contact.display_name ASC;");
119 resultSet = statement.executeQuery(
120 "SELECT mimetype,data1, raw_contacts.display_name AS display_name \n"
121 +
"FROM raw_contacts JOIN contacts ON (raw_contacts.contact_id=contacts._id) \n"
122 +
"LEFT OUTER JOIN data ON (data.raw_contact_id=raw_contacts._id) \n"
123 +
"LEFT OUTER JOIN mimetypes ON (data.mimetype_id=mimetypes._id) \n"
124 +
"WHERE mimetype = 'vnd.android.cursor.item/phone_v2' OR mimetype = 'vnd.android.cursor.item/email_v2'\n"
125 +
"ORDER BY raw_contacts.display_name ASC;");
128 BlackboardArtifact bba;
129 bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT);
134 while (resultSet.next()) {
135 name = resultSet.getString(
"display_name");
136 data1 = resultSet.getString(
"data1");
137 mimetype = resultSet.getString(
"mimetype");
139 if (name.equals(oldName) ==
false) {
140 bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT);
141 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID(), moduleName, name));
143 if (mimetype.equals(
"vnd.android.cursor.item/phone_v2")) {
144 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER.getTypeID(), moduleName, data1));
146 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL.getTypeID(), moduleName, data1));
151 }
catch (SQLException e) {
152 logger.log(Level.WARNING,
"Unable to execute contacts SQL query against {0} : {1}",
new Object[]{databasePath, e});
153 }
catch (TskCoreException e) {
154 logger.log(Level.SEVERE,
"Error posting to blackboard", e);
157 if (resultSet != null) {
162 }
catch (Exception e) {
163 logger.log(Level.SEVERE,
"Error closing database", e);