LibGoblin_SectionInfo *
LibGoblin_Elf_GetSectionInfo(
LibGoblin_BinaryInfo *p_binfo,
- int i_analyzefid,
Byte b_secid )
{
+ LibGoblin_SectionInfo *p_secinfo;
+
+ if( LIBGOBLIN_ELF_SEC_ID_DEFAULT_MAX <= b_secid ) { return NULL; }
+
+ p_secinfo = &(p_binfo->t_section[b_secid]);
+
+ return p_secinfo;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBGOBLIN_ELF_EXTERN
+LibGoblin_SectionInfo *
+ LibGoblin_Elf_GetSectionInfo_fid(
+ LibGoblin_BinaryInfo *p_binfo,
+ Byte b_secid,
+ int i_analyzefid )
+{
LibGoblin_BinaryFile *p_bfile;
LibGoblin_SectionInfo *p_secinfo;
if( LIBGOBLIN_ELF_SEC_ID_DEFAULT_MAX <= b_secid ) { return NULL; }
- p_secinfo = &(p_binfo->t_section[b_secid]);
+ p_secinfo = &(p_bfile->t_section[b_secid]);
return p_secinfo;
}
Byte *LibGoblin_Elf_GetSection(
QWord *qw_secsize, LibGoblin_BinaryInfo *p_bin, int i_analyzefid, Byte b_secid );
LIBGOBLIN_ELF_EXTERN
+ LibGoblin_SectionInfo *LibGoblin_Elf_GetSectionInfo_fid(
+ LibGoblin_BinaryInfo *p_binfo, Byte b_secid, int i_analyzefid );
+LIBGOBLIN_ELF_EXTERN
LibGoblin_SectionInfo *LibGoblin_Elf_GetSectionInfo(
- LibGoblin_BinaryInfo *p_binfo, int i_analyzefid, Byte b_secid );
+ LibGoblin_BinaryInfo *p_binfo, Byte b_secid );
+LIBGOBLIN_ELF_EXTERN
+ LibGoblin_SectionInfo *LibGoblin_Elf_GetSectionInfo_fid(
+ LibGoblin_BinaryInfo *p_binfo, Byte b_secid, int i_analyzefid );
LIBGOBLIN_ELF_EXTERN
int LibGoblin_AnalyzeElf(
LibGoblin_BinaryInfo *p_binfo, int i_analyzefid );
int i_analyzefid )
{
Byte *pb_symtab;
- QWord qw_size;
DWord dw_symbols;
+ DWord dw_sworksz;
+ DWord dw_cnt;
Elf32_Shdr *p_shdr32;
Elf64_Shdr *p_shdr64;
+ Elf32_Sym *p_sym32;
+ Elf64_Sym *p_sym64;
LibGoblin_SectionInfo *p_secinfo;
+ LibGoblin_SymbolWork *p_symwork;
+ LibGoblin_SymbolWork *p_swnow;
assert( NULL != p_binfo );
// Check BinaryInfo & Get SymbolEntires
- // XXX
- p_secinfo = LibGoblin_Elf_GetSectionInfo( p_binfo, 0, LIBGOBLIN_ELF_SEC_ID_SYMTAB );
+ p_secinfo = LibGoblin_Elf_GetSectionInfo_fid(
+ p_binfo, LIBGOBLIN_ELF_SEC_ID_SYMTAB, i_analyzefid );
if( NULL == p_secinfo ) {
return 0x01;
}
dw_symbols = (DWord)p_shdr64->sh_size / (DWord)p_shdr64->sh_entsize;
pb_symtab = p_secinfo->pb_data;
}
- else if( IsBinfoType_Elf32( p_binfo ) ) {
-
+ else {
+ p_shdr32 = (Elf32_Shdr *)(p_secinfo->pb_sechdr);
+ if( 0 == p_shdr32->sh_entsize ) {
+ return -0x02;
+ }
+ dw_symbols = (DWord)p_shdr32->sh_size / (DWord)p_shdr32->sh_entsize;
+ pb_symtab = p_secinfo->pb_data;
}
- // Create WorkTable
+ // Create & Alloc SymbolWorkTable
+ dw_sworksz = dw_symbols * sizeof( LibGoblin_SymbolWork );
+ p_symwork = (LibGoblin_SymbolWork *)malloc( dw_sworksz );
+ if( NULL == p_symwork ) {
+ return -0x03;
+ }
+ memset( p_symwork, 0x00, dw_sworksz );
- // Sort WorkTable
+ // Read SymbolSection to SymbolWorkTable
+ p_swnow = p_symwork;
+ if( IsBinfoType_Elf64( p_binfo ) ) {
+ p_sym64 = (Elf64_Sym *)pb_symtab;
- // Create SymbolTable
+ for( dw_cnt = 0; dw_cnt < dw_symbols; dw_cnt++ ) {
+ p_swnow->pb_symbol = (Byte *)p_sym64;
+ p_swnow->ptr_address = p_sym64->st_value;
- // Update Symbol Table
+ p_sym64++;
+ p_swnow++;
+ }
+ }
- // Create SymbolTable Index
+ // Sort WorkTable
return 0x00;
}