forked from iGio90/GDumper
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dumper.py
181 lines (152 loc) · 5.64 KB
/
dumper.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# GDumper is a free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import frida
import json
import os
import socket
import sys
import time
def parse_message(message, data):
payload = message["payload"]
arr = payload.split("::::")
sess_file = None
if mode == "dump":
if arr[0] == "0":
print("PK:" + arr[1])
sess_file = open(path + "/pk" + ".bin", "w")
sess_file.write(arr[1])
elif arr[0] == "1":
print("SK:" + arr[1])
sess_file = open(path + "/sk" + ".bin", "w")
sess_file.write(arr[1])
elif arr[0] == "2":
print("PKS:" + arr[1])
sess_file = open(path + "/pks" + ".bin", "w")
sess_file.write(arr[1])
elif arr[0] == "3":
msgId = int(arr[1][:4], 16)
sess_file = open(path + "/" + str(int(round(time.time() * 1000))) + "_client_" + str(msgId) + ".bin", "w")
sess_file.write(arr[1])
print("[CLIENT] " + str(msgId))
elif arr[0] == "4":
msgId = int(arr[1][:4], 16)
sess_file = open(path + "/" + str(int(round(time.time() * 1000))) + "_server_" + str(msgId) + ".bin", "w")
sess_file.write(arr[1])
print("[SERVER] " + str(msgId))
if sess_file is not None:
sess_file.close()
elif mode == "proxy":
msglen = len(payload)
totalSent = 0
while totalSent < msglen:
sent = clientsocket.send(payload[totalSent:].encode())
if sent == 0:
raise RuntimeError("socket connection broken")
totalSent = totalSent + sent
if arr[0] == "0":
print("PK:" + arr[1])
elif arr[0] == "1":
print("SK:" + arr[1])
elif arr[0] == "2":
print("PKS:" + arr[1])
elif arr[0] == "3":
msgId = int(arr[1][:4], 16)
print("[CLIENT] " + str(msgId))
elif arr[0] == "4":
msgId = int(arr[1][:4], 16)
print("[SERVER] " + str(msgId) + " " + str(totalSent))
time.sleep(50.0 / 1000.0)
def get_table():
with open('xptable.json') as data_file:
return json.load(data_file)
def instrument_debugger_checks():
injector = open("dumper.js", "r").read()
if arch == "arm":
cpuType = "1"
else:
cpuType = "0"
gameType = ""
if game == "bb":
gameType = "0"
elif game == "coc":
gameType = "1"
elif game == "cr":
gameType = "2"
xptable = get_table()[gameType][cpuType]
xp1 = int(xptable["1"], 16)
xp2 = int(xptable["2"], 16)
xp3 = int(xptable["3"], 16)
thumb = xptable["thumb"]
if thumb:
xp1 = xp1 + 1
xp2 = xp2 + 1
xp3 = xp3 + 1
return injector.replace("xxp1", str(xp1)).replace("xxp2", str(xp2)).replace("xxp3", str(xp3))
def runCmd(cmd):
os.system(cmd)
package_name = ""
path = ""
parser = argparse.ArgumentParser(description='Dump SC protocol data.')
parser.add_argument('-m', '--mode', help="Mode for dumper to run.", required=True)
parser.add_argument('-g', '--game', help="Game to run.", required=True)
parser.add_argument('-a', '--arch', help="Device architecture.", required=True)
args = parser.parse_args()
mode = args.mode
game = args.game
arch = args.arch
if mode != "proxy" and mode != "dump":
print("Mode \"" + mode + "\" is not valid. Try \"proxy\" or \"dump\"")
print("Proxy: Connects to the local node proxy server.")
print("Dump: Starts a dump session.")
sys.exit(1)
if game != "coc" and game != "bb" and game != "cr":
print("Game \"" + game + "\" is not valid. Try \"coc\" - \"bb\" - \"cr\"")
print("COC: Clash of Clans")
print("BB: Boom Beach")
sys.exit(1)
if arch != "arm" and arch != "x86":
print("CPU Architecture \"" + arch + "\" is not valid. Try \"arm\" or \"x86\"")
print("ARM: Recommended for most physical devices.")
print("x86: Recommended for a few physical devices and most emulators.")
sys.exit(1)
if game == "bb":
package_name = "com.supercell.boombeach"
elif game == "coc":
package_name = "com.supercell.clashofclans"
elif game == "cr":
package_name = "com.supercell.clashroyale"
print("Starting dumper for " + package_name)
if not os.path.exists("dumps"):
os.makedirs("dumps")
if mode == "proxy":
print("Requesting connection to proxy.")
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(('localhost', 10101))
elif mode == "dump":
print("Preparing file dumps.")
t = str(int(round(time.time() * 1000)))
path = "dumps/" + package_name + "_" + t
os.makedirs(path)
print("Killing " + package_name)
runCmd("adb shell am force-stop " + package_name)
print("Starting " + package_name)
runCmd("adb shell am start -n " + package_name + "/" + package_name + ".GameApp")
process = frida.get_usb_device().attach(package_name)
print("Frida attached.")
script = process.create_script(instrument_debugger_checks())
print("Dumper loaded.")
script.on('message', parse_message)
print("parse_message registered within script object.")
script.load()
sys.stdin.read()