IEnumerable <FieldDefinition> getPossibleFields(TypeDefinition type) { var typeToFields = new TypeDefinitionDict <List <FieldDefinition> >(); foreach (var field in type.Fields) { if (field.Attributes != FieldAttributes.Private) { continue; } var fieldType = DotNetUtils.getType(module, field.FieldType); if (fieldType == null) { continue; } if (!checkBaseType(fieldType)) { continue; } var list = typeToFields.find(fieldType); if (list == null) { typeToFields.add(fieldType, list = new List <FieldDefinition>()); } list.Add(field); } foreach (var list in typeToFields.getValues()) { if (list.Count == 1) { yield return(list[0]); } } }
public bool exists(MethodReference method) { if (method == null) { return(false); } if (method.DeclaringType != null && types.find(method.DeclaringType)) { return(true); } return(methods.find(method)); }
FieldDefinition getNewField(FieldReference structField, FieldReference oldFieldRef) { var fieldsDict = typeToFieldsDict.find(structField.DeclaringType); if (fieldsDict == null) { throw new ApplicationException("Could not find structField declaringType"); } var newField = fieldsDict.find(oldFieldRef); if (newField == null) { throw new ApplicationException("Could not find new field"); } return(newField); }
public void deobfuscate(Blocks blocks) { var instrsToRemove = new List <int>(); foreach (var block in blocks.MethodBlocks.getAllBlocks()) { instrsToRemove.Clear(); var instrs = block.Instructions; for (int i = 0; i < instrs.Count; i++) { var instr = instrs[i]; int indexToRemove; TypeReference type; VariableDefinition local = null; if (instr.OpCode.Code == Code.Newobj) { if (i + 1 >= instrs.Count) { continue; } var ctor = instr.Operand as MethodReference; if (ctor == null || ctor.DeclaringType == null) { continue; } if (ctor.Name != ".ctor") { continue; } var next = instrs[i + 1]; if (!next.isStloc() && !next.isLeave() && next.OpCode.Code != Code.Pop) { continue; } indexToRemove = i; type = ctor.DeclaringType; if (next.isStloc()) { local = Instr.getLocalVar(blocks.Locals, next); } } else if (instr.OpCode.Code == Code.Ldfld) { if (i == 0) { continue; } var ldloc = instrs[i - 1]; if (!ldloc.isLdloc()) { continue; } var field = instr.Operand as FieldReference; if (field == null || field.DeclaringType == null) { continue; } indexToRemove = i; type = field.DeclaringType; local = Instr.getLocalVar(blocks.Locals, ldloc); } else { continue; } if (type == null) { continue; } var info = typeToInfo.find(type); if (info == null) { continue; } info.referenced = true; instrsToRemove.Add(indexToRemove); if (local != null) { local.VariableType = info.localType; } } block.remove(instrsToRemove); } }
public MType getType(TypeReference typeReference) { return(typeReferenceToType.find(typeReference)); }
public bool checkCanInline(MethodDefinition method) { return(methodsTypes.find(method.DeclaringType)); }
IEnumerable<FieldDefinition> getPossibleFields(TypeDefinition type) { var typeToFields = new TypeDefinitionDict<List<FieldDefinition>>(); foreach (var field in type.Fields) { if (field.Attributes != FieldAttributes.Private) continue; var fieldType = DotNetUtils.getType(module, field.FieldType); if (fieldType == null || !fieldType.IsValueType) continue; var list = typeToFields.find(fieldType); if (list == null) typeToFields.add(fieldType, list = new List<FieldDefinition>()); list.Add(field); } foreach (var list in typeToFields.getValues()) { if (list.Count == 1) yield return list[0]; } }