Amour v4.6.9版本的 MD5 值为:60db0759ce21a7c5858136dd0821206f
以下内容为反编译后的 JsCallJava.java 源代码,内容仅作参考
package com.just.agentweb;
import a1.i;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebView;
import androidx.constraintlayout.motion.utils.a;
import androidx.core.app.NotificationCompat;
import com.meizu.cloud.pushsdk.notification.model.NotifyType;
import java.lang.reflect.Method;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class JsCallJava {
private static final String[] IGNORE_UNSAFE_METHODS = {"getClass", "hashCode", "notify", "notifyAll", "equals", "toString", "wait"};
private static final String KEY_ARGS = "args";
private static final String KEY_METHOD = "method";
private static final String KEY_OBJ = "obj";
private static final String KEY_TYPES = "types";
private static final String MSG_PROMPT_HEADER = "AgentWeb:";
private static final String RETURN_RESULT_FORMAT = "{\"CODE\": %d, \"result\": %s}";
private static final String TAG = "JsCallJava";
private Object mInterfaceObj;
private String mInterfacedName;
private HashMap<String, Method> mMethodsMap;
private String mPreloadInterfaceJs;
public JsCallJava(Object obj, String str) {
try {
if (!TextUtils.isEmpty(str)) {
this.mInterfaceObj = obj;
this.mInterfacedName = str;
this.mMethodsMap = new HashMap<>();
Method[] methods = this.mInterfaceObj.getClass().getMethods();
StringBuilder sb2 = new StringBuilder("javascript:(function(b){console.log(\"");
sb2.append(this.mInterfacedName);
sb2.append(" init begin\");var a={queue:[],callback:function(){var d=Array.prototype.slice.call(arguments,0);var c=d.shift();var e=d.shift();this.queue[c].apply(this,d);if(!e){delete this.queue[c]}}};");
for (Method method : methods) {
Log.i("Info", "method:" + method);
String genJavaMethodSign = genJavaMethodSign(method);
if (genJavaMethodSign != null) {
this.mMethodsMap.put(genJavaMethodSign, method);
sb2.append(String.format("a.%s=", method.getName()));
}
}
sb2.append("function(){var f=Array.prototype.slice.call(arguments,0);if(f.length<1){throw\"");
sb2.append(this.mInterfacedName);
sb2.append(" call result, message:miss method name\"}var e=[];for(var h=1;h<f.length;h++){var c=f[h];var j=typeof c;e[e.length]=j;if(j==\"function\"){var d=a.queue.length;a.queue[d]=c;f[h]=d}}var k = new Date().getTime();var l = f.shift();var m=prompt('");
sb2.append(MSG_PROMPT_HEADER);
sb2.append("'+JSON.stringify(");
sb2.append(promptMsgFormat("'" + this.mInterfacedName + "'", NotifyType.LIGHTS, "e", "f"));
sb2.append("));console.log(\"invoke \"+l+\", time: \"+(new Date().getTime()-k));var g=JSON.parse(m);if(g.CODE!=200){throw\"");
sb2.append(this.mInterfacedName);
sb2.append(" call result, CODE:\"+g.CODE+\", message:\"+g.result}return g.result};Object.getOwnPropertyNames(a).forEach(function(d){var c=a[d];if(typeof c===\"function\"&&d!==\"callback\"){a[d]=function(){return c.apply(a,[d].concat(Array.prototype.slice.call(arguments,0)))}}});b.");
sb2.append(this.mInterfacedName);
sb2.append("=a;console.log(\"");
sb2.append(this.mInterfacedName);
sb2.append(" init end\")})(window)");
this.mPreloadInterfaceJs = sb2.toString();
sb2.setLength(0);
return;
}
throw new Exception("injected name can not be null");
} catch (Exception e10) {
if (LogUtils.isDebug()) {
Log.e(TAG, "init js result:" + e10.getMessage());
}
}
}
private String genJavaMethodSign(Method method) {
StringBuilder h2;
String str;
String name = method.getName();
Class<?>[] parameterTypes = method.getParameterTypes();
for (String str2 : IGNORE_UNSAFE_METHODS) {
if (str2.equals(name)) {
if (LogUtils.isDebug()) {
Log.w(TAG, "method(" + name + ") is unsafe, will be pass");
return null;
}
return null;
}
}
for (Class<?> cls : parameterTypes) {
if (cls == String.class) {
h2 = i.h(name);
str = "_S";
} else if (cls != Integer.TYPE && cls != Long.TYPE && cls != Float.TYPE && cls != Double.TYPE) {
if (cls == Boolean.TYPE) {
h2 = i.h(name);
str = "_B";
} else if (cls == JSONObject.class) {
h2 = i.h(name);
str = "_O";
} else if (cls == JsCallback.class) {
h2 = i.h(name);
str = "_F";
} else {
h2 = i.h(name);
str = "_P";
}
} else {
h2 = i.h(name);
str = "_N";
}
h2.append(str);
name = h2.toString();
}
return name;
}
public static String getInterfacedName(JSONObject jSONObject) {
return jSONObject.optString(KEY_OBJ);
}
public static JSONObject getMsgJSONObject(String str) {
try {
return new JSONObject(str.substring(9));
} catch (JSONException e10) {
e10.printStackTrace();
return new JSONObject();
}
}
private String getReturn(JSONObject jSONObject, int i, Object obj, long j10) {
String valueOf;
if (obj == null) {
valueOf = "null";
} else if (obj instanceof String) {
valueOf = "\"".concat(String.valueOf(((String) obj).replace("\"", "\\\""))).concat("\"");
} else {
valueOf = String.valueOf(obj);
}
String format = String.format(RETURN_RESULT_FORMAT, Integer.valueOf(i), valueOf);
if (LogUtils.isDebug()) {
Log.d(TAG, "call time: " + (SystemClock.uptimeMillis() - j10) + ", request: " + jSONObject + ", result:" + format);
}
return format;
}
public static boolean isSafeWebViewCallMsg(String str) {
return str.startsWith(MSG_PROMPT_HEADER);
}
private static String promptMsgFormat(String str, String str2, String str3, String str4) {
StringBuilder q = a.q("{obj:", str, ",method:", str2, ",types:");
q.append(str3);
q.append(",args:");
q.append(str4);
q.append("}");
return q.toString();
}
public String call(WebView webView, JSONObject jSONObject) {
long j10;
StringBuilder sb2;
String sb3;
int i;
if (LogUtils.isDebug()) {
j10 = SystemClock.uptimeMillis();
} else {
j10 = 0;
}
if (jSONObject != null) {
try {
String string = jSONObject.getString("method");
JSONArray jSONArray = jSONObject.getJSONArray(KEY_TYPES);
JSONArray jSONArray2 = jSONObject.getJSONArray(KEY_ARGS);
int length = jSONArray.length();
Object[] objArr = new Object[length];
int i10 = 0;
for (int i11 = 0; i11 < length; i11++) {
String optString = jSONArray.optString(i11);
Object obj = null;
if ("string".equals(optString)) {
string = string + "_S";
if (!jSONArray2.isNull(i11)) {
obj = jSONArray2.getString(i11);
}
objArr[i11] = obj;
} else if ("number".equals(optString)) {
string = string + "_N";
i10 = (i10 * 10) + i11 + 1;
} else if ("boolean".equals(optString)) {
string = string + "_B";
objArr[i11] = Boolean.valueOf(jSONArray2.getBoolean(i11));
} else if ("object".equals(optString)) {
string = string + "_O";
if (!jSONArray2.isNull(i11)) {
obj = jSONArray2.getJSONObject(i11);
}
objArr[i11] = obj;
} else if ("function".equals(optString)) {
string = string + "_F";
objArr[i11] = new JsCallback(webView, this.mInterfacedName, jSONArray2.getInt(i11));
} else {
string = string + "_P";
}
}
Method method = this.mMethodsMap.get(string);
if (method == null) {
return getReturn(jSONObject, 500, "not found method(" + string + ") with valid parameters", j10);
}
if (i10 > 0) {
Class<?>[] parameterTypes = method.getParameterTypes();
while (i10 > 0) {
int i12 = (i10 - ((i10 / 10) * 10)) - 1;
Class<?> cls = parameterTypes[i12];
if (cls == Integer.TYPE) {
objArr[i12] = Integer.valueOf(jSONArray2.getInt(i12));
} else if (cls == Long.TYPE) {
objArr[i12] = Long.valueOf(Long.parseLong(jSONArray2.getString(i12)));
} else {
objArr[i12] = Double.valueOf(jSONArray2.getDouble(i12));
}
i10 /= 10;
}
}
return getReturn(jSONObject, 200, method.invoke(this.mInterfaceObj, objArr), j10);
} catch (Exception e10) {
e = e10;
LogUtils.safeCheckCrash(TAG, NotificationCompat.CATEGORY_CALL, e);
if (e.getCause() != null) {
sb2 = new StringBuilder("method execute result:");
e = e.getCause();
} else {
sb2 = new StringBuilder("method execute result:");
}
sb2.append(e.getMessage());
sb3 = sb2.toString();
i = 500;
}
} else {
i = 500;
sb3 = "call data empty";
}
return getReturn(jSONObject, i, sb3, j10);
}
public String getPreloadInterfaceJs() {
return this.mPreloadInterfaceJs;
}
}