Skip to content

Commit 6c7d8da

Browse files
committed
Improve WPF rename analysis
Fix yck1509#443
1 parent 0b3a8e0 commit 6c7d8da

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

Confuser.Renamer/Analyzers/WPFAnalyzer.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ public void PostRename(ConfuserContext context, INameService service, Protection
147147
void AnalyzeMethod(ConfuserContext context, INameService service, MethodDef method) {
148148
var dpRegInstrs = new List<Tuple<bool, Instruction>>();
149149
var routedEvtRegInstrs = new List<Instruction>();
150-
foreach (Instruction instr in method.Body.Instructions) {
150+
for (int i = 0; i < method.Body.Instructions.Count; i++) {
151+
Instruction instr = method.Body.Instructions[i];
151152
if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt)) {
152153
var regMethod = (IMethod)instr.Operand;
153154

@@ -160,6 +161,15 @@ void AnalyzeMethod(ConfuserContext context, INameService service, MethodDef meth
160161
routedEvtRegInstrs.Add(instr);
161162
}
162163
}
164+
else if (instr.OpCode.Code == Code.Newobj) {
165+
var methodRef = (IMethod)instr.Operand;
166+
167+
if (methodRef.DeclaringType.FullName == "System.Windows.Data.PropertyGroupDescription" &&
168+
methodRef.Name == ".ctor" && i - 1 >= 0 && method.Body.Instructions[i - 1].OpCode.Code == Code.Ldstr) {
169+
foreach (var property in analyzer.LookupProperty((string)method.Body.Instructions[i - 1].Operand))
170+
service.SetCanRename(property, false);
171+
}
172+
}
163173
else if (instr.OpCode == OpCodes.Ldstr) {
164174
var operand = ((string)instr.Operand).ToUpperInvariant();
165175
if (operand.EndsWith(".BAML") || operand.EndsWith(".XAML")) {

0 commit comments

Comments
 (0)