Ejemplo n.º 1
0
        static public MsDosHeader readMSDOSHeader(SourceFile source)
        {
            MsDosHeader dosHeader = new MsDosHeader();

            dosHeader.signature = source.getTwo();
            if (dosHeader.signature != 0x5a4d)
            {
                throw new Win32ReadException("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);
        }
Ejemplo n.º 2
0
        public void loadStringTable(SourceFile source)
        {
            uint pos = symbolTblAddr + (symbolCount * 0x12);

            source.seek(pos);
            uint len = source.getFour() - 4;

            byte[] data = source.getRange(len);
            String str  = "";
            int    idx  = 4;

            for (int i = 0; i < len; i++)
            {
                if (data[i] != 0)
                {
                    str += (char)data[i];
                }
                else
                {
                    stringTbl.Add(idx, str);
                    str = "";
                    idx = i + 5;
                }
            }
        }
Ejemplo n.º 3
0
//- reading in ----------------------------------------------------------------

        public static Section loadSection(SourceFile source)
        {
            Section section = new Section();

            section.secName = source.getAsciiString(8);

            section.memsize  = source.getFour();
            section.memloc   = source.getFour();
            section.filesize = source.getFour();
            section.fileloc  = source.getFour();

            section.pRelocations = source.getFour();
            section.pLinenums    = source.getFour();
            section.relocCount   = (int)source.getTwo();
            section.linenumCount = (int)source.getTwo();
            section.flags        = source.getFour();
            section.data         = source.getRange(section.fileloc, section.filesize);  //load section data

            return(section);
        }
Ejemplo n.º 4
0
        //leaf node of resource directory tree, this rec points to actual data
        private void parseResourceData(SourceFile 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;
            }
        }