Skip to content

Commit fb2e207

Browse files
committed
core: Finish actually removing static state
1 parent cae273a commit fb2e207

28 files changed

Lines changed: 111 additions & 1120 deletions

‎Cpp2IL.Core/Analysis/WriteBarrierRecovery.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private static ulong FindBarrierFlagAddress(ApplicationAnalysisContext appContex
138138

139139
try
140140
{
141-
foreach (var instruction in X86Utils.GetMethodBodyAtVirtAddressNew(barrier, false, appContext.Binary))
141+
foreach (var instruction in X86Utils.GetMethodBodyAtVirtAddressNew(barrier, false, appContext))
142142
{
143143
if (instruction is { Mnemonic: Iced.Intel.Mnemonic.Cmp, Op0Kind: Iced.Intel.OpKind.Memory }
144144
&& instruction.MemoryIndex == Iced.Intel.Register.None

‎Cpp2IL.Core/Cpp2IL.Core.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<!--For X86/X64 disassembly-->
5050
<PackageReference Include="Iced" Version="1.21.0" />
5151

52-
<!--For ARM64 and ARMv7 disassembly. Future: Remove once disarm is stable and move ARMv7 to CapstoneSharp by 6pak-->
52+
<!--For ARMv7 disassembly only. Future: replace with a disarm equivalent-->
5353
<PackageReference Include="AssetRipper.Gee.External.Capstone" Version="2.3.2" />
5454

5555
<!--Not used at runtime, but needed for the build-->

‎Cpp2IL.Core/Cpp2IlApi.cs‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System;
22
using System.Diagnostics.CodeAnalysis;
33
using System.IO;
4-
using System.Linq;
54
using System.Runtime.CompilerServices;
65
using AssetRipper.Primitives;
76
using Cpp2IL.Core.Exceptions;
87
using Cpp2IL.Core.Logging;
98
using Cpp2IL.Core.Model.Contexts;
10-
using Cpp2IL.Core.Utils;
11-
using Cpp2IL.Core.Utils.AsmResolver;
129
using LibCpp2IL;
1310
using LibCpp2IL.Logging;
1411

@@ -124,9 +121,6 @@ public static void InitializeLibCpp2Il(byte[] assemblyData, byte[] metadataData,
124121
[MemberNotNull(nameof(CurrentAppContext))]
125122
private static void OnLibInitialized(LibCpp2IlContext libContext)
126123
{
127-
libContext.Binary.AllCustomAttributeGenerators.ToList()
128-
.ForEach(ptr => SharedState.AttributeGeneratorStarts.Add(ptr));
129-
130124
var start = DateTime.Now;
131125
Logger.InfoNewline("Creating application model...");
132126
CurrentAppContext = new(libContext);
@@ -135,40 +129,9 @@ private static void OnLibInitialized(LibCpp2IlContext libContext)
135129

136130
public static void ResetInternalState()
137131
{
138-
SharedState.Clear();
139-
140-
MiscUtils.Reset();
141-
142-
AsmResolverUtils.Reset();
143-
144132
CurrentAppContext = null;
145133
}
146134

147-
// public static void PopulateConcreteImplementations()
148-
// {
149-
// CheckLibInitialized();
150-
//
151-
// Logger.InfoNewline("Populating Concrete Implementation Table...");
152-
//
153-
// foreach (var def in LibCpp2IlMain.TheMetadata!.typeDefs)
154-
// {
155-
// if (def.IsAbstract)
156-
// continue;
157-
//
158-
// var baseTypeReflectionData = def.BaseType;
159-
// while (baseTypeReflectionData != null)
160-
// {
161-
// if (baseTypeReflectionData.baseType == null)
162-
// break;
163-
//
164-
// if (baseTypeReflectionData.isType && baseTypeReflectionData.baseType.IsAbstract && !SharedState.ConcreteImplementations.ContainsKey(baseTypeReflectionData.baseType))
165-
// SharedState.ConcreteImplementations[baseTypeReflectionData.baseType] = def;
166-
//
167-
// baseTypeReflectionData = baseTypeReflectionData.baseType.BaseType;
168-
// }
169-
// }
170-
// }
171-
172135
private static bool IsLibInitialized()
173136
{
174137
return CurrentAppContext != null;

‎Cpp2IL.Core/Cpp2IlCorePlugin.cs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ public override void OnLoad()
3030
InstructionSetRegistry.RegisterInstructionSet<WasmInstructionSet>(DefaultInstructionSets.WASM);
3131
InstructionSetRegistry.RegisterInstructionSet<ArmV7InstructionSet>(DefaultInstructionSets.ARM_V7);
3232

33-
if (Environment.GetEnvironmentVariable("CPP2IL_LEGACY_ARM64") != null)
34-
InstructionSetRegistry.RegisterInstructionSet<Arm64InstructionSet>(DefaultInstructionSets.ARM_V8);
35-
else
36-
InstructionSetRegistry.RegisterInstructionSet<NewArmV8InstructionSet>(DefaultInstructionSets.ARM_V8);
33+
InstructionSetRegistry.RegisterInstructionSet<NewArmV8InstructionSet>(DefaultInstructionSets.ARM_V8);
3734

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

‎Cpp2IL.Core/Extensions/MiscExtensions.cs‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using System.Text;
66
using Gee.External.Capstone.Arm;
7-
using Gee.External.Capstone.Arm64;
87
using Iced.Intel;
98
using Instruction = Iced.Intel.Instruction;
109

@@ -29,16 +28,6 @@ public static class MiscExtensions
2928
public static ArmRegister? MemoryIndex(this ArmInstruction instruction) => MemoryOperand(instruction)?.Memory.Index;
3029
public static int MemoryOffset(this ArmInstruction instruction) => MemoryOperand(instruction)?.Memory.Displacement ?? 0;
3130

32-
//Arm64 Extensions
33-
public static Arm64Register? RegisterSafe(this Arm64Operand operand) => operand.Type != Arm64OperandType.Register ? null : operand.Register;
34-
public static bool IsImmediate(this Arm64Operand operand) => operand.Type is Arm64OperandType.CImmediate or Arm64OperandType.Immediate;
35-
public static long ImmediateSafe(this Arm64Operand operand) => operand.IsImmediate() ? operand.Immediate : 0;
36-
internal static Arm64Operand? MemoryOperand(this Arm64Instruction instruction) => instruction.Details.Operands.FirstOrDefault(a => a.Type == Arm64OperandType.Memory);
37-
38-
public static Arm64Register? MemoryBase(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Base;
39-
public static Arm64Register? MemoryIndex(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Index;
40-
public static int MemoryOffset(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Displacement ?? 0;
41-
4231
public static bool IsConditionalMove(this Instruction instruction)
4332
{
4433
switch (instruction.Mnemonic)

0 commit comments

Comments
 (0)