Exemplo n.º 1
0
        private void readOptionalHeader(BinaryIn source)
        {
            magicNum                = source.getTwo();
            majorLinkerVersion      = source.getOne();
            minorLinkerVersion      = source.getOne();
            sizeOfCode              = source.getFour();
            sizeOfInitializedData   = source.getFour();
            sizeOfUninitializedData = source.getFour();
            addressOfEntryPoint     = source.getFour();
            baseOfCode              = source.getFour();
            baseOfData              = source.getFour();
            imageBase               = source.getFour();
            memAlignment            = source.getFour();
            fileAlignment           = source.getFour();
            majorOSVersion          = source.getTwo();
            minorOSVersion          = source.getTwo();
            majorImageVersion       = source.getTwo();
            minorImageVersion       = source.getTwo();
            majorSubsystemVersion   = source.getTwo();
            minorSubsystemVersion   = source.getTwo();
            win32VersionValue       = source.getFour();
            sizeOfImage             = source.getFour();
            sizeOfHeaders           = source.getFour();
            checksum                = source.getFour();
            subsystem               = source.getTwo();
            dLLCharacteristics      = source.getTwo();
            sizeOfStackReserve      = source.getFour();
            sizeOfStackCommit       = source.getFour();
            sizeOfHeapReserve       = source.getFour();
            sizeOfHeapCommit        = source.getFour();
            loaderFlags             = source.getFour();
            numberOfRvaAndSizes     = source.getFour();

            dExportTable            = DataDirectory.readIn(source);
            dImportTable            = DataDirectory.readIn(source);
            dResourceTable          = DataDirectory.readIn(source);
            exceptionTable          = DataDirectory.readIn(source);
            certificatesTable       = DataDirectory.readIn(source);
            baseRelocationTable     = DataDirectory.readIn(source);
            debugTable              = DataDirectory.readIn(source);
            architecture            = DataDirectory.readIn(source);
            globalPtr               = DataDirectory.readIn(source);
            threadLocalStorageTable = DataDirectory.readIn(source);
            loadConfigurationTable  = DataDirectory.readIn(source);
            boundImportTable        = DataDirectory.readIn(source);
            importAddressTable      = DataDirectory.readIn(source);
            delayImportDescriptor   = DataDirectory.readIn(source);
            CLRRuntimeHeader        = DataDirectory.readIn(source);
            reserved = DataDirectory.readIn(source);
        }
Exemplo n.º 2
0
 public static ResImageGroupDataEntry parseData(BinaryIn src)
 {
     ResImageGroupDataEntry cgdata = new ResImageGroupDataEntry();
     cgdata.bWidth = src.getOne();
     cgdata.bHeight = src.getOne();
     cgdata.bColorCount = src.getOne();
     uint res = src.getOne();
     cgdata.wPlanes = src.getTwo();
     cgdata.wBitCount = src.getTwo();
     cgdata.dwBytesInRes = src.getFour();
     cgdata.nID = src.getTwo();
     cgdata.image = null;
     return cgdata;
 }
Exemplo n.º 3
0
        public static ImportEntry loadFromFile(BinaryIn infile)
        {
            string      name = infile.getAsciiZString();
            uint        addr = infile.getFour();
            uint        b    = infile.getOne();
            ImportEntry imp  = new ImportEntry(name, addr, (IMPORTTYPE)b);

            return(imp);
        }
Exemplo n.º 4
0
        public static void loadSymbols(BinaryIn source, uint count, byte[] strtbl, Win32Obj objfile)
        {
            for (int i = 0; i < count;)
            {
                //get short name or pos in string tbl
                uint   nameloc   = source.getPos();
                uint   namezeros = source.getFour();
                String name      = "";
                if (namezeros == 0)         //if first 4 bytes = 0, 2nd 4 bytes = ofs into str tbl
                {
                    int namepos = (int)source.getFour();
                    name = readString(strtbl, namepos);
                }
                else
                {
                    source.seek(nameloc);
                    name = source.getAsciiString(8);
                }

                //read rest of sym entry
                uint             val     = source.getFour();
                uint             secval  = source.getTwo();
                uint             type    = source.getTwo();
                CoffStorageClass storage = (CoffStorageClass)source.getOne();
                uint             aux     = source.getOne();

                CoffSymbol         sym  = null;
                CoffSymbol.SYMBIND bind = CoffSymbol.SYMBIND.EXTERNAL;
                uint        size        = 0;
                uint        addr        = 0;
                CoffSection sec         = null;

                switch (storage)
                {
                case CoffStorageClass.IMAGE_SYM_CLASS_EXTERNAL:
                    if (secval == 0)
                    {
                        if (val == 0)
                        {
                            bind = CoffSymbol.SYMBIND.EXTERNAL;
                        }
                        else
                        {
                            bind = CoffSymbol.SYMBIND.COMMON;
                            size = val;
                        }
                    }
                    else
                    {
                        bind = CoffSymbol.SYMBIND.GLOBAL;
                        sec  = objfile.sections[(int)secval - 1];
                        if (val >= sec.memPos)
                        {
                            addr = val - sec.memPos;
                        }
                    }
                    sym         = new CoffSymbol(name);
                    sym.bind    = bind;
                    sym.typ     = CoffSymbol.SYMTYPE.FUNCTION;
                    sym.section = sec;
                    sym.ofs     = addr;
                    sym.size    = size;
                    break;

                case CoffStorageClass.IMAGE_SYM_CLASS_STATIC:
                case CoffStorageClass.IMAGE_SYM_CLASS_LABEL:
                    if (secval != 0xffff)
                    {
                        sec = objfile.sections[(int)secval - 1];
                        if (val >= sec.memPos)
                        {
                            addr = val - sec.memPos;
                        }
                        sym         = new CoffSymbol(name);
                        sym.bind    = CoffSymbol.SYMBIND.LOCAL;
                        sym.typ     = CoffSymbol.SYMTYPE.FUNCTION;
                        sym.section = sec;
                        sym.ofs     = addr;
                        sym.size    = size;
                    }
                    break;

                case CoffStorageClass.IMAGE_SYM_CLASS_SECTION:
                    sec         = objfile.sections[(int)secval - 1];
                    sym         = new CoffSymbol(name);
                    sym.bind    = CoffSymbol.SYMBIND.LOCAL;
                    sym.typ     = CoffSymbol.SYMTYPE.FUNCTION;
                    sym.section = sec;
                    sym.ofs     = addr;
                    sym.size    = size;
                    break;

                case CoffStorageClass.IMAGE_SYM_CLASS_FUNCTION:
                case CoffStorageClass.IMAGE_SYM_CLASS_FILE:
                    break;

                default:
                    break;
                }
                i++;

                objfile.symbols.Add(sym);
                if (sym != null)
                {
                    objfile.symNames[sym.name] = sym;
                }

                //skip any aux sym entries
                for (int j = 0; j < aux; j++)
                {
                    source.skip(CoffSymbol.SYMTBLENTRYSIZE);
                    objfile.symbols.Add(null);
                    i++;
                }
            }
        }