예제 #1
0
        private static void InspectMethod(IType type, MethodReference meth)
        {
            var     methName = Deobfuscate(meth.Name);
            var     retType  = Deobfuscate(meth.ReturnType.FullName);
            var     parms    = Deobfuscate(GetParamStr(meth));
            var     key      = $"{methName} {retType} {parms}";
            IMethod pmethod;

            if (!type.Methods.TryGetValue(key, out pmethod))
            {
                type.Methods[key] = pmethod = new AssemblyMethod(methName, retType);
            }
            pmethod.Parameters.Clear();
            foreach (var parm in meth.Parameters)
            {
                var parmName = Deobfuscate(parm.Name);
                var pparm    = new MethodParameter(parmName, Deobfuscate(parm.ParameterType.FullName));
                pmethod.Parameters.Add(pparm);
            }
        }
예제 #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);
        }