OSDN Git Service

* WorkBackup: 2015/11/05(Thr) AM 05:20 (Before delete BinaryInfo.p_format member)
authorKoine Yuusuke(koinec) <koinec@users.osdn.me>
Wed, 4 Nov 2015 20:22:01 +0000 (05:22 +0900)
committerKoine Yuusuke(koinec) <koinec@users.osdn.me>
Wed, 4 Nov 2015 20:22:01 +0000 (05:22 +0900)
libgoblin/drd64_libgoblin_checkbin.c
libgoblin/drd64_libgoblin_checkbin.h
libgoblin/drd64_libgoblin_dwarf.c
libgoblin/drd64_libgoblin_elf.c
libgoblin/drd64_libgoblin_elf64.c
libgoblin/drd64_libgoblin_type.h

index 48c871c..7b06778 100644 (file)
@@ -41,8 +41,32 @@ Comment:
 LIBGOBLIN_CHECKBIN_EXTERN
 int
        LibGoblin_CheckBinary(
-               LibGoblin_BinaryInfo    *p_bin )
+                       LibGoblin_BinaryInfo    *p_binfo,
+                       int             i_analyzefid )
 {
+       Byte    *pb_data;
+       LibGoblin_BinaryFile    *p_bfile;
+
+       assert( NULL != p_binfo );
+       pb_data = p_binfo->t_binfile[i_analyzefid].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; }
+       else
+               { return -0x01; }
+
+       /* 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; }
+       else
+               { return -0x02; }
+
 
        return 0x00;
 }
index e8b4e8e..b70b3c5 100644 (file)
@@ -47,9 +47,8 @@ Comment:
 
 
 LIBGOBLIN_CHECKBIN_EXTERN
-       int
-               LibGoblin_CheckBinary(
-                       LibGoblin_BinaryInfo  *p_bin );
+       int LibGoblin_CheckBinary(
+                               LibGoblin_BinaryInfo *p_bin, int i_analyzefid );
 
 
 #endif /* DRD64_HEADER_LIBGOBLIN_CHECKBIN */
index 457be1a..0a35037 100644 (file)
@@ -103,7 +103,7 @@ int
        LibGoblin_Dwarf_SourceFile      *p_src;
 
        assert( NULL != p_bin );
-       assert( NULL != p_bin->p_format );
+       //assert( NULL != p_bin->p_format );
 
        /* Alloc Debug-Info(Dwarf) Struct Memory */
        p_dwarf = (LibGoblin_Debug_Dwarf *)malloc( sizeof(LibGoblin_Debug_Dwarf) );
index 114d844..31720da 100644 (file)
@@ -71,16 +71,17 @@ Byte *
                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;
@@ -88,6 +89,12 @@ Byte *
 
        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];
@@ -100,7 +107,7 @@ Byte *
                pb_data         = (Byte *)(pb_binary + p_elfshr32->sh_offset);
                *qw_secsize     = (QWord)p_elfshr32->sh_size;
        }
-
+*/
        return pb_data;
 }
 
@@ -113,6 +120,7 @@ int
                LibGoblin_BinaryInfo    *p_binfo,
                int             i_analyzefid )
 {
+       int             i_result;
        Byte    *pb_data;
        LibGoblin_BinaryFile    *p_bfile;
 
@@ -121,20 +129,9 @@ int
        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();
        }
@@ -144,8 +141,15 @@ int
        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 );
        }
index c0eb41f..29bef6f 100644 (file)
@@ -40,6 +40,7 @@ Comment:
 
 /*----------------------------------------------------------------------
 ----------------------------------------------------------------------*/
+/*
 LIBGOBLIN_ELF64_EXTERN
 void *
        LibGoblin_Elf64_AllocFormat(
@@ -55,57 +56,81 @@ void *
        
        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++;
                }
 
@@ -124,74 +149,23 @@ int
                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 ----------------------------------- */
index 5506e4e..9f4c527 100644 (file)
@@ -166,7 +166,9 @@ typedef struct      {
 
 /*=====================================================================*/
 typedef struct {
+       Byte    *pb_sechdr;
        Byte    *pb_data;
+       char    *pstr_secname;
        QWord   qw_size;
        int             i_fid;
 } LibGoblin_SectionTable;
@@ -189,7 +191,7 @@ typedef struct      {
        LibGoblin_BinaryFile    t_binfile[3];
 
        /* Binary-Format Depending Info. (ELF)*/
-       void            *p_format;
+       //void          *p_format;
 
        LibGoblin_SectionTable  t_section[LIBGOBLIN_ELF_SEC_ID_MAX];