Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Commit

Permalink
Fix string reference to types
Browse files Browse the repository at this point in the history
Fix #51
  • Loading branch information
yck1509 committed Jul 30, 2014
1 parent 78af582 commit f3c1406
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Confuser.Renamer/Analyzers/LdtokenEnumAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Confuser.Core;
using Confuser.Renamer.References;
using dnlib.DotNet;
using dnlib.DotNet.Emit;

Expand Down Expand Up @@ -41,6 +42,10 @@ public void Analyze(ConfuserContext context, INameService service, IDnlibDef def
} else if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt) &&
((IMethod)instr.Operand).Name == "ToString") {
HandleEnum(context, service, method, i);
} else if (instr.OpCode.Code == Code.Ldstr) {
TypeDef typeDef = method.Module.FindReflection((string)instr.Operand);
if (typeDef != null)
service.AddReference(typeDef, new StringTypeReference(instr, typeDef));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Confuser.Renamer/Confuser.Renamer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Compile Include="References\BAMLAttributeReference.cs" />
<Compile Include="References\BAMLConverterTypeReference.cs" />
<Compile Include="References\BAMLConverterMemberReference.cs" />
<Compile Include="References\StringTypeReference.cs" />
<Compile Include="References\TypeRefReference.cs" />
<Compile Include="References\OverrideDirectiveReference.cs" />
<Compile Include="References\MemberRefReference.cs" />
Expand Down
25 changes: 25 additions & 0 deletions Confuser.Renamer/References/StringTypeReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using Confuser.Core;
using dnlib.DotNet;
using dnlib.DotNet.Emit;

namespace Confuser.Renamer.References {
public class StringTypeReference : INameReference<TypeDef> {
private readonly Instruction reference;
private readonly TypeDef typeDef;

public StringTypeReference(Instruction reference, TypeDef typeDef) {
this.reference = reference;
this.typeDef = typeDef;
}

public bool UpdateNameReference(ConfuserContext context, INameService service) {
reference.Operand = typeDef.ReflectionFullName;
return true;
}

public bool ShouldCancelRename() {
return false;
}
}
}

0 comments on commit f3c1406

Please sign in to comment.