OSDN Git Service

2019/02/24(Sun) 20:43
[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         char    *pstr_linkname;
121         DWord   dw_hash_linkname;
122
123         union   {
124                 Byte            b_data[128];
125
126                 struct  {
127                         DWord   dw_type;                // Entry type.
128                         DWord   dw_flags;               // Access permission flags.
129                         QWord   qw_align;               // Alignment in memory and file.
130                         void    *pv_proghdr;    // Program Header Pointer
131                 } proghdr;
132
133                 struct  {
134                         QWord   qw_flag;                // sh_flags - Section flags.
135                         QWord   qw_align;               // sh_addralign - Alignment in bytes.
136                         QWord   qw_entsize;             // sh_entsize - Size of each entry in section.
137                         DWord   dw_type;                // sh_type - Section type.
138                         DWord   dw_link;                // sh_link - Index of a related section.
139                         DWord   dw_info;                // sh_info - Depends on section type.
140                         void    *pv_sechdr;
141                 } section;
142
143                 struct  {
144                         Byte    b_type;                 // st_info - Type and binding information.
145                         Byte    b_binding;              // st_info - Type and binding information.
146                         Byte    b_visibility;   // st_other - Reserved (not used).
147                         Word    w_secindex;             // st_shndx - Section index of symbol.
148                 } symbol;
149
150         } info;
151
152         int             i_secid;
153         
154         int             i_srcid;                // SourceInfo struct ID
155
156         Byte    b_elf_flags;
157         Word    w_secid;                // ==OLD== SectionInfo ItemIndex belong with this object.
158
159 } LibGoblin_ObjectInfo;
160
161
162 /*=====================================================================*/
163 typedef struct  {
164         Ptr             ptr_addr;
165         int             i_objid;
166 } LibGoblin_AddressInfo;
167
168 /*=====================================================================*/
169 typedef struct  {
170         int             i_id;
171         DWord   dw_hash;
172         char    str_filename[DRD64_MAX_PATH];
173         char    str_localpath[DRD64_MAX_PATH];
174         char    str_remotepath[DRD64_MAX_PATH];
175 } LibGoblin_SrcFile;
176
177
178 /*=====================================================================*/
179 #define BINFILE_FLAGMASK_FILE                   (DWord)0x00000007
180 #define BINFILE_FLAG_FILE_MMAP                  (DWord)0x00000001
181 #define BINFILE_FLAG_FILE_EXTALLOC              (DWord)0x00000002
182 #define BINFILE_FLAG_FILE_INTALLOC              (DWord)0x00000004
183
184 #define BINFILE_FLAGMASK_RELTYPE                (DWord)0x00000010
185 #define BINFILE_FLAG_RELTYPE_REL                (DWord)0x00000000
186 #define BINFILE_FLAG_RELTYPE_RELA               (DWord)0x00000010
187
188 typedef struct  {
189         int                     i_id;
190         int                     i_refcount;
191
192         /* Binary-File Info. */
193         int                     i_fd;
194         DWord           dw_flag;
195
196         // EXEC-program / shared lib. filename (without directry)
197         char            str_filename[DRD64_MAX_PATH];
198         char            str_localpath[DRD64_MAX_PATH];  // filepath in local machine path.(transported)
199         char            str_remotepath[DRD64_MAX_PATH]; // filepath in remote machine path.(local machine is NULL)
200
201         // .dynamic Section - rpath (.so location path - converted real-path) 
202         char            str_rpath[DRD64_MAX_PATH];
203         // .dynamic Section - runpath (.so location path - converted real-path) 
204         char            str_runpath[DRD64_MAX_PATH];
205
206         LibFileType_FileType    t_ftype;
207
208         /* Binary-File Memory Image Access Info. */
209         DWord           dw_size;
210         Byte            *pb_binary;
211
212         /* Binary-Format Depending Info. (ELF)*/
213         void            *p_elf;
214
215         LibGoblin_SectionInfo   t_section[LIBGOBLIN_SECTION_ID_MAX];
216         int                                             i_secindex[LIBGOBLIN_SECTION_ID_MAX];
217 } LibGoblin_BinaryFile;
218
219
220 /*=====================================================================*/
221 #define LIBGOBLIN_BINFO_PHASE_INIT              0x00
222 #define LIBGOBLIN_BINFO_PHASE_ALLOCED   0x10
223 #define LIBGOBLIN_BINFO_PHASE_SETNAME   0x20
224 #define LIBGOBLIN_BINFO_PHASE_SETPROG   0x30
225 #define LIBGOBLIN_BINFO_PHASE_BINREAD   0x40
226 #define LIBGOBLIN_BINFO_PHASE_ELF1READ  0x51
227 #define LIBGOBLIN_BINFO_PHASE_ELF2READ  0x52
228 #define LIBGOBLIN_BINFO_PHASE_ANALYZED  0x50
229
230 #define LIBGOBLIN_BINFO_TYPE_NONE               0x00
231 #define LIBGOBLIN_BINFO_TYPE_ELF                0x01
232 #define LIBGOBLIN_BINFO_TYPE_ELF64              0x64
233 #define LIBGOBLIN_BINFO_TYPE_ELF32              0x32
234
235 #define isElf64(n) \
236         ((LIBGOBLIN_BINFO_TYPE_ELF64==((n)->b_type)) ? 0x01 : 0x00)
237 #define isElf32(n) \
238         ((LIBGOBLIN_BINFO_TYPE_ELF32==((n)->b_type)) ? 0x01 : 0x00)
239 #define IsBinfoType_Elf64(n) \
240         ((LIBGOBLIN_BINFO_TYPE_ELF64==((n)->b_type)) ? 0x01 : 0x00)
241 #define IsBinfoType_Elf32(n) \
242         ((LIBGOBLIN_BINFO_TYPE_ELF32==((n)->b_type)) ? 0x01 : 0x00)
243
244 #define LIBGOBLIN_BINFO_ENDIAN_NONE             0x00
245 #define LIBGOBLIN_BINFO_ENDIAN_LITTLE   0x01
246 #define LIBGOBLIN_BINFO_ENDIAN_BIG              0x02
247
248 #define LIBGOBLIN_BINFO_SECTION_TEXT    0x00
249 #define LIBGOBLIN_BINFO_SECTION_DATA    0x01
250 #define LIBGOBLIN_BINFO_SECTION_BSS             0x02
251
252 #define LIBGOBLIN_BINFO_MAXFILES                3       // Except FILE_LIBRARY
253 #define LIBGOBLIN_BINFO_FILE_EXEC               0
254 #define LIBGOBLIN_BINFO_FILE_CORE               1
255 #define LIBGOBLIN_BINFO_FILE_DEBUG              2
256 #define LIBGOBLIN_BINFO_FILE_LIBRARY    -1
257
258 typedef struct  {
259         /* BinaryInfo Struct ID */
260         int                     i_id;
261         Byte            b_phase;
262
263         /* BinaryInfo Common Info. */
264         Byte            b_type;
265         Byte            b_endian;
266         Byte            b_bits;
267         int                     i_filetype;
268
269         /* Debug-Format Depending Info. (DWarf) */
270         void            *p_debug;
271
272         /* Address Table Info. */
273 /*
274         LibGoblin_AddressInfo   *p_addrinfo;
275         DWord           dw_alloc_addrinfo;
276         DWord           dw_max_addrinfo;
277 */
278
279         /* Exec. File Info. */
280         char            str_filename[DRD64_MAX_PATH];
281         DWord           dw_hash;
282         
283         int                     i_binfile;              // binaryFile ID
284
285         int                     i_pginfo;
286         int                     i_binfo_parent;
287         int                     i_binfo_next;
288
289         /* Binary-Format Depending Info. (ELF)*/
290         //void          *p_format;
291
292
293 }       LibGoblin_BinaryInfo;
294
295
296 /*=====================================================================*/
297 typedef struct  {
298
299         int                                             i_id;
300
301         int                                             i_num_binfo;
302         LibGoblin_BinaryInfo    *p_binfo[LIBGOBLIN_BINFO_MAXFILES];
303
304         LibGoblin_SectionInfo   t_section[LIBGOBLIN_SECTION_ID_MAX];
305
306         /* Address Table Info. */
307         //LibGoblin_AddressInfo *p_addrinfo;
308         //DWord         dw_alloc_addrinfo;
309         //DWord         dw_max_addrinfo;
310
311         // Object Table & Address Table ---
312         struct  {
313                 LibGoblin_ObjectInfo    *p_objinfo;
314                 int                                             i_empty;        // Empty ObjectInfo Chain Top-ID.
315                 int                                             i_alloced;      // Alloced ObjectInfo
316                 int                                             i_used;         // ObjectInfo Items
317                 int                                             i_topid;        // Top-Ptr ObjectInfo
318         } objinfo;
319         LibGoblin_AddressInfo   *p_addrinfo;
320         
321
322         DWord                                   dw_flag;
323         
324         
325 }       LibGoblin_ProgramInfo;
326
327
328 #endif  /* DRD64_HEADER_LIBGOBLIN_TYPE*/
329
330 /* EOF of drd64_.h ----------------------------------- */