김가영

데이터 sqlite 형식으로 변경

No preview for this file type
@echo
cd C:\Users\%USERNAME%\Desktop\batch_file
adb devices > C:\Users\%USERNAME%\Desktop\batch_file\device.txt
adb shell dumpsys alarm > C:\Users\%USERNAME%\Desktop\batch_file\alarm.txt
adb shell ps -A > C:\Users\%USERNAME%\Desktop\batch_file\process.txt
adb shell dumpsys alarm | grep -e "[set]" -e "[trigger]" -e "[remove]" | grep "com.sec.android.app.clockpackage" > C:\Users\%USERNAME%\Desktop\batch_file\alarm.txt
adb shell ps -Af > C:\Users\%USERNAME%\Desktop\batch_file\process.txt
adb shell uptime > C:\Users\%USERNAME%\Desktop\batch_file\uptime.txt
adb shell getprop ro.product.model > C:\Users\%USERNAME%\Desktop\batch_file\model.txt
adb shell getprop ro.build.version.release > C:\Users\%USERNAME%\Desktop\batch_file\sdk_version.txt
......
import os.path
import sys
import requests
import sqlite3
import os
def data_check(data_path):
def create_adb_info_db():
path = os.path.expanduser('~')+"\\Desktop\\batch_file\\"
if(os.path.isfile(path+'adb_info.db')):
os.remove(path+'adb_info.db')
conn=sqlite3.connect('adb_info.db')
c = conn.cursor()
c.execute("CREATE TABLE process (UID TEXT, PID TEXT, PPID TEXT, C TEXT, STIME TEXT, TTY TEXT, TIME TEXT, CMD TEXT)")
c.execute("CREATE TABLE info (android_version TEXT, sdk_version TEXT, device TEXT, model TEXT, uptime TEXT)")
c.execute("CREATE TABLE alarm (TIME TEXT, TYPE TEXT, DETAIL TEXT)")
conn.commit()
c.close()
def insert_alarm_db_file(info):
conn=sqlite3.connect('adb_info.db')
c = conn.cursor()
c.execute(
'insert into alarm(TIME, TYPE, DETAIL) values (?, ?, ?)'\
, (info[0], info[1], info[2])
)
conn.commit()
c.close()
def insert_info_db_file(info):
conn=sqlite3.connect('adb_info.db')
c = conn.cursor()
c.execute(
'insert into info(android_version, sdk_version, device, model, uptime) values (?, ?, ?, ?, ?)'\
, (info[0], info[1], info[2], info[3], info[4])
)
conn.commit()
c.close()
def insert_process_db_file(data_path):
conn=sqlite3.connect('adb_info.db')
c = conn.cursor()
with open(data_path) as f:
file_data = f.readlines()
for item in file_data:
info = item.strip().split()
c.execute(
'insert into process(UID, PID, PPID, C, STIME, TTY, TIME, CMD) values (?, ?, ?, ?, ?, ?, ?, ?)'\
, (info[0], info[1], info[2], info[3], info[4], info[5], info[6], info[7])
)
conn.commit()
c.close()
def data_processing(data_path, info):
while(True):
if(os.path.isfile(data_path)):
print("file")
......@@ -9,20 +58,61 @@ def data_check(data_path):
else:
print("x")
continue
data_transfer(data_path)
if(data_path.endswith('android_version.txt') or data_path.endswith('sdk_version.txt') or data_path.endswith('model.txt') or data_path.endswith('uptime.txt')):
with open(data_path) as f:
file_data = f.readlines()
info.append(file_data[0].strip())
print(info)
if(data_path.endswith('uptime.txt')):
insert_info_db_file(info)
elif(data_path.endswith('device.txt')):
with open(data_path) as f:
f.readline()
file_data = f.readlines()
info.append((file_data[0].strip().split())[0])
print(info)
elif(data_path.endswith('process.txt')):
insert_process_db_file(data_path)
elif(data_path.endswith('alarm.txt')):
with open(data_path) as f:
f.readline()
file_data = f.readlines()
for i in file_data:
if(i.endswith("wakeups:\n")):
continue
else:
if("[set]" in i or "[trigger]" in i or "[remove]" in i):
alarm_list = []
temp = i.strip().split('[') #time
temp2 = temp[1].split(']') #set 정보, detail
alarm_list.append(temp[0])
alarm_list.extend(temp2)
print(alarm_list)
insert_alarm_db_file(alarm_list)
def data_transfer(data_path):
with open(data_path, 'rb') as files:
header = {'Authorization':'Bearer ',}
header = {'Authorization':'..',}
upload = {'file':files}
response = requests.post('http://13.209.3.132/extractions', files=upload, headers=header)
print(response.text)
def main():
try:
info = []
path = os.path.expanduser('~')+"\\Desktop\\batch_file\\"
data_tup = [path+"android_version.txt", path+"alarm.txt", path+"device.txt", path+"model.txt", path+"process.txt", path+"sdk_version.txt", path+"uptime.txt", path+"InnerDatabase_test.db", path+"networkDatabase_test.db"]
data_tup = [path+"android_version.txt", path+"sdk_version.txt", path+"device.txt", path+"model.txt", path+"uptime.txt", path+"process.txt", path+"alarm.txt", path+"InnerDatabase_test.db", path+"networkDatabase_test.db"]
create_adb_info_db()
for i in data_tup:
print(i)
data_check(i)
data_processing(i, info)
trans_data_tup = [path+"adb_info.db", path+"InnerDatabase_test.db", path+"networkDatabase_test.db"]
for i in trans_data_tup:
print(i)
data_transfer(i)
except Exception as e:
exc_type, exc_obj, tb = sys.exc_info()
print('[error line No = {}]'.format(tb.tb_lineno))
print(e)
main()
......
No preview for this file type