Byte b_secid )
{
Byte *pb_data;
- Byte *pb_binary;
- LibGoblin_Format_Elf64 *p_elf64;
- LibGoblin_Format_Elf32 *p_elf32;
- Elf64_Shdr *p_elfshr64;
- Elf32_Shdr *p_elfshr32;
+ //Byte *pb_binary;
+ //LibGoblin_Format_Elf64 *p_elf64;
+ //LibGoblin_Format_Elf32 *p_elf32;
+ //Elf64_Shdr *p_elfshr64;
+ //Elf32_Shdr *p_elfshr32;
LibGoblin_BinaryFile *p_bfile;
+ LibGoblin_SectionTable *p_sectbl;
assert( NULL != p_binfo );
p_bfile = &(p_binfo->t_binfile[ i_analyzefid ]);
- pb_binary = p_bfile->pb_binary;
+ //pb_binary = p_bfile->pb_binary;
pb_data = NULL;
*qw_secsize = 0;
if( LIBGOBLIN_ELF_SEC_ID_DEFAULT_MAX <= b_secid ) { return NULL; }
+ p_sectbl = &(p_binfo->t_section[b_secid]);
+ if( NULL != p_sectbl->pb_sechdr ) {
+ pb_data = p_sectbl->pb_data;
+ *qw_secsize = p_sectbl->qw_size;
+ }
+/* XXX: old
if( IsBinfoType_Elf64(p_binfo) ) {
p_elf64 = (LibGoblin_Format_Elf64 *)p_binfo->p_format;
p_elfshr64 = p_elf64->p_section[b_secid];
pb_data = (Byte *)(pb_binary + p_elfshr32->sh_offset);
*qw_secsize = (QWord)p_elfshr32->sh_size;
}
-
+*/
return pb_data;
}
LibGoblin_BinaryInfo *p_binfo,
int i_analyzefid )
{
+ int i_result;
Byte *pb_data;
LibGoblin_BinaryFile *p_bfile;
pb_data = p_bfile->pb_binary;
assert( NULL != pb_data );
- /* Analyze ELF Ident Header from Bits ---*/
- if( ELFCLASS64 == *(pb_data + EI_CLASS) )
- { p_binfo->b_type = LIBGOBLIN_BINFO_TYPE_ELF64; }
- else if( ELFCLASS32 == *(pb_data + EI_CLASS) )
- { p_binfo->b_type = LIBGOBLIN_BINFO_TYPE_ELF32; }
-
- /* Analyze ELF Ident Header from Endian ---*/
- if( ELFDATA2LSB == *(pb_data + EI_DATA) )
- { p_binfo->b_endian = LIBGOBLIN_BINFO_ENDIAN_LITTLE; }
- else if( ELFDATA2MSB == *(pb_data + EI_DATA) )
- { p_binfo->b_endian = LIBGOBLIN_BINFO_ENDIAN_BIG; }
-
- /* Alloc BinaryInfo Format Struct Area from bits ---*/
+ /* XXX: Alloc BinaryInfo Format Struct Area from bits ---*/
+/*
if( LIBGOBLIN_BINFO_TYPE_ELF64 == p_binfo->b_type ) {
p_binfo->p_format = LibGoblin_Elf64_AllocFormat();
}
if( NULL == p_binfo->p_format ) {
return 0x01;
}
-
- /* Analyze ELF Header */
+*/
+
+ /* ReCheck ELF Header -------------------*/
+ i_result = LibGoblin_CheckBinary( p_binfo, i_analyzefid );
+ if( 0x00 != i_result ) {
+ return i_result;
+ }
+
+ /* Create Symbol-Table ------------------*/
if( LIBGOBLIN_BINFO_TYPE_ELF64 == p_binfo->b_type ) {
LibGoblin_Elf64_Analyze( p_binfo, i_analyzefid );
}
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
+/*
LIBGOBLIN_ELF64_EXTERN
void *
LibGoblin_Elf64_AllocFormat(
return (void *)p_elf;
}
-
+*/
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
int
- LibGoblin_Elf64_SetSectionHeader(
- LibGoblin_Format_Elf64 *p_elf,
- Byte *pb_data )
+ LibGoblin_Elf64_SetSectionTable(
+ LibGoblin_BinaryInfo *p_binfo,
+ int i_analyzefid )
{
int i_cnt;
int i_secnum;
int i_index;
int i_user_section;
char *pstr_secname;
+ Byte *pb_data;
Elf64_Ehdr *p_elfhdr;
Elf64_Shdr *p_sechdr;
Elf64_Shdr *p_secstrhdr;
+ LibGoblin_SectionTable *p_sectbl;
+ // XXX: old
+ //LibGoblin_Format_Elf64 *p_elf;
- assert( NULL != p_elf );
+ assert( NULL != p_binfo );
+ pb_data = p_binfo->t_binfile[i_analyzefid].pb_binary;
assert( NULL != pb_data );
- p_elfhdr = p_elf->p_elfhdr;
-
+ p_elfhdr = (Elf64_Ehdr *)pb_data;
i_user_section = LIBGOBLIN_ELF_SEC_ID_DEFAULT_MAX;
+ // XXX: old
+ //p_elf = (LibGoblin_Format_Elf64 *)p_binfo->p_format;
+
/* Get Section Header of the "Section-Name Section" */
p_secstrhdr = (Elf64_Shdr *)(pb_data + p_elfhdr->e_shoff
- + (p_elfhdr->e_shentsize * p_elfhdr->e_shstrndx));
+ + (p_elfhdr->e_shentsize * p_elfhdr->e_shstrndx));
i_secnum = p_elfhdr->e_shnum;
for( i_cnt = 0; i_cnt < i_secnum; i_cnt++ ) {
p_sechdr = (Elf64_Shdr *)(pb_data + (p_elfhdr->e_shoff)
+ (p_elfhdr->e_shentsize * i_cnt));
- pstr_secname = (char *)pb_data
- + p_secstrhdr->sh_offset
+ pstr_secname = (char *)pb_data + p_secstrhdr->sh_offset
+ p_sechdr->sh_name;
for( i_index = 0;
- i_index < LIBGOBLIN_ELF_SEC_ID_DEFAULT_MAX;
- i_index++ ) {
+ i_index < LIBGOBLIN_ELF_SEC_ID_DEFAULT_MAX; i_index++ ) {
if( !strncmp( pstr_secname,
- gstr_elf_section_name[i_index], 20 )) {
- p_elf->p_section[i_index] = p_sechdr;
+ gstr_elf_section_name[i_index], 20 )) {
+
+ p_sectbl = &(p_binfo->t_section[i_index]);
+
+ p_sectbl->pb_sechdr = (Byte *)p_sechdr;
+ p_sectbl->pb_data = (Byte *)(pb_data + p_sechdr->sh_offset);
+ p_sectbl->pstr_secname = pstr_secname;
+ p_sectbl->qw_size = p_sechdr->sh_size;
+ p_sectbl->i_fid = i_analyzefid;
+
+ // XXX: old
+ // p_elf->p_section[i_index] = p_sechdr;
break;
}
}
if( LIBGOBLIN_ELF_SEC_ID_DEFAULT_MAX == i_index ) {
- p_elf->p_section[i_user_section] = p_sechdr;
+ p_sectbl = &(p_binfo->t_section[i_index]);
+
+ p_sectbl->pb_sechdr = (Byte *)p_sechdr;
+ p_sectbl->pb_data = (Byte *)(pb_data + p_sechdr->sh_offset);
+ p_sectbl->pstr_secname = pstr_secname;
+ p_sectbl->qw_size = p_sechdr->sh_size;
+ p_sectbl->i_fid = i_analyzefid;
+
+ // XXX: old
+ // p_elf->p_section[i_user_section] = p_sechdr;
i_user_section++;
}
LibGoblin_BinaryInfo *p_binfo,
int i_analyzefid )
{
- //int i_err;
Byte *pb_data;
- LibGoblin_Format_Elf64 *p_elf;
+ //LibGoblin_Format_Elf64 *p_elf;
assert( NULL != p_binfo );
-
pb_data = p_binfo->t_binfile[i_analyzefid].pb_binary;
assert( NULL != pb_data );
- assert( NULL != p_binfo->p_format );
- p_elf = (LibGoblin_Format_Elf64 *)p_binfo->p_format;
-
- /* Set ELF64 Header */
- p_elf->p_elfhdr = (Elf64_Ehdr *)pb_data;
+ // XXX: old
+ //assert( NULL != p_binfo->p_format );
+ //p_elf = (LibGoblin_Format_Elf64 *)p_binfo->p_format;
+ //p_elf->p_elfhdr = (Elf64_Ehdr *)pb_data;
/* Read & Analyze Section Header */
- LibGoblin_Elf64_SetSectionHeader( p_elf, pb_data );
+ LibGoblin_Elf64_SetSectionTable( p_binfo, i_analyzefid );
- //test( p_binfo );
-
return 0x00;
}
-/*
-int test( LibGoblin_BinaryInfo *p_bin )
-{
-
- //int i_err;
- Byte *p_data;
- LibGoblin_Format_Elf64 *p_elf;
- Elf64_Ehdr *p_elfhdr;
- Elf64_Shdr *p_sechdr;
- Elf64_Shdr *p_secstrhdr;
- FILE *fp;
- int i_cnt;
- int i_secnum;
- char fname[256];
- Byte *p_start;
- DWord dw_size;
-
- assert( NULL != p_bin );
-
- assert( NULL != p_bin->pb_binary );
- p_data = p_bin->pb_binary;
-
- assert( NULL != p_bin->p_format );
- p_elf = (LibGoblin_Format_Elf64 *)p_bin->p_format;
- p_elfhdr = p_elf->p_elfhdr;
-
- p_secstrhdr = (Elf64_Shdr *)(p_bin->pb_binary + p_elfhdr->e_shoff + (p_elfhdr->e_shentsize * p_elfhdr->e_shstrndx));
-
- i_secnum = p_elfhdr->e_shnum;
- printf( "%d\n", i_secnum );
- for( i_cnt = 0; i_cnt < i_secnum; i_cnt++ ) {
- p_sechdr = p_bin->pb_binary + (p_elfhdr->e_shoff) + (p_elfhdr->e_shentsize * i_cnt);
- snprintf(fname, 256, "bin%s", ((char *)p_bin->pb_binary + p_secstrhdr->sh_offset + p_sechdr->sh_name));
- printf( "%d: %s\n", i_cnt, fname );
- p_start = (Byte *)p_bin->pb_binary + (p_sechdr->sh_offset);
- dw_size = p_sechdr->sh_size;
- fp = fopen( fname, "wb");
- fwrite( p_start, dw_size, 1, fp);
- fclose( fp);
- }
-
-
- return 0x00;
-}
-*/
-
/* EOF of drd64_.c ----------------------------------- */