data_sender.py
3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os.path
import sys
import requests
import sqlite3
import os
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")
break
else:
print("x")
continue
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':'..',}
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+"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_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()