首页
社区
课程
招聘
frida怎么在il2cpp里替换返回值byte[]类型
发表于: 2024-8-4 10:36 2183

frida怎么在il2cpp里替换返回值byte[]类型

2024-8-4 10:36
2183

YYY的c#定义:

1
public static byte[] YYY(ref string contentFile)

下面这样执行会报错 Error: expected a pointer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import "frida-il2cpp-bridge";
 
Il2Cpp.perform(() => {
 
    console.log("Unity version: " + Il2Cpp.unityVersion);
    const XXX = Il2Cpp.domain.assembly('Assembly-CSharp').image.class('XXX');
    const YYY = XXX.method("YYY");
 
    YYY.implementation = function (item): Uint8Array {
        var result = this.method<Uint8Array>("YYY").invoke(item);
        var file = new File("text.txt", "r");
        return file.readBytes(); // <------ Error: expected a pointer
    };
});

换下面则会卡住,应该是被hook的无法读取到这个内存地址

1
2
3
4
5
6
7
8
9
10
11
12
var byteArray = file.readBytes()
console.log(hexdump(byteArray, {
    offset: 0,
    length: byteArray.length,
    header: true,
    ansi: true,
}));
 
console.log(byteArray.byteLength);
var memAllocate = Memory.alloc(byteArray.byteLength);
Memory.writeByteArray(memAllocate, byteArray);
return memAllocate;

使用 Il2Cpp.array 下面代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import "frida-il2cpp-bridge";
 
Il2Cpp.perform(() => {
 
    console.log("Unity version: " + Il2Cpp.unityVersion);
    const XXX = Il2Cpp.domain.assembly('Assembly-CSharp').image.class('XXX');
    const YYY = XXX.method("YYY");
 
   const SystemByte = Il2Cpp.corlib.class("System.Byte");
 
   var byteArray;
 
    YYY.implementation = function (item): Uint8Array {
        var result = this.method<Uint8Array>("YYY").invoke(item);
        var file = new File("text.txt", "r");
         byteArray = file.readBytes()
         var bytePointer = Il2Cpp.array(SystemByte, byteArray);
            return bytePointer;
    };
});

报错:

1
2
3
4
5
Error: expected an unsigned integer
    at array (il2cpp/structs/array.ts:92)
    at <anonymous> (index.ts:xx) <---- return bytePointer line
    at call (native)
    at <anonymous> (il2cpp/structs/method.ts:354)

自己解决了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import "frida-il2cpp-bridge";
 
Il2Cpp.perform(() => {
 
    console.log("Unity version: " + Il2Cpp.unityVersion);
    const XXX = Il2Cpp.domain.assembly('Assembly-CSharp').image.class('XXX');
    const YYY = XXX.method("YYY");
    var byteArray;
    YYY.implementation = function (item): Uint8Array {
        var result = this.method<Uint8Array>("YYY").invoke(item);
        var file = new File("text.txt", "r");
        byteArray = file.readBytes();
        result.handle = byteArray.unwrap();
        return result;
    };
});

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2024-8-4 14:07 被张馆长编辑 ,原因:
收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 20
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
2
byte[] 返回值是指针,对于覆盖内容的地方,要偏移下,用js 的nativePoint 或者memcpy都可以覆盖
```
            var fileArrayBuff = file.readBytes()
            var resultPoint = new NativePointer(result.handle)
            var newResultPoint = resultPoint.add(32)
            
            // console.log(hexdump(result, {
            //     offset: 0,
            //     length: fileArrayBuff.byteLength,
            //     header: true,
            //     ansi: true,
            // }));
            console.log(resultPoint);
            newResultPoint.writeByteArray(fileArrayBuff);
            // Memory.copy(resultPoint.add(32), fileArrayBuff.unwrap(), fileArrayBuff.byteLength);
            file.close();
            // console.log(hexdump(result, {
            //     offset: 0,
            //     length: fileArrayBuff.byteLength,
            //     header: true,
            //     ansi: true,
            // }));
            return result;
```
2024-8-6 16:26
0
游客
登录 | 注册 方可回帖
返回
//