LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
OAT/Binary.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_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>>;
49
50 using classes_t = std::unordered_map<std::string, Class*>;
51 using classes_list_t = std::vector<std::unique_ptr<Class>>;
54
55 using oat_dex_files_t = std::vector<std::unique_ptr<DexFile>>;
59
60 using methods_t = std::vector<std::unique_ptr<Method>>;
63
64 using dex2dex_info_t = std::unordered_map<const DEX::File*, DEX::dex2dex_info_t>;
65
66 public:
67 Binary& operator=(const Binary& copy) = delete;
68 Binary(const Binary& copy) = delete;
69
73
77
81
85
87 bool has_class(const std::string& class_name) const;
88
89
92 const Class* get_class(const std::string& class_name) const LIEF_LIFETIMEBOUND;
93
94 Class* get_class(const std::string& class_name) LIEF_LIFETIMEBOUND;
95
98 const Class* get_class(size_t index) const LIEF_LIFETIMEBOUND;
99
101
105
107
108 std::string dex2dex_json_info();
109
110 bool has_vdex() const {
111 return vdex_ != nullptr;
112 }
113
114 static bool classof(const LIEF::Binary* bin) {
115 return bin->format() == Binary::FORMATS::OAT;
116 }
117
118 void accept(Visitor& visitor) const override;
119
120 ~Binary() override;
121
122 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Binary& binary);
123
124 private:
125 Binary();
126 void add_class(std::unique_ptr<Class> cls);
127
128 Header header_;
129 methods_t methods_;
130 dex_files_t dex_files_;
131 oat_dex_files_t oat_dex_files_;
132
133 classes_t classes_;
134 classes_list_t classes_list_;
135
136 // For OAT > 79
137 std::unique_ptr<VDEX::File> vdex_;
138};
139
140}
141}
142
143#endif
Generic interface representing a binary executable.
Definition Abstract/Binary.hpp:59
@ OAT
Definition Abstract/Binary.hpp:79
FORMATS format() const
Executable format (ELF, PE, Mach-O) of the underlying binary.
Definition Abstract/Binary.hpp:124
Class that represents a DEX file.
Definition DEX/File.hpp:39
Class which represents an ELF binary.
Definition ELF/Binary.hpp:59
ref_iterator< methods_t &, Method * > it_methods
Definition OAT/Binary.hpp:61
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
std::unordered_map< std::string, Class * > classes_t
Definition OAT/Binary.hpp:50
void accept(Visitor &visitor) const override
Method associated with the visitor pattern.
dex2dex_info_t dex2dex_info() const
ref_iterator< classes_list_t &, Class * > it_classes
Definition OAT/Binary.hpp:52
const_ref_iterator< const dex_files_t &, const DEX::File * > it_const_dex_files
Definition OAT/Binary.hpp:47
std::vector< std::unique_ptr< DEX::File > > dex_files_t
Definition OAT/Binary.hpp:45
const_ref_iterator< const methods_t &, const Method * > it_const_methods
Definition OAT/Binary.hpp:62
const_ref_iterator< const classes_list_t &, const Class * > it_const_classes
Definition OAT/Binary.hpp:53
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.
std::vector< std::unique_ptr< Method > > methods_t
Definition OAT/Binary.hpp:60
std::string dex2dex_json_info()
friend class Parser
Definition OAT/Binary.hpp:42
std::vector< std::unique_ptr< Class > > classes_list_t
Definition OAT/Binary.hpp:51
it_const_methods methods() const
Iterator over LIEF::OAT::Method.
std::vector< std::unique_ptr< DexFile > > oat_dex_files_t
Definition OAT/Binary.hpp:55
ref_iterator< oat_dex_files_t &, DexFile * > it_oat_dex_files
Definition OAT/Binary.hpp:56
it_const_classes classes() const
Iterator over LIEF::OAT::Class.
Binary & operator=(const Binary &copy)=delete
std::unordered_map< const DEX::File *, DEX::dex2dex_info_t > dex2dex_info_t
Definition OAT/Binary.hpp:64
const Header & header() const
OAT Header.
const_ref_iterator< const oat_dex_files_t &, const DexFile * > it_const_oat_dex_files
Definition OAT/Binary.hpp:57
~Binary() override
ref_iterator< dex_files_t &, DEX::File * > it_dex_files
Definition OAT/Binary.hpp:46
bool has_vdex() const
Definition OAT/Binary.hpp:110
static bool classof(const LIEF::Binary *bin)
Definition OAT/Binary.hpp:114
Definition OAT/Class.hpp:36
Definition OAT/Header.hpp:36
Main interface to parse an executable regardless of its format.
Definition Abstract/Parser.hpp:30
Main class for the VDEX module which represents a VDEX file.
Definition VDEX/File.hpp:42
Definition Visitor.hpp:212
Iterator which returns reference on container's values.
Definition iterators.hpp:45
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DEX/Class.hpp:30
Definition ELF/Parser.hpp:32
Definition OAT/Binary.hpp:31
LIEF namespace.
Definition Abstract/Binary.hpp:40
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which returns a const ref on container's values.
Definition iterators.hpp:286
#define LIEF_API
Definition visibility.h:45