LIEF: Library to Instrument Executable Formats Version 2.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 <string_view>
19#include <ostream>
20
21#include "LIEF/visibility.h"
22
23#include "LIEF/DEX/deopt.hpp"
24#include "LIEF/ELF/Binary.hpp"
25#include "LIEF/OAT/Header.hpp"
26
27namespace LIEF {
28namespace DEX {
29class File;
30}
31
32namespace VDEX {
33class File;
34}
35
36namespace OAT {
37class Parser;
38class Class;
39class Method;
40class DexFile;
41
42class LIEF_API Binary : public ELF::Binary {
43 friend class Parser;
44
45 public:
46 using dex_files_t = std::vector<std::unique_ptr<DEX::File>>;
50
51 using classes_t = std::unordered_map<std::string, Class*>;
52 using classes_list_t = std::vector<std::unique_ptr<Class>>;
55
56 using oat_dex_files_t = std::vector<std::unique_ptr<DexFile>>;
60
61 using methods_t = std::vector<std::unique_ptr<Method>>;
64
65 using dex2dex_info_t = std::unordered_map<const DEX::File*, DEX::dex2dex_info_t>;
66
67 public:
68 Binary& operator=(const Binary& copy) = delete;
69 Binary(const Binary& copy) = delete;
70
74
78
82
86
88 bool has_class(std::string_view class_name) const;
89
90
93 const Class* get_class(std::string_view class_name) const LIEF_LIFETIMEBOUND;
94
95 Class* get_class(std::string_view class_name) LIEF_LIFETIMEBOUND;
96
99 const Class* get_class(size_t index) const LIEF_LIFETIMEBOUND;
100
102
106
108
109 std::string dex2dex_json_info();
110
111 bool has_vdex() const {
112 return vdex_ != nullptr;
113 }
114
115 static bool classof(const LIEF::Binary* bin) {
116 return bin->format() == Binary::FORMATS::OAT;
117 }
118
119 void accept(Visitor& visitor) const override;
120
121 ~Binary() override;
122
123 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Binary& binary);
124
125 private:
126 Binary();
127 void add_class(std::unique_ptr<Class> cls);
128
129 Header header_;
130 methods_t methods_;
131 dex_files_t dex_files_;
132 oat_dex_files_t oat_dex_files_;
133
134 classes_t classes_;
135 classes_list_t classes_list_;
136
137 // For OAT > 79
138 std::unique_ptr<VDEX::File> vdex_;
139};
140
141}
142}
143
144#endif
Generic interface representing a binary executable.
Definition Abstract/Binary.hpp:61
@ OAT
Definition Abstract/Binary.hpp:81
FORMATS format() const
Executable format (ELF, PE, Mach-O) of the underlying binary.
Definition Abstract/Binary.hpp:126
Class that represents a DEX file.
Definition DEX/File.hpp:40
Class which represents an ELF binary.
Definition ELF/Binary.hpp:61
ref_iterator< methods_t &, Method * > it_methods
Definition OAT/Binary.hpp:62
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:51
const Class * get_class(std::string_view class_name) const
Return the LIEF::OAT::Class with the given name or a nullptr if the class can't be found.
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:53
const_ref_iterator< const dex_files_t &, const DEX::File * > it_const_dex_files
Definition OAT/Binary.hpp:48
std::vector< std::unique_ptr< DEX::File > > dex_files_t
Definition OAT/Binary.hpp:46
const_ref_iterator< const methods_t &, const Method * > it_const_methods
Definition OAT/Binary.hpp:63
const_ref_iterator< const classes_list_t &, const Class * > it_const_classes
Definition OAT/Binary.hpp:54
it_oat_dex_files oat_dex_files()
Iterator over LIEF::OAT::DexFile.
std::vector< std::unique_ptr< Method > > methods_t
Definition OAT/Binary.hpp:61
std::string dex2dex_json_info()
friend class Parser
Definition OAT/Binary.hpp:43
std::vector< std::unique_ptr< Class > > classes_list_t
Definition OAT/Binary.hpp:52
bool has_class(std::string_view class_name) const
Check if the current OAT has the given class.
it_const_methods methods() const
Iterator over LIEF::OAT::Method.
std::vector< std::unique_ptr< DexFile > > oat_dex_files_t
Definition OAT/Binary.hpp:56
ref_iterator< oat_dex_files_t &, DexFile * > it_oat_dex_files
Definition OAT/Binary.hpp:57
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:65
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:58
~Binary() override
ref_iterator< dex_files_t &, DEX::File * > it_dex_files
Definition OAT/Binary.hpp:47
bool has_vdex() const
Definition OAT/Binary.hpp:111
static bool classof(const LIEF::Binary *bin)
Definition OAT/Binary.hpp:115
Definition OAT/Class.hpp:36
Definition OAT/Header.hpp:35
Main interface to parse an executable regardless of its format.
Definition Abstract/Parser.hpp:32
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:121
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DEX/Class.hpp:31
Definition ELF/Parser.hpp:34
Definition OAT/Binary.hpp:32
LIEF namespace.
Definition Abstract/Binary.hpp:42
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:386
#define LIEF_API
Definition visibility.h:45