Ejemplo n.º 1
0
        //public Section addSection(String name, Section.Flags flags, Section.Alignment align)
        //{
        //    Section sec = new Section(name, flags, align);
        //    sections.Add(sec);
        //    sec.secNum = sections.Count;
        //    secNames[name] = sec;
        //    return sec;
        //}

        public CoffSymbol findSymbol(String name)
        {
            CoffSymbol sym = null;

            if (symNames.ContainsKey(name))
            {
                sym = symNames[name];
            }
            return(sym);
        }
Ejemplo n.º 2
0
        public static void loadRelocations(BinaryIn source, CoffSection sec, Win32Obj objfile)
        {
            source.seek(sec.relocTblPos);
            for (int i = 0; i < sec.relocTblCount; i++)
            {
                uint addr      = source.getFour();
                int  symidx    = (int)source.getFour();
                uint reloctype = source.getTwo();

                CoffRelocation.Reloctype reltype = CoffRelocation.Reloctype.NONE;
                switch (reloctype)
                {
                case 06:
                    reltype = CoffRelocation.Reloctype.ABSOLUTE;            //IMAGE_REL_I386_DIR32
                    break;

                case 07:
                    reltype = CoffRelocation.Reloctype.RVA;                 //IMAGE_REL_I386_DIR32NB
                    break;

                case 11:
                    reltype = CoffRelocation.Reloctype.SECREL32;            //IMAGE_REL_I386_SECREL
                    break;

                case 20:
                    reltype = CoffRelocation.Reloctype.RELATIVE;            //IMAGE_REL_I386_REL32
                    break;

                default:
                    break;
                }

                CoffSymbol     sym   = objfile.symbols[symidx];
                CoffRelocation reloc = new CoffRelocation(addr - sec.memPos, sym, reltype);
                sec.relocations.Add(reloc);
            }
        }
Ejemplo n.º 3
0
 public CoffRelocation(uint _addr, CoffSymbol _sym, Reloctype _type)
 {
     address = _addr;
     symbol  = _sym;
     type    = _type;
 }
Ejemplo 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++;
                }
            }
        }