Back to index

enigmail  1.4.3
Classes | Public Member Functions | Protected Attributes | Private Attributes
ElfStrtab_Section Class Reference

#include <elfxx.h>

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

List of all members.

Classes

struct  table_storage

Public Member Functions

 ElfStrtab_Section (Elf_Shdr &s, std::ifstream *file, Elf *parent)
 ~ElfStrtab_Section ()
const char * getStr (unsigned int index)
const char * getStr (const char *string)
unsigned int getStrIndex (const char *string)
void serialize (std::ofstream &file, char ei_class, char ei_data)
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 ()

Protected Attributes

Elf_Shdr shdr
char * data
const char * name

Private Attributes

std::vector< table_storagetable

Detailed Description

Definition at line 599 of file elfxx.h.


Constructor & Destructor Documentation

ElfStrtab_Section::ElfStrtab_Section ( Elf_Shdr s,
std::ifstream *  file,
Elf parent 
) [inline]

Definition at line 601 of file elfxx.h.

    : ElfSection(s, file, parent)
    {
        table.push_back(table_storage(data, shdr.sh_size));
    }

Definition at line 607 of file elfxx.h.

    {
        for (std::vector<table_storage>::iterator t = table.begin() + 1;
             t != table.end(); t++)
            delete[] t->buf;
    }

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:

const char * ElfStrtab_Section::getStr ( unsigned int  index)

Definition at line 864 of file elf.cpp.

{
    for (std::vector<table_storage>::iterator t = table.begin();
         t != table.end(); t++) {
        if (index < t->used)
            return t->buf + index;
        index -= t->used;
    }
    assert(1 == 0);
    return NULL;
}

Here is the caller graph for this function:

const char * ElfStrtab_Section::getStr ( const char *  string)

Definition at line 877 of file elf.cpp.

{
    if (string == NULL)
        return NULL;

    // If the given string is within the section, return it
    for (std::vector<table_storage>::iterator t = table.begin();
         t != table.end(); t++)
        if ((string >= t->buf) && (string < t->buf + t->used))
            return string;

    // TODO: should scan in the section to find an existing string

    // If not, we need to allocate the string in the section
    size_t len = strlen(string) + 1;

    if (table.back().size - table.back().used < len)
        table.resize(table.size() + 1);

    char *alloc_str = table.back().buf + table.back().used;
    memcpy(alloc_str, string, len);
    table.back().used += len;

    shdr.sh_size += len;
    markDirty();

    return alloc_str;
}

Here is the call graph for this function:

unsigned int ElfStrtab_Section::getStrIndex ( const char *  string)

Definition at line 907 of file elf.cpp.

{
    if (string == NULL)
        return 0;

    unsigned int index = 0;
    string = getStr(string);
    for (std::vector<table_storage>::iterator t = table.begin();
         t != table.end(); t++) {
        if ((string >= t->buf) && (string < t->buf + t->used))
            return index + (string - t->buf);
        index += t->used;
    }

    assert(1 == 0);
    return 0;
}

Here is the call graph for this function:

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:

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 ElfStrtab_Section::serialize ( std::ofstream &  file,
char  ei_class,
char  ei_data 
) [virtual]

Reimplemented from ElfSection.

Definition at line 926 of file elf.cpp.

{
    file.seekp(getOffset());
    for (std::vector<table_storage>::iterator t = table.begin();
         t != table.end(); t++)
        file.write(t->buf, t->used);
}

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.

std::vector<table_storage> ElfStrtab_Section::table [private]

Definition at line 630 of file elfxx.h.


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