Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISIL -> CIL Decompiler #426

Open
wants to merge 30 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fbc3452
Decompiler IL
MrUser127 Mar 5, 2025
d4ae081
Print ISIL with decompiler IL and other changes
MrUser127 Mar 6, 2025
b31c53e
Resolve methods
MrUser127 Mar 6, 2025
33eb9f8
Control flow graph
MrUser127 Mar 7, 2025
6bb55cb
Decompiler warnings
MrUser127 Mar 7, 2025
fbe2a42
Stack analysis
MrUser127 Mar 8, 2025
a8bec4d
Stack analysis changes
MrUser127 Mar 9, 2025
2308de5
Remove nop instructions
MrUser127 Mar 9, 2025
6fa1a0f
Stack analysis fixes
MrUser127 Mar 9, 2025
d6e1a2c
Use blocks as branch targets instead of instructions
MrUser127 Mar 9, 2025
839c217
Try to trace where stack pointer value came from
MrUser127 Mar 9, 2025
9b0a8b5
Fix stack analyzer only updating first operand
MrUser127 Mar 9, 2025
6f18b2c
Stack analysis fixes (now it actually works)
MrUser127 Mar 11, 2025
d45f70e
Use-def info and other changes
MrUser127 Mar 13, 2025
dce2e2c
Dominance info
MrUser127 Mar 13, 2025
5381ea4
SSA form
MrUser127 Mar 13, 2025
89022d6
SSA phi functions
MrUser127 Mar 14, 2025
88aa99d
Local variables and basic type propagation
MrUser127 Mar 15, 2025
8483557
Convert SSA back to normal form, many bug fixes, use object as operan…
MrUser127 Mar 17, 2025
f63a17d
Progress bar
MrUser127 Mar 17, 2025
ae982e9
SSA and inlining bug fixes
MrUser127 Mar 17, 2025
6664c31
Move platform specific stuff to X86InstructionSet
MrUser127 Mar 17, 2025
c9895e0
Update IL output format id and name
MrUser127 Mar 18, 2025
81e24e4
Decompile in parallel, resolve global types and key functions, bug fixes
MrUser127 Mar 19, 2025
5b233da
Initial IL generation
MrUser127 Mar 20, 2025
8fc6417
Resolve static fields, add call params
MrUser127 Mar 20, 2025
11829e7
Catch all decompiler exceptions
MrUser127 Mar 20, 2025
726f09e
Merge branch 'SamboyCoding:development' into development
MrUser127 Mar 20, 2025
3517bb8
Rename from decompiler to Cpp2IL.Decompiler
MrUser127 Mar 20, 2025
4aa36af
Better CIL
MrUser127 Mar 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cpp2IL.Core/Api/Cpp2IlInstructionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Cpp2IL.Core.Il2CppApiFunctions;
using Cpp2IL.Core.ISIL;
using Cpp2IL.Core.Model.Contexts;
using Cpp2IL.Decompiler.IL;
using LibCpp2IL.Metadata;

namespace Cpp2IL.Core.Api;
Expand Down Expand Up @@ -34,6 +35,8 @@ public abstract class Cpp2IlInstructionSet
/// <returns>An array of <see cref="IsilInstructionStatement"/> structs representing the functionality of this method in an instruction-set-independent manner.</returns>
public abstract List<InstructionSetIndependentInstruction> GetIsilFromMethod(MethodAnalysisContext context);

public abstract List<Instruction> GetDecompilerIlFromMethod(MethodAnalysisContext context, out List<object> ilParams);

Comment on lines +38 to +39
Copy link
Contributor

Choose a reason for hiding this comment

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

Why decompilation is specific to each instruction set if you're using ISIL?

/// <summary>
/// Create and populate a BaseKeyFunctionAddresses object which can then be populated.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Cpp2IL.Core/Cpp2IL.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@

<ItemGroup>
<ProjectReference Include="..\LibCpp2IL\LibCpp2IL.csproj" />

<ProjectReference Include="..\Cpp2IL.Decompiler\Cpp2IL.Decompiler.csproj"/>

Comment on lines +68 to +69
Copy link
Contributor

Choose a reason for hiding this comment

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

Sam would need to weigh in on this, but I feel like everything should be in one project.

<!--Future: Consider moving to its own project and moving the impl in cpp2il to a plugin-->
<ProjectReference Include="..\StableNameDotNet\StableNameDotNet.csproj" />
</ItemGroup>
Expand Down
7 changes: 5 additions & 2 deletions Cpp2IL.Core/Cpp2IlCorePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class Cpp2IlCorePlugin : Cpp2IlPlugin
{
public override string Name => "Cpp2IL Built-In";

public override string Description => "Core Cpp2IL plugin containing built-in instruction sets, binaries, and other core functionality.";
public override string Description =>
"Core Cpp2IL plugin containing built-in instruction sets, binaries, and other core functionality.";
Comment on lines +19 to +20
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

formatter did that

Copy link
Contributor

Choose a reason for hiding this comment

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

You should avoid using automatic formatters on existing files.


public override void OnLoad()
{
Expand Down Expand Up @@ -50,6 +51,7 @@ public override void OnLoad()
OutputFormatRegistry.Register<IsilDumpOutputFormat>();
OutputFormatRegistry.Register<WasmMappingOutputFormat>();
OutputFormatRegistry.Register<WasmNameSectionOutputFormat>();
OutputFormatRegistry.Register<IlOutputFormat>();

Logger.VerboseNewline("\tRegistering built-in processing layers", "Core Plugin");

Expand All @@ -61,7 +63,8 @@ public override void OnLoad()
ProcessingLayerRegistry.Register<DeobfuscationMapProcessingLayer>();

var elapsed = DateTime.Now - start;
Logger.VerboseNewline($"Core plugin loaded in {elapsed.Ticks} ticks ({elapsed.TotalMilliseconds}ms)", "Core Plugin");
Logger.VerboseNewline($"Core plugin loaded in {elapsed.Ticks} ticks ({elapsed.TotalMilliseconds}ms)",
"Core Plugin");
Comment on lines +66 to +67
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

formatter did that

}

private sealed class AsmResolverDllOutputFormatLegacy : AsmResolverDllOutputFormatDefault
Expand Down
7 changes: 7 additions & 0 deletions Cpp2IL.Core/InstructionSets/Arm64InstructionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Cpp2IL.Core.ISIL;
using Cpp2IL.Core.Model.Contexts;
using Cpp2IL.Core.Utils;
using Cpp2IL.Decompiler.IL;
using LibCpp2IL;

namespace Cpp2IL.Core.InstructionSets;
Expand Down Expand Up @@ -38,6 +39,12 @@ public override List<InstructionSetIndependentInstruction> GetIsilFromMethod(Met
return [];
}

public override List<Instruction> GetDecompilerIlFromMethod(MethodAnalysisContext context, out List<object> ilParams)
{
ilParams = [];
return [];
}

public override BaseKeyFunctionAddresses CreateKeyFunctionAddressesInstance() => new Arm64KeyFunctionAddresses();

public override string PrintAssembly(MethodAnalysisContext context)
Expand Down
7 changes: 7 additions & 0 deletions Cpp2IL.Core/InstructionSets/ArmV7InstructionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Cpp2IL.Core.ISIL;
using Cpp2IL.Core.Model.Contexts;
using Cpp2IL.Core.Utils;
using Cpp2IL.Decompiler.IL;

namespace Cpp2IL.Core.InstructionSets;

Expand All @@ -28,6 +29,12 @@ public override List<InstructionSetIndependentInstruction> GetIsilFromMethod(Met
return [];
}

public override List<Instruction> GetDecompilerIlFromMethod(MethodAnalysisContext context, out List<object> ilParams)
{
ilParams = [];
return [];
}

public override BaseKeyFunctionAddresses CreateKeyFunctionAddressesInstance()
{
//TODO Fix
Expand Down
7 changes: 7 additions & 0 deletions Cpp2IL.Core/InstructionSets/NewArmV8InstructionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Cpp2IL.Core.ISIL;
using Cpp2IL.Core.Model.Contexts;
using Cpp2IL.Core.Utils;
using Cpp2IL.Decompiler.IL;
using Disarm.InternalDisassembly;
using LibCpp2IL;

Expand Down Expand Up @@ -57,6 +58,12 @@ public override List<InstructionSetIndependentInstruction> GetIsilFromMethod(Met
return builder.BackingStatementList;
}

public override List<Instruction> GetDecompilerIlFromMethod(MethodAnalysisContext context, out List<object> ilParams)
{
ilParams = [];
return [];
}

private void ConvertInstructionStatement(Arm64Instruction instruction, IsilBuilder builder, MethodAnalysisContext context)
{
switch (instruction.Mnemonic)
Expand Down
7 changes: 7 additions & 0 deletions Cpp2IL.Core/InstructionSets/WasmInstructionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Cpp2IL.Core.Logging;
using Cpp2IL.Core.Model.Contexts;
using Cpp2IL.Core.Utils;
using Cpp2IL.Decompiler.IL;
using WasmDisassembler;

namespace Cpp2IL.Core.InstructionSets;
Expand Down Expand Up @@ -38,6 +39,12 @@ public override List<InstructionSetIndependentInstruction> GetIsilFromMethod(Met
return [];
}

public override List<Instruction> GetDecompilerIlFromMethod(MethodAnalysisContext context, out List<object> ilParams)
{
ilParams = [];
return [];
}

public override BaseKeyFunctionAddresses CreateKeyFunctionAddressesInstance()
{
return new WasmKeyFunctionAddresses();
Expand Down
Loading
Loading