예제 #1
0
        public static INode Read(InspectableAssembly ia, MethodSignature signature, MethodBodyBlock rawBody)
        {
            /*Console.WriteLine("=== IL Bytes ===");
            foreach (var b in ilBytes)
                Console.Write("{0:X2} ", b);
            Console.WriteLine();*/

            var parser = new ILMethodParser(ia, signature, rawBody);
            return parser.Parse();
        }
        public MethodSignature Clone()
        {
            var ret = new MethodSignature()
            {
                ReturnType = ReturnType,
                Flags = Flags,
                ThisType = ThisType,
                NumGeneric = NumGeneric,
                NumNormal = NumNormal,
                ParameterTypes = new List<ElementType>()
            };

            foreach (var type in ParameterTypes)
                ret.ParameterTypes.Add(type);

            return ret;
        }
예제 #3
0
        public static MethodSignature ParseMethodSignature(InspectableAssembly ia, byte[] blob)
        {
            var ret = new MethodSignature();

            int index = 0;

            ret.Flags = (EMethodFlags)blob[index++];
            if (ret.Flags.HasFlag(EMethodFlags.Generic))
                ret.NumGeneric = UncompressInt(blob, ref index);
     
            ret.NumNormal = UncompressInt(blob, ref index);

            ret.ReturnType = ReadType(ia, blob, ref index);
            if (ret.Flags.HasFlag(EMethodFlags.ExplicitThis))
            {
                ret.ThisType = ReadType(ia, blob, ref index);
                ret.NumNormal--;
            }

            for(int i = 0; i < ret.NumNormal; i++)
            {
                ret.ParameterTypes.Add(ReadType(ia, blob, ref index));
            }

            return ret;
        }
        public void ParseMethods(MethodDefinitionHandleCollection methods, string name, MethodSignature signature)
        {
            foreach (var methodHandle in methods)
            {
                var method = Reader.GetMethodDefinition(methodHandle);
                var methodName = Reader.GetString(method.Name);

                if (name == string.Empty || name == methodName)
                {

                    if (signature != null)
                    {
                        var sig = ILReader.ParseMethodSignature(this, Reader.GetBlobBytes(method.Signature));
#if DEBUG_SIG
                        Console.WriteLine("=== Sig ===");
                        foreach (var b in sig)
                            Console.Write("{0:X2} ", b);
                        Console.WriteLine();
#endif
                        if (sig != signature)
                            continue;
                    }

                    var m = ParseMethodHeader(methodHandle, false);
                    ParseMethodBody(m);
                }
            }
        }
        public void ParseClass(TypeDefinitionHandle typeHandle, string methodName = "", MethodSignature signature = null)
        {
            var type = Reader.GetTypeDefinition(typeHandle);
            var typeName = Reader.GetString(type.Name);

            if (CilParser.IgnoreClassList.Contains(typeName))
                return;

            var fqName = GetFullyQualifiedName(type);
            Class clazz;
            if (Context.Program.Classes.ContainsKey(fqName))
                clazz = Context.Program.Classes[fqName];
            else
            {
                clazz = new Class(fqName);
                Context.AddClass(this, typeHandle, clazz);
            }

            //Console.WriteLine("=== Class: " + fqName + " ===");
            if (methodName != null)
            {
                ParseMethods(type.GetMethods(), methodName, signature);
            }
        }