|
|
// ElfExe - adding symbols to running Elf processes // Copyright (C) 1998,1999 Colin McCormack, // see LICENSE (MD5 f5220f8f599e5e926f37cf32efe3ab68) for terms // $Id extern "C" { #include <glibc-inc/link.h> #include <glibc-inc/elf.h> } extern "C" { struct link_map; } /** ElfExe - direct meddling in elf executable symbol table to add new symbols * * this class modifies the symbol table of the currently running * process' executable by directly modifying the internal data * of the ld-linux and libdl.so libraries. * * This is regrettable, but the alternative is to beg the glibc * `maintainers' to fix bugs they hardly even seem to recognise. * * The result is a glibc2 version-specific meddling object which will * completely die as soon as the internal representation used in libdl.so * and ld.so changes. It will need to be ported to new architectures, and * may not even be portable to some. */ class ElfExe { // Elf direct meddling unsigned int cursymcnt; // symbol table occupancy unsigned int strtablen; // real strtab size ElfW(Addr) orgSymTab; const ElfW(Symndx) *orgBuckets; const ElfW(Symndx) *orgChain; ElfW(Symndx) orgNbuckets; ElfW(Addr) orgHash; ElfW(Addr) orgStrTab; static const unsigned int STRTINC = 1024; // strtab increment static const unsigned int SYMTINC = 1024; // symtab increment unsigned char *dupStrTab(); size_t addStrTab(const char *str); unsigned long elf_hash (const unsigned char *name); static const size_t elf_buckets[]; unsigned int nrChain(); ElfW(Symndx) *mkShadow(int additional = SYMTINC); link_map *_so; // the executable's link_map public: /** create an ElfExe for the current process * * Permits new symbols to be defined in the current process */ ElfExe(); /** restore the process' symbol table to a pristine state */ ~ElfExe(); /** add a global symbol to the executable * @param name symbol's mangled name * @param value symbol's value * @param size symbol's allocation size * @param type symbol's STT_ type * @param type symbol's STB_ binding (def: STB_GLOBAL) * @param section symbol's program .section (def: SHN_ABS) */ void addSym(const char *name, void *value, int size, int type, int bind = STB_GLOBAL, int section = SHN_ABS); };
Generated by: colin@sharedtech.dhis.org on Sat Nov 6 11:59:21 199. |