示例#1
0
        static public MsDosHeader readMSDOSHeader(BinaryIn source)
        {
            MsDosHeader dosHeader = new MsDosHeader();

            dosHeader.signature = source.getTwo();
            if (dosHeader.signature != 0x5a4d)
            {
                throw new Win32FormatException("this is not a valid win32 executable file");
            }

            dosHeader.lastsize  = source.getTwo();
            dosHeader.nblocks   = source.getTwo();
            dosHeader.nreloc    = source.getTwo();
            dosHeader.hdrsize   = source.getTwo();
            dosHeader.minalloc  = source.getTwo();
            dosHeader.maxalloc  = source.getTwo();
            dosHeader.ss        = source.getTwo();
            dosHeader.sp        = source.getTwo();
            dosHeader.checksum  = source.getTwo();
            dosHeader.ip        = source.getTwo();
            dosHeader.cs        = source.getTwo();
            dosHeader.relocpos  = source.getTwo();
            dosHeader.noverlay  = source.getTwo();
            dosHeader.reserved1 = source.getRange(8);
            dosHeader.oem_id    = source.getTwo();
            dosHeader.oem_info  = source.getTwo();
            dosHeader.reserved2 = source.getRange(20);
            dosHeader.e_lfanew  = source.getFour();

            return(dosHeader);
        }
示例#2
0
        //- reading in ----------------------------------------------------------------

        public static CoffSection readSection(BinaryIn source)
        {
            string      name = source.getAsciiString(8);
            CoffSection sec  = new CoffSection(name);

            sec.memSize  = source.getFour();
            sec.memPos   = source.getFour();
            sec.fileSize = source.getFour();
            sec.filePos  = source.getFour();

            sec.relocTblPos = source.getFour();
            uint skip1 = source.getFour();              //line numbers are deprecated

            sec.relocTblCount = source.getTwo();
            uint skip2 = source.getTwo();

            uint flagval = source.getFour();

            sec.settings = SectionSettings.decodeFlags(flagval);

            uint mark = source.getPos();

            source.seek(sec.filePos);
            byte[] secdata = source.getRange(sec.fileSize);
            sec.data = new List <byte>(secdata);
            source.seek(mark);

            return(sec);
        }
示例#3
0
        //- reading in --------------------------------------------------------

        internal static OboeBlock loadSection(BinaryIn infile, uint secaddr, uint secsize, uint sectype)
        {
            infile.seek(secaddr);
            String    blockname   = infile.getAsciiZString();
            OboeBlock block       = new OboeBlock(blockname, sectype);
            uint      blockaddr   = infile.getFour();
            uint      blocksize   = infile.getFour();
            uint      importaddr  = infile.getFour();
            uint      importcount = infile.getFour();
            uint      exportaddr  = infile.getFour();
            uint      exportcount = infile.getFour();

            //block data
            infile.seek(blockaddr);
            block.blockdata = new List <byte>(infile.getRange(blocksize));

            //import list
            infile.seek(importaddr);
            for (int i = 0; i < importcount; i++)
            {
                ImportEntry imp = ImportEntry.loadFromFile(infile);
                block.imports.Add(imp);
            }

            //export list
            infile.seek(exportaddr);
            for (int i = 0; i < exportcount; i++)
            {
                ExportEntry exp = ExportEntry.loadFromFile(infile);
                block.exports.Add(exp);
            }

            return(block);
        }
示例#4
0
        public static Win32Obj readFromFile(String filename)
        {
            Win32Obj objfile = new Win32Obj(filename);
            BinaryIn source  = new BinaryIn(filename);

            //coff header
            objfile.machine = (MachineType)source.getTwo();
            uint sectionCount = source.getTwo();

            objfile.timeStamp = source.getFour();
            uint symbolTblAddr   = source.getFour();
            uint symbolCount     = source.getFour();
            uint optionalHdrSize = source.getTwo();

            objfile.characteristics = (int)source.getTwo();

            //string tbl - follows symbol tbl
            uint strtblpos = symbolTblAddr + symbolCount * CoffSymbol.SYMTBLENTRYSIZE;

            source.seek(strtblpos);
            byte[] strtbl = null;
            uint   len    = source.getFour();

            if (len > 4)
            {
                source.seek(strtblpos);
                strtbl = source.getRange(len);
            }

            //section tbl
            source.seek(COFFHDRSIZE);
            for (int i = 0; i < sectionCount; i++)
            {
                //if section name is stored in string tbl, we read in index & let caller deref the actual name
                String secname = source.getAsciiString(8);
                if (secname[0] == '/')
                {
                    int stridx = Int32.Parse(secname.Substring(1));
                    secname = readString(strtbl, stridx);
                }

                //read section hdr field
                uint memSize  = source.getFour();       //don't use - 0 in object files
                uint memPos   = source.getFour();
                uint fileSize = source.getFour();
                uint filePos  = source.getFour();

                uint relocPos     = source.getFour();
                uint lineNumPos   = source.getFour();   //don't use - deprecated
                uint relocCount   = source.getTwo();
                uint lineNumCount = source.getTwo();    //don't use
                uint flagval      = source.getFour();

                SectionSettings settings = SectionSettings.decodeFlags(flagval);
                CoffSection     section  = new CoffSection(secname, settings);
                section.owner         = objfile;
                section.secNum        = i + 1;
                section.memPos        = memPos;
                section.fileSize      = fileSize;
                section.filePos       = filePos;
                section.relocTblPos   = relocPos;
                section.relocTblCount = relocCount;

                objfile.sections.Add(section);
                objfile.secNames[section.name] = section;
            }

            //load symbols
            source.seek(symbolTblAddr);
            loadSymbols(source, symbolCount, strtbl, objfile);

            foreach (CoffSection section in objfile.sections)
            {
                //load section data
                section.data = new List <Byte>(source.getRange(section.filePos, section.fileSize));

                //load sectionrelocs
                loadRelocations(source, section, objfile);
            }


            return(objfile);
        }
示例#5
0
        //leaf node of resource directory tree, this rec points to actual data
        private void parseResourceData(BinaryIn source)
        {
            uint datapos = source.getFour();
            uint datasize = source.getFour();
            uint codepage = source.getFour();
            uint reserved = source.getFour();
            datapos -= resourceRVA;
            byte[] resdata = source.getRange(datapos, datasize);        //get resource data

            //get the store type/id/lang vals we stored in our decent to this node
            uint restype = resIdNameValues[0];
            uint resid = resIdNameValues[1];
            String resname = (resid >= 0x80000000) ? getResourceName(source, resid) : null;            
            uint reslang = resIdNameValues[2];

            switch (restype)
            {
                case 1:
                    ResData curdata = new ResData(resid, resname, reslang, resdata);
                    cursorItems.Add(curdata);                    
                    break;

                case 2:
                    Bitmap bmp = ResBitmap.parseData(resdata);
                    addBitmap(resid, resname, reslang, bmp);
                    getDataItem(bitmaps, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;

                case 3:
                    ResData icondata = new ResData(resid, resname, reslang, resdata);
                    iconItems.Add(icondata);                    
                    break;

                case 4:
                    addMenu(resid, resname, reslang, resdata);                    
                    //List<String> menu = ResMenu.parseData(resdata);
                    //addMenu(resid, resname, reslang, menu);                    
                    getDataItem(menus, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;

                case 5:
                    addDialog(resid, resname, reslang, resdata);                    
                    //List<String> dlg = ResDialog.parseData(resdata);
                    //addDialog(resid, resname, reslang, dlg);                    
                    getDataItem(dialogs, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;

                case 6: 
                    List<String> strings = ResStringTable.parseData(resdata);
                    addStringTable(resid, resname, reslang, strings);
                    getDataItem(stringtable, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;

                case 7:
                    addFontDirectory(resid, resname, reslang, resdata);                    
                    getDataItem(fontDirectories, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;

                case 8:
                    addFont(resid, resname, reslang, resdata);
                    getDataItem(fonts, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;

                case 9:
                    List<String> accel = ResAccelerator.parseData(resdata);
                    addAccelerator(resid, resname, reslang, accel);
                    getDataItem(accelerators, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;

                case 10:
                    addUserData(resid, resname, reslang, resdata);
                    getDataItem(userData, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;

                case 12:
                    ResImageGroupData cg = ResImageGroupData.parseData(resdata);
                    addCursorGroup(resid, resname, reslang, cg);
                    getDataItem(cursorGroups, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;

                case 14:
                    ResImageGroupData ig = ResImageGroupData.parseData(resdata);
                    addIconGroup(resid, resname, reslang, ig);
                    getDataItem(iconGroups, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;

                case 16:
                    addVersion(resid, resname, reslang, resdata);

                    //List<String> version = ResVersion.parseData(resdata);
                    //addVersion(resid, resname, reslang, version);
                    getDataItem(versions, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;

                default:
                    addUserData(resid, resname, reslang, resdata);
                    getDataItem(userData, resid, resname).getItem(reslang).dataBuf = resdata;
                    break;
            }
        }