Пример #1
0
        public void buildRelocSection()
        {
            relocList.Sort();

            BinaryOut relData   = new BinaryOut();
            uint      basepage  = relocList[0].addr & 0xFFFFF000;
            uint      blocksize = 8;

            relData.putFour(basepage);
            uint blockstart = relData.getPos();

            relData.putFour(0);
            foreach (CoffRelocationEntry rel in relocList)
            {
                uint page = rel.addr & 0xFFFFF000;
                if (page != basepage)
                {
                    if (blocksize % 4 != 0)
                    {
                        relData.putTwo(0);
                        blocksize += 2;
                    }
                    uint blockend = relData.getPos();
                    relData.seek(blockstart);
                    relData.putFour(blocksize);
                    relData.seek(blockend);
                    basepage  = page;
                    blocksize = 8;
                    relData.putFour(basepage);
                    blockstart = relData.getPos();
                    relData.putFour(0);
                }
                uint ofs = rel.addr % 0x1000;
                ofs += 0x3000;
                relData.putTwo(ofs);
                blocksize += 2;
            }
            if (blocksize % 4 != 0)
            {
                relData.putTwo(0);
                blocksize += 2;
            }
            relData.seek(blockstart);
            relData.putFour(blocksize);

            relocSec      = new CoffSection(".reloc");
            relocSec.data = new List <byte>(relData.getData());
            uint datasize = (uint)relocSec.data.Count;

            relocSec.filePos  = filepos;
            relocSec.fileSize = (datasize + (fileAlignment - 1)) & ~(fileAlignment - 1);
            filepos          += relocSec.fileSize;

            relocSec.memPos  = mempos;
            relocSec.memSize = datasize;
            mempos          += (datasize + (memAlignment - 1)) & ~(memAlignment - 1);

            relocSec.settings.canRead     = true;
            relocSec.settings.hasInitData = true;
            relocSec.settings.canDiscard  = true;

            uint msize = (relocSec.memSize + fileAlignment - 1) & ~(fileAlignment - 1);

            sizeOfInitializedData += msize;

            sections.Add(relocSec);
            baseRelocationTable.rva  = relocSec.memPos;
            baseRelocationTable.size = relocSec.memSize;
        }
Пример #2
0
        //standard sections
        public void buildExportSection()
        {
            uint      ordinalBase = 1;
            BinaryOut expData     = new BinaryOut();

            expData.putFour(0);
            expData.putFour((uint)getTimestamp());
            expData.putTwo(1);
            expData.putTwo(0);
            expData.putFour(0);                             //filename addr
            expData.putFour(ordinalBase);
            expData.putFour((uint)exportList.Count);
            expData.putFour((uint)exportList.Count);
            expData.putFour(0x28 + mempos);
            uint expnametbl = 0x28 + 4 * (uint)exportList.Count;

            expData.putFour(expnametbl + mempos);
            uint ordtbl = expnametbl + 4 * (uint)exportList.Count;

            expData.putFour(ordtbl + mempos);

            //export addr tbl
            foreach (CoffExportEntry exp in exportList)
            {
                expData.putFour(exp.addr);
            }

            //export name tbl
            expData.skip(4 * (uint)exportList.Count);

            //ordinal number tbl
            foreach (CoffExportEntry exp in exportList)
            {
                expData.putTwo(exp.ord - ordinalBase);
            }

            uint faddr = expData.getPos() + mempos;

            expData.putString(filename);
            List <uint> nameaddrs = new List <uint>();

            foreach (CoffExportEntry exp in exportList)
            {
                nameaddrs.Add(expData.getPos() + mempos);
                expData.putString(exp.name);
            }

            expData.seek(0xc);
            expData.putFour(faddr);
            expData.seek(expnametbl);
            foreach (uint nameaddr in nameaddrs)
            {
                expData.putFour(nameaddr);
            }

            exportSec      = new CoffSection(".edata");
            exportSec.data = new List <byte>(expData.getData());
            uint datasize = (uint)exportSec.data.Count;

            exportSec.filePos  = filepos;
            exportSec.fileSize = (datasize + (fileAlignment - 1)) & ~(fileAlignment - 1);
            filepos           += exportSec.fileSize;

            exportSec.memPos  = mempos;
            exportSec.memSize = datasize;
            mempos           += (datasize + (memAlignment - 1)) & ~(memAlignment - 1);

            exportSec.settings.canRead     = true;
            exportSec.settings.hasInitData = true;

            uint msize = (exportSec.memSize + fileAlignment - 1) & ~(fileAlignment - 1);

            sizeOfInitializedData += msize;

            sections.Add(exportSec);
            dExportTable.rva  = exportSec.memPos;
            dExportTable.size = exportSec.memSize;
        }