Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def maketable(reportfile, case):
reportfiledb = os.path.join(case, "extracted data", "mms-sms", "db", "mmssms.db")
reportfile_connection=apsw.Connection(reportfiledb)
reportfile_cursor1=reportfile_connection.cursor()
reportfile_cursor2=reportfile_connection.cursor()
reportfile_cursor3=reportfile_connection.cursor()
contactfiledb = os.path.join(case, "extracted data", "contacts", "db", "contacts2.db")
contactfile_connection=apsw.Connection(contactfiledb)
contactfile_cursor1=contactfile_connection.cursor()
contactfile_cursor2=contactfile_connection.cursor()
phone1 = re.compile("0")
phone2 = re.compile("\+")
reportfile.write("\n")
reportfile.write("<table valign="TOP" cellspacing="0" cellpadding="8"></table>\n")
reportfile.write("<div class="\"ResultsTable\"">\n")
reportfile.write("\n")
reportfile.write("\n")
for row1 in reportfile_cursor1.execute("SELECT _id FROM sms ORDER BY date DESC"):
for entry in row1:
for row2 in reportfile_cursor2.execute("SELECT type FROM sms where _id = " + str(entry)):
for status in row2:
if str(status) == '1':
<table><tbody><tr class="\"title\""><td><b>Status</b></td><td><b>Name</b></td><td><b>Number</b></td><td><b>Content</b></td><td><b>Date/Time Recieved</b></td><td><b>Date/Time Sent</b></td></tr></tbody></table></div>
Returns:
connection to the sqlite db who stores warehouse data.
"""
if getattr(self, '_connection', None):
logger.debug('Connection to warehouse db already exists. Using existing one.')
else:
dsn = self._dsn
if dsn == 'sqlite://':
dsn = ':memory:'
else:
dsn = dsn.replace('sqlite:///', '')
logger.debug(
'Creating new apsw connection.\n dsn: {}, config_dsn: {}'
.format(dsn, self._dsn))
self._connection = apsw.Connection(dsn)
return self._connection
def tlmake(case):
reportfiledb = os.path.join(case, "extracted data", "calendar", "db", "calendar.db")
reportfile_connection=apsw.Connection(reportfiledb)
reportfile_cursor1=reportfile_connection.cursor()
reportfile_cursor2=reportfile_connection.cursor()
reportfile_cursor3=reportfile_connection.cursor()
tldb = os.path.join(case, "reports", "timeline.db")
tl_connection=apsw.Connection(tldb)
tl_cursor=tl_connection.cursor()
for row1 in reportfile_cursor1.execute("SELECT DISTINCT account_name from calendars"):
for account in row1:
for row2 in reportfile_cursor2.execute("SELECT _id FROM view_events WHERE account_name = \"" + account + "\" ORDER BY calendar_displayName DESC"):
for rowid in row2:
for row3 in reportfile_cursor3.execute("SELECT title FROM view_events WHERE _id = " + str(rowid)):
for evtname in row3:
name = str(evtname)
name = name.replace("'", "''")
name = name.replace('"', '""')
def tlmake(case):
reportdb = os.path.join(case, "extracted data", "call-log", "db", "contacts2.db")
report_connection=apsw.Connection(reportdb)
report_cursor1=report_connection.cursor()
report_cursor2=report_connection.cursor()
report_cursor3=report_connection.cursor()
tldb = os.path.join(case, "reports", "timeline.db")
tl_connection=apsw.Connection(tldb)
tloutput=io.StringIO()
tl_cursor=tl_connection.cursor()
for row1 in report_cursor1.execute("SELECT _id FROM calls"):
for entry in row1:
for row2 in report_cursor2.execute("SELECT type FROM calls where _id = " + str(entry)):
for status in row2:
if str(status) == '1':
statusdesc = 'Recieved a call from '
elif str(status) == '2':
def createbfp(chemicalite_path, chembldb_path):
'''Create indexed virtual tables containing the bfp data'''
connection = apsw.Connection(chembldb_path)
connection.enableloadextension(True)
connection.loadextension(chemicalite_path)
connection.enableloadextension(False)
cursor = connection.cursor()
# sorry for the hard-coded bfp sizes in bytes (128, 64).
# I will fix this
cursor.execute("CREATE VIRTUAL TABLE torsion USING rdtree(id, bfp bytes(128))");
cursor.execute("CREATE VIRTUAL TABLE morgan USING rdtree(id, bfp bytes(64))");
cursor.execute("CREATE VIRTUAL TABLE feat_morgan USING rdtree(id, bfp bytes(64))");
cursor.execute("INSERT INTO torsion(id, bfp) SELECT id, mol_topological_torsion_bfp(molecule) FROM chembl")
cursor.execute("INSERT INTO morgan(id, bfp) SELECT id, mol_morgan_bfp(molecule, 2) FROM chembl")
cursor.execute("INSERT INTO feat_morgan(id, bfp) SELECT id, mol_feat_morgan_bfp(molecule, 2) FROM chembl")
def _get_conn(self):
'''Return thread-local connection object
'''
try:
conn = self.conn[thread.get_ident()]
except KeyError:
log.debug("Creating new db connection (active conns: %d)...", len(self.conn))
conn = apsw.Connection(self.dbfile)
conn.setbusytimeout(self.retrytime)
if self.initsql:
conn.cursor().execute(self.initsql)
self.conn[thread.get_ident()] = conn
return conn
def extract(case, userdata):
print("--> Extracting call logs\n\n")
extractdir = os.path.join(case, "extracted data")
if not os.path.exists(extractdir):
os.makedirs(extractdir)
extractdir = os.path.join(extractdir, "call-log")
if not os.path.exists(extractdir):
os.makedirs(extractdir)
dbdir = os.path.join(extractdir, "db")
if not os.path.exists(dbdir):
os.makedirs(dbdir)
db_src = os.path.join(userdata, "data", "com.android.providers.contacts", "databases", "contacts2.db")
db_dest = os.path.join(dbdir, "contacts2.db")
shutil.copyfile(db_src, db_dest)
dbconnection = apsw.Connection(db_dest)
filepath = os.path.join(extractdir, "Call log.txt")
fileopen = open(filepath, "w", encoding='utf8')
dbshell = apsw.Shell(stdout=fileopen, db=dbconnection)
dbshell.process_command(".header on")
dbshell.process_sql("select * from calls")
fileopen.close()
database = os.path.join(user, "threads_db2")
outputfile = os.path.join(user, "..", "threads_db2.txt")
output = open(outputfile, 'w', encoding='utf8')
extractSQLconnect = apsw.Connection(database)
SQLShell = apsw.Shell(stdout=output, db=extractSQLconnect)
try:
SQLShell.process_command(".header on")
SQLShell.process_sql("select * from messages")
except:
print("Could not extract messages")
output.close()
database = os.path.join(user, "call_log.sqlite")
outputfile = os.path.join(user, "..", "call_log.sqlite.txt")
output = open(outputfile, 'w', encoding='utf8')
extractSQLconnect = apsw.Connection(database)
SQLShell = apsw.Shell(stdout=output, db=extractSQLconnect)
try:
SQLShell.process_command(".header on")
SQLShell.process_sql("select * from person_summary")
except Exception:
print("Could not extract call log")
output.close()
def connect(self, db):
''' Connect to the DB, enable foreign keys, set autocommit mode,
and return the open connection object. '''
con = apsw.Connection(db)
cur = con.cursor()
cur.execute('PRAGMA foreign_keys = ON')
cur.close()
return con
def maketable(reportfile, case):
reportfiledb = os.path.join(case, "extracted data", "facebook", "db", "threads_db2")
reportfile_connection=apsw.Connection(reportfiledb)
reportfile_cursor1=reportfile_connection.cursor()
reportfile_cursor2=reportfile_connection.cursor()
reportfile_cursor3=reportfile_connection.cursor()
reportfile.write("\n")
reportfile.write("\n")
reportfile.write("<table valign="TOP" cellspacing="0" cellpadding="8"><tbody><tr><td><a href="reportfile-contacts.html">Contacts</a></td></tr></tbody></table>\n")
reportfile.write("<div class="\"ResultsTable\"">\n")
reportfile.write("\n")
reportfile.write("\n")
for row1 in reportfile_cursor1.execute("select msg_id from messages order by timestamp_ms DESC"):
for entry1 in row1:
reportfile.write("\n")
for row2 in reportfile_cursor2.execute("select thread_key from messages WHERE msg_id = '" + str(entry1) + "'"):
for entry2 in row2:
<table><tbody><tr><td><b>Conversation</b></td><td><b>Message</b></td><td><b>Sent By</b></td><td><b>Attachments</b></td><td><b>Coordinates</b></td><td><b>Time</b></td></tr><tr></tr></tbody></table></div>