OSDN Git Service

*WorkBackup: 2016/01/31(Sun) 21:33 (Coding for drd64_libgoblin_elf_dynver.c: resolvin...
authorKoine Yuusuke(koinec) <koinec@users.osdn.me>
Sun, 31 Jan 2016 12:34:38 +0000 (21:34 +0900)
committerKoine Yuusuke(koinec) <koinec@users.osdn.me>
Sun, 31 Jan 2016 12:34:38 +0000 (21:34 +0900)
libgoblin/drd64_libgoblin.h
libgoblin/drd64_libgoblin_binfo.c
libgoblin/drd64_libgoblin_elf_dynver.c
libgoblin/drd64_libgoblin_type.h

index c136292..6af465b 100644 (file)
@@ -44,6 +44,8 @@ Comment:
 #include<fcntl.h>
 #include<unistd.h>
 #include<assert.h>
+#include<sys/param.h>
+#include<sys/limits.h>
 
 #ifdef __FreeBSD__
 #include<elf.h>
index 7bc6236..bf3309d 100644 (file)
@@ -81,7 +81,11 @@ int
                        LibGoblin_BinaryInfo    *p_binfo,
                        const char      *pstr_program )
 {
+       int                     i_len;
+       char            str_temp[MAXPATHLEN];
+       char            *pstr_temp;
        LibGoblin_BinaryFile    *p_bfile;
+
        assert( NULL != p_binfo );
 
        if( LIBGOBLIN_BINFO_PHASE_ALLOCED < p_binfo->b_phase )  {
@@ -94,7 +98,25 @@ int
                return -0x02;
        }
 
-       strncpy( p_bfile->str_filepath, pstr_program, DRD64_MAX_PATH );
+       // Convert relative-filepath to absolute-filepath. 
+       pstr_temp       = realpath( pstr_program, str_temp );
+       if( NULL == pstr_temp ) {
+               return -0x03;
+       }
+
+       i_len   = strnlen( str_temp, MAXPATHLEN );
+       if( DRD64_MAX_PATH <= i_len )   {
+               return -0x04;
+       }
+       
+       strncpy( p_bfile->str_filepath, str_temp, DRD64_MAX_PATH );
+
+       for( pstr_temp = str_temp + i_len;
+                       ((pstr_temp != str_temp) && ('/' != *pstr_temp)); pstr_temp-- );
+       *pstr_temp      = '\0';
+
+       strncpy( p_binfo->str_filename, (pstr_temp + 1), DRD64_MAX_PATH );
+       strncpy( p_binfo->str_path, str_temp, DRD64_MAX_PATH );
 
        p_binfo->b_phase        = LIBGOBLIN_BINFO_PHASE_SETPROG;
 
index e8e49c0..5263595 100644 (file)
@@ -47,18 +47,22 @@ int
                int             i_analyzefid )
 {
        Byte                                    *pb_data;
+       Byte                                    *pb_dynstr;
        int                                             i_sz_elfdyn;
        QWord                                   qw_tag;
        QWord                                   qw_value;
        Ptr                                             ptr_addr;
        Elf64_Dyn                               *p_dyn64;
        Elf32_Dyn                               *p_dyn32;
+       LibGoblin_BinaryInfo    *p_bin_next;
        LibGoblin_BinaryFile    *p_bfile;
        LibGoblin_SectionInfo   *p_sec_dynamic;
        LibGoblin_SectionInfo   *p_sec_dynstr;
+       LibGoblin_ProgramInfo   *p_pginfo;
 
        assert( NULL != p_binfo );
        p_bfile = &(p_binfo->t_binfile[i_analyzefid]);
+       p_pginfo        = (LibGoblin_ProgramInfo *)p_binfo->pv_pginfo;
 
        // Read & Check SectionInfo ---
        p_sec_dynamic   = LibGoblin_Section_GetSectionInfo_fid(
@@ -72,6 +76,7 @@ int
        if( NULL == p_sec_dynstr )              {
                return 0x02;
        }
+       pb_dynstr       = p_sec_dynstr->pb_data;
 
        pb_data = p_sec_dynamic->pb_data;
        if( IsBinfoType_Elf64( p_binfo ) )
@@ -94,6 +99,18 @@ int
                        qw_value        = (QWord)p_dyn32->d_un.d_val;
                        ptr_addr        = (Ptr)p_dyn32->d_un.d_ptr;
                }
+
+               if( DT_NEEDED == qw_tag )       {
+                       //p_bin_next    = LibGoblin_ProgInfo_AddBinaryInfo( p_pginfo );
+                       //printf("%s\n", pb_dynstr + qw_value );
+               }
+               else if( DT_RPATH == qw_tag )   {
+                       strncpy( p_binfo->str_rpath, (char *)(pb_dynstr + qw_value), DRD64_MAX_PATH );
+               }
+               /*
+               else if( DT_SONAME == qw_tag )  { }
+               */
+
                pb_data += i_sz_elfdyn;
        }while( DT_NULL != qw_tag );
 
index 1ca0e92..2ff1bdf 100644 (file)
@@ -137,6 +137,10 @@ typedef struct     {
        DWord           dw_max_addrinfo;
 
        /* Exec. File Info. */
+       char            str_filename[DRD64_MAX_PATH];
+       char            str_path[DRD64_MAX_PATH];
+       char            str_rpath[DRD64_MAX_PATH];
+       
        LibGoblin_BinaryFile    t_binfile[3];
 
        /* Binary-Format Depending Info. (ELF)*/