Skip to content

Commit

Permalink
support elf64 get section info
Browse files Browse the repository at this point in the history
  • Loading branch information
4ch12dy committed Nov 18, 2019
1 parent 1dd3be7 commit 576f158
Show file tree
Hide file tree
Showing 3 changed files with 655 additions and 2 deletions.
24 changes: 22 additions & 2 deletions XB1nLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,25 @@ XRange* macho64_get_sec_range_by_name(struct mach_header_64* mh, const char* seg
return the_segment;
}

// ==================================================================arm64 lib==================================================================

XRange* elf64_get_sec_range_by_name(Elf64_Ehdr* elfh, const char* sec_name){
Elf64_Off shoff = elfh->e_shoff;
Elf64_Quarter shnum = elfh->e_shnum;
Elf64_Quarter shstrndx = elfh->e_shstrndx;
Elf64_Shdr* shdr = (Elf64_Shdr*)((uint8_t *)elfh + shoff);
Elf64_Shdr* strsh = shdr + shstrndx;

char* strtab = (char*)((uint8_t *)elfh + strsh->sh_offset);
XRange* the_range = malloc(sizeof(XRange));

for (int i = 0; i < shnum; ++i) {
Elf64_Shdr* cur_shdr = shdr + i;
Elf64_Half cur_sec_name_idx = cur_shdr->sh_name;
char* cur_sec_name = strtab+cur_sec_name_idx;
if (!strcmp(cur_sec_name, sec_name)) {
the_range->start = (uint64_t)((uint8_t *)elfh + cur_shdr->sh_offset);
the_range->end = the_range->start + cur_shdr->sh_size;
return the_range;
}
}
return NULL;
}
3 changes: 3 additions & 0 deletions XB1nLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "xia0.h"
#include "macho64.h"
#include "arch/arm64.h"
#include "exec_elf.h"


typedef struct XRange
Expand All @@ -37,6 +38,8 @@ void* map_file_2_mem(const char* file_path);

XRange* macho64_get_sec_range_by_name(struct mach_header_64* mh, const char* seg_name, const char* sec_name);

XRange* elf64_get_sec_range_by_name(Elf64_Ehdr* elfh, const char* sec_name);

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 576f158

Please sign in to comment.