示例#1
0
        //- writing out to file -----------------------------------------------

        public void writeOboeFile(String outname)
        {
            BinaryOut outfile = new BinaryOut(outname);

            this.writeOboeFile(outfile);
            outfile.writeOut();
        }
示例#2
0
        public void writeToFile(String filename)
        {
            //layout .obj file
            uint filepos = 0x14;                               //coff hdr size

            //sections
            filepos += (uint)sections.Count * 0x28;            //add sec tbl size
            for (int i = 0; i < sections.Count; i++)           //add section data sizes
            {
                if (sections[i].data.Count > 0)
                {
                    sections[i].filePos  = filepos;
                    sections[i].fileSize = (uint)(sections[i].data.Count);
                    filepos += sections[i].fileSize;
                    uint relocsize = (uint)(sections[i].relocations.Count * 0x0a);
                    sections[i].relocTblPos = filepos;
                    filepos += relocsize;
                }
            }

            //symbolTblAddr = filepos;
            //filepos += (uint)symbols.Count * 0x12;           //add symbol tbl size
            //filepos += 0x04;
            //for (int i = 0; i < stringTbl.Count; i++)
            //{
            //    filepos += (uint)(stringTbl[i].Length + 1);    //add string tbl size
            //}

            //now we have the size of the .obj file, write it out to disk
            BinaryOut outfile = new BinaryOut(filename, filepos);

            writeCoffHeader(outfile);
            writeSectionTable(outfile);
            writeSectionData(outfile);
            writeSymbolTable(outfile);
            writeStringTable(outfile);

            outfile.writeOut();
        }
示例#3
0
        //private void getResourceTable(SourceFile source)
        //{
        //    if (optHeader.dataDirectory[DataDirectory.IMAGE_DIRECTORY_ENTRY_RESOURCE].size > 0)
        //    {
        //        uint resOfs = optHeader.dataDirectory[DataDirectory.IMAGE_DIRECTORY_ENTRY_RESOURCE].rva;
        //        uint resSize = optHeader.dataDirectory[DataDirectory.IMAGE_DIRECTORY_ENTRY_RESOURCE].size;
        //        Section resSec = findSection(resOfs);
        //        if (resSec != null)
        //        {
        //            SourceFile secData = new SourceFile(resSec.data);
        //            resourceTable = new ResourceTable();
        //            resourceTable.imageBase = imageBase;
        //            resourceTable.resourceRVA = resOfs;
        //            resourceTable.data = secData.getRange(resOfs - resSec.memloc, resSize);
        //        }
        //    }
        //}

        //- writing out ----------------------------------------------------------------

        public void writeFile(String _filename)
        {
            filename = _filename;
            mempos   = 0x1000;
            filepos  = 0;

            //build dos header
            if (dosHeader == null)
            {
                dosHeader = new MsDosHeader();
            }
            uint winHdrPos = (((dosHeader.headerSize + 7) / 8) * 8);

            dosHeader.e_lfanew = winHdrPos;

            //win hdr fields
            characteristics.isExecutable   = true;
            characteristics.is32BitMachine = true;
            if (isDLL)
            {
                characteristics.isDLL = true;
                imageBase             = 0x10000000; //dll default image base
            }

            uint sectionCount = (uint)sections.Count;

            if (exportList.Count > 0)
            {
                sectionCount++;
            }
            if (relocList.Count > 0)
            {
                sectionCount++;
            }
            filepos       = (winHdrPos + 0x18 + 0xe0 + (uint)(sectionCount * 0x28) + (fileAlignment - 1)) & ~(fileAlignment - 1);
            sizeOfHeaders = filepos;

            buildSectionTable();

            //build standard sections
            //int importSecNum = -1;
            //if (importTable != null)
            //{
            //    importSecNum = sections.Count;
            //    CoffSection importSection = importTable.createSection();
            //    sections.Add(importSection);
            //}

            if (exportList.Count > 0)
            {
                buildExportSection();
            }

            //int resourceSecNum = -1;
            //if (resourceTable != null)
            //{
            //    resourceSecNum = sections.Count;
            //    CoffSection resourceSection = resourceTable.createSection();
            //    sections.Add(resourceSection);
            //}

            if (relocList.Count > 0)
            {
                buildRelocSection();
            }

            sizeOfImage = mempos;     //total image size

            BinaryOut outfile = new BinaryOut(filename);

            dosHeader.writeOut(outfile);
            outfile.putZeros(winHdrPos - dosHeader.headerSize);

            writeCoffHeader(outfile);
            writeOptionalHeader(outfile);
            writeSectionTable(outfile);
            outfile.putZeros(sizeOfHeaders - outfile.getPos());
            writeSectionData(outfile);

            outfile.writeOut();
        }