-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstant_info.h
225 lines (200 loc) · 6.26 KB
/
constant_info.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/**
* @file constant_info.h
* @brief Constants definitions
* File containing the definitions for each type of constant
* and the structures with the information of the .class file main components.
*
*/
#pragma once
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "utils.h"
#define CONSTANT_Utf8 1
#define CONSTANT_Integer 3
#define CONSTANT_Float 4
#define CONSTANT_Long 5
#define CONSTANT_Double 6
#define CONSTANT_Class 7
#define CONSTANT_String 8
#define CONSTANT_Fieldref 9
#define CONSTANT_Methodref 10
#define CONSTANT_InterfaceMethodref 11
#define CONSTANT_NameAndType 12
#define CONSTANT_read_verify(type) \
assert(ptr); \
assert(fp); \
/**
* @brief Info of type Class.
*
* Structure that stores specific information about a constant of type Class (id 7)
*/
/* id 7 */
typedef struct {
uint16_t name_index;
} CONSTANT_Class_info;
/**
* @brief Info of type Fieldref.
*
* Structure that stores specific information about a constant of type Fieldref (id 9)
*/
/* id 9 */
typedef struct {
uint16_t class_index;
uint16_t name_and_type_index;
} CONSTANT_Fieldref_info;
/**
* @brief Info of type Methodref.
*
* Structure that stores specific information about a constant of type Methodref (id 10)
*/
/* id 10 */
typedef struct {
uint16_t class_index;
uint16_t name_and_type_index;
} CONSTANT_Methodref_info;
/**
* @brief Info of type InterfaceMethodref.
*
* Structure that stores specific information about a constant of type InterfaceMethodref (id 11)
*/
/* id 11 */
typedef struct {
uint16_t class_index;
uint16_t name_and_type_index;
} CONSTANT_InterfaceMethodref_info;
/**
* @brief Info of type String.
*
* Structure that stores specific information about a constant of type String (id 8)
*/
/* id 8 */
typedef struct {
uint16_t string_index;
} CONSTANT_String_info;
/**
* @brief Info of type Integer.
*
* Structure that stores specific information about a constant of type Integer (id 3)
*/
/* id 3 */
typedef struct {
uint32_t bytes;
} CONSTANT_Integer_info;
/**
* @brief Info of type Float.
*
* Structure that stores specific information about a constant of type Float (id 4)
*/
/* id 4 */
typedef struct {
uint32_t bytes;
} CONSTANT_Float_info;
/**
* @brief Info of type Long.
*
* Structure that stores specific information about a constant of type Long (id 5)
*/
/* id 5 */
typedef struct {
uint32_t high_bytes;
uint32_t low_bytes;
} CONSTANT_Long_info;
/**
* @brief Info of type Double.
*
* Structure that stores specific information about a constant of type Double (id 6)
*/
/* id 6 */
typedef struct {
uint32_t high_bytes;
uint32_t low_bytes;
} CONSTANT_Double_info;
/**
* @brief Info of type NameAndType.
*
* Structure that stores specific information about a constant of type Class (id 12)
*/
/* id 12 */
typedef struct {
uint16_t name_index;
uint16_t descriptor_index;
} CONSTANT_NameAndType_info;
/**
* @brief Info of type Utf8.
*
* Structure that stores specific information about a constant of type Utf8 (id 1)
*/
/* id 1 */
typedef struct {
uint16_t length;
uint8_t *bytes;
} CONSTANT_Utf8_info;
/**
* Get data from file and store in a Class_info structure.
* @param fp non-null pointer to .class file.
* @param ptr non-null pointer to a CONSTANT_Class_info structure that will receive the value.
*/
void read_Class_info(CONSTANT_Class_info *ptr, FILE *fp);
/**
* Get data from file and store in a Fieldref_info structure.
* @param fp non-null pointer to .class file.
* @param ptr non-null pointer to a CONSTANT_Fieldref_info structure that will receive the value.
*/
void read_Fieldref_info(CONSTANT_Fieldref_info *ptr, FILE *fp);
/**
* Get data from file and store in a NameAndType_info structure.
* @param fp non-null pointer to .class file
* @param ptr non-null pointer to a CONSTANT_NameAndType_info structure that will receive the value
*/
void read_NameAndType_info(CONSTANT_NameAndType_info *ptr, FILE *fp);
/**
* Get data from file and store in a Utf8_info structure.
* @param fp non-null pointer to .class file
* @param ptr non-null pointer to a CONSTANT_Utf8_info structure that will receive the value.
*/
void read_Utf8_info(CONSTANT_Utf8_info *ptr, FILE *fp);
/**
* Get data from file and store in a Methodref_info structure.
* @param fp non-null pointer to .class file
* @param ptr non-null pointer to a CONSTANT_Methodref_info structure that will receive the value.
*/
void read_Methodref_info(CONSTANT_Methodref_info *ptr, FILE *fp);
/**
* Get data from file and store in a InterfaceMethodref_info structure.
* @param fp non-null pointer to .class file
* @param ptr non-null pointer to a CONSTANT_InterfaceMethodref_info structure that will receive the value.
*/
void read_InterfaceMethodref_info(CONSTANT_InterfaceMethodref_info *ptr, FILE *fp);
/**
* Get data from file and store in a String_info structure.
* @param fp non-null pointer to .class file
* @param ptr non-null pointer to a CONSTANT_String_info structure that will receive the value.
*/
void read_String_info(CONSTANT_String_info *ptr, FILE *fp);
/**
* Get data from file and store in a Integer_info structure.
* @param fp non-null pointer to .class file
* @param ptr non-null pointer to a CONSTANT_Integer_info structure that will receive the value.
*/
void read_Integer_info(CONSTANT_Integer_info *ptr, FILE *fp);
/**
* Get data from file and store in a Float_info structure.
* @param fp non-null pointer to .class file
* @param ptr non-null pointer to a CONSTANT_Float_info structure that will receive the value.
*/
void read_Float_info(CONSTANT_Float_info *ptr, FILE *fp);
/**
* Get data from file and store in a Long_info structure.
* @param fp non-null pointer to .class file
* @param ptr non-null pointer to a CONSTANT_Long_info structure that will receive the value.
*/
void read_Long_info(CONSTANT_Long_info *ptr, FILE *fp);
/**
* Get data from file and store in a Double_info structure.
* @param fp non-null pointer to .class file
* @param ptr non-null pointer to a CONSTANT_Double_info structure that will receive the value.
*/
void read_Double_info(CONSTANT_Double_info *ptr, FILE *fp);