Manually invoke IL2CPP function?!

Long story short, I’m working on reverse-engineering an iOS game written with Unity (you can read more about it here).

I’ve successfully been able to inject a custom library into the game process, having it load my second Unity instance, and hook to a couple of functions I’m interested to give a look at.

Now, considering I’m interested into replacing a method implementation with my custom version, I used these hooks in order to pass the control to my dynamic library (rather than the actual game logic): everything works flawlessly, except when the custom method is supposed to call a function on an interface via the “InterfaceFuncInvoker” approach.

In this case, in fact, the application crashes with the following stack trace:

For anyone wondering, the game uses Google Protobuf to share data with a server, so I need to call the “MessageExtensions_ToByteArray_m2556561086” (which is throwing the error) in order to get a byte-array-representation of the message sent.

When I try to call this routine from the “Update” method on one of my scripts, it works without problems; but if I try to invoke it manually from inside one of my hooks, it crashes… I guess it’s something related to the fact that Unity is not really thread-safe etc, but honestly I have no idea.

Has anyone ever experienced something similar? Or maybe can help me figure this out?

UP!

@JoshPeterson you’re da man!

What is this? Is this solved? How?