Skip to content

Commit

Permalink
xzre: add string xrefs dumper
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-smx committed Apr 7, 2024
1 parent f1eaf30 commit 29dde4c
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions xzre.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,34 @@ static void *get_ldso_elf(){
return (void *)addr;
}

/**
* @brief quick and dirty hack to get the main ELF location
*
* @return void*
*/
static void *get_main_elf(){
char cmdBuf[128];
char getLdElf[] = "grep -E 'r--p 00000000.*/usr/sbin/sshd' /proc/%zu/maps | cut -d '-' -f1";
snprintf(cmdBuf, sizeof(cmdBuf), getLdElf, getpid());
FILE *hProc = popen(cmdBuf, "r");
memset(cmdBuf, 0x00, sizeof(cmdBuf));
char *s = fgets(cmdBuf, sizeof(cmdBuf), hProc);
pclose(hProc);
if(!s) return NULL;
u64 addr = strtoull(s, NULL, 16);
return (void *)addr;
}

extern void *got_ref;

void main_shared(){
// prevent fork bomb in system command
unsetenv("LD_PRELOAD");
xzre_secret_data_bypass();

void *ldso_elf = get_ldso_elf();
void *ldso_elf = get_main_elf();
if(!ldso_elf){
puts("Failed to get LDSO elf");
puts("Failed to get main elf");
exit(1);
}

Expand All @@ -96,6 +114,15 @@ void main_shared(){
return;
}

/** populate the string references table, and dump it */
string_references_t strings = { 0 };
elf_find_string_references(&einfo, &strings);
for(int i=0; i<ARRAY_SIZE(strings.entries); i++){
string_item_t *item = &strings.entries[i];
printf("str %2d: id=0x%x, start=%p, end=%p, xref=%p\n",
i, item->string_id, item->code_start, item->code_end, item->xref);
}

puts("main_shared(): OK");
}

Expand Down

0 comments on commit 29dde4c

Please sign in to comment.