Back to index

enigmail  1.4.3
Public Member Functions | Public Attributes | Protected Attributes
ElfSymtab_Section Class Reference

#include <elfxx.h>

Inheritance diagram for ElfSymtab_Section:
Inheritance graph
[legend]
Collaboration diagram for ElfSymtab_Section:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ElfSymtab_Section (Elf_Shdr &s, std::ifstream *file, Elf *parent)
void serialize (std::ofstream &file, char ei_class, char ei_data)
Elf_SymValuelookup (const char *name, unsigned int type_filter=STT(OBJECT)|STT(FUNC))
const char * getName ()
unsigned int getType ()
unsigned int getFlags ()
unsigned int getAddr ()
unsigned int getSize ()
unsigned int getAddrAlign ()
unsigned int getEntSize ()
const char * getData ()
ElfSectiongetLink ()
SectionInfo getInfo ()
void shrink (unsigned int newsize)
unsigned int getOffset ()
int getIndex ()
Elf_ShdrgetShdr ()
ElfSectiongetNext ()
ElfSectiongetPrevious ()
virtual bool isRelocatable ()
void insertAfter (ElfSection *section, bool dirty=true)
void markDirty ()

Public Attributes

std::vector< Elf_SymValuesyms

Protected Attributes

Elf_Shdr shdr
char * data
const char * name

Detailed Description

Definition at line 542 of file elfxx.h.


Constructor & Destructor Documentation

ElfSymtab_Section::ElfSymtab_Section ( Elf_Shdr s,
std::ifstream *  file,
Elf parent 
)

Definition at line 810 of file elf.cpp.

: ElfSection(s, file, parent)
{
    int pos = file->tellg();
    syms.resize(s.sh_size / s.sh_entsize);
    ElfStrtab_Section *strtab = (ElfStrtab_Section *)getLink();
    file->seekg(shdr.sh_offset);
    for (unsigned int i = 0; i < shdr.sh_size / shdr.sh_entsize; i++) {
        Elf_Sym sym(*file, parent->getClass(), parent->getData());
        syms[i].name = strtab->getStr(sym.st_name);
        syms[i].info = sym.st_info;
        syms[i].other = sym.st_other;
        ElfSection *section = (sym.st_shndx == SHN_ABS) ? NULL : parent->getSection(sym.st_shndx);
        new (&syms[i].value) ElfLocation(section, sym.st_value, ElfLocation::ABSOLUTE);
        syms[i].size = sym.st_size;
        syms[i].defined = (sym.st_shndx != SHN_UNDEF);
    }
    file->seekg(pos);
}

Here is the call graph for this function:


Member Function Documentation

unsigned int ElfSection::getAddr ( ) [inherited]

Definition at line 483 of file elf.cpp.

{
    if (shdr.sh_addr != (Elf32_Word)-1)
        return shdr.sh_addr;

    // It should be safe to adjust sh_addr for all allocated sections that
    // are neither SHT_NOBITS nor SHT_PROGBITS
    if ((previous != NULL) && isRelocatable()) {
        unsigned int addr = previous->getAddr();
        if (previous->getType() != SHT_NOBITS)
            addr += previous->getSize();

        if (addr & (getAddrAlign() - 1))
            addr = (addr | (getAddrAlign() - 1)) + 1;

        return (shdr.sh_addr = addr);
    }
    return shdr.sh_addr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int ElfSection::getAddrAlign ( ) [inline, inherited]

Definition at line 342 of file elfxx.h.

{ return shdr.sh_addralign; }

Here is the caller graph for this function:

const char* ElfSection::getData ( ) [inline, inherited]

Definition at line 344 of file elfxx.h.

{ return data; }

Here is the caller graph for this function:

unsigned int ElfSection::getEntSize ( ) [inline, inherited]

Definition at line 343 of file elfxx.h.

{ return shdr.sh_entsize; }

Here is the caller graph for this function:

unsigned int ElfSection::getFlags ( ) [inline, inherited]

Definition at line 339 of file elfxx.h.

{ return shdr.sh_flags; }

Here is the caller graph for this function:

int ElfSection::getIndex ( ) [inherited]

Definition at line 541 of file elf.cpp.

{
    if (index != -1)
        return index;
    if (getType() == SHT_NULL)
        return (index = 0);
    ElfSection *reference;
    for (reference = previous; (reference != NULL) && (reference->getType() == SHT_NULL); reference = reference->getPrevious());
    if (reference == NULL)
        return (index = 1);
    return (index = reference->getIndex() + 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

SectionInfo ElfSection::getInfo ( ) [inline, inherited]

Definition at line 346 of file elfxx.h.

{ return info; }

Here is the caller graph for this function:

ElfSection* ElfSection::getLink ( ) [inline, inherited]

Definition at line 345 of file elfxx.h.

{ return link; }

Here is the caller graph for this function:

const char* ElfSection::getName ( ) [inline, inherited]

Definition at line 337 of file elfxx.h.

{ return name; }

Here is the caller graph for this function:

ElfSection* ElfSection::getNext ( ) [inline, inherited]

Definition at line 360 of file elfxx.h.

{ return next; }

Here is the caller graph for this function:

unsigned int ElfSection::getOffset ( ) [inherited]

Definition at line 503 of file elf.cpp.

{
    if (shdr.sh_offset != (Elf32_Word)-1)
        return shdr.sh_offset;

    if (previous == NULL)
        return (shdr.sh_offset = 0);

    unsigned int offset = previous->getOffset();
    if (previous->getType() != SHT_NOBITS)
        offset += previous->getSize();

    Elf32_Word align = 0x1000;
    for (std::vector<ElfSegment *>::iterator seg = segments.begin(); seg != segments.end(); seg++)
        align = std::max(align, (*seg)->getAlign());

    Elf32_Word mask = align - 1;
    // SHF_TLS is used for .tbss which is some kind of special case.
    if (((getType() != SHT_NOBITS) || (getFlags() & SHF_TLS)) && (getFlags() & SHF_ALLOC)) {
        if ((getAddr() & mask) < (offset & mask))
            offset = (offset | mask) + (getAddr() & mask) + 1;
        else
            offset = (offset & ~mask) + (getAddr() & mask);
    }
    if ((getType() != SHT_NOBITS) && (offset & (getAddrAlign() - 1)))
        offset = (offset | (getAddrAlign() - 1)) + 1;

    // Two subsequent sections can't be mapped in the same page in memory
    // if they aren't in the same 4K block on disk.
    if ((getType() != SHT_NOBITS) && getAddr()) {
        if (((offset >> 12) != (previous->getOffset() >> 12)) &&
            ((getAddr() >> 12) == (previous->getAddr() >> 12)))
            throw std::runtime_error("Moving section would require overlapping segments");
    }

    return (shdr.sh_offset = offset);
}

Here is the call graph for this function:

Here is the caller graph for this function:

ElfSection* ElfSection::getPrevious ( ) [inline, inherited]

Definition at line 361 of file elfxx.h.

{ return previous; }

Here is the caller graph for this function:

Elf_Shdr & ElfSection::getShdr ( ) [inherited]

Definition at line 554 of file elf.cpp.

{
    getOffset();
    if (shdr.sh_link == (Elf32_Word)-1)
        shdr.sh_link = getLink() ? getLink()->getIndex() : 0;
    if (shdr.sh_info == (Elf32_Word)-1)
        shdr.sh_info = ((getType() == SHT_REL) || (getType() == SHT_RELA)) ?
                       (getInfo().section ? getInfo().section->getIndex() : 0) :
                       getInfo().index;

    return shdr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int ElfSection::getSize ( ) [inline, inherited]

Definition at line 341 of file elfxx.h.

{ return shdr.sh_size; }

Here is the caller graph for this function:

unsigned int ElfSection::getType ( ) [inline, inherited]

Definition at line 338 of file elfxx.h.

{ return shdr.sh_type; }

Here is the caller graph for this function:

void ElfSection::insertAfter ( ElfSection section,
bool  dirty = true 
) [inline, inherited]

Definition at line 379 of file elfxx.h.

                                                             {
        if (previous != NULL)
            previous->next = next;
        if (next != NULL)
            next->previous = previous;
        previous = section;
        if (section != NULL) {
            next = section->next;
            section->next = this;
        } else
            next = NULL;
        if (next != NULL)
            next->previous = this;
        if (dirty)
            markDirty();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool ElfSection::isRelocatable ( ) [inline, virtual, inherited]

Reimplemented in ElfRelHackCode_Section, and ElfRelHack_Section.

Definition at line 363 of file elfxx.h.

                                 {
        return ((getType() == SHT_SYMTAB) ||
                (getType() == SHT_STRTAB) ||
                (getType() == SHT_RELA) ||
                (getType() == SHT_HASH) ||
                (getType() == SHT_NOTE) ||
                (getType() == SHT_REL) ||
                (getType() == SHT_DYNSYM) ||
                (getType() == SHT_GNU_HASH) ||
                (getType() == SHT_GNU_verdef) ||
                (getType() == SHT_GNU_verneed) ||
                (getType() == SHT_GNU_versym) ||
                isInSegmentType(PT_INTERP)) &&
                (getFlags() & SHF_ALLOC);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Elf_SymValue * ElfSymtab_Section::lookup ( const char *  name,
unsigned int  type_filter = STT(OBJECT) | STT(FUNC) 
)

Definition at line 851 of file elf.cpp.

{
    for (std::vector<Elf_SymValue>::iterator sym = syms.begin();
         sym != syms.end(); sym++) {
        if ((type_filter & (1 << ELF32_ST_TYPE(sym->info))) &&
            (strcmp(sym->name, name) == 0)) {
            return &*sym;
        }
    }
    return NULL;
}

Here is the caller graph for this function:

void ElfSection::markDirty ( ) [inline, inherited]

Definition at line 396 of file elfxx.h.

                     {
        if (link != NULL)
            shdr.sh_link = -1;
        if (info.index)
            shdr.sh_info = -1;
        shdr.sh_offset = -1;
        if (isRelocatable())
            shdr.sh_addr = -1;
        if (next)
            next->markDirty();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ElfSymtab_Section::serialize ( std::ofstream &  file,
char  ei_class,
char  ei_data 
) [virtual]

Reimplemented from ElfSection.

Definition at line 831 of file elf.cpp.

{
    ElfStrtab_Section *strtab = (ElfStrtab_Section *)getLink();
    for (unsigned int i = 0; i < shdr.sh_size / shdr.sh_entsize; i++) {
        Elf_Sym sym;
        sym.st_name = strtab->getStrIndex(syms[i].name);
        sym.st_info = syms[i].info;
        sym.st_other = syms[i].other;
        sym.st_value = syms[i].value.getValue();
        ElfSection *section = syms[i].value.getSection();
        if (syms[i].defined)
            sym.st_shndx = section ? section->getIndex() : SHN_ABS;
        else
            sym.st_shndx = SHN_UNDEF;
        sym.st_size = syms[i].size;
        sym.serialize(file, ei_class, ei_data);
    }
}

Here is the call graph for this function:

void ElfSection::shrink ( unsigned int  newsize) [inline, inherited]

Definition at line 348 of file elfxx.h.

                                      {
        if (newsize < shdr.sh_size) {
            shdr.sh_size = newsize;
            if (next)
                next->markDirty();
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

char* ElfSection::data [protected, inherited]

Definition at line 431 of file elfxx.h.

const char* ElfSection::name [protected, inherited]

Definition at line 432 of file elfxx.h.

Elf_Shdr ElfSection::shdr [protected, inherited]

Definition at line 430 of file elfxx.h.

Definition at line 551 of file elfxx.h.


The documentation for this class was generated from the following files: