Bug 651892 part 1 - Add a helper function to lookup symbols in a ElfSymtab_Section. r=tglek
This commit is contained in:
@@ -830,6 +830,19 @@ ElfSymtab_Section::serialize(std::ofstream &file, char ei_class, char ei_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Elf_SymValue *
|
||||||
|
ElfSymtab_Section::lookup(const char *name, unsigned int type_filter)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
ElfStrtab_Section::getStr(unsigned int index)
|
ElfStrtab_Section::getStr(unsigned int index)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -153,15 +153,11 @@ public:
|
|||||||
// Find the init symbol
|
// Find the init symbol
|
||||||
entry_point = -1;
|
entry_point = -1;
|
||||||
int shndx = 0;
|
int shndx = 0;
|
||||||
for (std::vector<Elf_SymValue>::iterator sym = symtab->syms.begin();
|
Elf_SymValue *sym = symtab->lookup("init");
|
||||||
sym != symtab->syms.end(); sym++) {
|
if (sym) {
|
||||||
if (strcmp(sym->name, "init") == 0) {
|
entry_point = sym->value.getValue();
|
||||||
entry_point = sym->value.getValue();
|
shndx = sym->value.getSection()->getIndex();
|
||||||
shndx = sym->value.getSection()->getIndex();
|
} else
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (entry_point == -1)
|
|
||||||
throw std::runtime_error("Couldn't find an 'init' symbol in the injected code");
|
throw std::runtime_error("Couldn't find an 'init' symbol in the injected code");
|
||||||
|
|
||||||
// Adjust code sections offsets according to their size
|
// Adjust code sections offsets according to their size
|
||||||
|
|||||||
@@ -489,12 +489,16 @@ struct Elf_SymValue {
|
|||||||
bool defined;
|
bool defined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define STT(type) (1 << STT_ ##type)
|
||||||
|
|
||||||
class ElfSymtab_Section: public ElfSection {
|
class ElfSymtab_Section: public ElfSection {
|
||||||
public:
|
public:
|
||||||
ElfSymtab_Section(Elf_Shdr &s, std::ifstream *file, Elf *parent);
|
ElfSymtab_Section(Elf_Shdr &s, std::ifstream *file, Elf *parent);
|
||||||
|
|
||||||
void serialize(std::ofstream &file, char ei_class, char ei_data);
|
void serialize(std::ofstream &file, char ei_class, char ei_data);
|
||||||
|
|
||||||
|
Elf_SymValue *lookup(const char *name, unsigned int type_filter = STT(OBJECT) | STT(FUNC));
|
||||||
|
|
||||||
//private: // Until we have a real API
|
//private: // Until we have a real API
|
||||||
std::vector<Elf_SymValue> syms;
|
std::vector<Elf_SymValue> syms;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user