LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
OAT/Binary.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_BINARY_H
17#define LIEF_OAT_BINARY_H
18#include <ostream>
19
20#include "LIEF/visibility.h"
21
22#include "LIEF/ELF/Binary.hpp"
23#include "LIEF/OAT/Header.hpp"
24#include "LIEF/DEX/deopt.hpp"
25
26namespace LIEF {
27namespace DEX {
28class File;
29}
30
31namespace VDEX {
32class File;
33}
34
35namespace OAT {
36class Parser;
37class Class;
38class Method;
39class DexFile;
40
41class LIEF_API Binary : public ELF::Binary {
42 friend class Parser;
43
44 public:
45 using dex_files_t = std::vector<std::unique_ptr<DEX::File>>;
46 using it_dex_files = ref_iterator<dex_files_t&, DEX::File*>;
47 using it_const_dex_files = const_ref_iterator<const dex_files_t&, const DEX::File*>;
48
49 using classes_t = std::unordered_map<std::string, Class*>;
50 using classes_list_t = std::vector<std::unique_ptr<Class>>;
51 using it_classes = ref_iterator<classes_list_t&, Class*>;
52 using it_const_classes = const_ref_iterator<const classes_list_t&, const Class*>;
53
54 using oat_dex_files_t = std::vector<std::unique_ptr<DexFile>>;
55 using it_oat_dex_files = ref_iterator<oat_dex_files_t&, DexFile*>;
56 using it_const_oat_dex_files = const_ref_iterator<const oat_dex_files_t&, const DexFile*>;
57
58 using methods_t = std::vector<std::unique_ptr<Method>>;
59 using it_methods = ref_iterator<methods_t&, Method*>;
60 using it_const_methods = const_ref_iterator<const methods_t&, const Method*>;
61
62 using dex2dex_info_t = std::unordered_map<const DEX::File*, DEX::dex2dex_info_t>;
63
64 public:
65 Binary& operator=(const Binary& copy) = delete;
66 Binary(const Binary& copy) = delete;
67 const Header& header() const;
70 Header& header();
71 it_dex_files dex_files();
74 it_const_dex_files dex_files() const;
75 it_oat_dex_files oat_dex_files();
78 it_const_oat_dex_files oat_dex_files() const;
79 it_const_classes classes() const;
82 it_classes classes();
83 bool has_class(const std::string& class_name) const;
86
87 const Class* get_class(const std::string& class_name) const;
91
92 Class* get_class(const std::string& class_name);
93 const Class* get_class(size_t index) const;
97
98 Class* get_class(size_t index);
99 it_const_methods methods() const;
102 it_methods methods();
103
104 dex2dex_info_t dex2dex_info() const;
105
106 std::string dex2dex_json_info();
107
108 bool has_vdex() const {
109 return vdex_ != nullptr;
110 }
111
112 static bool classof(const LIEF::Binary* bin) {
113 return bin->format() == Binary::FORMATS::OAT;
114 }
115
116 void accept(Visitor& visitor) const override;
117
118 ~Binary() override;
119
120 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Binary& binary);
121
122 private:
123 Binary();
124 void add_class(std::unique_ptr<Class> cls);
125
126 Header header_;
127 methods_t methods_;
128 dex_files_t dex_files_;
129 oat_dex_files_t oat_dex_files_;
130
131 classes_t classes_;
132 classes_list_t classes_list_;
133
134 // For OAT > 79
135 std::unique_ptr<VDEX::File> vdex_;
136};
137
138}
139}
140
141#endif
FORMATS format() const
Executable format (ELF, PE, Mach-O) of the underlying binary.
Definition Abstract/Binary.hpp:109
Class that represents a DEX file.
Definition DEX/File.hpp:39
Definition OAT/Binary.hpp:41
Class * get_class(const std::string &class_name)
it_dex_files dex_files()
Iterator over LIEF::DEX::File.
friend std::ostream & operator<<(std::ostream &os, const Binary &binary)
Binary(const Binary &copy)=delete
it_methods methods()
void accept(Visitor &visitor) const override
Method associated with the visitor pattern.
Class * get_class(size_t index)
it_classes classes()
dex2dex_info_t dex2dex_info() const
const Class * get_class(size_t index) const
Return the LIEF::OAT::Class at the given index or a nullptr if it does not exist.
bool has_class(const std::string &class_name) const
Check if the current OAT has the given class.
Header & header()
const Class * get_class(const std::string &class_name) const
Return the LIEF::OAT::Class with the given name or a nullptr if the class can't be found.
it_oat_dex_files oat_dex_files()
Iterator over LIEF::OAT::DexFile.
it_const_oat_dex_files oat_dex_files() const
it_const_dex_files dex_files() const
std::string dex2dex_json_info()
it_const_methods methods() const
Iterator over LIEF::OAT::Method.
it_const_classes classes() const
Iterator over LIEF::OAT::Class.
Binary & operator=(const Binary &copy)=delete
const Header & header() const
OAT Header.
~Binary() override
bool has_vdex() const
Definition OAT/Binary.hpp:108
static bool classof(const LIEF::Binary *bin)
Definition OAT/Binary.hpp:112
Definition OAT/Class.hpp:36
Definition DexFile.hpp:36
Definition OAT/Method.hpp:34
Class to parse an OAT file to produce an OAT::Binary.
Definition OAT/Parser.hpp:38
Main class for the VDEX module which represents a VDEX file.
Definition VDEX/File.hpp:42
Definition DEX/Class.hpp:30
Definition ELF/Parser.hpp:32
Definition OAT/Binary.hpp:31
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41