LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
OAT/Header.hpp
Go to the documentation of this file.
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_OAT_HEADER_H
17#define LIEF_OAT_HEADER_H
18#include <functional>
19#include <map>
20#include <string>
21#include <vector>
22#include <utility>
23#include <array>
24
25#include "LIEF/iterators.hpp"
27#include "LIEF/OAT/enums.hpp"
28
29#include "LIEF/visibility.h"
30#include "LIEF/Object.hpp"
31
32namespace LIEF {
33namespace OAT {
34class Parser;
35
36class LIEF_API Header : public Object {
37 friend class Parser;
38
39 public:
40 struct element_t {
41 element_t(HEADER_KEYS key, const std::string& value) :
42 key(key), value(const_cast<std::string*>(&value)) {}
43
45 std::string* value = nullptr;
46 };
47 using magic_t = std::array<uint8_t, 4>; // oat\n
48 using key_values_t = std::map<HEADER_KEYS, std::string>;
51
53 using keys_t = std::vector<HEADER_KEYS>;
54 using values_t = std::vector<std::string>;
55
56 public:
58 static std::string key_to_string(HEADER_KEYS key);
59
60 public:
62 Header(const Header&);
64
65 template<class T>
66 LIEF_LOCAL Header(const T* header);
67
70
73
74 uint32_t checksum() const;
75
77 // TODO instruction_set_features_bitmap_() const;
78
79
80 uint32_t nb_dex_files() const;
81
82 // Since OAT 131
83 uint32_t oat_dex_files_offset() const;
84
85 uint32_t executable_offset() const;
86 uint32_t i2i_bridge_offset() const;
87 uint32_t i2c_code_bridge_offset() const;
88 uint32_t jni_dlsym_lookup_offset() const;
89
94
95 int32_t image_patch_delta() const;
96
99
100 uint32_t key_value_size() const;
101
104
105 keys_t keys() const;
107
108 const std::string* get(HEADER_KEYS key) const;
109 std::string* get(HEADER_KEYS key);
110
111 Header& set(HEADER_KEYS key, const std::string& value);
112
113 const std::string* operator[](HEADER_KEYS key) const;
114 std::string* operator[](HEADER_KEYS key);
115
116 void magic(const magic_t& magic);
117
118 void accept(Visitor& visitor) const override;
119
120
121 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Header& hdr);
122
123 private:
124 magic_t magic_;
125 oat_version_t version_ = 0;
126 uint32_t checksum_ = 0;
127 INSTRUCTION_SETS instruction_set_ = INSTRUCTION_SETS::INST_SET_NONE;
128 uint32_t instruction_set_features_bitmap_ = 0;
129 uint32_t dex_file_count_ = 0;
130 uint32_t oat_dex_files_offset_ = 0; // Since OAT 131 / Android 8.1.0
131 uint32_t executable_offset_ = 0;
132 uint32_t i2i_bridge_offset_ = 0;
133 uint32_t i2c_code_bridge_offset_ = 0;
134 uint32_t jni_dlsym_lookup_offset_ = 0;
135
136 uint32_t quick_generic_jni_trampoline_offset_ = 0;
137 uint32_t quick_imt_conflict_trampoline_offset_ = 0;
138 uint32_t quick_resolution_trampoline_offset_ = 0;
139 uint32_t quick_to_interpreter_bridge_offset_ = 0;
140
141 int32_t image_patch_delta_ = 0;
142
143 uint32_t image_file_location_oat_checksum_ = 0;
144 uint32_t image_file_location_oat_data_begin_ = 0;
145
146 uint32_t key_value_store_size_ = 0;
147
148 key_values_t dex2oat_context_;
149
150
151};
152
153}
154}
155
156#endif
Definition OAT/Header.hpp:36
uint32_t image_file_location_oat_checksum() const
uint32_t image_file_location_oat_data_begin() const
int32_t image_patch_delta() const
uint32_t nb_dex_files() const
it_const_key_values_t key_values() const
INSTRUCTION_SETS instruction_set() const
Header::magic_t magic() const
Magic value: oat
std::array< uint8_t, 4 > magic_t
Definition OAT/Header.hpp:47
uint32_t jni_dlsym_lookup_offset() const
uint32_t i2i_bridge_offset() const
friend std::ostream & operator<<(std::ostream &os, const Header &hdr)
uint32_t quick_resolution_trampoline_offset() const
uint32_t checksum() const
uint32_t i2c_code_bridge_offset() const
it_key_values_t key_values()
Header(const T *header)
const std::string * operator[](HEADER_KEYS key) const
void magic(const magic_t &magic)
void accept(Visitor &visitor) const override
oat_version_t version() const
OAT version.
static std::string key_to_string(HEADER_KEYS key)
Return the string value associated with the given key.
uint32_t quick_imt_conflict_trampoline_offset() const
Header & operator=(const Header &)
uint32_t oat_dex_files_offset() const
std::string * get(HEADER_KEYS key)
uint32_t key_value_size() const
uint32_t quick_to_interpreter_bridge_offset() const
std::vector< HEADER_KEYS > keys_t
Iterator type over.
Definition OAT/Header.hpp:53
values_t values() const
const std::string * get(HEADER_KEYS key) const
std::vector< std::string > values_t
Definition OAT/Header.hpp:54
uint32_t quick_generic_jni_trampoline_offset() const
uint32_t executable_offset() const
std::string * operator[](HEADER_KEYS key)
Header & set(HEADER_KEYS key, const std::string &value)
keys_t keys() const
Header(const Header &)
std::map< HEADER_KEYS, std::string > key_values_t
Definition OAT/Header.hpp:48
Class to parse an OAT file to produce an OAT::Binary.
Definition OAT/Parser.hpp:38
Definition Object.hpp:25
Definition Visitor.hpp:224
Iterator which returns reference on container's values.
Definition iterators.hpp:48
HEADER_KEYS
Definition OAT/enums.hpp:45
INSTRUCTION_SETS
Definition OAT/enums.hpp:60
uint32_t oat_version_t
Definition OAT/type_traits.hpp:22
LIEF namespace.
Definition Abstract/Binary.hpp:32
Definition OAT/Header.hpp:40
element_t(HEADER_KEYS key, const std::string &value)
Definition OAT/Header.hpp:41
HEADER_KEYS key
Definition OAT/Header.hpp:44
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42