Skip to content

light refactor of binary and metadata initialization#533

Open
Xpl0itR wants to merge 1 commit intoSamboyCoding:developmentfrom
Xpl0itR:refactor-init
Open

light refactor of binary and metadata initialization#533
Xpl0itR wants to merge 1 commit intoSamboyCoding:developmentfrom
Xpl0itR:refactor-init

Conversation

@Xpl0itR
Copy link
Contributor

@Xpl0itR Xpl0itR commented Mar 14, 2026

For the purpose of having greater control over the init process

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors LibCpp2IL initialization to split metadata and binary initialization steps, aiming to provide callers finer-grained control over the init process.

Changes:

  • Added LibCpp2IlMain.InitializeMetadata(...) and LibCpp2IlMain.Initialize(Il2CppMetadata, Il2CppBinary) to separate initialization phases.
  • Made LibCpp2IlBinaryRegistry.CreateAndInit(...) public and moved “find regs + init” orchestration into Il2CppBinary.Init(Il2CppMetadata).
  • Exposed PE image base/sections via public members and updated tests to call LibCpp2IlMain.Reset().

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
LibCpp2ILTests/Tests.cs Ensures test runs reset LibCpp2IL state before initialization.
LibCpp2IL/PE/PE.cs Renames/exposes PE section headers and image base for external access.
LibCpp2IL/LibCpp2IlMain.cs Splits init into metadata init + binary init + post-init mapping/caches.
LibCpp2IL/LibCpp2IlBinaryRegistry.cs Makes binary creation/init publicly callable and delegates init to Il2CppBinary.
LibCpp2IL/Il2CppBinary.cs Adds a convenience Init(Il2CppMetadata) wrapper around reg discovery + initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

internal readonly SectionHeader[] peSectionHeaders; //Internal for the one use in PlusSearch
internal readonly ulong peImageBase; //Internal for the one use in PlusSearch
public readonly SectionHeader[] PeSectionHeaders;
public ulong PeImageBase;
Comment on lines 52 to 70
@@ -64,22 +64,9 @@ internal static Il2CppBinary CreateAndInit(byte[] buffer, Il2CppMetadata metadat
var memStream = new MemoryStream(buffer, 0, buffer.Length, true, true);

LibLogger.InfoNewline("Searching Binary for Required Data...");
var start = DateTime.Now;

var binary = match.FactoryFunc(memStream);
binary.SetMetadataVersion(metadata.MetadataVersion);

LibCpp2IlMain.Binary = binary;

var (codereg, metareg) = binary.FindCodeAndMetadataReg(metadata);

LibLogger.InfoNewline($"Got Binary codereg: 0x{codereg:X}, metareg: 0x{metareg:X} in {(DateTime.Now - start).TotalMilliseconds:F0}ms.");
LibLogger.InfoNewline("Initializing Binary...");
start = DateTime.Now;

binary.Init(codereg, metareg, metadata);

LibLogger.InfoNewline($"Initialized Binary in {(DateTime.Now - start).TotalMilliseconds:F0}ms");

var binary = LibCpp2IlMain.Binary = match.FactoryFunc(memStream);
binary.Init(metadata);

Comment on lines 175 to 204
@@ -187,8 +201,6 @@ public static bool Initialize(byte[] binaryBytes, byte[] metadataBytes, UnityVer
}

LibCpp2IlReflection.InitCaches();

return true;
}
@SamboyCoding
Copy link
Owner

Rebase and fix conflicts, also some of this copilot feedback seems valid, there's some footguns introduced here.

@coveralls
Copy link

coveralls commented Mar 16, 2026

Pull Request Test Coverage Report for Build 23216409431

Details

  • 29 of 39 (74.36%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 35.127%

Changes Missing Coverage Covered Lines Changed/Added Lines %
LibCpp2IL/PE/PE.cs 6 16 37.5%
Totals Coverage Status
Change from base Build 23144759400: 0.04%
Covered Lines: 4360
Relevant Lines: 11085

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants