LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
OAT/Binary.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_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>>;
48
49 using classes_t = std::unordered_map<std::string, Class*>;
50 using classes_list_t = std::vector<std::unique_ptr<Class>>;
53
54 using oat_dex_files_t = std::vector<std::unique_ptr<DexFile>>;
57
58 using methods_t = std::vector<std::unique_ptr<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
69 const Header& header() const;
70 Header& header();
71
74 it_const_dex_files dex_files() const;
75
78 it_const_oat_dex_files oat_dex_files() const;
79
82 it_classes classes();
83
85 bool has_class(const std::string& class_name) const;
86
87
90 const Class* get_class(const std::string& class_name) const;
91
92 Class* get_class(const std::string& class_name);
93
96 const Class* get_class(size_t index) const;
97
98 Class* get_class(size_t index);
99
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
Abstract binary that exposes an uniform API for the different executable file formats.
Definition Abstract/Binary.hpp:39
FORMATS format() const
Executable format (ELF, PE, Mach-O) of the underlying binary.
Definition Abstract/Binary.hpp:98
Class which represents an ELF binary.
Definition ELF/Binary.hpp:59
Definition OAT/Binary.hpp:41
it_dex_files dex_files()
Iterator over LIEF::DEX::File.
void accept(Visitor &visitor) const override
Method associated with the visitor pattern.
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.
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_methods methods() const
Iterator over LIEF::OAT::Method.
it_const_classes classes() const
Iterator over LIEF::OAT::Class.
const Header & header() const
OAT Header.
Definition OAT/Class.hpp:35
Definition OAT/Header.hpp:36
Class to parse an OAT file to produce an OAT::Binary.
Definition OAT/Parser.hpp:38
Definition Visitor.hpp:219
Iterator which returns reference on container's values.
Definition iterators.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:32