Back to index

enigmail  1.4.3
Public Member Functions | Private Attributes
ElfSegment Class Reference

#include <elfxx.h>

Collaboration diagram for ElfSegment:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ElfSegment (Elf_Phdr *phdr)
unsigned int getType ()
unsigned int getFlags ()
unsigned int getAlign ()
ElfSectiongetFirstSection ()
int getVPDiff ()
unsigned int getFileSize ()
unsigned int getMemSize ()
unsigned int getOffset ()
unsigned int getAddr ()
void addSection (ElfSection *section)
std::list< ElfSection * >::iterator begin ()
std::list< ElfSection * >::iterator end ()
ElfSegmentsplitBefore (ElfSection *section)

Private Attributes

unsigned int type
int v_p_diff
unsigned int flags
unsigned int align
std::list< ElfSection * > sections
unsigned int vaddr
unsigned int filesz
unsigned int memsz

Detailed Description

Definition at line 441 of file elfxx.h.


Constructor & Destructor Documentation

Definition at line 567 of file elf.cpp.

: type(phdr->p_type), v_p_diff(phdr->p_paddr - phdr->p_vaddr),
  flags(phdr->p_flags), align(phdr->p_align), vaddr(phdr->p_vaddr),
  filesz(phdr->p_filesz), memsz(phdr->p_memsz) {}

Here is the caller graph for this function:


Member Function Documentation

void ElfSegment::addSection ( ElfSection section)

Definition at line 572 of file elf.cpp.

{
    // Make sure all sections in PT_GNU_RELRO won't be moved by elfhack
    assert(!((type == PT_GNU_RELRO) && (section->isRelocatable())));

    //TODO: Check overlapping sections
    std::list<ElfSection *>::iterator i;
    for (i = sections.begin(); i != sections.end(); ++i)
        if ((*i)->getAddr() > section->getAddr())
            break;
    sections.insert(i, section);
    section->addToSegment(this);
}

Here is the call graph for this function:

Here is the caller graph for this function:

std::list<ElfSection *>::iterator ElfSegment::begin ( ) [inline]

Definition at line 458 of file elfxx.h.

{ return sections.begin(); }

Here is the caller graph for this function:

std::list<ElfSection *>::iterator ElfSegment::end ( ) [inline]

Definition at line 459 of file elfxx.h.

{ return sections.end(); }

Here is the caller graph for this function:

unsigned int ElfSegment::getAddr ( )

Definition at line 627 of file elf.cpp.

{
    if ((type == PT_GNU_RELRO) && !sections.empty() &&
        (sections.front()->getAddr() != vaddr))
        throw std::runtime_error("PT_GNU_RELRO segment doesn't start on a section start");

    return sections.empty() ? 0 : sections.front()->getAddr();
}

Here is the caller graph for this function:

unsigned int ElfSegment::getAlign ( ) [inline]

Definition at line 447 of file elfxx.h.

{ return align; }

Here is the caller graph for this function:

unsigned int ElfSegment::getFileSize ( )

Definition at line 586 of file elf.cpp.

{
    if (type == PT_GNU_RELRO)
        return filesz;

    if (sections.empty())
        return 0;
    // Search the last section that is not SHT_NOBITS
    std::list<ElfSection *>::reverse_iterator i;
    for (i = sections.rbegin(); (i != sections.rend()) && ((*i)->getType() == SHT_NOBITS); ++i);
    // All sections are SHT_NOBITS
    if (i == sections.rend())
        return 0;

    unsigned int end = (*i)->getAddr() + (*i)->getSize();

    return end - sections.front()->getAddr();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 449 of file elfxx.h.

{ return sections.empty() ? NULL : sections.front(); }
unsigned int ElfSegment::getFlags ( ) [inline]

Definition at line 446 of file elfxx.h.

{ return flags; }
unsigned int ElfSegment::getMemSize ( )

Definition at line 605 of file elf.cpp.

{
    if (type == PT_GNU_RELRO)
        return memsz;

    if (sections.empty())
        return 0;

    unsigned int end = sections.back()->getAddr() + sections.back()->getSize();

    return end - sections.front()->getAddr();
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int ElfSegment::getOffset ( )

Definition at line 618 of file elf.cpp.

{
    if ((type == PT_GNU_RELRO) && !sections.empty() &&
        (sections.front()->getAddr() != vaddr))
        throw std::runtime_error("PT_GNU_RELRO segment doesn't start on a section start");

    return sections.empty() ? 0 : sections.front()->getOffset();
}
unsigned int ElfSegment::getType ( ) [inline]

Definition at line 445 of file elfxx.h.

{ return type; }
int ElfSegment::getVPDiff ( ) [inline]

Definition at line 450 of file elfxx.h.

{ return v_p_diff; }

Definition at line 636 of file elf.cpp.

{
    std::list<ElfSection *>::iterator i, rm;
    for (i = sections.begin(); (*i != section) && (i != sections.end()); ++i);
    if (i == sections.end())
        return NULL;

    // Probably very wrong.
    Elf_Phdr phdr;
    phdr.p_type = type;
    phdr.p_vaddr = 0;
    phdr.p_paddr = phdr.p_vaddr + v_p_diff;
    phdr.p_flags = flags;
    phdr.p_align = getAlign();
    phdr.p_filesz = (unsigned int)-1;
    phdr.p_memsz = (unsigned int)-1;
    ElfSegment *segment = new ElfSegment(&phdr);

    for (rm = i; i != sections.end(); ++i) {
        (*i)->removeFromSegment(this);
        segment->addSection(*i);
    }
    sections.erase(rm, sections.end());

    return segment;
}

Here is the call graph for this function:


Member Data Documentation

unsigned int ElfSegment::align [private]

Definition at line 466 of file elfxx.h.

unsigned int ElfSegment::filesz [private]

Definition at line 471 of file elfxx.h.

unsigned int ElfSegment::flags [private]

Definition at line 465 of file elfxx.h.

unsigned int ElfSegment::memsz [private]

Definition at line 471 of file elfxx.h.

std::list<ElfSection *> ElfSegment::sections [private]

Definition at line 467 of file elfxx.h.

unsigned int ElfSegment::type [private]

Definition at line 463 of file elfxx.h.

int ElfSegment::v_p_diff [private]

Definition at line 464 of file elfxx.h.

unsigned int ElfSegment::vaddr [private]

Definition at line 470 of file elfxx.h.


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