Skip to content

Commit

Permalink
Fix various causes of failing to save analyzed assemblies
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Byass committed Oct 14, 2021
1 parent 8798cc2 commit 7bc04d5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cpp2IL.Core/Analysis/AsmAnalyzerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions Cpp2IL.Core/Analysis/AsmAnalyzerX86.InstructionChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions Cpp2IL.Core/Analysis/ResultModels/ConstantDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ public Instruction[] GetILToLoad<TAnalysis>(MethodAnalysis<TAnalysis> 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))};
Expand Down
7 changes: 7 additions & 0 deletions Cpp2IL.Core/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7bc04d5

Please sign in to comment.