Ejemplo n.º 1
0
        /// <summary>Get fat method header sections</summary>
        /// <returns>Method header sections</returns>
        public IEnumerable <MethodSection> GetSections()
        {
            UInt32 padding      = this.Row.RVA + this.Header.HeaderSize;
            UInt32 methodLength = this.Header.CodeSize;

            if ((this.Header.Format & Cor.CorILMethod.FatFormat) == Cor.CorILMethod.FatFormat &&
                (this.Header.Format & Cor.CorILMethod.MoreSects) == Cor.CorILMethod.MoreSects)
            {
                padding += methodLength;
                PEHeader header       = this.Row.Row.Table.Root.Parent.Parent.Parent.Header;
                Boolean  moreSections = true;

                while (moreSections)
                {
                    //Each section should start on a 4 byte boundary
                    //so let's read from the stream until we find the next boundary.
                    padding = NativeMethods.AlignToInt(padding);
                    Cor.CorILMethodSection section = header.PtrToStructure <Cor.CorILMethodSection>(padding);
                    padding += MethodBody.SizeOfMethodSection;

                    //I have never seen anything else than an exception handling section...
                    //According to the documentation "Currently, the method data sections
                    //are only used for exception tables."
                    if ((section.Kind & Cor.CorILMethod_Sect.EHTable) != Cor.CorILMethod_Sect.EHTable)
                    {
                        throw new NotImplementedException("Only exception table supported");
                    }

                    //Check whether more sections follow after this one.
                    moreSections = section.HasMoreSections;

                    Cor.CorILMethodExceptionFat[]   fat   = new Cor.CorILMethodExceptionFat[section.IsFatFormat ? section.ClauseNumber : 0];
                    Cor.CorILMethodExceptionSmall[] small = new Cor.CorILMethodExceptionSmall[section.IsFatFormat ? 0 : section.ClauseNumber];
                    //Let's read the clauses...
                    for (Int32 clauseIndex = 0; clauseIndex < section.ClauseNumber; clauseIndex++)
                    {
                        //The structure of the clauses are the same in both Fat and
                        //Small format, only the sizes are different.
                        if (section.IsFatFormat)
                        {
                            fat[clauseIndex] = header.PtrToStructure <Cor.CorILMethodExceptionFat>(padding);
                            padding         += MethodBody.SizeOfMethodExceptionFat;
                        }
                        else
                        {
                            small[clauseIndex] = header.PtrToStructure <Cor.CorILMethodExceptionSmall>(padding);
                            padding           += MethodBody.SizeOfMethodExceptionSmall;
                        }
                    }
                    yield return(new MethodSection(section, fat, small));
                }
            }
        }
Ejemplo n.º 2
0
 internal MethodSection(Cor.CorILMethodSection section, Cor.CorILMethodExceptionFat[] fat, Cor.CorILMethodExceptionSmall[] small)
 {
     this.Section = section;
     this.Fat     = fat;
     this.Small   = small;
 }