19 package org.sleuthkit.autopsy.modules.iOS;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.OutputStream;
26 import java.sql.Connection;
27 import java.sql.DriverManager;
28 import java.sql.ResultSet;
29 import java.sql.SQLException;
30 import java.sql.Statement;
31 import java.util.List;
32 import java.util.logging.Level;
43 class ContactAnalyzer {
45 private Connection connection = null;
46 private ResultSet resultSet = null;
47 private Statement statement = null;
48 private String dbPath =
"";
49 private long fileId = 0;
50 private java.io.File jFile = null;
51 private String moduleName = iOSModuleFactory.getModuleName();
52 private static final Logger logger = Logger.getLogger(ContactAnalyzer.class.getName());
54 public void findContacts() {
56 List<AbstractFile> absFiles;
58 SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
59 absFiles = skCase.findAllFilesWhere(
"name LIKE '%call_history%' ");
60 if (absFiles.isEmpty()) {
63 for (AbstractFile AF : absFiles) {
65 jFile =
new java.io.File(Case.getCurrentCase().getTempDirectory(), AF.getName().replaceAll(
"[<>%|\"/:*\\\\]",
""));
67 ContentUtils.writeToFile(AF, jFile);
70 dbPath = jFile.toString();
73 }
catch (Exception e) {
74 logger.log(Level.SEVERE,
"Error parsing Contacts", e);
77 }
catch (TskCoreException e) {
78 logger.log(Level.SEVERE,
"Error finding Contacts", e);
88 private void findContactsInDB(String DatabasePath,
long fId) {
89 if (DatabasePath == null || DatabasePath.isEmpty()) {
93 Class.forName(
"org.sqlite.JDBC");
94 connection = DriverManager.getConnection(
"jdbc:sqlite:" + DatabasePath);
95 statement = connection.createStatement();
96 }
catch (ClassNotFoundException | SQLException e) {
97 logger.log(Level.SEVERE,
"Error opening database", e);
100 Case currentCase = Case.getCurrentCase();
101 SleuthkitCase skCase = currentCase.getSleuthkitCase();
103 AbstractFile f = skCase.getAbstractFileById(fId);
105 logger.log(Level.SEVERE,
"Error getting abstract file " + fId);
112 resultSet = statement.executeQuery(
113 "SELECT mimetype,data1, name_raw_contact.display_name AS display_name \n"
114 +
"FROM raw_contacts JOIN contacts ON (raw_contacts.contact_id=contacts._id) \n"
115 +
"JOIN raw_contacts AS name_raw_contact ON(name_raw_contact_id=name_raw_contact._id) "
116 +
"LEFT OUTER JOIN data ON (data.raw_contact_id=raw_contacts._id) \n"
117 +
"LEFT OUTER JOIN mimetypes ON (data.mimetype_id=mimetypes._id) \n"
118 +
"WHERE mimetype = 'vnd.android.cursor.item/phone_v2' OR mimetype = 'vnd.android.cursor.item/email_v2'\n"
119 +
"ORDER BY name_raw_contact.display_name ASC;");
121 BlackboardArtifact bba;
122 bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT);
127 while (resultSet.next()) {
128 name = resultSet.getString(
"display_name");
129 data1 = resultSet.getString(
"data1");
130 mimetype = resultSet.getString(
"mimetype");
132 if (name.equals(oldName) ==
false) {
133 bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT);
134 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID(), moduleName, name));
136 if (mimetype.equals(
"vnd.android.cursor.item/phone_v2")) {
137 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER.getTypeID(), moduleName, data1));
139 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL.getTypeID(), moduleName, data1));
144 }
catch (Exception e) {
145 logger.log(Level.SEVERE,
"Error parsing Contacts to Blackboard", e);
151 }
catch (Exception e) {
152 logger.log(Level.SEVERE,
"Error closing database", e);
155 }
catch (Exception e) {
156 logger.log(Level.SEVERE,
"Error parsing Contacts to Blackboard", e);
161 public static void copyFileUsingStream(AbstractFile file, File jFile)
throws IOException {
162 InputStream is =
new ReadContentInputStream(file);
163 OutputStream os =
new FileOutputStream(jFile);
164 byte[] buffer =
new byte[8192];
167 while ((length = is.read(buffer)) != -1) {
168 os.write(buffer, 0, length);
169 System.out.println(length);
180 public static void copyFileUsingStreams(AbstractFile file, File jFile) {
182 OutputStream ostream = null;
185 istream =
new ReadContentInputStream(file);
189 ostream =
new FileOutputStream(jFile);
190 while ((c = istream.read()) != EOF) {
193 }
catch (IOException e) {
194 System.out.println(
"Error: " + e.getMessage());
199 }
catch (IOException e) {
200 System.out.println(
"File did not close");