LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
java_structures.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_ART_JAVA_STRUCTURES_H
17#define LIEF_ART_JAVA_STRUCTURES_H
18
19#include <cstring>
20#include <tuple>
21
22#include "LIEF/types.hpp"
23#include "LIEF/ART/enums.hpp"
24#include "LIEF/ART/types.hpp"
25
26namespace LIEF {
28namespace ART {
29
30namespace details {
31
33
34// ======================
35// Android 6.0.1 - ART 17
36// ======================
37namespace ART_17 {
38
40namespace Java {
41
42using heap_reference_t = uint32_t;
43
45 uint32_t x_rb_ptr;
46 uint32_t x_xpadding;
47};
48
49template<class T>
55
56template<>
61template<class T = no_brooks_read_barrier_t>
62struct ALIGNED_(4) jarray_t {
63 jobject_t<T> object;
64 int32_t length;
65 uint32_t* elements;
66};
67
68template<class T = no_brooks_read_barrier_t>
69struct ALIGNED_(4) jclass_t {
70 jobject_t<T> object;
71
72 heap_reference_t class_loader;
73 heap_reference_t component_type;
74 heap_reference_t dex_cache;
75 heap_reference_t dex_cache_strings;
76 heap_reference_t iftable;
78 heap_reference_t super_class;
79 heap_reference_t verify_error_class;
80 heap_reference_t vtable;
81
82 uint32_t access_flags;
83 uint64_t direct_methods;
84 uint64_t ifields;
85 uint64_t sfields;
86 uint64_t virtual_methods;
87 uint32_t class_size;
88 uint32_t clinit_thread_id;
89 int32_t dex_class_def_idx;
90 int32_t dex_type_idx;
91 uint32_t num_direct_methods;
92 uint32_t num_instance_fields;
93 uint32_t num_reference_instance_fields;
94 uint32_t num_reference_static_fields;
95 uint32_t num_static_fields;
96 uint32_t num_virtual_methods;
97 uint32_t object_size;
98 uint32_t primitive_type;
99 uint32_t reference_instance_offsets;
100 int32_t status;
101};
102
103template<class T = no_brooks_read_barrier_t>
104struct ALIGNED_(4) jstring_t {
105 jobject_t<T> object;
106 int32_t count;
107 uint32_t hash_code;
108 uint16_t* value;
109};
110
111template<class T = no_brooks_read_barrier_t>
112struct ALIGNED_(4) jdex_cache_t {
113 jobject_t<T> object;
114
116 heap_reference_t location;
117 heap_reference_t resolved_fields;
118 heap_reference_t resolved_methods;
119 heap_reference_t resolved_types;
120 heap_reference_t strings;
121 uint64_t dex_file;
122};
123
124
125} // Namespace Java
126} // Namespace ART_17
127
128// ======================
129// Android 7.0.0 - ART 29
130// ======================
131namespace ART_29 {
132
134namespace Java {
137
138template<class T = no_brooks_read_barrier_t>
140
141template<class T = no_brooks_read_barrier_t>
142using jarray_t = ART_17::Java::jarray_t<T>;
143
144template<class T = no_brooks_read_barrier_t>
145struct ALIGNED_(4) jclass_t {
146 jobject_t<T> object;
147
148 heap_reference_t annotation_type; // ADDED in ART 29
149 heap_reference_t class_loader;
150 heap_reference_t component_type;
151 heap_reference_t dex_cache;
152 // heap_reference_t dex_cache_strings; // REMOVED in ART 29
153 heap_reference_t iftable;
154 heap_reference_t name;
155 heap_reference_t super_class;
156 heap_reference_t verify_error; // Type CHANGED from Class to Object
157 heap_reference_t vtable;
158
159 uint32_t access_flags;
160 uint64_t dex_cache_strings; // direct_methods REPLACED with dex_cache_string
161 uint64_t ifields;
162 uint64_t methods; // ADDED in ART 29
163 uint64_t sfields;
164 uint32_t class_flags; // virtual_methods REPLACED with class_flags
165 uint32_t class_size;
166 uint32_t clinit_thread_id;
167 int32_t dex_class_def_idx;
168 int32_t dex_type_idx;
169 // uint32_t num_direct_methods; // REMOVED in ART 29
170 // uint32_t num_instance_fields; // REMOVED in ART 29
171 uint32_t num_reference_instance_fields;
172 uint32_t num_reference_static_fields;
173 // uint32_t num_static_fields; // REMOVED in ART 29
174 // uint32_t num_virtual_methods; // REMOVED in ART 29
175 uint32_t object_size;
176 uint32_t primitive_type;
177 uint32_t reference_instance_offsets;
178 int32_t status;
179
180 uint16_t copied_methods_offset; // ADDED in ART 29
181 uint16_t virtual_methods_offset; // ADDED in ART 29
182};
183
184
185// No changes in jstring structure
186template<class T = no_brooks_read_barrier_t>
187using jstring_t = ART_17::Java::jstring_t<T>;
188
189template<class T = no_brooks_read_barrier_t>
190struct ALIGNED_(4) jdex_cache_t {
191 jobject_t<T> object;
192
194 heap_reference_t location;
195 uint64_t dex_file; // LOCATION CHANGED
196 uint64_t resolved_fields; // TYPE CHANGED from heap_reference_t to uint64_t
197 uint64_t resolved_methods; // TYPE CHANGED from heap_reference_t to uint64_t
198 uint64_t resolved_types; // TYPE CHANGED from heap_reference_t to uint64_t
199 uint64_t strings; // TYPE CHANGED from heap_reference_t to uint64_t
200 uint32_t num_resolved_fields; // ADDED in ART 29
201 uint32_t num_resolved_methods; // ADDED in ART 29
202 uint32_t num_resolved_types; // ADDED in ART 29
203 uint32_t num_strings; // ADDED in ART 29
204};
205
206
207} // Namespace Java
208} // Namespace ART_29
209
210
211// ======================
212// Android 7.1.X - ART 30
213// ======================
214namespace ART_30 {
215
217namespace Java {
218
221
222template<class T = no_brooks_read_barrier_t>
224
225template<class T = no_brooks_read_barrier_t>
227
228template<class T = no_brooks_read_barrier_t>
229using jclass_t = ART_29::Java::jclass_t<T>;
230
231// No changes in jstring structure
232template<class T = no_brooks_read_barrier_t>
234
235// No changes in jdex_cache structure
236template<class T = no_brooks_read_barrier_t>
237using jdex_cache_t = ART_29::Java::jdex_cache_t<T>;
238
239} // Namespace Java
240} // Namespace ART_30
241
242// ======================
243// Android 8.0.0 - ART 44
244// ======================
245namespace ART_44 {
246
248namespace Java {
249
250
253
254template<class T = no_brooks_read_barrier_t>
256
257template<class T = no_brooks_read_barrier_t>
259
260template<class T = no_brooks_read_barrier_t>
261struct ALIGNED_(4) jclass_t {
262 jobject_t<T> object;
263
264 // heap_reference_t annotation_type; // REMOVED in ART 44
265 heap_reference_t class_loader;
266 heap_reference_t component_type;
267 heap_reference_t dex_cache;
268 heap_reference_t ext_data; // ADDED in ART 44
269 heap_reference_t iftable;
270 heap_reference_t name;
271 heap_reference_t super_class;
272 // heap_reference_t verify_error; // REMOVED in ART 44
273 heap_reference_t vtable;
274
275 // uint32_t access_flags; // REMOVED in ART 44
276 // uint64_t dex_cache_strings; // REMOVED in ART 44
277 uint64_t ifields;
278 uint64_t methods;
279 uint64_t sfields;
280 uint32_t access_flags; // ADDED in ART 44
281 uint32_t class_flags;
282 uint32_t class_size;
283 uint32_t clinit_thread_id;
284 int32_t dex_class_def_idx;
285 int32_t dex_type_idx;
286 uint32_t num_reference_instance_fields;
287 uint32_t num_reference_static_fields;
288 uint32_t object_size;
289 uint32_t object_size_alloc_fast_path; // ADDED in ART 44
290 uint32_t primitive_type;
291 uint32_t reference_instance_offsets;
292 int32_t status;
293 uint16_t copied_methods_offset;
294 uint16_t virtual_methods_offset;
295};
296
297
298// No changes in jstring structure but string can be
299// encoded as as char16_t or char (compressed)
300// count[0] (LSB) == 1 ----> compressed
301// count[0] (LSB) == 0 ----> chat16_t
302template<class T = no_brooks_read_barrier_t>
304
305template<class T = no_brooks_read_barrier_t>
306struct ALIGNED_(4) jdex_cache_t {
307 jobject_t<T> object;
308
309 // heap_reference_t dex; // REMOVED in ART 44
310 heap_reference_t location;
311 uint32_t num_resolved_call_sites; // ADDED in ART 44 (related to DEX38 format)
312 uint64_t dex_file;
313 uint64_t resolved_call_sites; // ADDED in ART 44 (related to DEX38 format)
314 uint64_t resolved_fields;
315 uint64_t resolved_method_types; // ADDED in ART 44
316 uint64_t resolved_methods;
317 uint64_t resolved_types;
318 uint64_t strings;
319 uint32_t num_resolved_fields;
320 uint32_t num_resolved_methods_types; // ADDED in ART 44
321 uint32_t num_resolved_methods;
322 uint32_t num_resolved_types;
323 uint32_t num_strings;
324};
325
326
327} // Namespace Java
328} // Namespace ART_44
329
330
331// ======================
332// Android 8.1.X - ART 46
333// ======================
334namespace ART_46 {
335
337namespace Java {
338
341
342template<class T = no_brooks_read_barrier_t>
344
345template<class T = no_brooks_read_barrier_t>
347
348template<class T = no_brooks_read_barrier_t>
349using jclass_t = ART_44::Java::jclass_t<T>;
350
351template<class T = no_brooks_read_barrier_t>
353
354template<class T = no_brooks_read_barrier_t>
355using jdex_cache_t = ART_44::Java::jdex_cache_t<T>;
356
357} // Namespace Java
358} // Namespace ART_46
359
360// ======================
361// Android 9.0.0 - ART 66
362// ======================
363namespace ART_56 {
364
366namespace Java {
367
370
371template<class T = no_brooks_read_barrier_t>
373
374template<class T = no_brooks_read_barrier_t>
376
377template<class T = no_brooks_read_barrier_t>
379
380template<class T = no_brooks_read_barrier_t>
382
383template<class T = no_brooks_read_barrier_t>
385
386} // Namespace Java
387} // Namespace ART_56
388
389} // namespace details
390} // Namespace ART
391} // Namespace LIEF
392
393
394#endif
Namespace related to the Java part of ART 17.
Definition java_structures.hpp:40
uint32_t heap_reference_t
Definition java_structures.hpp:42
struct ALIGNED_(4) jarray_t
Definition java_structures.hpp:62
Definition java_structures.hpp:37
Namespace related to the Java part of ART 29.
Definition java_structures.hpp:134
ART_17::Java::jstring_t< T > jstring_t
Definition java_structures.hpp:187
struct ALIGNED_(4) jclass_t
Definition java_structures.hpp:145
ART_17::Java::jobject_t< T > jobject_t
Definition java_structures.hpp:139
ART_17::Java::jarray_t< T > jarray_t
Definition java_structures.hpp:142
ART_17::Java::brooks_read_barrier_t brooks_read_barrier_t
Definition java_structures.hpp:136
ART_17::Java::heap_reference_t heap_reference_t
Definition java_structures.hpp:135
Definition java_structures.hpp:131
Namespace related to the Java part of ART 30.
Definition java_structures.hpp:217
ART_29::Java::jstring_t< T > jstring_t
Definition java_structures.hpp:233
ART_29::Java::jdex_cache_t< T > jdex_cache_t
Definition java_structures.hpp:237
ART_29::Java::jarray_t< T > jarray_t
Definition java_structures.hpp:226
ART_29::Java::brooks_read_barrier_t brooks_read_barrier_t
Definition java_structures.hpp:220
ART_29::Java::jobject_t< T > jobject_t
Definition java_structures.hpp:223
ART_29::Java::heap_reference_t heap_reference_t
Definition java_structures.hpp:219
ART_29::Java::jclass_t< T > jclass_t
Definition java_structures.hpp:229
Definition java_structures.hpp:214
Namespace related to the Java part of ART 44.
Definition java_structures.hpp:248
ART_30::Java::jstring_t< T > jstring_t
Definition java_structures.hpp:303
ART_30::Java::heap_reference_t heap_reference_t
Definition java_structures.hpp:251
struct ALIGNED_(4) jclass_t
Definition java_structures.hpp:261
ART_30::Java::jobject_t< T > jobject_t
Definition java_structures.hpp:255
ART_30::Java::jarray_t< T > jarray_t
Definition java_structures.hpp:258
ART_30::Java::brooks_read_barrier_t brooks_read_barrier_t
Definition java_structures.hpp:252
Definition java_structures.hpp:245
Namespace related to the Java part of ART 46.
Definition java_structures.hpp:337
ART_44::Java::heap_reference_t heap_reference_t
Definition java_structures.hpp:339
ART_44::Java::jstring_t< T > jstring_t
Definition java_structures.hpp:352
ART_44::Java::jobject_t< T > jobject_t
Definition java_structures.hpp:343
ART_44::Java::jdex_cache_t< T > jdex_cache_t
Definition java_structures.hpp:355
ART_44::Java::jclass_t< T > jclass_t
Definition java_structures.hpp:349
ART_44::Java::brooks_read_barrier_t brooks_read_barrier_t
Definition java_structures.hpp:340
ART_44::Java::jarray_t< T > jarray_t
Definition java_structures.hpp:346
Definition java_structures.hpp:334
Namespace related to the Java part of ART 46.
Definition java_structures.hpp:366
ART_46::Java::jstring_t< T > jstring_t
Definition java_structures.hpp:381
ART_46::Java::jclass_t< T > jclass_t
Definition java_structures.hpp:378
ART_46::Java::jdex_cache_t< T > jdex_cache_t
Definition java_structures.hpp:384
ART_46::Java::jobject_t< T > jobject_t
Definition java_structures.hpp:372
ART_46::Java::jarray_t< T > jarray_t
Definition java_structures.hpp:375
ART_46::Java::brooks_read_barrier_t brooks_read_barrier_t
Definition java_structures.hpp:369
ART_46::Java::heap_reference_t heap_reference_t
Definition java_structures.hpp:368
Definition java_structures.hpp:363
Definition java_structures.hpp:30
Namespace related to the LIEF's ART module.
Definition ART/enums.hpp:20
LIEF namespace.
Definition Abstract/Binary.hpp:40
uint32_t x_rb_ptr
Definition java_structures.hpp:45
uint32_t x_xpadding
Definition java_structures.hpp:46
heap_reference_t klass
Definition java_structures.hpp:58
Definition java_structures.hpp:50
heap_reference_t klass
Definition java_structures.hpp:51
uint32_t monitor
Definition java_structures.hpp:52
T brooks_read_barrier
Definition java_structures.hpp:53
Definition java_structures.hpp:32