Exemple #1
0
        private void CalcOffsets()
        {
            if (sdata != null)
            {
                numSections++;
            }
            if (rsrc != null)
            {
                numSections++;
            }
            headerSize    = FileImage.fileHeaderSize + (numSections * FileImage.sectionHeaderSize);
            headerPadding = NumToAlign(headerSize, verInfo.fileAlign);
            headerSize   += headerPadding;
            uint offset = headerSize;
            uint rva    = FileImage.SectionAlignment;

            text.SetOffset(offset);
            text.SetRVA(rva);
            if (pdbWriter != null)
            {
                debugRVA = rva + debugOffset;
            }
            offset += text.Size();
            rva     = GetNextSectStart(rva, text.Tide());
            // Console.WriteLine("headerSize = " + headerSize);
            // Console.WriteLine("headerPadding = " + headerPadding);
            // Console.WriteLine("textOffset = " + Hex.Int(text.Offset()));
            if (sdata != null)
            {
                sdata.SetOffset(offset);
                sdata.SetRVA(rva);
                foreach (DataConstant cVal in data)
                {
                    cVal.DataOffset = sdata.Tide();
                    sdata.IncTide(cVal.GetSize());
                }
                sdata.SetSize(NumToAlign(sdata.Tide(), verInfo.fileAlign));
                offset       += sdata.Size();
                rva           = GetNextSectStart(rva, sdata.Tide());
                initDataSize += sdata.Size();
            }
            if (rsrc != null)
            {
                //Console.WriteLine("Resource section is not null");
                rsrc.SetSize(NumToAlign(rsrc.Tide(), verInfo.fileAlign));
                rsrc.SetOffset(offset);
                rsrc.SetRVA(rva);
                offset       += rsrc.Size();
                rva           = GetNextSectStart(rva, rsrc.Tide());
                initDataSize += rsrc.Size();
            }
            relocOffset = offset;
            relocRVA    = rva;
        }