private void AppendSectionHeader(MethodBodySection section, BinaryWriter writer)
        {
            byte signature = 0x01;

            if (section.IsFat)
            {
                signature |= 0x40;
            }
            if (section.HasMoreSections)
            {
                signature |= 0x80;
            }

            writer.Write(signature);

            if (section.IsFat)
            {
                writer.Write((byte)((section.ExceptionHandlers.Length * 12) + 4));
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write(BitConverter.GetBytes((section.ExceptionHandlers.Length * 24) + 4), 0, 3);
            }
        }
示例#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);
        }
 private void AppendSection(MethodBodySection section, BinaryWriter writer)
 {
     AppendSectionHeader(section, writer);
     foreach (ExceptionHandler handler in section.ExceptionHandlers)
     {
         AppendExceptionHandler(handler, writer, section.IsFat);
     }
 }
示例#4
0
        internal void ReadSections()
        {
            peImage.SetOffset(rawoffset + methodbody.HeaderSize + methodbody.CodeSize);


            List <MethodBodySection> sections = new List <MethodBodySection>();
            MethodBodySection        section  = ReadSection();

            sections.Add(section);

            while (section.HasMoreSections)
            {
                section = ReadSection();
                sections.Add(section);
            }

            this.sections = sections.ToArray();
        }
示例#5
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);
        }