LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
java_structures.hpp
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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>
50struct jobject_t {
51 heap_reference_t klass;
52 uint32_t monitor;
53 T brooks_read_barrier;
54};
55
56template<>
58 heap_reference_t klass;
59 uint32_t monitor;
60};
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;
77 heap_reference_t name;
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
115 heap_reference_t dex;
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 {
135using heap_reference_t = ART_17::Java::heap_reference_t;
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
193 heap_reference_t dex;
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
208
209} // Namespace Java
210} // Namespace ART_29
211
212
213// ======================
214// Android 7.1.X - ART 30
215// ======================
216namespace ART_30 {
217
219namespace Java {
220
221using heap_reference_t = ART_29::Java::heap_reference_t;
223
224template<class T = no_brooks_read_barrier_t>
226
227template<class T = no_brooks_read_barrier_t>
228using jarray_t = ART_29::Java::jarray_t<T>;
229
230template<class T = no_brooks_read_barrier_t>
231using jclass_t = ART_29::Java::jclass_t<T>;
232
233// No changes in jstring structure
234template<class T = no_brooks_read_barrier_t>
235using jstring_t = ART_29::Java::jstring_t<T>;
236
237// No changes in jdex_cache structure
238template<class T = no_brooks_read_barrier_t>
239using jdex_cache_t = ART_29::Java::jdex_cache_t<T>;
240
241} // Namespace Java
242} // Namespace ART_30
243
244// ======================
245// Android 8.0.0 - ART 44
246// ======================
247namespace ART_44 {
248
250namespace Java {
251
252
253using heap_reference_t = ART_30::Java::heap_reference_t;
255
256template<class T = no_brooks_read_barrier_t>
258
259template<class T = no_brooks_read_barrier_t>
260using jarray_t = ART_30::Java::jarray_t<T>;
261
262template<class T = no_brooks_read_barrier_t>
263struct ALIGNED_(4) jclass_t {
264 jobject_t<T> object;
265
266 // heap_reference_t annotation_type; // REMOVED in ART 44
267 heap_reference_t class_loader;
268 heap_reference_t component_type;
269 heap_reference_t dex_cache;
270 heap_reference_t ext_data; // ADDED in ART 44
271 heap_reference_t iftable;
272 heap_reference_t name;
273 heap_reference_t super_class;
274 // heap_reference_t verify_error; // REMOVED in ART 44
275 heap_reference_t vtable;
276
277 // uint32_t access_flags; // REMOVED in ART 44
278 // uint64_t dex_cache_strings; // REMOVED in ART 44
279 uint64_t ifields;
280 uint64_t methods;
281 uint64_t sfields;
282 uint32_t access_flags; // ADDED in ART 44
283 uint32_t class_flags;
284 uint32_t class_size;
285 uint32_t clinit_thread_id;
286 int32_t dex_class_def_idx;
287 int32_t dex_type_idx;
288 uint32_t num_reference_instance_fields;
289 uint32_t num_reference_static_fields;
290 uint32_t object_size;
291 uint32_t object_size_alloc_fast_path; // ADDED in ART 44
292 uint32_t primitive_type;
293 uint32_t reference_instance_offsets;
294 int32_t status;
295 uint16_t copied_methods_offset;
296 uint16_t virtual_methods_offset;
297};
298
299
300// No changes in jstring structure but string can be
301// encoded as as char16_t or char (compressed)
302// count[0] (LSB) == 1 ----> compressed
303// count[0] (LSB) == 0 ----> chat16_t
304template<class T = no_brooks_read_barrier_t>
305using jstring_t = ART_30::Java::jstring_t<T>;
306
307template<class T = no_brooks_read_barrier_t>
308struct ALIGNED_(4) jdex_cache_t {
309 jobject_t<T> object;
310
311 // heap_reference_t dex; // REMOVED in ART 44
312 heap_reference_t location;
313 uint32_t num_resolved_call_sites; // ADDED in ART 44 (related to DEX38 format)
314 uint64_t dex_file;
315 uint64_t resolved_call_sites; // ADDED in ART 44 (related to DEX38 format)
316 uint64_t resolved_fields;
317 uint64_t resolved_method_types; // ADDED in ART 44
318 uint64_t resolved_methods;
319 uint64_t resolved_types;
320 uint64_t strings;
321 uint32_t num_resolved_fields;
322 uint32_t num_resolved_methods_types; // ADDED in ART 44
323 uint32_t num_resolved_methods;
324 uint32_t num_resolved_types;
325 uint32_t num_strings;
326};
327
328
329} // Namespace Java
330} // Namespace ART_44
331
332
333// ======================
334// Android 8.1.X - ART 46
335// ======================
336namespace ART_46 {
337
339namespace Java {
340
341using heap_reference_t = ART_44::Java::heap_reference_t;
343
344template<class T = no_brooks_read_barrier_t>
346
347template<class T = no_brooks_read_barrier_t>
348using jarray_t = ART_44::Java::jarray_t<T>;
349
350template<class T = no_brooks_read_barrier_t>
351using jclass_t = ART_44::Java::jclass_t<T>;
352
353template<class T = no_brooks_read_barrier_t>
354using jstring_t = ART_44::Java::jstring_t<T>;
355
356template<class T = no_brooks_read_barrier_t>
357using jdex_cache_t = ART_44::Java::jdex_cache_t<T>;
358
359} // Namespace Java
360} // Namespace ART_46
361
362// ======================
363// Android 9.0.0 - ART 66
364// ======================
365namespace ART_56 {
366
368namespace Java {
369
370using heap_reference_t = ART_46::Java::heap_reference_t;
372
373template<class T = no_brooks_read_barrier_t>
375
376template<class T = no_brooks_read_barrier_t>
377using jarray_t = ART_46::Java::jarray_t<T>;
378
379template<class T = no_brooks_read_barrier_t>
380using jclass_t = ART_46::Java::jclass_t<T>;
381
382template<class T = no_brooks_read_barrier_t>
383using jstring_t = ART_46::Java::jstring_t<T>;
384
385template<class T = no_brooks_read_barrier_t>
386using jdex_cache_t = ART_46::Java::jdex_cache_t<T>;
387
388} // Namespace Java
389} // Namespace ART_56
390
391} // namespace details
392} // Namespace ART
393} // Namespace LIEF
394
395
396
397#endif
LIEF namespace.
Definition Abstract/Binary.hpp:32
Definition java_structures.hpp:50
Definition java_structures.hpp:32