Пример #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.ToInt32(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
        private void AppendExceptionHandler(ExceptionHandler handler, BinaryWriter writer, bool fatFormat)
        {
            if (fatFormat)
            {
                writer.Write((uint)handler.Type);
                writer.Write(handler.TryStart);
                writer.Write(handler.TryEnd - handler.TryStart);
                writer.Write(handler.HandlerStart);
                writer.Write(handler.HandlerEnd - handler.HandlerStart);

                if (handler.CatchType == null)
                    writer.Write(0);
                else
                    writer.Write(handler.CatchType.MetaDataToken);

                writer.Write(handler.FilterStart);
            }
            else
            {
                writer.Write((ushort)handler.Type);
                writer.Write((ushort)handler.TryStart);
                writer.Write((byte)(handler.TryEnd - handler.TryStart));
                writer.Write((ushort)handler.HandlerStart);
                writer.Write((byte)(handler.HandlerEnd - handler.HandlerStart));

                if (handler.CatchType == null)
                    writer.Write(0);
                else
                    writer.Write(handler.CatchType.MetaDataToken);

                writer.Write(handler.FilterStart);
            }
        }
Пример #3
0
        internal MethodBodySection ReadSmallSection(byte flag)
        {
            MethodBodySection section = new MethodBodySection(flag);

            int count = peImage.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.ReadByte(),
                        BitConverter.ToInt16(peImage.ReadBytes(2), 0),
                        peImage.ReadByte());

                if (handler.Type == ExceptionHandlerType.Catch)
                    handler.CatchType = (TypeReference)methodbody.Method.netheader.TokenResolver.ResolveMember(BitConverter.ToInt32(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;
        }