OSDN Git Service

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