forked from Eltion/Tiktok-SSL-Pinning-Bypass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch_lib.py
74 lines (59 loc) · 2.04 KB
/
patch_lib.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
import r2pipe
from zipfile import ZipFile
import tempfile
import argparse
import shutil
def patch_function_arm64(lib):
print("Finding function offset in " + lib)
r2 = r2pipe.open(lib, ["-w", "-2"])
r2.cmd('aae')
results = r2.cmdj('/j HandleVerifyResult')
offset = results[0]['offset']
results = r2.cmdj('axtj ' + str(offset))
usage_offset = results[0]['from']
r2.cmd("s " + str(usage_offset))
r2.cmd("e search.from="+str(usage_offset-1000))
r2.cmd("e search.to="+str(usage_offset))
results = r2.cmdj("/badj sub sp, sp")
offset = hex(results[-1]["offset"])
print(offset)
r2.cmd("s " + str(offset))
r2.cmd("wao ret0")
r2.quit()
def patch_function_arm(lib):
print("Finding function offset in " + lib)
r2 = r2pipe.open(lib, ["-w", "-2"])
r2.cmd('aae')
results = r2.cmdj('/j HandleVerifyResult')
offset = results[0]['offset']
results = r2.cmdj('axtj ' + str(offset))
usage_offset = results[0]['from']
r2.cmd("s " + str(usage_offset))
r2.cmd("e search.from="+str(usage_offset-1000))
r2.cmd("e search.to="+str(usage_offset))
results = r2.cmdj("/badj sub sp")
offset = hex(results[-1]["offset"]-4)
r2.cmd("s " + str(offset))
r2.cmd("wao ret0")
r2.quit()
def patch_function(lib, arch):
if arch == "arm64-v8a":
return patch_function_arm64(lib)
elif arch == "armeabi-v7a":
return patch_function_arm(lib)
else:
raise Exception("Architecture not supported")
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='Static patch for libsscronet.so')
parser.add_argument("-i", "--input", type=str,
help="libsscronet.so file.", required=True)
parser.add_argument("-a", "--arch", type=str,
help="App arch [arm64-v8a|armeabi-v7a]", required=True)
args = parser.parse_args()
lib = args.input
arch = args.arch
out_lib = "libsscronet_patched.so"
shutil.copy(lib, out_lib)
patch_function(out_lib, arch)
print("Done!")