vfsfitvnm / frida-il2cpp-bridge

A Frida module to dump, trace or hijack any Il2Cpp application at runtime, without needing the global-metadata.dat file.
https://github.com/vfsfitvnm/frida-il2cpp-bridge/wiki
MIT License
1.05k stars 203 forks source link

What is the best way to instantiate an object? #81

Closed wildsheepz closed 2 years ago

wildsheepz commented 2 years ago

Hi,

I cannot figure out how to instantiate a tuple.

class System.Tuple<T1,T2> : System.Object, System.Collections.IStructuralEquatable, System.Collections.IStructuralComparable, System.IComparable, System.ITupleInternal

I tried the following:

var tuple_class = corlibclasses['System.Tuple<T1,T2>'].inflate(corlibclasses['System.Int32'],corlibclasses['System.Int32'])
var data = tuple_class.alloc()
data.methods['.ctor'].invoke(this.fields['CurrentBattleId'].value, this.fields['CurrentDifficulty'].value)

but I got an error:

Error: expected an integer
    at <anonymous> (node_modules/frida-il2cpp-bridge/dist/il2cpp/structs/method.js:175)
    at try (node_modules/frida-il2cpp-bridge/dist/il2cpp/base.js:116)
    at invokeRaw (node_modules/frida-il2cpp-bridge/dist/il2cpp/structs/method.js:175)
    at <anonymous> (test.ts:199)
    at call (native)
    at replaceCallback (node_modules/frida-il2cpp-bridge/dist/il2cpp/structs/method.js:124)
vfsfitvnm commented 2 years ago

It means at least one of CurrentBattleIdor CurrentDifficulty is not a integer

wildsheepz commented 2 years ago

Nvm, I figured it out. I was supposed to call .new(). The following code worked for me:

var tuple_class = corlibclasses['System.Tuple<T1,T2>'].inflate(corlibclasses['System.Int32'], corlibclasses['System.Int32'])
var data = tuple_class.new()
data.methods['.ctor'].invoke(this.fields['CurrentBattleId'].value, this.fields['CurrentDifficulty'].value)
console.log(data)