OSDN Git Service

2019/03/23(Sat) 21:12
authorKoine Yuusuke(koinec) <koinec@users.osdn.me>
Sat, 23 Mar 2019 12:10:44 +0000 (21:10 +0900)
committerKoine Yuusuke(koinec) <koinec@users.osdn.me>
Sat, 23 Mar 2019 12:10:44 +0000 (21:10 +0900)
 (LibGoblin)
  * WorkBackup
  [TODO]
   * Add ptr_loadbase to Section ObjectInfo Address
   * Implement Duplicate reading SectionInfo to BinaryFile.

libgoblin/drd64_libgoblin_debug_elf.c
libgoblin/drd64_libgoblin_elf_dynamic.c
libgoblin/drd64_libgoblin_elf_dynsym.c
libgoblin/drd64_libgoblin_elf_gnuver.c
libgoblin/drd64_libgoblin_elf_hash.c
libgoblin/drd64_libgoblin_elf_rela.c
libgoblin/drd64_libgoblin_elf_symtab.c
libgoblin/drd64_libgoblin_section.c
libgoblin/drd64_libgoblin_section.h

index e124252..8142cfb 100644 (file)
@@ -57,7 +57,7 @@ int
                { puts("[DEBUG] Section Table -----------------------------------------------"); }
 
        for( b_cnt = 0; b_cnt < LIBGOBLIN_SECTION_ID_MAX; b_cnt++ )             {
-               p_secinfo       = Section_GetSectionInfo_fromBinaryInfo( p_binfo, b_cnt );
+               p_secinfo       = Section_GetSectionInfo( p_binfo, b_cnt );
                assert( NULL != p_secinfo );
                p_shdr          = (void *)p_secinfo->pb_sechdr;
 
index 8d6a239..26ea19a 100644 (file)
@@ -134,7 +134,6 @@ int
        QWord                                   qw_tag;
        QWord                                   qw_value;
        QWord                                   qw_dynsize;
-       //PtrValue                              ptr_value;
        PtrValue                                ptr_dynvalue;
        Elf64_Ehdr                              *p_elfhdr;
        Elf64_Phdr                              *p_pghdr_dynamic;
@@ -171,7 +170,6 @@ int
                p_dyn64         = (Elf64_Dyn *)pb_dynamic;
                qw_tag          = (QWord)p_dyn64->d_tag;
                qw_value        = (QWord)p_dyn64->d_un.d_val;
-               //ptr_value     = (PtrValue)p_dyn64->d_un.d_ptr;
 
                /* 05 - Address of string table. */
                if( DT_STRTAB == qw_tag )               { ptr_dynvalue  = qw_value; }
@@ -194,7 +192,7 @@ int
                p_pghdr_dynstr  = ELF64_ProgramHeader_Search_inRange( p_binfo, ptr_dynvalue, qw_dynsize );
                assert( NULL != p_pghdr_dynstr );
 
-               p_sec_dynstr    = Section_GetSectionInfo_fromBinaryInfo( p_binfo, LIBGOBLIN_SECTION_ID_DYNSTR );
+               p_sec_dynstr    = Section_GetSectionInfo_fromBinaryFile( p_bfile, LIBGOBLIN_SECTION_ID_DYNSTR );
                p_sec_dynstr->qw_size                   = qw_dynsize;
                p_sec_dynstr->ptr_addr.value    = ptr_dynvalue;
                p_sec_dynstr->pb_data                   = pb_data
@@ -220,15 +218,16 @@ void
        LibGoblin_SectionInfo   *p_secnow;
        LibGoblin_BinaryFile    *p_bfile;
 
-       p_secnow        = Section_GetSectionInfo_fromBinaryInfo( p_binfo, dw_secid );
+       p_bfile = BinaryFile_GetBinaryFile( p_binfo->i_binfile );
+       assert( NULL != p_bfile );
+
+       p_secnow        = Section_GetSectionInfo_fromBinaryFile( p_bfile, dw_secid );
        if( NULL == p_secnow->pb_sechdr )       {
                p_secnow->qw_size       = qw_value;
                p_secnow->i_binfile     = -0x01;        // Temporary.
 
                // Calc. Offset
                if(( 0x00000000 != p_secnow->ptr_addr.value ) && ( 0 < p_secnow->qw_size ))     {
-                       p_bfile = BinaryFile_GetBinaryFile( p_binfo->i_binfile );
-                       assert( NULL != p_bfile );
 
                        p_pghdr = ELF64_ProgramHeader_Search_inRange(
                                                        p_binfo, p_secnow->ptr_addr.value, p_secnow->qw_size );
@@ -256,15 +255,16 @@ void
        LibGoblin_SectionInfo   *p_secnow;
        LibGoblin_BinaryFile    *p_bfile;
 
-       p_secnow        = Section_GetSectionInfo_fromBinaryInfo( p_binfo, dw_secid );
+       p_bfile = BinaryFile_GetBinaryFile( p_binfo->i_binfile );
+       assert( NULL != p_bfile );
+
+       p_secnow        = Section_GetSectionInfo_fromBinaryFile( p_bfile, dw_secid );
        if( NULL == p_secnow->pb_sechdr )       {
                p_secnow->ptr_addr.value        = ptr_value;
                p_secnow->i_binfile                     = -0x01;        // Temporary.
 
                // Calc. Offset
                if(( 0x00000000 != p_secnow->ptr_addr.value ) && ( 0 < p_secnow->qw_size ))     {
-                       p_bfile = BinaryFile_GetBinaryFile( p_binfo->i_binfile );
-                       assert( NULL != p_bfile );
 
                        p_pghdr = ELF64_ProgramHeader_Search_inRange(
                                                        p_binfo, p_secnow->ptr_addr.value, p_secnow->qw_size );
@@ -306,16 +306,16 @@ int
        p_pginfo        = ProgInfo_GetProgInfo( p_binfo->i_pginfo );
 
        // Read & Check SectionInfo ---
-       p_sec_dynamic   = Section_GetSectionInfo_fromBinaryInfo(
-                                                       p_binfo, LIBGOBLIN_SECTION_ID_DYNAMIC );
+       p_sec_dynamic   = Section_GetSectionInfo_fromBinaryFile(
+                                                               p_bfile, LIBGOBLIN_SECTION_ID_DYNAMIC );
        assert( NULL != p_sec_dynamic );
        if( NULL == p_sec_dynamic->pb_data )    {
                return 0x01;
        }
        pb_data = p_sec_dynamic->pb_data;
 
-       p_sec_dynstr    = Section_GetSectionInfo_fromBinaryInfo(
-                                               p_binfo, LIBGOBLIN_SECTION_ID_DYNSTR );
+       p_sec_dynstr    = Section_GetSectionInfo_fromBinaryFile(
+                                                               p_bfile, LIBGOBLIN_SECTION_ID_DYNSTR );
        assert( NULL != p_sec_dynstr );
        if( NULL == p_sec_dynstr->pb_data )             {
                return 0x02;
index fc4ae42..c8286fe 100644 (file)
@@ -70,7 +70,7 @@ int
        LibGoblin_BinaryInfo    *p_binlib;
 
        // Check exist .dynsym section ---
-       psec_dynsym     = Section_GetSectionInfo_fromBinaryInfo(
+       psec_dynsym     = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_DYNSYM );
        assert( NULL != psec_dynsym );
        if( NULL == psec_dynsym->pb_sechdr )    {
@@ -78,7 +78,7 @@ int
        }
        p_shdr  = (Elf64_Shdr *)(psec_dynsym->pb_sechdr);
 
-       psec_dynstr     = Section_GetSectionInfo_fromBinaryInfo(
+       psec_dynstr     = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_DYNSTR );
        assert( NULL != psec_dynstr );
        if( NULL == psec_dynstr->pb_data )      {
@@ -89,7 +89,7 @@ int
        // Read & Generate DynSym_Version struct data ---
        p_verneed       = ELF64_GnuVer_GenerateGnuVerNeed( &dw_vermax, p_binfo );
        if( NULL != p_verneed ) {
-               psec_gnuver     = Section_GetSectionInfo_fromBinaryInfo(
+               psec_gnuver     = Section_GetSectionInfo(
                                                                p_binfo, LIBGOBLIN_SECTION_ID_GNU_VERSION );
                assert( NULL != psec_gnuver );
                if( NULL == psec_gnuver->pb_data )      {
index 5e15a9c..52db981 100644 (file)
@@ -58,7 +58,7 @@ int
        LibGoblin_SectionInfo   *psec_gnuver_d;
 
        //----------------------------
-       psec_gnuver_d   = Section_GetSectionInfo_fromBinaryInfo(
+       psec_gnuver_d   = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_GNU_VERSION_D );
        assert( NULL != psec_gnuver_d );
        if( NULL == psec_gnuver_d->pb_data )
@@ -66,7 +66,7 @@ int
 
        pb_gnuver_d     = psec_gnuver_d->pb_data;
 
-       psec_dynstr     = Section_GetSectionInfo_fromBinaryInfo(
+       psec_dynstr     = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_DYNSTR );
        assert( NULL != psec_dynstr );
        if( NULL == psec_dynstr->pb_data )
@@ -136,7 +136,7 @@ GnuVer_VerNeed *
 
 
        // Check exist .dynsym section ---
-       psec_dynsym     = Section_GetSectionInfo_fromBinaryInfo(
+       psec_dynsym     = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_DYNSYM );
        assert( NULL != psec_dynsym );
        if( NULL == psec_dynsym->pb_sechdr )
@@ -144,14 +144,14 @@ GnuVer_VerNeed *
        p_shdr  = (Elf64_Shdr *)(psec_dynsym->pb_sechdr);
        assert( NULL != p_shdr );
 
-       psec_dynstr     = Section_GetSectionInfo_fromBinaryInfo(
+       psec_dynstr     = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_DYNSTR );
        assert( NULL != psec_dynstr );
        if( NULL == psec_dynstr->pb_data )
                { goto  goto_ELF64_GnuVer_GenerateGnuVerNeed_post; }
        pb_dynstr       = psec_dynstr->pb_data;
 
-       psec_gnuver_r   = Section_GetSectionInfo_fromBinaryInfo(
+       psec_gnuver_r   = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_GNU_VERSION_R );
        assert( NULL != psec_gnuver_r );
        if( NULL == psec_gnuver_r->pb_data )
index 3fc734a..3fb129e 100644 (file)
@@ -87,7 +87,7 @@ int
 
 
        // ----------------
-       psec_dynsym     = Section_GetSectionInfo_fromBinaryInfo(
+       psec_dynsym     = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_DYNSYM );
        assert( NULL != psec_dynsym );
        if( NULL == psec_dynsym->pb_data )      {
@@ -97,7 +97,7 @@ int
        p_dynsym        = (Elf64_Sym *)pb_dynsym;
 
        // ----------------
-       psec_dynstr     = Section_GetSectionInfo_fromBinaryInfo(
+       psec_dynstr     = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_DYNSTR );
        assert( NULL != psec_dynstr );
        if( NULL == psec_dynstr->pb_data )      {
@@ -106,7 +106,7 @@ int
        pb_dynstr       = psec_dynstr->pb_data;
 
        // ----------------
-       psec_gnuhash    = Section_GetSectionInfo_fromBinaryInfo(
+       psec_gnuhash    = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_GNU_HASH );
        assert( NULL != psec_gnuhash );
        if( NULL == psec_gnuhash->pb_data )     {
@@ -115,7 +115,7 @@ int
        pb_gnuhash      = psec_gnuhash->pb_data;
 
        // ----------------
-       psec_gnuver     = Section_GetSectionInfo_fromBinaryInfo(
+       psec_gnuver     = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_GNU_VERSION );
        assert( NULL != psec_gnuver );
        if( NULL == psec_gnuver->pb_data )      {
index 8386513..886fd15 100644 (file)
@@ -60,7 +60,7 @@ int
        LibGoblin_ObjectInfo    *pobj_rel;
        LibGoblin_ObjectInfo    *pobj_origin;
 
-       psec_rela       = Section_GetSectionInfo_fromBinaryInfo( p_binfo, b_secid );
+       psec_rela       = Section_GetSectionInfo( p_binfo, b_secid );
        if( NULL == psec_rela ) {
                return 0x00;
        }
@@ -70,12 +70,12 @@ int
        pelf_rela       = (Elf64_Rela *)psec_rela->pb_data;
 
        // ----------------
-       psec_dynsym = Section_GetSectionInfo_fromBinaryInfo( p_binfo, LIBGOBLIN_SECTION_ID_DYNSYM );
+       psec_dynsym = Section_GetSectionInfo( p_binfo, LIBGOBLIN_SECTION_ID_DYNSYM );
        if( NULL == psec_dynsym )       { return 0x00; }
        if( NULL == psec_dynsym->pb_data )      { return 0x00; }
 
        // ----------------
-       psec_dynstr = Section_GetSectionInfo_fromBinaryInfo( p_binfo, LIBGOBLIN_SECTION_ID_DYNSTR );
+       psec_dynstr = Section_GetSectionInfo( p_binfo, LIBGOBLIN_SECTION_ID_DYNSTR );
        if( NULL == psec_dynstr )       { return 0x00; }
        if( NULL == psec_dynstr->pb_data )      {
                return -0x01;
index 95f7f4d..7cfe506 100644 (file)
@@ -134,7 +134,7 @@ int
        assert( NULL != p_binfo );
 
        // Check BinaryInfo & Get SymbolEntires
-       p_secinfo       = Section_GetSectionInfo_fromBinaryInfo(
+       p_secinfo       = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_SYMTAB );
        assert( NULL != p_secinfo );
        if( NULL == p_secinfo->pb_data )        {
@@ -142,7 +142,7 @@ int
        }
        pb_symtab       = p_secinfo->pb_data;
 
-       p_secstr        = Section_GetSectionInfo_fromBinaryInfo(
+       p_secstr        = Section_GetSectionInfo(
                                                        p_binfo, LIBGOBLIN_SECTION_ID_STRTAB );
        assert( NULL != p_secstr );
        if( NULL == p_secstr->pb_data ) {
index 3172e2d..1e612dc 100644 (file)
@@ -62,15 +62,13 @@ LibGoblin_SectionInfo *
 ----------------------------------------------------------------------*/
 LIBGOBLIN_SECTION_EXTERN
 LibGoblin_SectionInfo *
-       Section_GetSectionInfo_fromBinaryInfo(
-                       LibGoblin_BinaryInfo    *p_binfo,
+       Section_GetSectionInfo_fromBinaryFile(
+                       LibGoblin_BinaryFile    *p_bfile,
                        Byte    b_secid )
 {
-       LibGoblin_BinaryFile    *p_bfile;
        LibGoblin_SectionInfo   *p_secinfo;
 
-       assert( NULL != p_binfo );
-       p_bfile = BinaryFile_GetBinaryFile( p_binfo->i_binfile );
+       assert( NULL != p_bfile );
 
        if( LIBGOBLIN_SECTION_ID_MAX <= b_secid )       { return NULL; }
 
index b3f5fcc..fada65e 100644 (file)
@@ -106,8 +106,8 @@ Comment:
 LIBGOBLIN_SECTION_EXTERN
        LibGoblin_SectionInfo *Section_GetSectionInfo( LibGoblin_BinaryInfo *p_binfo, Byte b_secid );
 LIBGOBLIN_SECTION_EXTERN
-       LibGoblin_SectionInfo *Section_GetSectionInfo_fromBinaryInfo(
-                       LibGoblin_BinaryInfo *p_binfo, Byte b_secid );
+       LibGoblin_SectionInfo *Section_GetSectionInfo_fromBinaryFile(
+                       LibGoblin_BinaryFile *p_bfile, Byte b_secid );
 LIBGOBLIN_SECTION_EXTERN
        int Section_UpdateSectionInfo_inBinaryInfo( LibGoblin_BinaryInfo *p_binfo );
 LIBGOBLIN_SECTION_EXTERN