Exemplo 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);
            }
        }
Exemplo n.º 2
0
 public void writeSectionTable(BinaryOut outfile)
 {
     for (int i = 0; i < sections.Count; i++)
     {
         sections[i].writeSectionTblEntry(outfile);
     }
 }
Exemplo n.º 3
0
 public void writeSectionData(BinaryOut outfile)
 {
     for (int i = 0; i < sections.Count; i++)
     {
         sections[i].writeSectionData(outfile);
     }
 }
Exemplo n.º 4
0
 public void writeToFile(BinaryOut outfile)
 {
     outfile.putString(name);
     outfile.putFour((uint)addr);
     //int b = (typ == IMPORTTYPE.DIR32) ? 0 : 1;
     outfile.putOne((uint)typ);
 }
Exemplo n.º 5
0
 public void writeSymbolTable(BinaryOut outfile)
 {
     for (int i = 0; i < symbols.Count; i++)
     {
         symbols[i].writeSymbol(outfile);
     }
 }
Exemplo n.º 6
0
        //- writing out to file -----------------------------------------------

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

            this.writeOboeFile(outfile);
            outfile.writeOut();
        }
Exemplo n.º 7
0
        public void Dump()
        {
            var binaryOut = new BinaryOut(_bitsPerLine);

            binaryOut.ResetTotal();
            binaryOut.Write(_text);
            Console.WriteLine($"{binaryOut.TotalBits} bits");
        }
Exemplo n.º 8
0
        //- writing out ---------------------------------------------------------------

        public void writeCoffHeader(BinaryOut outfile)
        {
            //outfile.putTwo((uint)machine);
            //outfile.putTwo((uint)sections.Count);
            //outfile.putFour(timeStamp);
            //outfile.putFour(symbolTblAddr);
            //outfile.putFour((uint)symbols.Count);
            //outfile.putTwo((uint)0);                        //no line number entries
            //outfile.putTwo((uint)characteristics);
        }
Exemplo n.º 9
0
        public override void writeOut(BinaryOut outfile)
        {
            base.writeOut(outfile);
            outfile.putFour(bssSize);
            outfile.putFour((uint)exports.Count);

            //write export list
            foreach (ExportEntry exp in exports)
            {
                exp.writeToFile(outfile);
            }
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
 public void writeStringTable(BinaryOut outfile)
 {
     //uint tblSize = 4;
     //for (int i = 0; i < stringTbl.Count; i++)
     //{
     //    tblSize += (uint)(stringTbl[i].Length + 1);
     //}
     //outfile.putFour(tblSize);
     //for (int i = 0; i < stringTbl.Count; i++)
     //{
     //    outfile.putString(stringTbl[i]);
     //}
 }
Exemplo n.º 12
0
        public void writeCoffHeader(BinaryOut outfile)
        {
            outfile.putFour(0x00004550);            //PE sig
            outfile.putTwo((uint)machine);
            outfile.putTwo((uint)sections.Count);
            outfile.putFour((uint)getTimestamp());
            outfile.putFour(0);                     //no symbol table
            outfile.putFour(0);
            outfile.putTwo(0xe0);                   //optional hdr size
            uint flagval = characteristics.encodeFlags();

            outfile.putTwo(flagval);
        }
Exemplo n.º 13
0
    /**/
    public static void main(string[] strarr)
    {
        int num = 16;

        if (strarr.Length == 1)
        {
            num = Integer.parseInt(strarr[0]);
        }
        int num2 = 0;

        while (!BinaryStdIn.IsEmpty)
        {
            if (num == 0)
            {
                BinaryStdIn.readBoolean();
            }
            else
            {
                if (num2 != 0)
                {
                    bool expr_28 = num2 != 0;
                    int  expr_2A = num;
                    if (expr_2A == -1 || (expr_28 ? 1 : 0) % expr_2A == 0)
                    {
                        StdOut.println();
                    }
                }
                if (BinaryStdIn.readBoolean())
                {
                    StdOut.print(1);
                }
                else
                {
                    StdOut.print(0);
                }
            }
            num2++;
        }
        if (num != 0)
        {
            StdOut.println();
        }
        StdOut.println(new StringBuilder().append(num2).append(" bits").toString());
    }
}

public sealed class BinaryIn
{
    private const int EOF = -1;
    private BufferedInputStream @in;
    private int buffer;
    private int N;


    private void fillBuffer()
    {
        try
        {
            this.buffer = [email protected]();
            this.N      = 8;
        }
        catch (IOException arg_1C_0)
        {
            goto IL_20;
        }
        return;

IL_20:
        System.err.println("EOF");
        this.buffer = -1;
        this.N      = -1;
    }

    public virtual bool IsEmpty
    {
        return(this.buffer == -1);
    }


    public virtual char readChar()
    {
        if (this.IsEmpty)
        {
            string arg_12_0 = "Reading from empty input stream";

            throw new RuntimeException(arg_12_0);
        }
        int num;

        if (this.N == 8)
        {
            num = this.buffer;
            this.fillBuffer();
            return((char)(num & 255));
        }
        num   = this.buffer;
        num <<= 8 - this.N;
        int n = this.N;

        this.fillBuffer();
        if (this.IsEmpty)
        {
            string arg_6B_0 = "Reading from empty input stream";

            throw new RuntimeException(arg_6B_0);
        }
        this.N = n;
        num   |= (int)((uint)this.buffer >> this.N);
        return((char)(num & 255));
    }

    public virtual bool readBoolean()
    {
        if (this.IsEmpty)
        {
            string arg_12_0 = "Reading from empty input stream";

            throw new RuntimeException(arg_12_0);
        }
        this.N--;
        int result = ((this.buffer >> this.N & 1) == 1) ? 1 : 0;

        if (this.N == 0)
        {
            this.fillBuffer();
        }
        return(result != 0);
    }

    public virtual int readInt()
    {
        int num = 0;

        for (int i = 0; i < 4; i++)
        {
            int num2 = (int)this.readChar();
            num <<= 8;
            num  |= num2;
        }
        return(num);
    }

    public virtual long readLong()
    {
        long num = 0L;

        for (int i = 0; i < 8; i++)
        {
            int num2 = (int)this.readChar();
            num <<= 8;
            num  |= (long)num2;
        }
        return(num);
    }

    public BinaryIn(string str)
    {
        try
        {
            File file = new File(str);
            if (!file.exists())
            {
                URL uRL = java.lang.Object.instancehelper_getClass(this).getResource(str);
                if (uRL == null)
                {
                    uRL = new URL(str);
                }
                URLConnection uRLConnection = uRL.openConnection();
                InputStream   inputStream   = uRLConnection.getInputStream();
                this.@in = new BufferedInputStream(inputStream);
                this.fillBuffer();
                goto IL_74;
            }
            FileInputStream fileInputStream = new FileInputStream(file);
            this.@in = new BufferedInputStream(fileInputStream);
            this.fillBuffer();
        }
        catch (IOException arg_71_0)
        {
            goto IL_76;
        }
        return;

IL_74:
        return;

IL_76:
        System.err.println(new StringBuilder().append("Could not open ").append(str).toString());
    }

    public BinaryIn()
    {
        BufferedInputStream.__ <clinit>();
        this.@in = new BufferedInputStream(System.@in);
        this.fillBuffer();
    }

    public BinaryIn(InputStream @is)
    {
        this.@in = new BufferedInputStream(@is);
        this.fillBuffer();
    }

    public BinaryIn(Socket s)
    {
        try
        {
            InputStream inputStream = s.getInputStream();
            this.@in = new BufferedInputStream(inputStream);
            this.fillBuffer();
        }
        catch (IOException arg_25_0)
        {
            goto IL_29;
        }
        return;

IL_29:
        System.err.println(new StringBuilder().append("Could not open ").append(s).toString());
    }

    public BinaryIn(URL url)
    {
        try
        {
            URLConnection uRLConnection = url.openConnection();
            InputStream   inputStream   = uRLConnection.getInputStream();
            this.@in = new BufferedInputStream(inputStream);
            this.fillBuffer();
        }
        catch (IOException arg_2C_0)
        {
            goto IL_30;
        }
        return;

IL_30:
        System.err.println(new StringBuilder().append("Could not open ").append(url).toString());
    }

    public virtual bool exists()
    {
        return(this.@in != null);
    }

    public virtual char readChar(int i)
    {
        if (i < 1 || i > 16)
        {
            string arg_28_0 = new StringBuilder().append("Illegal value of r = ").append(i).toString();

            throw new RuntimeException(arg_28_0);
        }
        if (i == 8)
        {
            return(this.readChar());
        }
        int num = 0;

        for (int j = 0; j < i; j++)
        {
            num = (int)((ushort)(num << 1));
            int num2 = this.readBoolean() ? 1 : 0;
            if (num2 != 0)
            {
                num = (int)((ushort)(num | 1));
            }
        }
        return((char)num);
    }

    public virtual string readString()
    {
        if (this.IsEmpty)
        {
            string arg_12_0 = "Reading from empty input stream";

            throw new RuntimeException(arg_12_0);
        }
        StringBuilder stringBuilder = new StringBuilder();

        while (!this.IsEmpty)
        {
            int c = (int)this.readChar();
            stringBuilder.append((char)c);
        }
        return(stringBuilder.toString());
    }

    public virtual short readShort()
    {
        int num = 0;

        for (int i = 0; i < 2; i++)
        {
            int num2 = (int)this.readChar();
            num = (int)((short)(num << 8));
            num = (int)((short)(num | num2));
        }
        return((short)num);
    }

    public virtual int readInt(int i)
    {
        if (i < 1 || i > 32)
        {
            string arg_28_0 = new StringBuilder().append("Illegal value of r = ").append(i).toString();

            throw new RuntimeException(arg_28_0);
        }
        if (i == 32)
        {
            return(this.readInt());
        }
        int num = 0;

        for (int j = 0; j < i; j++)
        {
            num <<= 1;
            int num2 = this.readBoolean() ? 1 : 0;
            if (num2 != 0)
            {
                num |= 1;
            }
        }
        return(num);
    }

    public virtual double readDouble()
    {
        DoubleConverter doubleConverter;

        return(DoubleConverter.ToDouble(this.readLong(), ref doubleConverter));
    }

    public virtual float readFloat()
    {
        FloatConverter floatConverter;

        return(FloatConverter.ToFloat(this.readInt(), ref floatConverter));
    }

    public virtual byte readByte()
    {
        int num = (int)this.readChar();

        return((byte)((sbyte)(num & 255)));
    }

    /**/
    public static void main(string[] strarr)
    {
        BinaryIn binaryIn = new BinaryIn(strarr[0]);

        BinaryOut.__ <clinit>();
        BinaryOut binaryOut = new BinaryOut(strarr[1]);

        while (!binaryIn.IsEmpty)
        {
            int ch = (int)binaryIn.readChar();
            binaryOut.write((char)ch);
        }
        binaryOut.flush();
    }
Exemplo n.º 14
0
        public void writeOptionalHeader(BinaryOut outfile)
        {
            outfile.putTwo(magicNum);
            outfile.putOne(majorLinkerVersion);
            outfile.putOne(minorLinkerVersion);
            outfile.putFour(sizeOfCode);
            outfile.putFour(sizeOfInitializedData);
            outfile.putFour(sizeOfUninitializedData);
            outfile.putFour(addressOfEntryPoint);
            outfile.putFour(baseOfCode);
            outfile.putFour(baseOfData);
            outfile.putFour(imageBase);
            outfile.putFour(memAlignment);
            outfile.putFour(fileAlignment);
            outfile.putTwo(majorOSVersion);
            outfile.putTwo(minorOSVersion);
            outfile.putTwo(majorImageVersion);
            outfile.putTwo(minorImageVersion);
            outfile.putTwo(majorSubsystemVersion);
            outfile.putTwo(minorSubsystemVersion);
            outfile.putFour(win32VersionValue);
            outfile.putFour(sizeOfImage);
            outfile.putFour(sizeOfHeaders);
            outfile.putFour(checksum);
            outfile.putTwo(subsystem);
            outfile.putTwo(dLLCharacteristics);
            outfile.putFour(sizeOfStackReserve);
            outfile.putFour(sizeOfStackCommit);
            outfile.putFour(sizeOfHeapReserve);
            outfile.putFour(sizeOfHeapCommit);
            outfile.putFour(loaderFlags);
            outfile.putFour(numberOfRvaAndSizes);

            dExportTable.writeOut(outfile);
            dImportTable.writeOut(outfile);
            dResourceTable.writeOut(outfile);
            exceptionTable.writeOut(outfile);
            certificatesTable.writeOut(outfile);
            baseRelocationTable.writeOut(outfile);
            debugTable.writeOut(outfile);
            architecture.writeOut(outfile);
            globalPtr.writeOut(outfile);
            threadLocalStorageTable.writeOut(outfile);
            loadConfigurationTable.writeOut(outfile);
            boundImportTable.writeOut(outfile);
            importAddressTable.writeOut(outfile);
            delayImportDescriptor.writeOut(outfile);
            CLRRuntimeHeader.writeOut(outfile);
            reserved.writeOut(outfile);
        }
Exemplo n.º 15
0
            public void WriteIn(string identifier)
            {
                Trace.WriteLine(string.Format("Writing into {0}", identifier));
                //the intercal model is stream-based - calling WriteIn reads as
                //many chars as there are in the array (or fewer if EOF is reached)
                //Console.Write("{0}?>", s);

                int[] idx = new int[1];

                if ((identifier[0] == ',') || (identifier[0] == ';'))
                {
                    ArrayVariable av = this.Variables[identifier] as ArrayVariable;
                    if (av.Rank != 1)
                    {
                        throw new IntercalException(Messages.E241);
                    }

                    for (int i = av.GetLowerBound(0); i <= av.GetUpperBound(0); i++)
                    {
                        idx[0] = i;

                        uint c = (uint)BinaryOut.ReadChar();

                        uint v = (c - this.LastIn) % 256;
                        this.LastIn = c;

                        Trace.WriteLine(string.Format("Writing '{0}' into index {1}", (char)c, i));
                        this[identifier, idx] = v;
                    }
                }
                else
                {
                    string input = TextIn.ReadLine();
                    try
                    {
                        //Note that this compiler today only works in wimpmode.  To do it
                        //right we will need to have satellite assemblies, one for each of
                        //many different languages.
                        this[identifier] = UInt32.Parse(input);
                    }
                    catch
                    {
                        Lib.Fail(String.Format(Messages.E579, input));
                    }
                }
            }
Exemplo n.º 16
0
 public void writeSymbol(BinaryOut outfile)
 {
     //if (namePos == -1)
     //{
     //    outfile.putFixedString(name, 8);
     //}
     //else
     //{
     //    outfile.putFour(0);
     //    outfile.putFour((uint)namePos);
     //}
     //outfile.putFour(value);
     //uint sn = (uint)((sectionNum < 0) ? 0x10000 + sectionNum : sectionNum);
     //outfile.putTwo(sn);
     //outfile.putTwo(type);
     //outfile.putOne((uint)storageClass);
     //outfile.putOne(auxSymbolCount);
 }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        //- writing out ---------------------------------------------------------------

        public void writeSectionTblEntry(BinaryOut outfile)
        {
            outfile.putFixedString(name, 8);

            outfile.putFour(memSize);
            outfile.putFour(memPos);
            outfile.putFour(fileSize);
            outfile.putFour(filePos);

            //line numbers are deprecated, we don't write them
            outfile.putFour(relocTblPos);
            outfile.putFour(0);
            outfile.putTwo((uint)relocations.Count);
            outfile.putTwo(0);

            uint flagval = settings.encodeFlags();

            outfile.putFour(flagval);
        }
Exemplo n.º 19
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();
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
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();
        }
Exemplo n.º 22
0
        //public void writeToFile(BinaryOut outfile)
        //{
        //    outfile.putFour(address);
        //    outfile.putFour(symTblIdx);
        //    outfile.putTwo((uint)type);
        //}

        public static void write(BinaryOut outfile, uint pos)
        {
            //not implemented yet
        }
Exemplo n.º 23
0
 public void writeOut(BinaryOut outfile)
 {
     outfile.putFour(rva);
     outfile.putFour(size);
 }
Exemplo n.º 24
0
 public Genome()
 {
     _binaryOut = new BinaryOut(16);
 }
Exemplo n.º 25
0
 public void writeToFile(BinaryOut modfile)
 {
     modfile.putString(name);
     modfile.putFour((uint)addr);
 }
Exemplo n.º 26
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;
        }
Exemplo n.º 27
0
 public virtual void writeOut(BinaryOut outfile)
 {
     outfile.putString(name);
 }
Exemplo n.º 28
0
        public void Run()
        {
            //Console.WriteLine("Choose file:"); // Prompt
            //Console.WriteLine("1 - tinyT.txt"); // Prompt
            //Console.WriteLine("2 - tinyW.txt"); // Prompt
            //Console.WriteLine("3 - largeT.txt"); // Prompt
            //Console.WriteLine("4 - largeW.txt"); // Prompt
            //Console.WriteLine("or quit"); // Prompt

            //var fileNumber = Console.ReadLine();
            //var fieName = string.Empty;
            //switch (fileNumber)
            //{
            //    case "1":
            //        fieName = "tinyT.txt";
            //        break;
            //    case "2":
            //        fieName = "tinyW.txt";
            //        break;
            //    case "3":
            //        fieName = "largeT.txt";
            //        break;
            //    case "4":
            //        fieName = "largeW.txt";
            //        break;
            //    case "quit":
            //        return;
            //    default:
            //        return;
            //}


            var binaryOut = new BinaryOut(16);

            binaryOut.Write((byte)6);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();


            binaryOut.Write(true);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();


            binaryOut.Write(false);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();


            binaryOut.Write(short.MaxValue);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();



            binaryOut.Write((short)5);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();



            binaryOut.Write(int.MaxValue);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();



            binaryOut.Write((int)5);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();



            binaryOut.Write(long.MaxValue);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();

            binaryOut.Write((long)5);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();



            binaryOut.Write(float.MaxValue);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();



            binaryOut.Write((float)5.0);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();


            binaryOut.Write(double.MaxValue);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();



            binaryOut.Write((double)5.0);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();



            binaryOut.Write(decimal.MaxValue);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();



            binaryOut.Write((decimal)5.0);
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();

            binaryOut.Write('r');
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();

            binaryOut.Write("test");
            Console.WriteLine(binaryOut.TotalBits);
            binaryOut.ResetTotal();
            Console.WriteLine();

            Console.ReadLine();
        }
Exemplo n.º 29
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;
        }