Exemplo n.º 1
0
        internal void InspectType(IDependencyReport report, TypeReference typeRef,
                                  TypeDefinition typeDef, MemberReference[] myMembers, INamingStrategy strategy)
        {
            if (typeDef == null)
            {
                return;
            }
            var   purged     = report.Units;
            var   invRef     = typeDef.Module.Assembly;
            var   invRefName = strategy.GetName(invRef);
            IUnit purge;

            if (!purged.TryGetValue(invRefName, out purge))
            {
                purged[invRefName] = purge = new AssemblyUnit(invRefName, new Version(0, 0, 0, 0));
            }
            var   kind        = typeDef.GetTypeKind();
            var   typeDefName = strategy.GetName(typeDef);
            IType ptype;

            if (!purge.Types.TryGetValue(typeDefName, out ptype))
            {
                purge.Types[typeDefName] = ptype = new AssemblyType(typeDefName, kind);
            }
            var members = myMembers ?? typeDef.GetAllMembers();

            switch (kind)
            {
            case TypeKind.Enum:
                InspectEnum(ptype, typeDef);
                break;

            case TypeKind.Delegate:
                InspectDelegate(ptype, typeDef);
                break;

            case TypeKind.Struct:
            case TypeKind.Interface:
                InspectMembers(ptype, members);
                ExtractGenerics(ptype, typeDef);
                ExtractBases(ptype, typeDef);
                break;

            case TypeKind.Class:
                InspectClass(ptype, typeRef, typeDef, members);
                break;
            }
        }
Exemplo n.º 2
0
        private void Process(string name, IEnumerable <TypeDefinition> types,
                             IMetadataTokenProvider invRef, IDependencyReport report)
        {
            var             units           = report.Units;
            var             nativeTypeName  = Capitalize(Path.GetFileNameWithoutExtension(name));
            var             collot          = new TypeCollector();
            INamingStrategy nameArgStrategy = null;

            foreach (var meth in types.SelectMany(t => t.Methods))
            {
                PInvokeInfo pinv;
                if (!meth.HasPInvokeInfo || invRef != (pinv = meth.PInvokeInfo).Module)
                {
                    continue;
                }
                var   nativeMethName = pinv.EntryPoint;
                var   retType        = Deobfuscate(meth.ReturnType.ToString());
                var   parms          = Deobfuscate(GetParamStr(meth));
                var   key            = $"{nativeMethName} {retType} {parms}";
                IUnit unit;
                if (!units.TryGetValue(name, out unit))
                {
                    units[name] = unit = new AssemblyUnit(nativeTypeName, new Version("0.0.0.0"));
                }
                IType ptype;
                if (!unit.Types.TryGetValue(nativeTypeName, out ptype))
                {
                    unit.Types[nativeTypeName] = ptype = new AssemblyType(nativeTypeName, TypeKind.Class);
                }
                nameArgStrategy = new NativeArgNameStrategy(ptype);
                collot.Collect(meth);
                var newRetType  = nameArgStrategy.GetName(meth.ReturnType);
                var methRetType = Deobfuscate(meth.ReturnType.FullName);
                if (newRetType != null)
                {
                    methRetType = newRetType;
                }
                IMethod pmethod;
                if (!ptype.Methods.TryGetValue(key, out pmethod))
                {
                    ptype.Methods[key] = pmethod = new AssemblyMethod(nativeMethName, methRetType);
                }
                pmethod.Parameters.Clear();
                foreach (var parm in meth.Parameters)
                {
                    var newParmType = nameArgStrategy.GetName(parm.ParameterType);
                    var mparmType   = Deobfuscate(parm.ParameterType.FullName);
                    if (newParmType != null)
                    {
                        mparmType = newParmType;
                    }
                    var mparm = new MethodParameter(parm.Name, mparmType);
                    pmethod.Parameters.Add(mparm);
                }
                const StringSplitOptions sso = StringSplitOptions.None;
                var text = $"{meth}".Split(new[] { $"{meth.ReturnType}" }, 2, sso).Last().Trim();
                pmethod.Aliases.Add(Deobfuscate(text));
            }
            if (nameArgStrategy == null)
            {
                return;
            }
            foreach (var type in collot.Types)
            {
                CheckAndInclude(report, type, nameArgStrategy);
            }
            RewriteTypeNames(collot, nameArgStrategy, report);
        }