-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lupin_main.py
120 lines (77 loc) · 3.09 KB
/
Lupin_main.py
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
119
import os
import re
import tkinter as tk
from tkinter import filedialog
import shutil
from pathlib import Path
import xml.etree.ElementTree as ET
import subprocess
manifest_location = ''
apk_name = ''
def gen_decompilation():
global manifest_location, apk_name
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
name_search = re.search('[^/]*(?=[.][a-zA-Z]+$)', file_path)
name = name_search.group()
apk_name = name
cwd = os.getcwd() + '\\' + 'Decompiled_Apps\\' + name
manifest_location = cwd
apkt_cmd = 'cmd /c "apktool d -o ' + cwd + ' ' + file_path + '"'
os.system(apkt_cmd)
def get_package_name():
global manifest_location
root = ET.parse(manifest_location + "\AndroidManifest.xml").getroot()
packageName = root.attrib['package']
return packageName
def is_backup_allowed():
global manifest_location
root = ET.parse(manifest_location + "\AndroidManifest.xml").getroot()
application = root.findall("application")
try:
backup_value = application[0].attrib['{http://schemas.android.com/apk/res/android}allowBackup']
except:
return True
if backup_value == 'false':
return False
elif backup_value == 'true':
return True
def is_app_installed(package_name):
batcmd = "adb shell pm list packages"
result = subprocess.check_output(batcmd, shell=True).decode("utf-8")
if package_name in result:
return True
else:
return False
def create_backup(package_name):
global apk_name
cwd = os.getcwd() + '\\' + 'Backups\\'
backup_string = "adb backup -f " + cwd + apk_name + '.ab -noapk ' + package_name
path_to_zip_file = cwd + apk_name + '.tar'
path_to_backup = cwd + apk_name + '.ab'
decompress_string = "java -jar abe.jar unpack " + path_to_backup + ' ' + path_to_zip_file
unzip_string = "7z x " + path_to_zip_file + " -aoa -o" + cwd + apk_name
if is_backup_allowed():
subprocess.call(backup_string, shell=True)
subprocess.call(decompress_string, shell=True)
subprocess.call(unzip_string, shell=True)
def recover_artifacts(package_name):
global apk_name
dest_files = os.getcwd() + '\\' + 'Artifacts\\' + apk_name + '\\files'
if package_name == 'ws.clockthevault':
src_files = os.getcwd() + '\\' + 'Backups\\' + apk_name + '\\' + 'apps\\ws.clockthevault\\f\\lockerVault'
shutil.copytree(src_files, dest_files)
src_preferences = os.getcwd() + '\\' + 'Backups\\' + apk_name + '\\' + 'apps\\ws.clockthevault\\sp'
dest_preferences = os.getcwd() + '\\' + 'Artifacts\\' + apk_name + '\\preferences'
shutil.copytree(src_preferences, dest_preferences)
elif package_name == 'com.theronrogers.vaultyfree':
Path(dest_files).mkdir(parents=True, exist_ok=True)
pull_string = 'adb pull sdcard/Documents/Vaulty ' + dest_files
subprocess.call(pull_string, shell=True)
gen_decompilation()
package_name = get_package_name()
r = is_app_installed(package_name)
if r == True:
create_backup(package_name)
recover_artifacts(package_name)