-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathproto-parser.ts
More file actions
213 lines (200 loc) · 8.62 KB
/
proto-parser.ts
File metadata and controls
213 lines (200 loc) · 8.62 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import { b64Decode } from "../utils";
import { requestMessagesResponses } from "../constants";
import { DecodedProto } from "../types";
import POGOProtos from "@na-ji/pogo-protos";
let action_social = 0;
let action_gar_proxy = 0;
function DecoderInternalGarPayloadAsResponse(method: number, data: any): any {
action_gar_proxy = 0;
if (!data) {
return {};
}
switch (method) {
case 4:
return POGOProtos.Rpc.InternalCreateSharedLoginTokenResponse.decode(b64Decode(data)).toJSON();
default:
return { Not_Implemented_yet: data, method: method };
}
}
function DecoderInternalPayloadAsResponse(method: number, data: any): any {
action_social = 0;
let proto_tuple: any = Object.values(requestMessagesResponses)[method];
let result: any = { Not_Implemented_yet: data };
if (!data) {
return {};
}
for (let i = 0; i < Object.keys(requestMessagesResponses).length; i++) {
proto_tuple = Object.values(requestMessagesResponses)[i];
const my_req = proto_tuple[0];
if (my_req == method) {
if (proto_tuple[2] != null && data && b64Decode(data).length > 0) {
try {
result = proto_tuple[2].decode(b64Decode(data)).toJSON();
}
catch (error) {
console.error(`Intenal ProxySocial decoder ${my_req} Error: ${error}`);
let err = {
Error: error,
Data: data
};
result = err;
}
}
return result;
}
}
return result;
}
export function remasterOrCleanMethodString(str: string) {
return str.replace(/^REQUEST_TYPE_/, '')
.replace(/^METHOD_/, '')
.replace(/^PLATFORM_/, '')
.replace(/^SOCIAL_ACTION_/, '')
.replace(/^GAME_ANTICHEAT_ACTION_/, '')
.replace(/^GAME_BACKGROUND_MODE_ACTION_/, '')
.replace(/^GAME_IAP_ACTION_/, '')
.replace(/^GAME_LOCATION_AWARENESS_ACTION_/, '')
.replace(/^GAME_ACCOUNT_REGISTRY_ACTION_/, '')
.replace(/^GAME_FITNESS_ACTION_/, '')
.replace(/^TITAN_PLAYER_SUBMISSION_ACTION_/, '');
}
export const decodePayloadTraffic = (methodId: number, content: any, dataType: string): DecodedProto[] => {
let parsedProtoData: DecodedProto[] = [];
const decodedProto = decodeProto(methodId, content, dataType);
if (typeof decodedProto !== "string") {
parsedProtoData.push(decodedProto);
}
return parsedProtoData;
};
export const decodePayload = (contents: any, dataType: string): DecodedProto[] => {
let parsedProtoData: DecodedProto[] = [];
for (const proto of contents) {
const methodId = proto.method;
const data = proto.data;
const decodedProto = decodeProto(methodId, data, dataType);
if (typeof decodedProto !== "string") {
parsedProtoData.push(decodedProto);
}
}
return parsedProtoData;
};
export const decodeProto = (method: number, data: string, dataType: string): DecodedProto | string => {
let returnObject: DecodedProto | string = "Not Found";
let methodFound = false;
for (let i = 0; i < Object.keys(requestMessagesResponses).length; i++) {
let foundMethod: any = Object.values(requestMessagesResponses)[i];
let foundMethodString: string = Object.keys(requestMessagesResponses)[i];
const foundReq = foundMethod[0];
if (foundReq == method) {
methodFound = true;
if (foundMethod[1] != null && dataType === "request") {
try {
let parsedData;
if (!data || data === "") {
parsedData = {};
} else {
parsedData = foundMethod[1].decode(b64Decode(data)).toJSON();
}
if (foundMethod[0] === 5012) {
action_social = parsedData.action;
Object.values(requestMessagesResponses).forEach(val => {
let req: any = val;
if (req[0] == action_social && req[1] != null && parsedData.payload && b64Decode(parsedData.payload)) {
parsedData.payload = req[1].decode(b64Decode(parsedData.payload)).toJSON();
}
});
}
else if (foundMethod[0] === 600005) {
action_gar_proxy = parsedData.action;
switch (action_gar_proxy) {
case 4:
parsedData.payload = POGOProtos.Rpc.InternalGarAccountInfoProto.decode(b64Decode(parsedData.payload)).toJSON();
break;
default:
break;
}
}
returnObject = {
methodId: foundMethod[0],
methodName: remasterOrCleanMethodString(foundMethodString),
data: parsedData,
};
} catch (error) {
console.error(`Error parsing request ${foundMethodString} -> ${error}`);
returnObject = {
methodId: foundMethod[0],
methodName: remasterOrCleanMethodString(foundMethodString) + " [PARSE ERROR]",
data: {
error: "Failed to decode proto",
rawBase64: data,
errorMessage: error.toString()
},
};
}
} else if (dataType === "request") {
console.warn(`Request ${foundMethod[0]} Not Implemented`)
returnObject = {
methodId: foundMethod[0],
methodName: remasterOrCleanMethodString(foundMethodString) + " [NOT IMPLEMENTED]",
data: {
error: "Proto not implemented",
rawBase64: data
},
};
}
if (foundMethod[2] != null && dataType === "response") {
try {
let parsedData;
if (!data || data === "") {
parsedData = {};
} else {
parsedData = foundMethod[2].decode(b64Decode(data)).toJSON();
}
if (foundMethod[0] === 5012 && action_social > 0 && parsedData.payload) {
parsedData.payload = DecoderInternalPayloadAsResponse(action_social, parsedData.payload);
}
else if (foundMethod[0] === 600005 && action_gar_proxy > 0 && parsedData.payload) {
parsedData.payload = DecoderInternalGarPayloadAsResponse(action_gar_proxy, parsedData.payload);
}
returnObject = {
methodId: foundMethod[0],
methodName: remasterOrCleanMethodString(foundMethodString),
data: parsedData,
};
} catch (error) {
console.error(`Error parsing response ${foundMethodString} method: [${foundReq}] -> ${error}`);
returnObject = {
methodId: foundMethod[0],
methodName: remasterOrCleanMethodString(foundMethodString) + " [PARSE ERROR]",
data: {
error: "Failed to decode proto",
rawBase64: data,
errorMessage: error.toString()
},
};
}
} else if (dataType === "response") {
console.warn(`Response ${foundReq} Not Implemented`)
returnObject = {
methodId: foundMethod[0],
methodName: remasterOrCleanMethodString(foundMethodString) + " [NOT IMPLEMENTED]",
data: {
error: "Proto not implemented",
rawBase64: data
},
};
}
}
}
if (!methodFound && returnObject === "Not Found") {
returnObject = {
methodId: method.toString(),
methodName: `Unknown Method ${method} [UNKNOWN]`,
data: {
error: "Unknown method ID",
rawBase64: data
},
};
}
return returnObject;
};