diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-08-17 12:24:26 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2024-08-17 12:24:26 +0200 |
| commit | fa87b0fcef3dff593a507b3200ef83d846101d64 (patch) | |
| tree | 66894b342323cf40892b43d6f92bc8793c792489 /src/include | |
| parent | 0f1bce0f32a8429fc414f92cb6b85ff0d30b5d8f (diff) | |
| download | box64-fa87b0fcef3dff593a507b3200ef83d846101d64.tar.gz box64-fa87b0fcef3dff593a507b3200ef83d846101d64.zip | |
[BOX32] prepare elfheader_t structure for 32bits elfs
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/box32.h | 112 | ||||
| -rw-r--r-- | src/include/elfload_dump.h | 23 | ||||
| -rw-r--r-- | src/include/elfloader.h | 2 | ||||
| -rw-r--r-- | src/include/x64run.h | 4 |
4 files changed, 124 insertions, 17 deletions
diff --git a/src/include/box32.h b/src/include/box32.h new file mode 100644 index 00000000..ab8fa184 --- /dev/null +++ b/src/include/box32.h @@ -0,0 +1,112 @@ +#ifndef __BOX32_64__H_ +#define __BOX32_64__H_ + +#include <stdint.h> +#include <stdlib.h> + +#ifndef BOX32_DEF +#define BOX32_DEF +typedef uint32_t ptr_t; +typedef int32_t long_t; +typedef uint32_t ulong_t; +#endif + +#define TEST32 +#define TEST_ABORT + +static inline uintptr_t from_ptr(ptr_t p) { + return (uintptr_t)p; +} +static inline void* from_ptrv(ptr_t p) { + return (void*)(uintptr_t)p; +} +static inline long from_long(long_t l) { + return (long)l; +} +static inline unsigned long from_ulong(ulong_t l) { + return (unsigned long)l; +} +uintptr_t from_hash(ulong_t l); +uintptr_t from_hash_d(ulong_t l); +#ifdef TEST32 +#include "debug.h" + +static inline ptr_t to_ptr(uintptr_t p) { + if(p!=0xffffffffffffffffLL && (p>>32)) { + printf_log(LOG_NONE, "Warning, pointer %p is not a 32bits value\n", (void*)p); + #ifdef TEST_ABORT + abort(); + #endif + } + return (ptr_t)p; +} +static inline ptr_t to_ptrv(void* p2) { + uintptr_t p = (uintptr_t)p2; + if(p!=0xffffffffffffffffLL && (p>>32)) { + printf_log(LOG_NONE, "Warning, pointer %p is not a 32bits value\n", (void*)p); + #ifdef TEST_ABORT + abort(); + #endif + } + return (ptr_t)p; +} +static inline long_t to_long(long l) { + long_t ret = (long_t)l; + if(l!=ret) + printf_log(LOG_NONE, "Warning, long %ld is not a 32bits value\n", l); + return ret; +} +static inline ulong_t to_ulong(unsigned long l) { + if(l!=0xffffffffffffffffLL && (l>>32)) + printf_log(LOG_NONE, "Warning, long 0x%p is not a 32bits value\n", (void*)l); + return (ulong_t)l; +} +#else //TEST32 +static inline ptr_t to_ptr(uintptr_t p) { + return (ptr_t)p; +} +static inline ptr_t to_ptrv(void* p) { + return (ptr_t)(uintptr_t)p; +} +static inline long_t to_long(long l) { + return (long_t)l; +} +static inline ulong_t to_ulong(unsigned long l) { + return (ulong_t)l; +} +#endif //TEST32 + +static inline ptr_t to_ptr_silent(uintptr_t p) { + return (ptr_t)p; +} +static inline ptr_t to_ptrv_silent(void* p) { + return (ptr_t)(uintptr_t)p; +} +// indirect l -> T +#define from_ptri(T, l) *(T*)from_ptr(l) +// indirect l -> void* +static inline void* from_ptriv(ptr_t l) { + return from_ptrv(from_ptri(ptr_t, l)); +} + +ulong_t to_hash(uintptr_t p); +ulong_t to_hash_d(uintptr_t p); +static inline ulong_t to_hashv(void* p) {return to_hash((uintptr_t)p);} +static inline ulong_t to_hashv_d(uintptr_t p) {return to_hash_d((uintptr_t)p);} + +void* from_locale(ptr_t l); +void* from_locale_d(ptr_t l); +ptr_t to_locale(void* p); +ptr_t to_locale_d(void* p); + +void init_hash_helper(); +void fini_hash_helper(); + +typedef struct x86emu_s x86emu_t; + +void* my_mmap(x86emu_t* emu, void* addr, unsigned long length, int prot, int flags, int fd, int offset); +void* my_mmap64(x86emu_t* emu, void *addr, unsigned long length, int prot, int flags, int fd, int64_t offset); +int my_munmap(x86emu_t* emu, void* addr, unsigned long length); +int my_mprotect(x86emu_t* emu, void *addr, unsigned long len, int prot); + +#endif //__BOX32_64__H_ diff --git a/src/include/elfload_dump.h b/src/include/elfload_dump.h index ad2ecd71..74906b5e 100644 --- a/src/include/elfload_dump.h +++ b/src/include/elfload_dump.h @@ -3,22 +3,17 @@ 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, int version); -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); +const char* SymName64(elfheader_t *h, Elf64_Sym* sym); +const char* DumpRelType64(int t); +void DumpMainHeader64(Elf64_Ehdr *header, elfheader_t *h); +void DumpSymTab64(elfheader_t *h); +void DumpDynamicSections64(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 DumpRelRTable(elfheader_t *h, int cnt, Elf64_Relr *relr, const char *name); +void DumpDynSym64(elfheader_t *h); +void DumpRelTable64(elfheader_t *h, int cnt, Elf64_Rel *rel, const char* name); +void DumpRelATable64(elfheader_t *h, int cnt, Elf64_Rela *rela, const char* name); +void DumpRelRTable64(elfheader_t *h, int cnt, Elf64_Relr *relr, const char *name); void DumpBinary(char* p, int sz); diff --git a/src/include/elfloader.h b/src/include/elfloader.h index 770709c8..2bce3c64 100644 --- a/src/include/elfloader.h +++ b/src/include/elfloader.h @@ -91,7 +91,7 @@ int GetNeededVersionForLib(elfheader_t* h, const char* libname, const char* ver) void* ElfGetLocalSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *sz, const char* symname, int* ver, const char** vername, int local, int* veropt); void* ElfGetGlobalSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *sz, const char* symname, int* ver, const char** vername, int local, int* veropt); void* ElfGetWeakSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *sz, const char* symname, int* ver, const char** vername, int local, int* veropt); -int ElfGetSymTabStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname); +int ElfGetSymTabStartEnd64(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname); void* GetNativeSymbolUnversioned(void* lib, const char* name); diff --git a/src/include/x64run.h b/src/include/x64run.h index b6c9e960..a5d4528e 100644 --- a/src/include/x64run.h +++ b/src/include/x64run.h @@ -9,8 +9,8 @@ int RunTest(x64test_t *test); void DynaRun(x64emu_t *emu); uint32_t LibSyscall(x64emu_t *emu); -void PltResolver(x64emu_t* emu); -extern uintptr_t pltResolver; +void PltResolver64(x64emu_t* emu); +extern uintptr_t pltResolver64; int GetTID(void); #endif //__X64RUN_H_ \ No newline at end of file |