OSDN Git Service

2019/02/17(Sun) 20:31
[drdeamon64/drdeamon64.git] / libgoblin / drd64_libgoblin_type.h
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_.h
33 Function: Header 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #ifndef DRD64_HEADER_LIBGOBLIN_TYPE
38 #define DRD64_HEADER_LIBGOBLIN_TYPE
39
40
41 /*=====================================================================*/
42 typedef struct  {
43         Byte    *pb_sechdr;
44         Byte    *pb_data;               // FileLocation (Offset)
45         Word    w_index;
46         Ptr             ptr_addr;
47         QWord   qw_size;
48         char    *pstr_secname;
49         int             i_fid;
50 } LibGoblin_SectionInfo;
51
52
53 /*=====================================================================*/
54 /*typedef       struct  {
55         Ptr             ptr_address;    // Object Address
56         DWord   dw_size;                // Object Size (Address Range)
57         char    *pstr_name;             // Object Name (Param./Func./etc...)
58         //DWord dw_srcid;               // SourceInfo struct ID
59         DWord   dw_next;
60         Byte    b_elf_flags;
61         Word    w_secid;                // SectionInfo ItemIndex belong with this object.
62 } LibGoblin_AddressInfo ****OLD****   ;*/
63
64
65 /*=====================================================================*/
66 #define LIBGOBLIN_OBJINFO_INVALID       0x00
67 #define LIBGOBLIN_OBJINFO_VALID         0x01
68
69 #define OBJINFO_TYPE_NULL               0x00
70 #define OBJINFO_TYPE_MASTER             0x01
71 #define OBJINFO_TYPE_PROGHDR    0x02
72 #define OBJINFO_TYPE_SECTION    0x03
73 #define OBJINFO_TYPE_FUNCTION   0x04
74 #define OBJINFO_TYPE_OBJECT             0x05
75 #define OBJINFO_TYPE_COMMON             0x06
76 #define OBJINFO_TYPE_TLS                0x07
77
78 typedef struct  {
79         int             i_id;
80         Byte    b_status;
81         Byte    b_type;
82
83         // Address & Memory-Range Info ----
84         struct  {
85                 Ptr             ptr_addr;               // Object Address
86                 //   [Section] sh_addr - Address in memory image.
87                 //   [Symbol ] st_value - Symbol value.
88                 QWord   qw_size;                // Object Size (Address Range)
89                 //   [Symbol ] st_size - Size of associated object.
90         } addr;
91
92         // Group(Parent-Child) Order Link ---
93         struct  {
94                 int             i_parent_id;    // Parent ObjectInfo
95                 int             i_child_topid;  // Child Top ObjectInfo
96                 int             i_prev_id;
97                 int             i_next_id;              // Next 
98         } grplink;
99
100         // Address Order Link ---
101         struct  {
102                 int             i_next_id;              // Next Address ObjectInfo
103                 int             i_prev_id;              // Prev Address ObjectInfo
104         } addrlink;
105
106         // File Info ---
107         struct  {
108                 int             i_fid;
109                 void    *pv_offset;
110                 //   [Section] sh_offset - Offset in file.
111                 QWord   qw_size;
112         } file;
113
114         // ObjectInfo (DATA) ---
115         char    *pstr_name;             // Object Name (Param./Func./etc...)
116         //   [Section] = sh_name - Section name (index into the section header string table).
117         //   [Symbol ] = st_name - String table index of name.
118         DWord   dw_hash;
119
120         union   {
121                 Byte            b_data[128];
122
123                 struct  {
124                         DWord   dw_type;                // Entry type.
125                         DWord   dw_flags;               // Access permission flags.
126                         QWord   qw_align;               // Alignment in memory and file.
127                         void    *pv_proghdr;    // Program Header Pointer
128                 } proghdr;
129
130                 struct  {
131                         QWord   qw_flag;                // sh_flags - Section flags.
132                         QWord   qw_align;               // sh_addralign - Alignment in bytes.
133                         QWord   qw_entsize;             // sh_entsize - Size of each entry in section.
134                         DWord   dw_type;                // sh_type - Section type.
135                         DWord   dw_link;                // sh_link - Index of a related section.
136                         DWord   dw_info;                // sh_info - Depends on section type.
137                         void    *pv_sechdr;
138                 } section;
139
140                 struct  {
141                         Byte    b_type;                 // st_info - Type and binding information.
142                         Byte    b_binding;              // st_info - Type and binding information.
143                         Byte    b_visibility;   // st_other - Reserved (not used).
144                         Word    w_secindex;             // st_shndx - Section index of symbol.
145                 } symbol;
146
147         } info;
148
149         int             i_secid;
150         
151         int             i_srcid;                // SourceInfo struct ID
152
153         Byte    b_elf_flags;
154         Word    w_secid;                // ==OLD== SectionInfo ItemIndex belong with this object.
155
156 } LibGoblin_ObjectInfo;
157
158
159 /*=====================================================================*/
160 typedef struct  {
161         Ptr             ptr_addr;
162         int             i_objid;
163 } LibGoblin_AddressInfo;
164
165 /*=====================================================================*/
166 typedef struct  {
167         int             i_id;
168         DWord   dw_hash;
169         char    str_filename[DRD64_MAX_PATH];
170         char    str_localpath[DRD64_MAX_PATH];
171         char    str_remotepath[DRD64_MAX_PATH];
172 } LibGoblin_SrcFile;
173
174
175 /*=====================================================================*/
176 #define BINFILE_FLAGMASK_FILE                   (DWord)0x00000007
177 #define BINFILE_FLAG_FILE_MMAP                  (DWord)0x00000001
178 #define BINFILE_FLAG_FILE_EXTALLOC              (DWord)0x00000002
179 #define BINFILE_FLAG_FILE_INTALLOC              (DWord)0x00000004
180
181 #define BINFILE_FLAGMASK_RELTYPE                (DWord)0x00000010
182 #define BINFILE_FLAG_RELTYPE_REL                (DWord)0x00000000
183 #define BINFILE_FLAG_RELTYPE_RELA               (DWord)0x00000010
184
185 typedef struct  {
186         int                     i_id;
187         int                     i_refcount;
188
189         /* Binary-File Info. */
190         int                     i_fd;
191         DWord           dw_flag;
192
193         // EXEC-program / shared lib. filename (without directry)
194         char            str_filename[DRD64_MAX_PATH];
195         char            str_localpath[DRD64_MAX_PATH];  // filepath in local machine path.(transported)
196         char            str_remotepath[DRD64_MAX_PATH]; // filepath in remote machine path.(local machine is NULL)
197
198         // .dynamic Section - rpath (.so location path - converted real-path) 
199         char            str_rpath[DRD64_MAX_PATH];
200         // .dynamic Section - runpath (.so location path - converted real-path) 
201         char            str_runpath[DRD64_MAX_PATH];
202
203         LibFileType_FileType    t_ftype;
204
205         /* Binary-File Memory Image Access Info. */
206         DWord           dw_size;
207         Byte            *pb_binary;
208
209         /* Binary-Format Depending Info. (ELF)*/
210         void            *p_elf;
211
212         LibGoblin_SectionInfo   t_section[LIBGOBLIN_SECTION_ID_MAX];
213         int                                             i_secindex[LIBGOBLIN_SECTION_ID_MAX];
214 } LibGoblin_BinaryFile;
215
216
217 /*=====================================================================*/
218 #define LIBGOBLIN_BINFO_PHASE_INIT              0x00
219 #define LIBGOBLIN_BINFO_PHASE_ALLOCED   0x10
220 #define LIBGOBLIN_BINFO_PHASE_SETNAME   0x20
221 #define LIBGOBLIN_BINFO_PHASE_SETPROG   0x30
222 #define LIBGOBLIN_BINFO_PHASE_BINREAD   0x40
223 #define LIBGOBLIN_BINFO_PHASE_ELF1READ  0x51
224 #define LIBGOBLIN_BINFO_PHASE_ELF2READ  0x52
225 #define LIBGOBLIN_BINFO_PHASE_ANALYZED  0x50
226
227 #define LIBGOBLIN_BINFO_TYPE_NONE               0x00
228 #define LIBGOBLIN_BINFO_TYPE_ELF                0x01
229 #define LIBGOBLIN_BINFO_TYPE_ELF64              0x64
230 #define LIBGOBLIN_BINFO_TYPE_ELF32              0x32
231
232 #define isElf64(n) \
233         ((LIBGOBLIN_BINFO_TYPE_ELF64==((n)->b_type)) ? 0x01 : 0x00)
234 #define isElf32(n) \
235         ((LIBGOBLIN_BINFO_TYPE_ELF32==((n)->b_type)) ? 0x01 : 0x00)
236 #define IsBinfoType_Elf64(n) \
237         ((LIBGOBLIN_BINFO_TYPE_ELF64==((n)->b_type)) ? 0x01 : 0x00)
238 #define IsBinfoType_Elf32(n) \
239         ((LIBGOBLIN_BINFO_TYPE_ELF32==((n)->b_type)) ? 0x01 : 0x00)
240
241 #define LIBGOBLIN_BINFO_ENDIAN_NONE             0x00
242 #define LIBGOBLIN_BINFO_ENDIAN_LITTLE   0x01
243 #define LIBGOBLIN_BINFO_ENDIAN_BIG              0x02
244
245 #define LIBGOBLIN_BINFO_SECTION_TEXT    0x00
246 #define LIBGOBLIN_BINFO_SECTION_DATA    0x01
247 #define LIBGOBLIN_BINFO_SECTION_BSS             0x02
248
249 #define LIBGOBLIN_BINFO_MAXFILES                3       // Except FILE_LIBRARY
250 #define LIBGOBLIN_BINFO_FILE_EXEC               0
251 #define LIBGOBLIN_BINFO_FILE_CORE               1
252 #define LIBGOBLIN_BINFO_FILE_DEBUG              2
253 #define LIBGOBLIN_BINFO_FILE_LIBRARY    -1
254
255 typedef struct  {
256         /* BinaryInfo Struct ID */
257         int                     i_id;
258         Byte            b_phase;
259
260         /* BinaryInfo Common Info. */
261         Byte            b_type;
262         Byte            b_endian;
263         Byte            b_bits;
264         int                     i_filetype;
265
266         /* Debug-Format Depending Info. (DWarf) */
267         void            *p_debug;
268
269         /* Address Table Info. */
270 /*
271         LibGoblin_AddressInfo   *p_addrinfo;
272         DWord           dw_alloc_addrinfo;
273         DWord           dw_max_addrinfo;
274 */
275
276         /* Exec. File Info. */
277         int                     i_parent_bid;
278         char            str_filename[DRD64_MAX_PATH];
279         
280         int                     i_binfile;              // binaryFile ID
281
282         /* Binary-Format Depending Info. (ELF)*/
283         //void          *p_format;
284
285         int                     i_pginfo;
286         int                     i_binfo_next;
287
288 }       LibGoblin_BinaryInfo;
289
290
291 /*=====================================================================*/
292 typedef struct  {
293
294         int                                             i_id;
295
296         int                                             i_num_binfo;
297         LibGoblin_BinaryInfo    *p_binfo[LIBGOBLIN_BINFO_MAXFILES];
298
299         LibGoblin_SectionInfo   t_section[LIBGOBLIN_SECTION_ID_MAX];
300
301         /* Address Table Info. */
302         //LibGoblin_AddressInfo *p_addrinfo;
303         //DWord         dw_alloc_addrinfo;
304         //DWord         dw_max_addrinfo;
305
306         // Object Table & Address Table ---
307         struct  {
308                 LibGoblin_ObjectInfo    *p_objinfo;
309                 int                                             i_empty;        // Empty ObjectInfo Chain Top-ID.
310                 int                                             i_alloced;      // Alloced ObjectInfo
311                 int                                             i_used;         // ObjectInfo Items
312                 int                                             i_topid;        // Top-Ptr ObjectInfo
313         } objinfo;
314         LibGoblin_AddressInfo   *p_addrinfo;
315         
316
317         DWord                                   dw_flag;
318         
319         
320 }       LibGoblin_ProgramInfo;
321
322
323 #endif  /* DRD64_HEADER_LIBGOBLIN_TYPE*/
324
325 /* EOF of drd64_.h ----------------------------------- */