diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-03-01 15:52:05 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-03-01 15:52:05 +0100 |
| commit | 311842a43aa34276dc41da6e2f3a63ac80d4849c (patch) | |
| tree | 4da4eeeb2c3c4de462389e06b6e1ed504dfea6e9 /src/include | |
| parent | 4ea8ebb3367810a1a789acdfedb2d346491f603a (diff) | |
| download | box64-311842a43aa34276dc41da6e2f3a63ac80d4849c.tar.gz box64-311842a43aa34276dc41da6e2f3a63ac80d4849c.zip | |
Read elf header of launched executable
Diffstat (limited to 'src/include')
| -rwxr-xr-x | src/include/box64context.h | 6 | ||||
| -rw-r--r-- | src/include/custommem.h | 52 | ||||
| -rwxr-xr-x | src/include/elfload_dump.h | 24 | ||||
| -rwxr-xr-x | src/include/elfloader.h | 59 |
4 files changed, 141 insertions, 0 deletions
diff --git a/src/include/box64context.h b/src/include/box64context.h index 680b2d5e..0697e16a 100755 --- a/src/include/box64context.h +++ b/src/include/box64context.h @@ -4,6 +4,8 @@ #include <pthread.h> #include "pathcoll.h" +typedef struct elfheader_s elfheader_t; + typedef void* (*procaddess_t)(const char* name); typedef void* (*vkprocaddess_t)(void* instance, const char* name); @@ -43,6 +45,10 @@ typedef struct box64context_s { int stackalign; void* stack; // alocated stack + elfheader_t **elfs; // elf headers and memory + int elfcap; + int elfsize; // number of elf loaded + int deferedInit; pthread_key_t tlskey; // then tls key to have actual tlsdata diff --git a/src/include/custommem.h b/src/include/custommem.h new file mode 100644 index 00000000..d6bca59c --- /dev/null +++ b/src/include/custommem.h @@ -0,0 +1,52 @@ +#ifndef __CUSTOM_MEM__H_ +#define __CUSTOM_MEM__H_ +#include <unistd.h> +#include <stdint.h> + + +typedef struct box64context_s box64context_t; + +//void* customMalloc(size_t size); +//void* customCalloc(size_t n, size_t size); +//void* customRealloc(void* p, size_t size); +//void customFree(void* p); + +//#define kcalloc customCalloc +//#define kmalloc customMalloc +//#define krealloc customRealloc +//#define kfree customFree + +#ifdef DYNAREC +//typedef struct dynablock_s dynablock_t; +//typedef struct dynablocklist_s dynablocklist_t; +//// custom protection flag to mark Page that are Write protected for Dynarec purpose +//uintptr_t AllocDynarecMap(dynablock_t* db, int size); +//void FreeDynarecMap(dynablock_t* db, uintptr_t addr, uint32_t size); + +//void addDBFromAddressRange(uintptr_t addr, uintptr_t size); +//void cleanDBFromAddressRange(uintptr_t addr, uintptr_t size, int destroy); + +//dynablocklist_t* getDB(uintptr_t idx); +//void addJumpTableIfDefault(void* addr, void* jmp); +//void setJumpTableDefault(void* addr); +//uintptr_t getJumpTable(); +//uintptr_t getJumpTableAddress(uintptr_t addr); +#endif + +#define PROT_DYNAREC 0x80 +void updateProtection(uintptr_t addr, uintptr_t size, uint32_t prot); +void setProtection(uintptr_t addr, uintptr_t size, uint32_t prot); +uint32_t getProtection(uintptr_t addr); +#ifdef DYNAREC +//void protectDB(uintptr_t addr, uintptr_t size); +//void protectDBnolock(uintptr_t addr, uintptr_t size); +//void unprotectDB(uintptr_t addr, uintptr_t size); +//void lockDB(); +//void unlockDB(); +#endif + + +void init_custommem_helper(box64context_t* ctx); +void fini_custommem_helper(box64context_t* ctx); + +#endif //__CUSTOM_MEM__H_ \ No newline at end of file diff --git a/src/include/elfload_dump.h b/src/include/elfload_dump.h new file mode 100755 index 00000000..251ea3b8 --- /dev/null +++ b/src/include/elfload_dump.h @@ -0,0 +1,24 @@ +#ifndef ELFLOADER_DUMP_H +#define ELFLOADER_DUMP_H + +typedef struct elfheader_s elfheader_t; + +const char* DumpSection(Elf64_Shdr *s, char* SST); +const char* DumpDynamic(Elf64_Dyn *s); +const char* DumpPHEntry(Elf64_Phdr *e); +const char* DumpSym(elfheader_t *h, Elf64_Sym* sym); +const char* DumpRelType(int t); +const char* SymName(elfheader_t *h, Elf64_Sym* sym); +const char* IdxSymName(elfheader_t *h, int sym); +void DumpMainHeader(Elf64_Ehdr *header, elfheader_t *h); +void DumpSymTab(elfheader_t *h); +void DumpDynamicSections(elfheader_t *h); +void DumpDynamicNeeded(elfheader_t *h); +void DumpDynamicRPath(elfheader_t *h); +void DumpDynSym(elfheader_t *h); +void DumpRelTable(elfheader_t *h, int cnt, Elf64_Rel *rel, const char* name); +void DumpRelATable(elfheader_t *h, int cnt, Elf64_Rela *rela, const char* name); + +void DumpBinary(char* p, int sz); + +#endif //ELFLOADER_DUMP_H \ No newline at end of file diff --git a/src/include/elfloader.h b/src/include/elfloader.h new file mode 100755 index 00000000..56a51c51 --- /dev/null +++ b/src/include/elfloader.h @@ -0,0 +1,59 @@ +#ifndef __ELF_LOADER_H_ +#define __ELF_LOADER_H_ +#include <stdio.h> + +typedef struct elfheader_s elfheader_t; +//typedef struct lib_s lib_t; +//typedef struct library_s library_t; +//typedef struct kh_mapsymbols_s kh_mapsymbols_t; +typedef struct box64context_s box64context_t; +//typedef struct x86emu_s x86emu_t; +//typedef struct needed_libs_s needed_libs_t; +//#ifdef DYNAREC +//typedef struct dynablocklist_s dynablocklist_t; +//#endif + +elfheader_t* LoadAndCheckElfHeader(FILE* f, const char* name, int exec); // exec : 0 = lib, 1 = exec +void FreeElfHeader(elfheader_t** head); +const char* ElfName(elfheader_t* head); +//void ElfAttachLib(elfheader_t* head, library_t* lib); + +// return 0 if OK +int CalcLoadAddr(elfheader_t* head); +int AllocElfMemory(box64context_t* context, elfheader_t* head, int mainbin); +void FreeElfMemory(elfheader_t* head); +//int LoadElfMemory(FILE* f, box64context_t* context, elfheader_t* head); +//int ReloadElfMemory(FILE* f, box64context_t* context, elfheader_t* head); +//int RelocateElf(lib_t *maplib, lib_t* local_maplib, elfheader_t* head); +//int RelocateElfPlt(lib_t *maplib, lib_t* local_maplib, elfheader_t* head); +//void CalcStack(elfheader_t* h, uint32_t* stacksz, int* stackalign); +//uintptr_t GetEntryPoint(lib_t* maplib, elfheader_t* h); +//uintptr_t GetLastByte(elfheader_t* h); +//void AddSymbols(lib_t *maplib, kh_mapsymbols_t* mapsymbols, kh_mapsymbols_t* weaksymbols, kh_mapsymbols_t* localsymbols, elfheader_t* h); +//int LoadNeededLibs(elfheader_t* h, lib_t *maplib, needed_libs_t* neededlibs, int local, box64context_t *box86, x86emu_t* emu); +//uintptr_t GetElfInit(elfheader_t* h); +//uintptr_t GetElfFini(elfheader_t* h); +//void RunElfInit(elfheader_t* h, x86emu_t *emu); +//void RunElfFini(elfheader_t* h, x86emu_t *emu); +//void RunDeferedElfInit(x86emu_t *emu); +//void* GetBaseAddress(elfheader_t* h); +//void* GetElfDelta(elfheader_t* h); +//uint32_t GetBaseSize(elfheader_t* h); +//int IsAddressInElfSpace(elfheader_t* h, uintptr_t addr); +//elfheader_t* FindElfAddress(box64context_t *context, uintptr_t addr); +//const char* FindNearestSymbolName(elfheader_t* h, void* p, uintptr_t* start, uint32_t* sz); +//int32_t GetTLSBase(elfheader_t* h); +//uint32_t GetTLSSize(elfheader_t* h); +//void* GetTLSPointer(box64context_t* context, elfheader_t* h); +//void* GetDTatOffset(box64context_t* context, int index, int offset); +//#ifdef DYNAREC +//dynablocklist_t* GetDynablocksFromAddress(box64context_t *context, uintptr_t addr); +//dynablocklist_t* GetDynablocksFromElf(elfheader_t* h); +//#endif +//void ResetSpecialCaseMainElf(elfheader_t* h); +//void CreateMemorymapFile(box64context_t* context, int fd); + +//int ElfCheckIfUseTCMallocMinimal(elfheader_t* h); // return 1 if tcmalloc is used + + +#endif //__ELF_LOADER_H_ \ No newline at end of file |