OSDN Git Service

2018/11/02(Fri) 21:34
[drdeamon64/drdeamon64.git] / libgoblin / drd64_libgoblin_elf.c
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11  1. Redistributions of source code must retain the above copyright notice,
12     this list of conditions and the following disclaimer.
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_.c
33 Function: 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #define DRD64_SRC_LIBGOBLIN_ELF
38 #include"drd64_libgoblin.h"
39
40
41 /*----------------------------------------------------------------------
42 ----------------------------------------------------------------------*/
43 LIBGOBLIN_ELF_EXTERN 
44 int
45         ELF_IsElf(
46                 Byte    *p_data )
47 {
48
49         assert( NULL != p_data );
50         if( ( ELFMAG0 == *(p_data + EI_MAG0) )
51                         && ( ELFMAG1 == *(p_data + EI_MAG1) )
52                         && ( ELFMAG2 == *(p_data + EI_MAG2) )
53                         && ( ELFMAG3 == *(p_data + EI_MAG3) ) )
54                 { return 0x01; }
55
56         return 0x00;
57 }
58
59
60 /*----------------------------------------------------------------------
61 Will Deprecate Functions!!! - Not Use!
62 ----------------------------------------------------------------------*/
63 LIBGOBLIN_ELF_EXTERN
64 Byte *
65         ELF_GetSection(
66                 QWord   *qw_secsize,
67                 LibGoblin_BinaryInfo    *p_binfo,
68                 Byte    b_secid )
69 {
70         Byte                                    *pb_data;
71         LibGoblin_BinaryFile    *p_bfile;
72         LibGoblin_SectionInfo   *p_sectbl;
73
74         assert( NULL != p_binfo );
75         p_bfile = BinaryFile_GetBinaryFile( p_binfo->i_binfile );
76
77         pb_data         = NULL;
78         *qw_secsize     = 0;
79
80
81         if( LIBGOBLIN_SECTION_ID_DEFAULT_MAX <= b_secid )       { return NULL; }
82
83         p_sectbl        = &(p_bfile->t_section[b_secid]);
84         if( NULL != p_sectbl->pb_sechdr )       {
85                 pb_data         = p_sectbl->pb_data;
86                 *qw_secsize     = p_sectbl->qw_size;
87         }
88
89         return pb_data;
90 }
91
92
93 /*----------------------------------------------------------------------
94 ----------------------------------------------------------------------*/
95 LIBGOBLIN_ELF_EXTERN
96 int
97         ELF_ReadELF_Phase1(
98                 LibGoblin_BinaryInfo    *p_binfo )
99 {
100         int             i_result        = 0x00;
101
102         assert( NULL != p_binfo );
103
104         /* ReCheck ELF Header -------------------*/
105         i_result        = LibGoblin_CheckBinary( p_binfo );
106         if( 0x00 != i_result )  {
107                 return i_result;
108         }
109
110         /* Analyze ELF Basical Struct & data -----*/
111         if( LIBGOBLIN_BINFO_TYPE_ELF64 == p_binfo->b_type )             {
112                 i_result        = LibGoblin_Elf64_SetSectionInfo( p_binfo );
113         }
114         else if( LIBGOBLIN_BINFO_TYPE_ELF32 == p_binfo->b_type )        {
115         }
116
117         if( 0x00 != i_result )  {
118                 return -0x01;
119         }
120
121         i_result        = LibGoblin_Elf_DynVer_ReadDynamicSection( p_binfo );
122         if( 0x00 > i_result )   {
123                 return -0x02;
124         }
125
126         return i_result;
127 }
128
129
130 /*----------------------------------------------------------------------
131 ----------------------------------------------------------------------*/
132 LIBGOBLIN_ELF_EXTERN
133 int
134         ELF_ReadELF_Phase2(
135                 LibGoblin_BinaryInfo    *p_binfo )
136 {
137         int             i_result;
138         Byte    *pb_data;
139         LibGoblin_BinaryFile            *p_bfile;
140         LibGoblin_SymbolWorkTable       t_symwork;
141
142         assert( NULL != p_binfo );
143         p_bfile = BinaryFile_GetBinaryFile( p_binfo->i_binfile );
144         pb_data = p_bfile->pb_binary;
145         assert( NULL != pb_data );
146
147         /* Create Symbol-Table ------------------*/
148
149         i_result        = LibGoblin_Section_ReadSymtabSection_toWorkTable(
150                                                                         p_binfo, &t_symwork );
151         if( 0x00 != i_result )  {
152                 return i_result;
153         }
154
155
156         LibGoblin_Debug_SymWork_PrintWorkTable( &t_symwork, 0x02 );
157
158
159         /* Analyze Dwarf-Debug Info. */
160 /*
161         if( 0x00 != LibGoblin_IsDwarf( p_binfo ) )      {
162                 LibGoblin_AnalyzeDwarf( p_binfo );
163         }
164 */
165
166         LibGoblin_SymWork_FreeSymbolWorkTable( &t_symwork );
167
168         return 0x00;
169 }
170
171
172
173 /* EOF of drd64_.c ----------------------------------- */
174
175