示例#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 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);
            }
        }
示例#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;
        }
示例#4
0
 private void AppendSection(MethodBodySection section, BinaryWriter writer)
 {
     AppendSectionHeader(section, writer);
     foreach (ExceptionHandler handler in section.ExceptionHandlers)
         AppendExceptionHandler(handler, writer, section.IsFat);
 }