BinaryFile_ClearBinaryFile(
LibGoblin_BinaryFile *p_binfile )
{
+ int i_cnt;
+
assert( NULL != p_binfile );
memset( p_binfile, 0x00, sizeof( LibGoblin_BinaryFile ) );
p_binfile->i_id = -0x01;
+ for( i_cnt = 0; i_cnt < LIBGOBLIN_SECTION_ID_MAX; i_cnt++ )
+ { p_binfile->i_secindex[i_cnt] = -0x01; }
+
return;
}
#define DRD64_SRC_LIBGOBLIN_DEBUG_OBJINFO
#include"drd64_libgoblin.h"
-static char gstr_type[256][8] = {
+static char gstr_type[256][9] = {
"NULL",
"MASTER",
"PROGHDR",
"SECTION",
- "",
- "",
- "",
- "",
+ "FUNCTION",
+ "OBJECT",
+ "COMMON",
+ "TLS",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
pstr_space, p_obj->info.section.qw_entsize,
p_obj->info.section.dw_link, p_obj->info.section.dw_info );
- printf(" %s\n", pstr_space );
-
return;
}
printf(" %s\t\t[PROGHDR] Flag[%5s] Type: %s, align= %ld\n",
pstr_space, str_flag, str_type, p_obj->info.proghdr.qw_align );
- printf(" %s\n", pstr_space );
return;
}
default:
break;
}
+ printf(" %s\n", pstr_space );
*(pstr_space + i_len) = '\0';
return i_result;
}
- Debug_ObjectInfo_Print_AllGroupLink( p_pginfo, 0xff );
-
/* Read SymbolTable to ObjectInfo ---------------------*/
+ i_result = ELF64_Symtab_ReadSection( p_binfo );
+ if( 0x00 != i_result ) {
+ return i_result;
+ }
+
+ Debug_ObjectInfo_Print_AllGroupLink( p_pginfo, 0xff );
/* Create Symbol-Table ------------------*/
/*
// sh_addr - Address in memory image.
p_sectbl->ptr_addr.value = p_sechdr->sh_addr;
p_sectbl->i_fid = p_binfo->i_filetype;
+ p_sectbl->w_index = (Word)i_cnt;
+
+ p_bfile->i_secindex[ i_cnt ] = i_index;
break;
}
}
// sh_addr - Address in memory image.
p_sectbl->ptr_addr.value = p_sechdr->sh_addr;
p_sectbl->i_fid = p_binfo->i_filetype;
+ p_sectbl->w_index = (Word)i_cnt;
+ p_bfile->i_secindex[ i_cnt ] = i_user_section;
+
i_user_section++;
}
{
Byte *pb_symtab;
+ Byte *pb_strtab;
int i_result = 0x00;
DWord dw_symbols;
DWord dw_cnt;
Elf64_Shdr *p_shdr;
Elf64_Sym *p_sym = NULL;
LibGoblin_SectionInfo *p_secinfo;
+ LibGoblin_SectionInfo *p_secstr;
+ LibGoblin_SrcFile *p_srcfile;
+ LibGoblin_ObjectInfo *p_obj;
+ LibGoblin_ProgramInfo *p_pginfo;
assert( NULL != p_binfo );
// Check BinaryInfo & Get SymbolEntires
p_secinfo = LibGoblin_Section_GetSectionInfo_fid(
- p_binfo, LIBGOBLIN_SECTION_ID_SYMTAB );
+ p_binfo, LIBGOBLIN_SECTION_ID_SYMTAB );
if( NULL == p_secinfo ) {
return 0x00;
}
+ pb_symtab = p_secinfo->pb_data;
+
+ p_secstr = LibGoblin_Section_GetSectionInfo_fid(
+ p_binfo, LIBGOBLIN_SECTION_ID_STRTAB );
+ if( NULL == p_secstr ) {
+ return 0x00;
+ }
+ pb_strtab = p_secstr->pb_data;
p_shdr = (Elf64_Shdr *)(p_secinfo->pb_sechdr);
if( 0 == p_shdr->sh_entsize ) {
return -0x02;
}
dw_symbols = (DWord)p_shdr->sh_size / (DWord)p_shdr->sh_entsize;
- pb_symtab = p_secinfo->pb_data;
+
+ p_pginfo = ProgInfo_GetProgInfo( p_binfo->i_pginfo );
+ assert( NULL != p_pginfo );
p_sym = (Elf64_Sym *)pb_symtab;
for( dw_cnt = 0; ((dw_cnt < dw_symbols) && (0x00 == i_result)); dw_cnt++, p_sym++ ) {
-
-
+ // Source file.
+ if( STT_FILE == ELF64_ST_TYPE( p_sym->st_info ) ) {
+ p_srcfile = SrcFile_DispenseSrcFile( (char *)pb_strtab + p_sym->st_name );
+ assert( NULL != p_srcfile );
+ continue;
+ }
+
+ if(( 0x00000000 == p_sym->st_value )
+ && ( STT_NOTYPE == ELF64_ST_TYPE( p_sym->st_info ) ))
+ { continue; }
+
+ // st_value - Symbol value.
+ // st_size - Size of associated object.
+ p_obj = ObjectInfo_InsetObject( p_pginfo,
+ (PtrValue)p_sym->st_value, (QWord)p_sym->st_size, NULL, 0x01 );
+
+ // st_name - String table index of name.
+ p_obj->pstr_name = (char *)(pb_strtab + p_sym->st_name);
+
+ // st_info - Type and binding information.
+ p_obj->info.symbol.b_type = ELF64_ST_TYPE( p_sym->st_info );
+ switch( ELF64_ST_TYPE( p_sym->st_info ) ) {
+ // Unspecified type.
+ case STT_NOTYPE:
+ p_obj->b_type = OBJINFO_TYPE_NULL; break;
+ // Data object.
+ case STT_OBJECT:
+ p_obj->b_type = OBJINFO_TYPE_OBJECT; break;
+ // Function.
+ case STT_FUNC:
+ p_obj->b_type = OBJINFO_TYPE_FUNCTION; break;
+ // Section.
+ case STT_SECTION:
+ p_obj->b_type = OBJINFO_TYPE_SECTION; break;
+ // Uninitialized common block.
+ case STT_COMMON:
+ p_obj->b_type = OBJINFO_TYPE_COMMON; break;
+ // TLS object.
+ case STT_TLS:
+ p_obj->b_type = OBJINFO_TYPE_TLS; break;
+ default:
+ p_obj->b_type = OBJINFO_TYPE_NULL; break;
+ }
+
+ // st_info - Type and binding information.
+ p_obj->info.symbol.b_binding = ELF64_ST_BIND( p_sym->st_info );
+
+ // st_other - Reserved (not used).
+ p_obj->info.symbol.b_visibility = p_sym->st_other;
+
+ // st_shndx - Section index of symbol.
+ p_obj->info.symbol.w_secindex = p_sym->st_shndx;
}
+
if( 0x00 != i_result ) {
return -0x04;
}
typedef struct {
Byte *pb_sechdr;
Byte *pb_data; // FileLocation (Offset)
+ Word w_index;
Ptr ptr_addr;
QWord qw_size;
char *pstr_secname;
#define OBJINFO_TYPE_MASTER 0x01
#define OBJINFO_TYPE_PROGHDR 0x02
#define OBJINFO_TYPE_SECTION 0x03
+#define OBJINFO_TYPE_FUNCTION 0x04
+#define OBJINFO_TYPE_OBJECT 0x05
+#define OBJINFO_TYPE_COMMON 0x06
+#define OBJINFO_TYPE_TLS 0x07
typedef struct {
int i_id;
struct {
Ptr ptr_addr; // Object Address
// [Section] sh_addr - Address in memory image.
+ // [Symbol ] st_value - Symbol value.
QWord qw_size; // Object Size (Address Range)
+ // [Symbol ] st_size - Size of associated object.
} addr;
// Group(Parent-Child) Order Link ---
// ObjectInfo (DATA) ---
char *pstr_name; // Object Name (Param./Func./etc...)
// [Section] = sh_name - Section name (index into the section header string table).
+ // [Symbol ] = st_name - String table index of name.
DWord dw_hash;
union {
void *pv_sechdr;
} section;
+ struct {
+ Byte b_type; // st_info - Type and binding information.
+ Byte b_binding; // st_info - Type and binding information.
+ Byte b_visibility; // st_other - Reserved (not used).
+ Word w_secindex; // st_shndx - Section index of symbol.
+ } symbol;
+
} info;
+
+ int i_secid;
int i_srcid; // SourceInfo struct ID
Byte b_elf_flags;
- Word w_secid; // SectionInfo ItemIndex belong with this object.
+ Word w_secid; // ==OLD== SectionInfo ItemIndex belong with this object.
} LibGoblin_ObjectInfo;
void *p_elf;
LibGoblin_SectionInfo t_section[LIBGOBLIN_SECTION_ID_MAX];
+ int i_secindex[LIBGOBLIN_SECTION_ID_MAX];
} LibGoblin_BinaryFile;