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
package com.fear1ess.reyunaditool.adsfinder;
import android.util.Log;
import com.fear1ess.reyunaditool.HttpParser;
import com.fear1ess.reyunaditool.IDoCommandService;
import org.json.JSONException;
import org.json.JSONObject;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
public class UnityFinder extends Finder {
public UnityFinder(String adsName, String adsClassName, ClassLoader cl, IDoCommandService service) {
super(adsName, adsClassName, cl, service);
}
@Override
public void hookAdsApi() {
registerSSLHook(new SSLOutputStreamHookedCallback() {
@Override
public void onSSLOutputStreamHooked(HttpParser hp) {
if(!hp.getMethod().equals("POST") || !hp.getPath().contains("/v6/games")) return;
Log.d(TAG, "onSSLOutputStreamHooked: unity0");
String unityGameId = match(hp.getPath(), "v6/games/.*/requests").replace("v6/games/","")
.replace("/requests","");
if(unityGameId == null) return;
Log.d(TAG, "onSSLOutputStreamHooked: unity1");
JSONObject jo = hp.getJsonBody();
String gameSessionId = null;
try {
gameSessionId = jo.getString("gameSessionId");
Log.d(TAG, "onSSLOutputStreamHooked: unity2");
String projectId = jo.getString("projectId");
String token = jo.getString("token");
// if(gameSessionId == null || projectId == null || token == null) return;
Map<String, String> map = new HashMap<>();
map.put("gameSessionId", gameSessionId);
map.put("token", token);
map.put("projectId", projectId);
map.put("unityGameId", unityGameId);
uploadAdsData(map);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
/*
try {
XposedBridge.hookAllMethods(mAppClassLoader.loadClass("com.unity3d.ads.UnityAds"), "initialize",
new AdsApiHook("AD", "unityGameId", 1));
XposedHelpers.findAndHookMethod("com.unity3d.services.core.request.WebRequest", mAppClassLoader,
"makeRequest", new UnityNetWorkHook("AD", "unityParam", 0));
XposedHelpers.findAndHookMethod("java.net.SocketOutputStream", mAppClassLoader, "write",
byte[].class, int.class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
Log.d(TAG, "socketos hook success!!!!");
// String data = new String((byte[])param.args[0]);
// Log.d(TAG, "SocketOutput data: " + data);
}
});
XposedHelpers.findAndHookMethod("sun.nio.cs.StreamEncoder", mAppClassLoader, "write",
String.class, int.class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
Log.d(TAG, "streamencoder hook success!!!!");
// String data = new String((byte[])param.args[0]);
Log.d(TAG, "streamencoder data: " + param.args[0]);
}
});
} catch (ClassNotFoundException e) {
e.printStackTrace();
}*/
}
public class UnityNetWorkHook extends AdsApiHook{
public UnityNetWorkHook(String s, String dataName, int posInArgs) {
super(s, dataName, posInArgs);
}
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Object o = param.thisObject;
URL url = (URL) XposedHelpers.getObjectField(o, "_url");
String urlStr = url.toString();
Log.d(TAG, "urlStr: " + urlStr);
Pattern pattern = Pattern.compile("v6/games/.*/requests");
Matcher matcher = pattern.matcher(urlStr);
if(!matcher.find()) return;
Log.d(TAG, "1");
String body = (String) XposedHelpers.getObjectField(o, "_body");
JSONObject jo = new JSONObject(body);
Log.d(TAG, "2");
if(!jo.has("gameSessionId") || !jo.has("token") || !jo.has("projectId")) return;
Log.d(TAG, "3");
Map<String,String> map = new HashMap<>();
map.put("gameSessionId", jo.getString("gameSessionId"));
map.put("token", jo.getString("token"));
map.put("projectId", jo.getString("projectId"));
String unityGameId = matcher.group(0).replace("v6/games/","").replace("/requests","");
map.put("unityGameId", unityGameId);
uploadAdsData(map);
}
}
}