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

randomguy123:

我是逆向工程的新手,我需要在frida中获得一些帮助。

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

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) 

    }

})

如何执行它并获得返回值?

让·巴蒂斯特·马丁(Jean-Baptiste Martin):

我了解您想钩住函数以检查其返回的值。您无需为此担心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;
  };
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

会话问题-不断获取“无法在写上下文中使用函数返回值”

使用其他函数的返回值作为参数调用函数时是否使用了调用堆栈和执行上下文?

从获取请求获取null,但上下文返回值

如何测试使用上下文参数的Flask API

如何测试使用上下文的 Azure 函数?

如何在函数中使用上下文?

PHP致命错误:无法在写入上下文中使用函数返回值

奇怪的PHP错误:“无法在写上下文中使用函数返回值”

致命错误:无法在写入上下文中使用函数返回值

无法在CI_Controller的写入上下文中使用函数返回值

致命错误:无法在/中的写入上下文中使用函数返回值

在写上下文php脚本中不能使用函数返回值

Flask-Security上下文处理器的返回值如何使用?

如何使用上下文

如何将函数作为上下文参数传递?

如何使用异步函数的返回值作为参数?

使用上下文值作为初始状态值 - 反应钩子

如何使用参数获取函数的返回值?

Pytest模拟使用装饰器模拟包含上下文管理器返回值的函数未传递

WordPress:致命错误:无法在第130行的写上下文中使用函数返回值

致命错误:在第3行(PHP)的代码的写入上下文中无法使用函数返回值

致命错误:无法在第50行的写上下文中使用函数返回值

使用上下文管理器作为功能

使用Mockito测试使用上下文的函数

Mapstruct :在@Mapping 的源参数中使用上下文

在响应式上下文中捕获函数的标准输出和返回值

在JavaScript中获取函数返回值作为参数

获取我使用上下文菜单的路径

获取调用上下文的父上下文