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

Split instruction sets into their own packages #221

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 4 additions & 6 deletions Cpp2IL.Core.Tests/Cpp2IL.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Cpp2IL.Core\Cpp2IL.Core.csproj" />
<ProjectReference Include="..\Cpp2IL.InstructionSets.All\Cpp2IL.InstructionSets.All.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.5.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>

</Project>
18 changes: 2 additions & 16 deletions Cpp2IL.Core.Tests/GameLoader.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using AssetRipper.VersionUtilities;
using Cpp2IL.Core.Api;
using Cpp2IL.Core.InstructionSets;
using Cpp2IL.Core.Model.Contexts;
using Cpp2IL.InstructionSets.All;
using LibCpp2IL;

namespace Cpp2IL.Core.Tests;
Expand All @@ -10,20 +9,7 @@ public static class GameLoader
{
static GameLoader()
{
InstructionSetRegistry.RegisterInstructionSet<X86InstructionSet>(DefaultInstructionSets.X86_32);
InstructionSetRegistry.RegisterInstructionSet<X86InstructionSet>(DefaultInstructionSets.X86_64);
InstructionSetRegistry.RegisterInstructionSet<WasmInstructionSet>(DefaultInstructionSets.WASM);
InstructionSetRegistry.RegisterInstructionSet<ArmV7InstructionSet>(DefaultInstructionSets.ARM_V7);
var useNewArm64 = true;
if (useNewArm64)
{
InstructionSetRegistry.RegisterInstructionSet<NewArmV8InstructionSet>(DefaultInstructionSets.ARM_V8);
}
else
{
InstructionSetRegistry.RegisterInstructionSet<Arm64InstructionSet>(DefaultInstructionSets.ARM_V8);
}

AllInstructionSets.Register();
LibCpp2IlBinaryRegistry.RegisterBuiltInBinarySupport();
}

Expand Down
41 changes: 6 additions & 35 deletions Cpp2IL.Core/Cpp2IL.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,56 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Sam Byass (Samboy063)</Authors>
<Company>N/A</Company>
<Copyright>Copyright © Samboy063 2019-2023</Copyright>
<DebugType>embedded</DebugType>
<TargetFrameworks>net7.0;net6.0;netstandard2.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<Description>Reverses Unity's IL2CPP Build Process</Description>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageId>Samboy063.Cpp2IL.Core</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/SamboyCoding/Cpp2IL</PackageProjectUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/SamboyCoding/Cpp2IL.git</RepositoryUrl>
<TargetFrameworks>net7.0;net6.0;netstandard2.0</TargetFrameworks>
<Title>Cpp2IL.Core</Title>
<VersionPrefix>2022.1.0</VersionPrefix>
<!--Plugins make this non-trimmable-->

<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<!--Needed for DLL output-->
<PackageReference Include="AsmResolver.DotNet" Version="5.1.0" />

<!--For ARM64 dissassembly-->
<PackageReference Include="Disarm" Version="2022.1.0-master.26" />
<PackageReference Include="AsmResolver.DotNet" Version="5.3.0" />

<!--For X86/X64 disassembly-->
<PackageReference Include="Iced" Version="1.18.0" />

<!--For ARM64 and ARMv7 disassembly. Future: Remove once disarm is stable and move ARMv7 to CapstoneSharp by 6pak-->
<PackageReference Include="js6pak.Gee.External.Capstone" Version="2.1.0" />

<!--Not used at runtime, but needed for the build-->
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />

<PackageReference Include="PolySharp" Version="1.12.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net6.0'">
<!--Supplementary packages to provide modern runtime features on netstandard2-->
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="PolySharp" Version="1.13.2" PrivateAssets="all" />
</ItemGroup>

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

<!--Future: Consider moving to its own project and moving the impl in cpp2il to a plugin-->
<ProjectReference Include="..\StableNameDotNet\StableNameDotNet.csproj" />
</ItemGroup>
Expand Down
17 changes: 1 addition & 16 deletions Cpp2IL.Core/Cpp2IlCorePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using Cpp2IL.Core;
using Cpp2IL.Core.Api;
using Cpp2IL.Core.Attributes;
using Cpp2IL.Core.InstructionSets;
using Cpp2IL.Core.OutputFormats;
using Cpp2IL.Core.ProcessingLayers;
//Need this for the assembly attribute definition below.
Expand All @@ -22,19 +20,7 @@ public override void OnLoad()
{
Logger.VerboseNewline("Initializing...", "Core Plugin");
var start = DateTime.Now;

Logger.VerboseNewline("\tRegistering built-in instruction set handlers...", "Core Plugin");

InstructionSetRegistry.RegisterInstructionSet<X86InstructionSet>(DefaultInstructionSets.X86_32);
InstructionSetRegistry.RegisterInstructionSet<X86InstructionSet>(DefaultInstructionSets.X86_64);
InstructionSetRegistry.RegisterInstructionSet<WasmInstructionSet>(DefaultInstructionSets.WASM);
InstructionSetRegistry.RegisterInstructionSet<ArmV7InstructionSet>(DefaultInstructionSets.ARM_V7);

if(Environment.GetEnvironmentVariable("CPP2IL_NEW_ARM64") != null)
InstructionSetRegistry.RegisterInstructionSet<NewArmV8InstructionSet>(DefaultInstructionSets.ARM_V8);
else
InstructionSetRegistry.RegisterInstructionSet<Arm64InstructionSet>(DefaultInstructionSets.ARM_V8);


Logger.VerboseNewline("\tRegistering built-in binary parsers...", "Core Plugin");

LibCpp2IlBinaryRegistry.RegisterBuiltInBinarySupport();
Expand All @@ -44,7 +30,6 @@ public override void OnLoad()
OutputFormatRegistry.Register<AsmResolverDummyDllOutputFormat>();
OutputFormatRegistry.Register<DiffableCsOutputFormat>();
OutputFormatRegistry.Register<IsilDumpOutputFormat>();
OutputFormatRegistry.Register<WasmMappingOutputFormat>();

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

Expand Down
60 changes: 0 additions & 60 deletions Cpp2IL.Core/Extensions/MiscExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,66 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using Cpp2IL.Core.ISIL;
using Gee.External.Capstone.Arm;
using Gee.External.Capstone.Arm64;
using Iced.Intel;
using Instruction = Iced.Intel.Instruction;

namespace Cpp2IL.Core.Extensions
{
public static class MiscExtensions
{
public static InstructionSetIndependentOperand MakeIndependent(this Register reg) => InstructionSetIndependentOperand.MakeRegister(reg.ToString().ToLower());

public static ulong GetImmediateSafe(this Instruction instruction, int op) => instruction.GetOpKind(op).IsImmediate() ? instruction.GetImmediate(op) : 0;

public static bool IsJump(this Mnemonic mnemonic) => mnemonic is Mnemonic.Call or >= Mnemonic.Ja and <= Mnemonic.Js;
public static bool IsConditionalJump(this Mnemonic mnemonic) => mnemonic.IsJump() && mnemonic != Mnemonic.Jmp && mnemonic != Mnemonic.Call;

//Arm Extensions
public static ArmRegister? RegisterSafe(this ArmOperand operand) => operand.Type != ArmOperandType.Register ? null : operand.Register;
public static bool IsImmediate(this ArmOperand operand) => operand.Type is ArmOperandType.CImmediate or ArmOperandType.Immediate or ArmOperandType.PImmediate;
public static int ImmediateSafe(this ArmOperand operand) => operand.IsImmediate() ? operand.Immediate : 0;
private static ArmOperand? MemoryOperand(ArmInstruction instruction) => instruction.Details.Operands.FirstOrDefault(a => a.Type == ArmOperandType.Memory);

public static ArmRegister? MemoryBase(this ArmInstruction instruction) => MemoryOperand(instruction)?.Memory.Base;
public static ArmRegister? MemoryIndex(this ArmInstruction instruction) => MemoryOperand(instruction)?.Memory.Index;
public static int MemoryOffset(this ArmInstruction instruction) => MemoryOperand(instruction)?.Memory.Displacement ?? 0;

//Arm64 Extensions
public static Arm64Register? RegisterSafe(this Arm64Operand operand) => operand.Type != Arm64OperandType.Register ? null : operand.Register;
public static bool IsImmediate(this Arm64Operand operand) => operand.Type is Arm64OperandType.CImmediate or Arm64OperandType.Immediate;
public static long ImmediateSafe(this Arm64Operand operand) => operand.IsImmediate() ? operand.Immediate : 0;
internal static Arm64Operand? MemoryOperand(this Arm64Instruction instruction) => instruction.Details.Operands.FirstOrDefault(a => a.Type == Arm64OperandType.Memory);

public static Arm64Register? MemoryBase(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Base;
public static Arm64Register? MemoryIndex(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Index;
public static int MemoryOffset(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Displacement ?? 0;

public static bool IsConditionalMove(this Instruction instruction)
{
switch (instruction.Mnemonic)
{
case Mnemonic.Cmove:
case Mnemonic.Cmovne:
case Mnemonic.Cmovs:
case Mnemonic.Cmovns:
case Mnemonic.Cmovg:
case Mnemonic.Cmovge:
case Mnemonic.Cmovl:
case Mnemonic.Cmovle:
case Mnemonic.Cmova:
case Mnemonic.Cmovae:
case Mnemonic.Cmovb:
case Mnemonic.Cmovbe:
return true;
default:
return false;
}
}
public static Stack<T> Clone<T>(this Stack<T> original)
{
var arr = new T[original.Count];
Expand Down Expand Up @@ -130,9 +73,6 @@ public static T[] SubArray<T>(this T[] source, Range range)
return arr[i];
}

public static bool IsImmediate(this OpKind opKind) => opKind is >= OpKind.Immediate8 and <= OpKind.Immediate32to64;


public static void TrimEndWhile<T>(this List<T> instructions, Func<T, bool> predicate)
{
var i = instructions.Count - 1;
Expand Down
Loading