Пример #1
0
        internal MethodBodySection ReadFatSection(byte flag)
        {
            MethodBodySection section = new MethodBodySection(flag);
            peImage.SetOffset(peImage.Stream.Position - 1);
            int count = (BitConverter.ToInt32(peImage.ReadBytes(4),0) >> 8) / 0x18;

            for (int i = 0; i < count; i++)
            {
               ExceptionHandler handler = new ExceptionHandler((ExceptionHandlerType)(BitConverter.ToInt32(peImage.ReadBytes(4),0) & 7),
                        BitConverter.ToInt32(peImage.ReadBytes(4), 0),
                        BitConverter.ToInt32(peImage.ReadBytes(4), 0),
                        BitConverter.ToInt32(peImage.ReadBytes(4), 0),
                        BitConverter.ToInt32(peImage.ReadBytes(4), 0));

                if (handler.Type == ExceptionHandlerType.Catch)
                    try
                    {
                        handler.CatchType = (TypeReference)methodbody.Method._netheader.TokenResolver.ResolveMember(BitConverter.ToUInt32(peImage.ReadBytes(4), 0));
                    }
                    catch { handler.CatchType = methodbody.Method._netheader.TypeSystem.Object; }

                else if (handler.Type == ExceptionHandlerType.Filter)
                    handler.FilterStart = BitConverter.ToInt32(peImage.ReadBytes(4), 0);
                else
                    peImage.ReadBytes(4);
                section._handlers.Add(handler);
            }
            return section;
        }
Пример #2
0
        internal MethodBodySection ReadSmallSection(byte flag)
        {
            MethodBodySection section = new MethodBodySection(flag);

            int count = peImage.Reader.ReadByte() / 12;
            peImage.ReadBytes(2);

            for (int i = 0; i < count; i++)
            {
                ExceptionHandler handler = new ExceptionHandler((ExceptionHandlerType)(BitConverter.ToInt16(peImage.ReadBytes(2), 0) & 7),
                        BitConverter.ToInt16(peImage.ReadBytes(2), 0),
                        peImage.Reader.ReadByte(),
                        BitConverter.ToInt16(peImage.ReadBytes(2), 0),
                        peImage.Reader.ReadByte());

                if (handler.Type == ExceptionHandlerType.Catch)
                    handler.CatchType = (TypeReference)methodbody.Method._netheader.TokenResolver.ResolveMember(BitConverter.ToUInt32(peImage.ReadBytes(4), 0));
                else if (handler.Type == ExceptionHandlerType.Filter)
                    handler.FilterStart = BitConverter.ToInt32(peImage.ReadBytes(4), 0);
                else
                    peImage.ReadBytes(4);
                section._handlers.Add(handler);

            }
            return section;
        }