更新 hook_conversions.js

master
wangsiyuan 2023-10-18 09:59:41 +08:00
parent 7a34565a64
commit 115626622b
1 changed files with 50 additions and 35 deletions

View File

@ -2,24 +2,29 @@ console.log("Script loaded successfully");
// hook_okhttp_client()
if (Java.available) {
hook_json()
// hook_okhttp3_client()
Java.perform(function () {
try {
var OkHttpClient = Java.use("okhttp3.OkHttpClient");
console.log("OkHttp detected in the app");
console.log(OkHttpClient.toString())
if (OkHttpClient != null){
hook_okhttp_client();
log_info("OkHttp detected in the app");
}
} catch (e) {
console.log("OkHttp not detected in the app");
log_info("OkHttp not detected in the app");
}
});
Java.perform(function () {
console.log("start hook java.net.URL");
log_info("start hook java.net.URL");
var URL = Java.use('java.net.URL');
URL.$init.overload('java.lang.String').implementation = function (spec) {
// console.log("URL request:" + spec)
log_info("URL request: " + spec)
if (spec.includes("appsflyer")) {
console.log("URL request: " + spec);
// console.log("URL request: " + spec);
if (spec.includes("conversions")) {
var stackTrace = Java.use('java.lang.Exception').$new().getStackTrace().toString();
console.log(stackTrace);
// console.log(stackTrace);
}
}
return this.$init(spec);
@ -28,36 +33,43 @@ if (Java.available) {
}
function printMethods(className) {
log_info("start print methods.")
var jclass = Java.use(className);
var methods = jclass.class.getDeclaredMethods();
console.log("Printing methods of " + className + ":\n");
methods.forEach(function (method) {
console.log(method);
// console.log(method);
log_info("The methods under the class" + className + " are: " + method);
});
}
function hook_okhttp_client() {
if (Java.available) {
Java.perform(function () {
log_info("start hook_okhttp_client.")
try {
var OkHttpClient = Java.use("okhttp3.OkHttpClient");
// log_info("OkHttpClient: " + OkHttpClient.toString());
var class_name = OkHttpClient.$className;
console.log(class_name+ "-------")
printMethods(OkHttpClient.toString());
OkHttpClient.newCall.overload('okhttp3.Request').implementation = function (request) {
console.log("OkHttp Request URL: " + request.url().toString());
console.log("OkHttp Request Headers: " + request.headers().toString());
if (request.method() == "POST") {
console.log("OkHttp Request Body: " + request.body().contentType().toString());
// Here you can further extract the request body if needed.
var requestUrl = request.url();
if (requestUrl) {
console.log("OkHttp Request URL: " + requestUrl.toString());
} else {
console.log("OkHttp Request URL is not available");
}
// console.log("OkHttp Request Headers: " + request.headers().toString());
var response = this.newCall(request).execute();
// if (request.method() == "POST") {
// console.log("OkHttp Request Body: " + request.body().contentType().toString());
// }
var call = this.newCall(request);
var response = call.execute();
console.log("OkHttp Response: " + response.body().string());
// Note: Calling response.body().string() consumes the response body.
// You might need to recreate the response if the app expects to read it again.
return this.newCall(request);
return call;
};
} catch (e) {
@ -118,20 +130,6 @@ function hook_HttpURLConnection_stream() {
}
function hook_okhttp3_client() {
Java.perform(function () {
var OkHttpClient = Java.use("okhttp3.OkHttpClient");
OkHttpClient.newCall.overload("okhttp3.Request").implementation = function (request) {
console.log("okhttp3 Request -> " + request.url().toString());
var response = this.newCall(request).execute();
console.log("okhttp3 Response -> " + response.body().string());
return response;
}
});
}
function hook_retrofit() {
Java.perform(function () {
@ -160,8 +158,25 @@ function hook_json() {
var JSONObject = Java.use('org.json.JSONObject');
JSONObject.toString.overload().implementation = function () {
var result = this.toString.call(this);
console.log("Serialized JSONObject: " + result);
// console.log("Serialized JSONObject: " + result);
log_info("Serialized JSONObject: " + result)
return result;
};
});
}
function log_info(messages) {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are 0-based
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
const milliseconds = String(now.getMilliseconds()).padStart(3, '0');
const timestamp = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}:${milliseconds}`;
console.log(`${timestamp} - ${messages}`);
}