BepInEx / Il2CppInterop

A tool interoperate between CoreCLR and Il2Cpp at runtime
GNU Lesser General Public License v3.0
185 stars 59 forks source link

Memory validation and runtime module dump #122

Open krulci opened 3 months ago

krulci commented 3 months ago
  1. Memory region protection validation Current main stream implementation of FindMethodSignature fails when the memory region is protected. This leads to an access violation error. This pull request implemented memory validation and set them to execute_read_write before signature scanning. Protection right is restore after signature scanning.

  2. Runtime module dump to support obscure game assembly Current main stream implementation of interop generation uses raw GameAssembly.dll and global-metadata.dat. This will fail if the game is packed and if global-metadata.dat is embedded in GameAssembly.dll. This pull request implemented runtime module dump. global-metadata.dat is extracted using pattern matching.

krulci commented 3 months ago

This implementation is Windows-only so that would have to change.

But this is not something that's needed for vanilla unity and is highly specific to particular games, so maybe we should expose hooks for preloader plugins in BepInEx to handle this instead?

If I am not mistaken, Preloader patches are applied after interop generation. The implementation I applied to BepInEx was before interop generation and after Cecil assembly definitions are generated. If we were to do something similar to a preloader, we will need to change the execution order.