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.List;
29 import java.util.logging.Level;
30 import org.openide.util.NbBundle;
47 class ContactAnalyzer {
49 private static final String moduleName = AndroidModuleFactory.getModuleName();
50 private static final Logger logger = Logger.getLogger(ContactAnalyzer.class.getName());
52 public static void findContacts(Content dataSource, FileManager fileManager) {
54 List<AbstractFile> absFiles;
56 absFiles = fileManager.findFiles(dataSource,
"contacts.db");
57 absFiles.addAll(fileManager.findFiles(dataSource,
"contacts2.db"));
58 if (absFiles.isEmpty()) {
61 for (AbstractFile AF : absFiles) {
63 File jFile =
new File(Case.getCurrentCase().getTempDirectory(), AF.getName());
64 ContentUtils.writeToFile(AF, jFile);
65 findContactsInDB(jFile.toString(), AF);
66 }
catch (Exception e) {
67 logger.log(Level.SEVERE,
"Error parsing Contacts", e);
70 }
catch (TskCoreException e) {
71 logger.log(Level.SEVERE,
"Error finding Contacts", e);
82 private static void findContactsInDB(String databasePath, AbstractFile f) {
83 Connection connection = null;
84 ResultSet resultSet = null;
85 Statement statement = null;
86 Blackboard blackboard = Case.getCurrentCase().getServices().getBlackboard();
88 if (databasePath == null || databasePath.isEmpty()) {
92 Class.forName(
"org.sqlite.JDBC");
93 connection = DriverManager.getConnection(
"jdbc:sqlite:" + databasePath);
94 statement = connection.createStatement();
95 }
catch (ClassNotFoundException | SQLException e) {
96 logger.log(Level.SEVERE,
"Error opening database", e);
104 Boolean column_found =
false;
105 DatabaseMetaData metadata = connection.getMetaData();
106 ResultSet columnListResultSet = metadata.getColumns(null, null,
"contacts", null);
107 while (columnListResultSet.next()) {
108 if (columnListResultSet.getString(
"COLUMN_NAME").equals(
"name_raw_contact_id")) {
114 resultSet = statement.executeQuery(
115 "SELECT mimetype,data1, name_raw_contact.display_name AS display_name \n"
116 +
"FROM raw_contacts JOIN contacts ON (raw_contacts.contact_id=contacts._id) \n"
117 +
"JOIN raw_contacts AS name_raw_contact ON(name_raw_contact_id=name_raw_contact._id) "
118 +
"LEFT OUTER JOIN data ON (data.raw_contact_id=raw_contacts._id) \n"
119 +
"LEFT OUTER JOIN mimetypes ON (data.mimetype_id=mimetypes._id) \n"
120 +
"WHERE mimetype = 'vnd.android.cursor.item/phone_v2' OR mimetype = 'vnd.android.cursor.item/email_v2'\n"
121 +
"ORDER BY name_raw_contact.display_name ASC;");
123 resultSet = statement.executeQuery(
124 "SELECT mimetype,data1, raw_contacts.display_name AS display_name \n"
125 +
"FROM raw_contacts JOIN contacts ON (raw_contacts.contact_id=contacts._id) \n"
126 +
"LEFT OUTER JOIN data ON (data.raw_contact_id=raw_contacts._id) \n"
127 +
"LEFT OUTER JOIN mimetypes ON (data.mimetype_id=mimetypes._id) \n"
128 +
"WHERE mimetype = 'vnd.android.cursor.item/phone_v2' OR mimetype = 'vnd.android.cursor.item/email_v2'\n"
129 +
"ORDER BY raw_contacts.display_name ASC;");
132 BlackboardArtifact bba;
133 bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT);
138 while (resultSet.next()) {
139 name = resultSet.getString(
"display_name");
140 data1 = resultSet.getString(
"data1");
141 mimetype = resultSet.getString(
"mimetype");
142 if (name.equals(oldName) ==
false) {
143 bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT);
144 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, moduleName, name));
146 if (mimetype.equals(
"vnd.android.cursor.item/phone_v2")) {
147 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER, moduleName, data1));
149 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL, moduleName, data1));
155 blackboard.indexArtifact(bba);
156 }
catch (Blackboard.BlackboardException ex) {
157 logger.log(Level.SEVERE, NbBundle.getMessage(Blackboard.class,
"Blackboard.unableToIndexArtifact.error.msg", bba.getDisplayName()), ex);
158 MessageNotifyUtil.Notify.error(
159 NbBundle.getMessage(Blackboard.class,
"Blackboard.unableToIndexArtifact.exception.msg"), bba.getDisplayName());
163 }
catch (SQLException e) {
164 logger.log(Level.WARNING,
"Unable to execute contacts SQL query against {0} : {1}",
new Object[]{databasePath, e});
165 }
catch (TskCoreException e) {
166 logger.log(Level.SEVERE,
"Error posting to blackboard", e);
169 if (resultSet != null) {
174 }
catch (Exception e) {
175 logger.log(Level.SEVERE,
"Error closing database", e);