OSDN Git Service

2019/02/18(Mon) 20:43
authorKoine Yuusuke(koinec) <koinec@users.osdn.me>
Mon, 18 Feb 2019 11:42:59 +0000 (20:42 +0900)
committerKoine Yuusuke(koinec) <koinec@users.osdn.me>
Mon, 18 Feb 2019 11:42:59 +0000 (20:42 +0900)
 (LibGoblin)
  * WorkBackup

libgoblin/Makefile
libgoblin/drd64_libgoblin.h
libgoblin/drd64_libgoblin_debug_elf.c
libgoblin/drd64_libgoblin_elf_dynsym.c [new file with mode: 0644]
libgoblin/drd64_libgoblin_elf_dynsym.h [new file with mode: 0644]
libgoblin/drd64_libgoblin_elf_symtab.h
libgoblin/drd64_libgoblin_section.c
libgoblin/drd64_libgoblin_section.h

index 63a31d7..ece3eb3 100644 (file)
@@ -61,6 +61,7 @@ OBJS = drd64_libgoblin_api.o \
                drd64_libgoblin_section.o \
                drd64_libgoblin_elf.o \
                drd64_libgoblin_elf_dynamic.o \
+               drd64_libgoblin_elf_dynsym.o \
                drd64_libgoblin_elf_symtab.o \
                drd64_libgoblin_elf_proghdr.o \
                drd64_libgoblin_elf_section.o \
@@ -89,6 +90,7 @@ HEADER = drd64_libgoblin.h \
                drd64_libgoblin_section.h \
                drd64_libgoblin_elf.h \
                drd64_libgoblin_elf_dynamic.h \
+               drd64_libgoblin_elf_dynsym.h \
                drd64_libgoblin_elf_symtab.h \
                drd64_libgoblin_elf_proghdr.h \
                drd64_libgoblin_elf_section.h \
@@ -180,6 +182,9 @@ drd64_libgoblin_elf.o: drd64_libgoblin_elf.c $(HEADER)
 drd64_libgoblin_elf_dynamic.o: drd64_libgoblin_elf_dynamic.c $(HEADER)
        $(CC) -c -o drd64_libgoblin_elf_dynamic.o $(FLAGS_DEBUG) \
                                drd64_libgoblin_elf_dynamic.c
+drd64_libgoblin_elf_dynsym.o: drd64_libgoblin_elf_dynsym.c $(HEADER)
+       $(CC) -c -o drd64_libgoblin_elf_dynsym.o $(FLAGS_DEBUG) \
+                               drd64_libgoblin_elf_dynsym.c
 drd64_libgoblin_elf_symtab.o: drd64_libgoblin_elf_symtab.c $(HEADER)
        $(CC) -c -o drd64_libgoblin_elf_symtab.o $(FLAGS_DEBUG) \
                                drd64_libgoblin_elf_symtab.c
index fc3fecf..a0258b3 100644 (file)
@@ -83,6 +83,7 @@ Comment:
 #include"drd64_libgoblin_objinfo.h"
 #include"drd64_libgoblin_elf.h"
 #include"drd64_libgoblin_elf_dynamic.h"
+#include"drd64_libgoblin_elf_dynsym.h"
 #include"drd64_libgoblin_elf_symtab.h"
 #include"drd64_libgoblin_elf_proghdr.h"
 #include"drd64_libgoblin_elf_section.h"
index 40eafea..5e009dc 100644 (file)
@@ -48,10 +48,7 @@ int
 {
        Byte                                    b_cnt;
        void                                    *p_shdr;
-       PtrValue                                ptr_start;
        LibGoblin_SectionInfo   *p_secinfo;
-       Elf64_Shdr                              *p_shdr64;
-       Elf32_Shdr                              *p_shdr32;
 
        if( 0x00 < b_level )
                { puts("[DEBUG] Section Table -----------------------------------------------"); }
diff --git a/libgoblin/drd64_libgoblin_elf_dynsym.c b/libgoblin/drd64_libgoblin_elf_dynsym.c
new file mode 100644 (file)
index 0000000..3bf6e65
--- /dev/null
@@ -0,0 +1,156 @@
+/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
+
+                         D r . D e a m o n  6 4
+                        for INTEL64(R), AMD64(R)
+       
+   Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+    this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
+
+/* File Info -----------------------------------------------------------
+File: drd64_.c
+Function: 
+Comment: 
+----------------------------------------------------------------------*/
+
+#define        DRD64_SRC_LIBGOBLIN_ELF_DYNSYM
+#include"drd64_libgoblin.h"
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBGOBLIN_ELF_DYNSYM_EXTERN
+int
+       ELF64_DynSym_ReadSection(
+                       LibGoblin_BinaryInfo    *p_binfo )
+{
+/*
+       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_DYNSYM );
+       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;
+
+       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;
+       }
+*/
+       return 0x00;
+}
+
+
+
+/* EOF of drd64_.c ----------------------------------- */
+
+
diff --git a/libgoblin/drd64_libgoblin_elf_dynsym.h b/libgoblin/drd64_libgoblin_elf_dynsym.h
new file mode 100644 (file)
index 0000000..a87a34d
--- /dev/null
@@ -0,0 +1,60 @@
+/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
+
+                         D r . D e a m o n  6 4
+                        for INTEL64(R), AMD64(R)
+       
+   Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+    this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
+
+/* File Info -----------------------------------------------------------
+File: drd64_.h
+Function: Header 
+Comment: 
+----------------------------------------------------------------------*/
+
+#ifndef DRD64_HEADER_LIBGOBLIN_ELF_DYNSYM
+#define DRD64_HEADER_LIBGOBLIN_ELF_DYNSYM
+
+#include"drd64_libgoblin.h"
+
+#ifdef DRD64_SRC_LIBGOBLIN_ELF_DYNSYM
+       #define LIBGOBLIN_ELF_DYNSYM_EXTERN
+#else
+       #define LIBGOBLIN_ELF_DYNSYM_EXTERN     extern
+#endif
+
+
+#ifdef DRD64_SRC_LIBGOBLIN_ELF_DYNSYM
+#endif
+
+
+LIBGOBLIN_ELF_DYNSYM_EXTERN
+       int ELF64_DynSym_ReadSection(
+                       LibGoblin_BinaryInfo    *p_binfo );
+
+
+#endif /* DRD64_HEADER_LIBGOBLIN_BINFO */
+
+/* EOF of drd64_.h ----------------------------------- */
index d64a6ea..03b3fd0 100644 (file)
@@ -51,8 +51,8 @@ Comment:
 
 
 LIBGOBLIN_ELF_SYMTAB_EXTERN
-       int Elf_Symtab_ReadSymtabSection(
-                       LibGoblin_ProgramInfo   *p_pginfo );
+       int ELF64_Symtab_ReadSection(
+                       LibGoblin_BinaryInfo    *p_binfo );
 
 
 #endif /* DRD64_HEADER_LIBGOBLIN_BINFO */
index a47100d..561187e 100644 (file)
@@ -278,6 +278,7 @@ int
 
 /*----------------------------------------------------------------------
 ----------------------------------------------------------------------*/
+LIBGOBLIN_SECTION_EXTERN
 int
        Section_InsetObjectInfo_fromSection(
                LibGoblin_ProgramInfo   *p_pginfo )
index 62f063d..29196fd 100644 (file)
@@ -120,6 +120,9 @@ LIBGOBLIN_SECTION_EXTERN
 LIBGOBLIN_SECTION_EXTERN
        int Section_UpdateSectionInfo_inProgInfo(
                        LibGoblin_ProgramInfo *p_pginfo, LibGoblin_BinaryInfo *p_binfo );
+LIBGOBLIN_SECTION_EXTERN
+       int Section_InsetObjectInfo_fromSection( LibGoblin_ProgramInfo *p_pginfo );
+
 
 #endif /* DRD64_HEADER_LIBGOBLIN_BINFO */