From 7bc04d595ea84608c3bc4706a9920c3d9e23c2a1 Mon Sep 17 00:00:00 2001 From: Sam Byass Date: Thu, 14 Oct 2021 01:33:18 +0100 Subject: [PATCH] Fix various causes of failing to save analyzed assemblies --- Cpp2IL.Core/Analysis/AsmAnalyzerBase.cs | 2 ++ Cpp2IL.Core/Analysis/AsmAnalyzerX86.InstructionChecks.cs | 3 --- Cpp2IL.Core/Analysis/ResultModels/ConstantDefinition.cs | 6 ++++++ Cpp2IL.Core/Utils.cs | 7 +++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Cpp2IL.Core/Analysis/AsmAnalyzerBase.cs b/Cpp2IL.Core/Analysis/AsmAnalyzerBase.cs index 7f59c473..1f8a9c0c 100644 --- a/Cpp2IL.Core/Analysis/AsmAnalyzerBase.cs +++ b/Cpp2IL.Core/Analysis/AsmAnalyzerBase.cs @@ -123,6 +123,8 @@ public StringBuilder BuildILToString() varType = git2.Resolve(); if (varType is GenericInstanceType git) varType = processor.ImportRecursive(git, MethodDefinition); + if (varType is ArrayType arr && arr.GetUltimateElementType().IsGenericParameter) + throw new InvalidOperationException(); localDefinition.Variable = new VariableDefinition(processor.ImportReference(varType, MethodDefinition)); body.Variables.Add(localDefinition.Variable); diff --git a/Cpp2IL.Core/Analysis/AsmAnalyzerX86.InstructionChecks.cs b/Cpp2IL.Core/Analysis/AsmAnalyzerX86.InstructionChecks.cs index 053ceaef..fdd838c0 100644 --- a/Cpp2IL.Core/Analysis/AsmAnalyzerX86.InstructionChecks.cs +++ b/Cpp2IL.Core/Analysis/AsmAnalyzerX86.InstructionChecks.cs @@ -25,9 +25,6 @@ private void CheckForZeroOpInstruction(Instruction instruction) private void CheckForSingleOpInstruction(Instruction instruction) { - if (instruction.IP == 0x1804ae0ac) - Debugger.Break(); - var reg = Utils.GetRegisterNameNew(instruction.Op0Register == Register.None ? instruction.MemoryBase : instruction.Op0Register); var operand = Analysis.GetOperandInRegister(reg); diff --git a/Cpp2IL.Core/Analysis/ResultModels/ConstantDefinition.cs b/Cpp2IL.Core/Analysis/ResultModels/ConstantDefinition.cs index 5f24540b..cbbef501 100644 --- a/Cpp2IL.Core/Analysis/ResultModels/ConstantDefinition.cs +++ b/Cpp2IL.Core/Analysis/ResultModels/ConstantDefinition.cs @@ -106,8 +106,14 @@ public Instruction[] GetILToLoad(MethodAnalysis context, I ilProcessor.Create(OpCodes.Ldc_R8, (double) Value), }; + if(Type == typeof(MethodReference) && Value is GenericInstanceMethod gim) + return new[] {ilProcessor.Create(OpCodes.Ldftn, ilProcessor.ImportRecursive(gim))}; + if (Type == typeof(MethodReference) && Value is MethodReference reference) return new[] {ilProcessor.Create(OpCodes.Ldftn, ilProcessor.ImportReference(reference))}; + + if(Type == typeof(TypeReference) && Value is GenericInstanceType git) + return new[] {ilProcessor.Create(OpCodes.Ldtoken, ilProcessor.ImportRecursive(git))}; if (Type == typeof(TypeReference) && Value is TypeReference typeReference) return new[] {ilProcessor.Create(OpCodes.Ldtoken, ilProcessor.ImportReference(typeReference))}; diff --git a/Cpp2IL.Core/Utils.cs b/Cpp2IL.Core/Utils.cs index 15dec234..0b653e6f 100644 --- a/Cpp2IL.Core/Utils.cs +++ b/Cpp2IL.Core/Utils.cs @@ -595,6 +595,13 @@ public static string GetRegisterNameNew(Register register) return ret; } + public static TypeReference GetUltimateElementType(this ArrayType arr) => + arr.ElementType switch + { + ArrayType arr2 => arr2.GetUltimateElementType(), + { } other => other, + }; + public static string GetRegisterNameNew(Arm64RegisterId registerId) { var key = registerId;