forked from Bin4ry/deejayeye-modder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defog_strings.py
executable file
·77 lines (68 loc) · 1.88 KB
/
defog_strings.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
#!/usr/bin/env python
import base64
import sys
import re
import os
# defog dji fw 4.1.4 strings by adding the defogged version as comment to smali files
# - by nopcode, miek and bin4ry
key_414 = 'I Love Android'
key_415 = 'Y9*PI8B#gD^6Yhd1'
def defog(s,l):
s = base64.decodestring(s)
decr = ''.join([chr(ord(c) ^ ord(key[i%l*2])) for i,c in enumerate(s)])
decr = decr.replace('\r', '').replace('\n', '').replace('"', '').replace('\\','')
return decr
if len(sys.argv) != 3:
print "Defogs base64 + silly fogging in DJI Go4 4.1.4 smali files. Adds defogged string as comment. Original smali file is replaced!"
print "Syntax: {0} <key1 for 414 (1) or key2 for >=415 (2)> <folder>".format(sys.argv[0])
sys.exit(1)
if sys.argv[1] == '1':
key=key_414
klen=7
if sys.argv[1] == '2':
key=key_415
klen=8
path = sys.argv[2]
for directory, subdirectories, files in os.walk(path):
for file in files:
fname = os.path.join(directory, file)
if fname.endswith('.smali'):
print(fname)
base64_str_rex = re.compile('\s*const-string.*\s*v[0-9]+\s*,\s*\"([^\"]*)\"\s*')
skip = 1
i = 0
with open(fname, "r") as fd:
lines = list(fd)
with open(fname, "w") as fd:
for l in lines:
i += 1
if (skip == 1):
l = l.rstrip()
match = base64_str_rex.match(l)
if match:
#print(l)
enc = match.group(1)
if enc:
#print(l)
next = lines[i+1]
if (("com/dji/k/a/a/b" in next) or ("com/dji/k/a/a/a" in next) or ("com/dji/f/a/a/b" in next)):
dec = defog(enc,klen)
l = l.replace(enc,dec)
print(l)
fd.write(l + "\n")
skip += 1
else:
fd.write(l + "\n")
skip = 1
#else:
#print("Empty string!")
else:
fd.write(l + "\n")
else:
l=""
if (skip == 5):
skip = 1
else:
skip += 1
else:
foo=""