Skip to content

Instantly share code, notes, and snippets.

@uyjulian
Created January 19, 2025 00:40
Show Gist options
  • Save uyjulian/4b91ebab054c3010c4bc5b1aeb834020 to your computer and use it in GitHub Desktop.
Save uyjulian/4b91ebab054c3010c4bc5b1aeb834020 to your computer and use it in GitHub Desktop.
#if 0
if ( !has_symtab )
{
// Some modules have missing symtab/strtab section, so make our own
elf_syment **symp;
elf_section *sp_y;
unsigned int shdr_entrise = elf->ehp->e_shnum;
sp_y = (elf_section *)calloc(1, sizeof(elf_section));
sp_y->shr.sh_size = shdr_entrise * sizeof(Elf32_Sym);
sp_y->shr.sh_entsize = sizeof(Elf32_Sym);
sp_y->shr.sh_addralign = 4;
sp_y->shr.sh_type = SHT_SYMTAB;
symp = (elf_syment **)calloc(shdr_entrise, sizeof(elf_syment *));
sp_y->data = (uint8_t *)symp;
for ( i_5 = 0; shdr_entrise > i_5; i_5 += 1 )
{
symp[i_5] = (elf_syment *)calloc(1, sizeof(elf_syment));
symp[i_5]->number = i_5;
symp[i_5]->shptr = elf->scp[i_5];
symp[i_5]->sym.st_shndx = i_5;
symp[i_5]->sym.st_info = ((i_5 == 0) ? STT_NOTYPE : ((STB_LOCAL << 4) | STT_SECTION));
symp[i_5]->sym.st_value = symp[i_5]->shptr->shr.sh_addr;
symp[i_5]->bind = symp[i_5]->sym.st_info >> 4;
symp[i_5]->type = symp[i_5]->sym.st_info & 0xF;
}
sp_y->name = strdup(".symtab");
elf->scp[count_2] = sp_y;
count_2 += 1;
elf->ehp->e_shnum += 1;
for ( i_3 = 0; count_2 > i_3; i_3 += 1 )
{
switch ( elf->scp[i_3]->shr.sh_type )
{
case SHT_RELA:
case SHT_REL:
elf->scp[i_3]->link = sp_y;
elf->scp[i_3]->shr.sh_link = count_2 - 1;
break;
case SHT_STRTAB:
sp_y->link = elf->scp[i_3];
sp_y->shr.sh_link = i_3;
break;
default:
break;
}
}
}
#endif
#if 1
for ( i_6 = 0; count_2 > i_6; i_6 += 1 )
{
unsigned int pos_5;
pos_5 = elf->scp[i_6]->shr.sh_offset;
if ( elf->scp[i_6]->shr.sh_type == SHT_REL && pos_5 != 0 && elf->scp[i_6]->shr.sh_size )
{
elf_syment **symp;
elf_section *sp_x;
unsigned int i_w;
sp_x = elf->scp[i_6];
symp = NULL;
if (sp_x && sp_x->link)
{
symp = (elf_syment **)sp_x->link->data;
}
unsigned int shdr_entrise;
shdr_entrise = 0;
if (sp_x->link->shr.sh_entsize)
{
shdr_entrise = sp_x->link->shr.sh_size / sp_x->link->shr.sh_entsize;
}
if (symp)
{
printf("Sect '%s'\n", sp_x->name ? sp_x->name : NULL);
printf("Sect info '%s'\n", sp_x->info->name ? sp_x->info->name : NULL);
for ( i_w = 0; shdr_entrise > i_w; i_w += 1 )
{
printf("Syn name %2d '%s'\n", symp[i_w]->sym.st_shndx, symp[i_w]->shptr ? symp[i_w]->shptr->name : NULL);
}
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment