예제 #1
0
        private void SecondOption(object obj)
        {
            byte[] fieldValue = SuperDynamicReader.GetFieldValue <byte[]>(obj, "m_code");
            bool   flag       = fieldValue == null;
            bool   flag2      = flag;

            if (flag2)
            {
                throw new Exception("No code");
            }
            this.codeSize = fieldValue.Length;
            MethodBase fieldValue2 = SuperDynamicReader.GetFieldValue <MethodBase>(obj, "m_method");
            bool       flag3       = fieldValue2 == null;
            bool       flag4       = flag3;

            if (flag4)
            {
                throw new Exception("No method");
            }
            this.maxStack = SuperDynamicReader.GetFieldValue <int>(obj, "m_maxStackSize");
            object fieldValue3 = SuperDynamicReader.GetFieldValue <object>(obj, "m_scope");
            bool   flag5       = fieldValue3 == null;
            bool   flag6       = flag5;

            if (flag6)
            {
                throw new Exception("No scope");
            }
            IList fieldValue4 = SuperDynamicReader.GetFieldValue <IList>(fieldValue3, "m_tokens");
            bool  flag7       = fieldValue4 == null;
            bool  flag8       = flag7;

            if (flag8)
            {
                throw new Exception("No tokens");
            }
            this.tokens = new List <object>(fieldValue4.Count);
            for (int i = 0; i < fieldValue4.Count; i++)
            {
                this.tokens.Add(fieldValue4[i]);
            }
            this.ehHeader = SuperDynamicReader.GetFieldValue <byte[]>(obj, "m_exceptions");
            this.UpdateLocals(SuperDynamicReader.GetFieldValue <byte[]>(obj, "m_localSignature"));
            this.reader     = MemoryImageStream.Create(fieldValue);
            this.method     = this.CreateMethodDef(fieldValue2);
            this.parameters = this.method.Parameters;
        }
예제 #2
0
        private void CreateExceptionHandlers()
        {
            bool flag  = this.ehHeader != null && this.ehHeader.Length != 0;
            bool flag2 = flag;

            if (flag2)
            {
                BinaryReader binaryReader = new BinaryReader(new MemoryStream(this.ehHeader));
                byte         b            = binaryReader.ReadByte();
                bool         flag3        = (b & 64) == 0;
                bool         flag4        = flag3;
                if (flag4)
                {
                    int num = (int)((ushort)((binaryReader.ReadByte() - 2) / 12));
                    binaryReader.ReadInt16();
                    for (int i = 0; i < num; i++)
                    {
                        dnlib.DotNet.Emit.ExceptionHandler exceptionHandler = new dnlib.DotNet.Emit.ExceptionHandler();
                        exceptionHandler.HandlerType = (ExceptionHandlerType)binaryReader.ReadInt16();
                        int num2 = (int)binaryReader.ReadUInt16();
                        exceptionHandler.TryStart = base.GetInstructionThrow((uint)num2);
                        exceptionHandler.TryEnd   = base.GetInstruction((uint)((int)binaryReader.ReadSByte() + num2));
                        num2 = (int)binaryReader.ReadUInt16();
                        exceptionHandler.HandlerStart = base.GetInstructionThrow((uint)num2);
                        exceptionHandler.HandlerEnd   = base.GetInstruction((uint)((int)binaryReader.ReadSByte() + num2));
                        bool flag5 = exceptionHandler.HandlerType == ExceptionHandlerType.Catch;
                        bool flag6 = flag5;
                        if (flag6)
                        {
                            exceptionHandler.CatchType = (this.ReadToken(binaryReader.ReadUInt32()) as ITypeDefOrRef);
                        }
                        else
                        {
                            bool flag7 = exceptionHandler.HandlerType == ExceptionHandlerType.Filter;
                            bool flag8 = flag7;
                            if (flag8)
                            {
                                exceptionHandler.FilterStart = base.GetInstruction(binaryReader.ReadUInt32());
                            }
                            else
                            {
                                binaryReader.ReadUInt32();
                            }
                        }
                        this.exceptionHandlers.Add(exceptionHandler);
                    }
                }
                else
                {
                    Stream baseStream = binaryReader.BaseStream;
                    long   position   = baseStream.Position;
                    baseStream.Position = position - 1L;
                    int num3 = (int)((ushort)(((binaryReader.ReadUInt32() >> 8) - 4U) / 24U));
                    for (int j = 0; j < num3; j++)
                    {
                        dnlib.DotNet.Emit.ExceptionHandler exceptionHandler2 = new dnlib.DotNet.Emit.ExceptionHandler();
                        exceptionHandler2.HandlerType = (ExceptionHandlerType)binaryReader.ReadInt32();
                        int num4 = binaryReader.ReadInt32();
                        exceptionHandler2.TryStart = base.GetInstructionThrow((uint)num4);
                        exceptionHandler2.TryEnd   = base.GetInstruction((uint)(binaryReader.ReadInt32() + num4));
                        num4 = binaryReader.ReadInt32();
                        exceptionHandler2.HandlerStart = base.GetInstructionThrow((uint)num4);
                        exceptionHandler2.HandlerEnd   = base.GetInstruction((uint)(binaryReader.ReadInt32() + num4));
                        bool flag9  = exceptionHandler2.HandlerType == ExceptionHandlerType.Catch;
                        bool flag10 = flag9;
                        if (flag10)
                        {
                            exceptionHandler2.CatchType = (this.ReadToken(binaryReader.ReadUInt32()) as ITypeDefOrRef);
                        }
                        else
                        {
                            bool flag11 = exceptionHandler2.HandlerType == ExceptionHandlerType.Filter;
                            bool flag12 = flag11;
                            if (flag12)
                            {
                                exceptionHandler2.FilterStart = base.GetInstruction(binaryReader.ReadUInt32());
                            }
                            else
                            {
                                binaryReader.ReadUInt32();
                            }
                        }
                        this.exceptionHandlers.Add(exceptionHandler2);
                    }
                }
            }
            else
            {
                bool flag13 = this.ehInfos != null;
                bool flag14 = flag13;
                if (flag14)
                {
                    foreach (SuperDynamicReader.ExceptionInfo exceptionInfo in SuperDynamicReader.CreateExceptionInfos(this.ehInfos))
                    {
                        Instruction instructionThrow = base.GetInstructionThrow((uint)exceptionInfo.StartAddr);
                        Instruction instruction      = base.GetInstruction((uint)exceptionInfo.EndAddr);
                        Instruction instruction2     = (exceptionInfo.EndFinally < 0) ? null : base.GetInstruction((uint)exceptionInfo.EndFinally);
                        for (int k = 0; k < exceptionInfo.CurrentCatch; k++)
                        {
                            dnlib.DotNet.Emit.ExceptionHandler exceptionHandler3 = new dnlib.DotNet.Emit.ExceptionHandler();
                            exceptionHandler3.HandlerType  = (ExceptionHandlerType)exceptionInfo.Type[k];
                            exceptionHandler3.TryStart     = instructionThrow;
                            exceptionHandler3.TryEnd       = ((exceptionHandler3.HandlerType == ExceptionHandlerType.Finally) ? instruction2 : instruction);
                            exceptionHandler3.FilterStart  = null;
                            exceptionHandler3.HandlerStart = base.GetInstructionThrow((uint)exceptionInfo.CatchAddr[k]);
                            exceptionHandler3.HandlerEnd   = base.GetInstruction((uint)exceptionInfo.CatchEndAddr[k]);
                            exceptionHandler3.CatchType    = this.importer.Import(exceptionInfo.CatchClass[k]);
                            this.exceptionHandlers.Add(exceptionHandler3);
                        }
                    }
                }
            }
        }