Ejemplo n.º 1
0
        public void writeOboeFile(BinaryOut outfile)
        {
            //write header
            outfile.putFixedString(OBOESIG, 4);
            outfile.putFour((uint)sections.Count);

            //write initial section tbl
            uint sectblsize = (uint)(sections.Count * SECTIONENTRYSIZE);
            uint sectbl     = outfile.getPos();

            outfile.skip(sectblsize);

            //write section data
            uint pos = outfile.getPos();

            foreach (Section sec in sections)
            {
                sec.addr = pos;
                sec.writeOut(outfile);
                pos      = outfile.getPos();
                sec.size = pos - sec.addr;
            }

            //adjust section tbl
            outfile.seek(sectbl);
            foreach (Section sec in sections)
            {
                outfile.putFour(sec.sectype);
                outfile.putFour(sec.addr);
                outfile.putFour(sec.size);
            }
        }
Ejemplo n.º 2
0
        //- writing out -------------------------------------------------------

        public override void writeOut(BinaryOut outfile)
        {
            base.writeOut(outfile);

            //initize block header
            uint hdrpos = outfile.getPos();

            outfile.skip(24);

            //write block data
            uint blockaddr = outfile.getPos();
            uint blocksize = (uint)blockdata.Count;

            outfile.putRange(blockdata.ToArray());

            //write import list
            uint importaddr  = outfile.getPos();
            uint importcount = (uint)imports.Count;

            foreach (ImportEntry imp in imports)
            {
                imp.writeToFile(outfile);
            }

            //write export list
            uint exportaddr  = outfile.getPos();
            uint exportcount = (uint)exports.Count;

            foreach (ExportEntry exp in exports)
            {
                exp.writeToFile(outfile);
            }
            uint endpos = outfile.getPos();

            //go back and adjust block header
            outfile.seek(hdrpos);
            outfile.putFour(blockaddr);
            outfile.putFour(blocksize);
            outfile.putFour(importaddr);
            outfile.putFour(importcount);
            outfile.putFour(exportaddr);
            outfile.putFour(exportcount);
            outfile.seek(endpos);
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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;
        }