ROM Hack Discussion il2cpp now supports NSO files!

DaRockLobsta

Member
OP
Newcomer
Joined
Jan 10, 2019
Messages
15
Trophies
0
Age
41
XP
106
Country
Bangladesh
found at:
https://github.com/Perfare/Il2CppDumper

To get the scripts.py to populate in IDA you need to run nx2elf.exe and load up that generated .elf file in ida then run scripts.py on that, make your edits then run elf2nx.exe to convert it back

https://github.com/Mila432/switch_rom_hacking#uncompressing-main-recommended

Code:
xtract .NET metadata from il2cpp binaries. (types, methods, fields, etc.)

Extraction code is based on Il2CppDumper
Features

    Supports il2cpp binaries in ELF, ELF64, Mach-O, NSO and PE format
    Supports global-metadata version 16 and 19-24
    Extracts .NET metadata including types, fields, properties, methods and attributes
    Supports automated IDA script generation
        name and tag methods
        store dynamic string literals in comments
        makefunction to improve ida analysis
    Generates dummy DLLs that can be viewed in .NET decompilers

Usage

Run Il2CppDumper.exe and choose the main il2cpp executable (in ELF, Mach-O, NSO or PE format) and global-metadata.dat file, then select the extraction mode. The program will then generate all the output files in current working directory.
Extraction Modes
Manual

The parameters (CodeRegistration and MetadataRegistration) that are passed to il2cpp::vm::MetadataCache::Register() needs to be manually reverse engineered and passed to the program.
Auto

Automatically finds the il2cpp_codegen_register() function by signature matching and read out the first (CodeRegistration) and second (MetadataRegistration) parameter passed to the il2cpp::vm::MetadataCache::Register() method that will be invoked in the registration function. May not work well due to compiler optimizations.
Auto(Advanced)

Matches possible pointers in the data section. Generally works better than Auto mode.

Supports metadata version 20 and later (only CodeRegistration address can be found on metadata version 16).
Auto(Plus) - Recommended

Matches possible pointers in the data section with some guidance from global-metadata. Works better than Auto(Advanced) mode on certain binaries.

Supports metadata version 20 and later (only CodeRegistration address can be found on metadata version 16).
Auto(Symbol)

Uses symbols in the il2cpp binary to locate CodeRegistration and MetadataRegistration.

Only supports certain Android ELF files.
Output files
dump.cs

C# pseudocode. Can be viewed in text editors (syntax highlighting recommended)
script.py

Requires IDA and IDAPython. Can be loaded in IDA via File -> Script file.
DummyDll

DLLs generated by Mono.Cecil which contain the .NET metadata extracted from the binary (no code included). Can be viewed in .NET decompilers.
Configuration

All the configuration options are located in config.json Available options:

    DumpMethod, DumpField, DumpProperty, DumpAttribute, DumpFieldOffset, DumpMethodOffset, DumpTypeDefIndex
        Whether or not the program should extract these information

    DummyDll
        Whether or not the program should generate dummy DLLs

    ForceIl2CppVersion, ForceVersion
        If ForceIl2CppVersion is true, the program will use the version number specified in ForceVersion to choose parser for il2cpp binaries (does not affect the choice of metadata parser). This may be useful on some older il2cpp version (e.g. the program may need to use v16 parser on ilcpp v20 (Android) binaries in order to work properly)
 
Last edited by DaRockLobsta,
  • Like
Reactions: masagrator

DaRockLobsta

Member
OP
Newcomer
Joined
Jan 10, 2019
Messages
15
Trophies
0
Age
41
XP
106
Country
Bangladesh
Auto(plus) mode seems to be the best, if it says metadata not able to load or something similar run as admin that is what worked for me
Capture.png


Capture2.png
 
  • Like
Reactions: masagrator

zellfy

Member
Newcomer
Joined
Mar 8, 2019
Messages
22
Trophies
0
Age
33
XP
138
Country
China
found at:
https://github.com/Perfare/Il2CppDumper

Code:
xtract .NET metadata from il2cpp binaries. (types, methods, fields, etc.)

Extraction code is based on Il2CppDumper
Features

    Supports il2cpp binaries in ELF, ELF64, Mach-O, NSO and PE format
    Supports global-metadata version 16 and 19-24
    Extracts .NET metadata including types, fields, properties, methods and attributes
    Supports automated IDA script generation
        name and tag methods
        store dynamic string literals in comments
        makefunction to improve ida analysis
    Generates dummy DLLs that can be viewed in .NET decompilers

Usage

Run Il2CppDumper.exe and choose the main il2cpp executable (in ELF, Mach-O, NSO or PE format) and global-metadata.dat file, then select the extraction mode. The program will then generate all the output files in current working directory.
Extraction Modes
Manual

The parameters (CodeRegistration and MetadataRegistration) that are passed to il2cpp::vm::MetadataCache::Register() needs to be manually reverse engineered and passed to the program.
Auto

Automatically finds the il2cpp_codegen_register() function by signature matching and read out the first (CodeRegistration) and second (MetadataRegistration) parameter passed to the il2cpp::vm::MetadataCache::Register() method that will be invoked in the registration function. May not work well due to compiler optimizations.
Auto(Advanced)

Matches possible pointers in the data section. Generally works better than Auto mode.

Supports metadata version 20 and later (only CodeRegistration address can be found on metadata version 16).
Auto(Plus) - Recommended

Matches possible pointers in the data section with some guidance from global-metadata. Works better than Auto(Advanced) mode on certain binaries.

Supports metadata version 20 and later (only CodeRegistration address can be found on metadata version 16).
Auto(Symbol)

Uses symbols in the il2cpp binary to locate CodeRegistration and MetadataRegistration.

Only supports certain Android ELF files.
Output files
dump.cs

C# pseudocode. Can be viewed in text editors (syntax highlighting recommended)
script.py

Requires IDA and IDAPython. Can be loaded in IDA via File -> Script file.
DummyDll

DLLs generated by Mono.Cecil which contain the .NET metadata extracted from the binary (no code included). Can be viewed in .NET decompilers.
Configuration

All the configuration options are located in config.json Available options:

    DumpMethod, DumpField, DumpProperty, DumpAttribute, DumpFieldOffset, DumpMethodOffset, DumpTypeDefIndex
        Whether or not the program should extract these information

    DummyDll
        Whether or not the program should generate dummy DLLs

    ForceIl2CppVersion, ForceVersion
        If ForceIl2CppVersion is true, the program will use the version number specified in ForceVersion to choose parser for il2cpp binaries (does not affect the choice of metadata parser). This may be useful on some older il2cpp version (e.g. the program may need to use v16 parser on ilcpp v20 (Android) binaries in order to work properly)

I can't find the latest version, can you tell me where it is or update the file here, thank you.
 

Canna

Bad Ass Poisonous Mushroom
Member
Joined
Jul 14, 2018
Messages
1,396
Trophies
0
Age
36
Location
AZ
XP
1,539
Country
United States
ilccp
FILE FORMAT ?

Code:
Console.WriteLine("Initializing metadata...");
            metadata = new Metadata(new MemoryStream(metadataBytes), metadataVersion);
            //判断il2cpp的magic
            var il2cppMagic = BitConverter.ToUInt32(il2cppBytes, 0);
            var isElf = false;
            var isPE = false;
            var is64bit = false;
            var isNSO = false;
            switch (il2cppMagic)
            {
                default:
                    throw new Exception("ERROR: il2cpp file not supported.");
                case 0x304F534E:
                    isNSO = true;
                    is64bit = true;
                    break;
                case 0x905A4D: //PE
                    isPE = true;
                    break;
                case 0x464c457f: //ELF
                    isElf = true;
                    if (il2cppBytes[4] == 2) //ELF64
                    {
                        is64bit = true;
                    }
                    break;
                case 0xCAFEBABE: //FAT Mach-O
                case 0xBEBAFECA:
                    var machofat = new MachoFat(new MemoryStream(il2cppBytes));
                    Console.Write("Select Platform: ");
                    for (var i = 0; i < machofat.fats.Length; i++)
                    {
                        var fat = machofat.fats[i];
                        Console.Write(fat.magic == 0xFEEDFACF ? $"{i + 1}.64bit " : $"{i + 1}.32bit ");
                    }
 
Last edited by Canna,

zellfy

Member
Newcomer
Joined
Mar 8, 2019
Messages
22
Trophies
0
Age
33
XP
138
Country
China
ilccp
FILE FORMAT ?

Code:
Console.WriteLine("Initializing metadata...");
            metadata = new Metadata(new MemoryStream(metadataBytes), metadataVersion);
            //判断il2cpp的magic
            var il2cppMagic = BitConverter.ToUInt32(il2cppBytes, 0);
            var isElf = false;
            var isPE = false;
            var is64bit = false;
            var isNSO = false;
            switch (il2cppMagic)
            {
                default:
                    throw new Exception("ERROR: il2cpp file not supported.");
                case 0x304F534E:
                    isNSO = true;
                    is64bit = true;
                    break;
                case 0x905A4D: //PE
                    isPE = true;
                    break;
                case 0x464c457f: //ELF
                    isElf = true;
                    if (il2cppBytes[4] == 2) //ELF64
                    {
                        is64bit = true;
                    }
                    break;
                case 0xCAFEBABE: //FAT Mach-O
                case 0xBEBAFECA:
                    var machofat = new MachoFat(new MemoryStream(il2cppBytes));
                    Console.Write("Select Platform: ");
                    for (var i = 0; i < machofat.fats.Length; i++)
                    {
                        var fat = machofat.fats[i];
                        Console.Write(fat.magic == 0xFEEDFACF ? $"{i + 1}.64bit " : $"{i + 1}.32bit ");
                    }


I have run il2cppdumper.exe as administrator, but it also returned the error.
"Initializing metadata...
System.Exception: ERROR: il2cpp file not supported.
at Il2CppDumper.Program.Init(Byte[] il2cppBytes, Byte[] metadataBytes) in C:\projects\il2cppdumper\Il2CppDumper\Program.cs:line 77
at Il2CppDumper.Program.Main(String[] args) in C:\projects\il2cppdumper\Il2CppDumper\Program.cs:line 65
Press any key to exit..."

--------------------- MERGED ---------------------------

Maybe I missed a file in the folder?
 

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,278
Trophies
3
XP
12,044
Country
Poland
Something is not right. Your overview is different than in github.
Topic said:
Supports il2cpp binaries in ELF, ELF64, Mach-O, NSO and PE format
github said:
Supports il2cpp binaries in ELF, ELF64, Mach-O and PE format

?

Maybe he pulled out release? Last release is from 28 days ago and there is nothing about NSO, only in source code.
Can you upload this release?

Edit: OK, found here
https://ci.appveyor.com/api/buildjobs/mupv3vwwdxy7bp3h/artifacts/Il2CppDumper/bin/Il2CppDumper-v4.2.5.zip

When is asking what version you have (Yes or No) try both, for Mages of Mystralia "No" is working, for "Yes" i got the same errors.
 
Last edited by masagrator,
  • Like
Reactions: DaRockLobsta

DaRockLobsta

Member
OP
Newcomer
Joined
Jan 10, 2019
Messages
15
Trophies
0
Age
41
XP
106
Country
Bangladesh
@masagrator he never did update the readme, it fully supports NSO, infact i asked him to look into add support for the switch about 30 days ago and he finally added support a few days ago. Its trail and error some games could be built with older versions or newer versions. try both options but always Auto(plus) seems to work 100% of the time.
 

zellfy

Member
Newcomer
Joined
Mar 8, 2019
Messages
22
Trophies
0
Age
33
XP
138
Country
China
@masagrator he never did update the readme, it fully supports NSO, infact i asked him to look into add support for the switch about 30 days ago and he finally added support a few days ago. Its trail and error some games could be built with older versions or newer versions. try both options but always Auto(plus) seems to work 100% of the time.

hey brother, I have dump many dlls with il2cppdumper.exe as what you said, thank you.
but now I have some questions to ask you, please do me a favor.
how to edit&save the main file?
1.get the script.py with il2cppdumper.exe.(done)
2.get the main.elf with nx2elf?(not, nx2elf seems not work on my computer.)
3.load main.elf with IDA and run script.py?(not, switch.py seems not work on my computer.)
4.edit and save to main.elf?(not)
5.get main.nso with nso2nx?(not)

Is that right?
Thank you for reading.
 

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,278
Trophies
3
XP
12,044
Country
Poland
3. You need to load main.elf and wait for disassembling done before you load scripts.py
And this is not working properly for every game for now
 

zellfy

Member
Newcomer
Joined
Mar 8, 2019
Messages
22
Trophies
0
Age
33
XP
138
Country
China
3. You need to load main.elf and wait for disassembling done before you load scripts.py
And this is not working properly for every game for now

OK, but script.py is working for what?
I have open the main file(not main.elf) with switch64.dll from another tools

--------------------- MERGED ---------------------------

just like this tool
https://github.com/pgarba/SwitchIDAProLoader
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: @Mondooooo, there was a power outage while you were sleeping?