Пример #1
0
        public void writeSectionData(BinaryOut outfile)
        {
            uint pos = outfile.getPos();

            outfile.putRange(data.ToArray());

            //these get written directly after the section data
            CoffRelocation.write(outfile, relocTblPos);
            uint padding = fileSize - (outfile.getPos() - pos);

            outfile.putZeros(padding);
        }
Пример #2
0
        public void writeOut(BinaryOut outfile)
        {
            outfile.putTwo(signature);

            outfile.putTwo(lastsize);
            outfile.putTwo(nblocks);
            outfile.putTwo(nreloc);
            outfile.putTwo(hdrsize);
            outfile.putTwo(minalloc);
            outfile.putTwo(maxalloc);
            outfile.putTwo(ss);
            outfile.putTwo(sp);
            outfile.putTwo(checksum);
            outfile.putTwo(ip);
            outfile.putTwo(cs);
            outfile.putTwo(relocpos);
            outfile.putTwo(noverlay);
            outfile.putZeros(8);
            outfile.putTwo(oem_id);
            outfile.putTwo(oem_info);
            outfile.putZeros(20);
            outfile.putFour(e_lfanew);
            outfile.putRange(stub);
        }
Пример #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();
        }