| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent acfd9b8 commit adff278
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,6 @@ | |||
| 12 | 12 | #elif defined(__linux__) | |
| 13 | 13 | #include <elf.h> | |
| 14 | 14 | #include <link.h> | |
| 15 | - #include <sys/auxv.h> | ||
| 16 | 15 | #include <sys/param.h> | |
| 17 | 16 | #elif defined(_WIN32) | |
| 18 | 17 | #include <windows.h> | |
@@ -44,6 +43,16 @@ static inline bool postject_has_resource() { | |||
| 44 | 43 | return sentinel[sizeof(POSTJECT_SENTINEL_FUSE)] == '1'; | |
| 45 | 44 | } | |
| 46 | 45 | ||
| 46 | + #if defined(__linux__) | ||
| 47 | + static int postject__dl_iterate_phdr_callback(struct dl_phdr_info* info, | ||
| 48 | + size_t size, | ||
| 49 | + void* data) { | ||
| 50 | + // Snag the dl_phdr_info struct for the main program, then stop iterating | ||
| 51 | + *((struct dl_phdr_info*)data) = *info; | ||
| 52 | + return 1; | ||
| 53 | + } | ||
| 54 | + #endif | ||
| 55 | + | ||
| 47 | 56 | static const void* postject_find_resource( | |
| 48 | 57 | const char* name, | |
| 49 | 58 | size_t* size, | |
@@ -114,9 +123,12 @@ static const void* postject_find_resource( | |||
| 114 | 123 | name = options->elf_section_name; | |
| 115 | 124 | } | |
| 116 | 125 | ||
| 117 | - uintptr_t p = getauxval(AT_PHDR); | ||
| 118 | - size_t n = getauxval(AT_PHNUM); | ||
| 119 | - uintptr_t base_addr = p - sizeof(ElfW(Ehdr)); | ||
| 126 | + struct dl_phdr_info main_program_info; | ||
| 127 | + dl_iterate_phdr(postject__dl_iterate_phdr_callback, &main_program_info); | ||
| 128 | + | ||
| 129 | + uintptr_t p = (uintptr_t)main_program_info.dlpi_phdr; | ||
| 130 | + size_t n = main_program_info.dlpi_phnum; | ||
| 131 | + uintptr_t base_addr = main_program_info.dlpi_addr; | ||
| 120 | 132 | ||
| 121 | 133 | // iterate program header | |
| 122 | 134 | for (; n > 0; n--, p += sizeof(ElfW(Phdr))) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,6 @@ | |||
| 10 | 10 | "author": "", | |
| 11 | 11 | "license": "ISC", | |
| 12 | 12 | "dependencies": { | |
| 13 | - "postject": "^1.0.0-alpha.4" | ||
| 13 | + "postject": "^1.0.0-alpha.5" | ||
| 14 | 14 | } | |
| 15 | 15 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments