gpt4 book ai didi

java - 如何使用上下文作为参数获取函数的返回值?

转载 作者:行者123 更新时间:2023-12-01 17:01:10 24 4
gpt4 key购买 nike

我是逆向工程新手,我需要弗里达的一些帮助。

下面的函数使用上下文作为参数。我需要获取返回值。

private final String getActiveMCCMNC(Context context) {
Object systemService = context.getSystemService("phone");
if (systemService != null) {
String simOperator = ((TelephonyManager) systemService).getSimOperator();
String str = "";
if (simOperator != null && (!Intrinsics.areEqual((Object) simOperator, (Object) ""))) {
try {
StringBuilder sb = new StringBuilder();
sb.append("");
String substring = simOperator.substring(0, 3);
Intrinsics.checkExpressionValueIsNotNull(substring, "(this as java.lang.Strin…ing(startIndex, endIndex)");
sb.append(substring);
String sb2 = sb.toString();
StringBuilder sb3 = new StringBuilder();
sb3.append(sb2);
sb3.append(HelpFormatter.DEFAULT_OPT_PREFIX);
String substring2 = simOperator.substring(3);
Intrinsics.checkExpressionValueIsNotNull(substring2, "(this as java.lang.String).substring(startIndex)");
sb3.append(substring2);
str = sb3.toString();
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
return !TextUtils.isEmpty(str) ? str : "";
}
throw new TypeCastException("null cannot be cast to non-null type android.telephony.TelephonyManager");
}

我在一些文章的帮助下尝试过,但遇到了一些错误。

Java.perform(function x(){
console.log("Inside java perform function");
var my_class = Java.use("util.PlayerDeviceIdentifier")
var context = Java.use('android.app.ActivityThread').currentApplication().getApplicationContext();

// context.getActiveMCCMNC.implementation = function(){

// console.log(this.val)

// } // tried with context

my_class.getActiveMCCMNC.implementation = function(){

console.log(this.val)

}

})

如何执行并获取返回值?

最佳答案

我知道您想要 Hook 一个函数以检查它返回的值。您无需为此关心 Context 参数。您需要检索它才能进行自定义调用,但我认为这不是您想要的。

尝试这样的事情:

Java.perform(function() {
var my_class = Java.use("util.PlayerDeviceIdentifier");
my_class.getActiveMCCMNC.implementation = function (context) { // replace original implementation
var value = this.getActiveMCCMNC(context); // call original implementation
// then do what you want with the returned value HERE
// and finally return it so you don't break the app
return value;
};
});

关于java - 如何使用上下文作为参数获取函数的返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61504942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com