IMethod ResolveMethod_Helper(ITypeDefOrRef declaringType, MethodData data) { TypeDef declaringDef = declaringType.ResolveTypeDefThrow(); MethodSig methodSig = GetMethodSig(data); // Has a GenericMVar if (data.HasGenericArguments) { MethodSig detectedSig = null; MethodDef method = FindMethodCheckBaseType(declaringType, data, out detectedSig); if (method == null || detectedSig == null) { throw new Exception(String.Format( "Unable to find generic method from the declaring/base types: DeclaringType={0}, MethodName={1}, MethodSig={2}", declaringType.ReflectionFullName, data.Name, methodSig)); } MethodSpec methodSpec = new MethodSpecUser(method, ToGenericInstMethodSig(data)); return(this.Importer.Import(methodSpec)); } else // No GenericMVars { MethodDef method = declaringDef.FindMethodCheckBaseType(data.Name, methodSig); if (method == null) { throw new Exception(String.Format( "Unable to find method from the declaring/base types: DeclaringType={0}, MethodName={1}, MethodSig={2}", declaringType.ReflectionFullName, data.Name, methodSig)); } return(this.Importer.Import(method)); } }
// Token: 0x0600002E RID: 46 RVA: 0x00003FF4 File Offset: 0x000021F4 private void AnalyzeCAArgument(ConfuserContext context, INameService service, CAArgument arg) { if (arg.Type.DefinitionAssembly.IsCorLib() && arg.Type.FullName == "System.Type") { TypeSig typeSig = (TypeSig)arg.Value; using (IEnumerator <ITypeDefOrRef> enumerator = typeSig.FindTypeRefs().GetEnumerator()) { while (enumerator.MoveNext()) { ITypeDefOrRef typeRef = enumerator.Current; TypeDef typeDef = typeRef.ResolveTypeDefThrow(); if (context.Modules.Contains((ModuleDefMD)typeDef.Module)) { if (typeRef is TypeRef) { service.AddReference <TypeDef>(typeDef, new TypeRefReference((TypeRef)typeRef, typeDef)); } service.ReduceRenameMode(typeDef, RenameMode.ASCII); } } return; } } if (arg.Value is CAArgument[]) { CAArgument[] array = (CAArgument[])arg.Value; for (int i = 0; i < array.Length; i++) { CAArgument elem = array[i]; this.AnalyzeCAArgument(context, service, elem); } } }
// Token: 0x06000022 RID: 34 RVA: 0x0000321C File Offset: 0x0000141C private void HandleEnum(ConfuserContext context, INameService service, MethodDef method, int index) { IMethod target = (IMethod)method.Body.Instructions[index].Operand; if (target.FullName == "System.String System.Object::ToString()" || target.FullName == "System.String System.Enum::ToString(System.String)") { int prevIndex = index - 1; while (prevIndex >= 0 && method.Body.Instructions[prevIndex].OpCode.Code == Code.Nop) { prevIndex--; } if (prevIndex < 0) { return; } Instruction prevInstr = method.Body.Instructions[prevIndex]; TypeSig targetType; if (prevInstr.Operand is MemberRef) { MemberRef memberRef = (MemberRef)prevInstr.Operand; targetType = (memberRef.IsFieldRef ? memberRef.FieldSig.Type : memberRef.MethodSig.RetType); } else if (prevInstr.Operand is IField) { targetType = ((IField)prevInstr.Operand).FieldSig.Type; } else if (prevInstr.Operand is IMethod) { targetType = ((IMethod)prevInstr.Operand).MethodSig.RetType; } else if (prevInstr.Operand is ITypeDefOrRef) { targetType = ((ITypeDefOrRef)prevInstr.Operand).ToTypeSig(); } else if (prevInstr.GetParameter(method.Parameters) != null) { targetType = prevInstr.GetParameter(method.Parameters).Type; } else { if (prevInstr.GetLocal(method.Body.Variables) == null) { return; } targetType = prevInstr.GetLocal(method.Body.Variables).Type; } ITypeDefOrRef targetTypeRef = targetType.ToBasicTypeDefOrRef(); if (targetTypeRef == null) { return; } TypeDef targetTypeDef = targetTypeRef.ResolveTypeDefThrow(); if (targetTypeDef != null && targetTypeDef.IsEnum && context.Modules.Contains((ModuleDefMD)targetTypeDef.Module)) { this.DisableRename(service, targetTypeDef, true); } } }
public bool TypeEquals(ITypeDefOrRef td, Type t) { if (!AssemblyEquals(td.Module.Assembly, t.Assembly) || td.FullName != t.FullName) { return(false); } return(TypeEquals(td.ResolveTypeDefThrow(), t)); }
public static TypeDef ResolveOrThrow(this ITypeDefOrRef type) { try { return(type.ResolveTypeDefThrow()); } catch (TypeResolveException ex) { throw new ReferenceResolvingException(ex.Message, ex); } }
TypeDef GetAttributeType(IDnlibDef attr) { ITypeDefOrRef retType = null; if (attr is PropertyDef) { retType = ((PropertyDef)attr).PropertySig.RetType.ToBasicTypeDefOrRef(); } else if (attr is EventDef) { retType = ((EventDef)attr).EventType; } return((retType == null) ? null : retType.ResolveTypeDefThrow()); throw new UnreachableException(); }
CANamedArgument Clone(ITypeDefOrRef sourceType, CANamedArgument source) { var name = source.Name; var st = sourceType.ResolveTypeDefThrow(); var member = source.IsField ? (IMemberDef)st.FindFieldCheckBaseType(name) : st.FindPropertyCheckBaseType(name); if (Context.Plugin <INaming>().FindNewName(member, out _, out var newName)) { name = newName; } return(new CANamedArgument(source.IsField, Importer.Import(source.Type), name, Clone(source.Argument))); }
Tuple <IDnlibDef, AttributeInfoRecord, TypeDef> AnalyzeAttributeReference(TypeDef declType, AttributeInfoRecord rec) { IDnlibDef retDef = null; ITypeDefOrRef retType = null; while (declType != null) { var property = declType.FindProperty(rec.Name); if (property != null) { retDef = property; retType = property.PropertySig.RetType.ToBasicTypeDefOrRef(); if (context.Modules.Contains((ModuleDefMD)declType.Module)) { service.AddReference(property, new BAMLAttributeReference(property, rec)); } break; } var evt = declType.FindEvent(rec.Name); if (evt != null) { retDef = evt; retType = evt.EventType; if (context.Modules.Contains((ModuleDefMD)declType.Module)) { service.AddReference(evt, new BAMLAttributeReference(evt, rec)); } break; } if (declType.BaseType == null) { break; } declType = declType.BaseType.ResolveTypeDefThrow(); } return(Tuple.Create(retDef, rec, retType == null ? null : retType.ResolveTypeDefThrow())); }
IMethod ResolveMethod_Helper(ITypeDefOrRef declaringType, MethodData data) { TypeDef declaringDef = declaringType.ResolveTypeDefThrow(); MethodSig methodSig = GetMethodSig(data); // Has a GenericMVar if (data.HasGenericArguments) { MethodSig detectedSig = null; MethodDef method = FindMethodCheckBaseType(declaringType, data, out detectedSig); if (method == null || detectedSig == null) { throw new Exception(String.Format( "Unable to find generic method from the declaring/base types: DeclaringType={0}, MethodName={1}, MethodSig={2}", declaringType.ReflectionFullName, data.Name, methodSig)); } MethodSpec methodSpec = new MethodSpecUser(method, ToGenericInstMethodSig(data)); return this.Importer.Import(methodSpec); } else // No GenericMVars { MethodDef method = declaringDef.FindMethodCheckBaseType(data.Name, methodSig); if (method == null) { throw new Exception(String.Format( "Unable to find method from the declaring/base types: DeclaringType={0}, MethodName={1}, MethodSig={2}", declaringType.ReflectionFullName, data.Name, methodSig)); } return this.Importer.Import(method); } }
public bool TypeEquals(ITypeDefOrRef td, Type t) { if (!AssemblyEquals(td.Module.Assembly, t.Assembly) || td.FullName != t.FullName) return false; return TypeEquals(td.ResolveTypeDefThrow(), t); }