LIEF: Library to Instrument Executable Formats Version 0.15.1
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>>;
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;
71
75
79
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
103
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:41
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
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
std::unordered_map< std::string, Class * > classes_t
Definition OAT/Binary.hpp:49
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
std::vector< std::unique_ptr< DEX::File > > dex_files_t
Definition OAT/Binary.hpp:45
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.
std::vector< std::unique_ptr< Method > > methods_t
Definition OAT/Binary.hpp:58
it_const_oat_dex_files oat_dex_files() const
it_const_dex_files dex_files() const
std::string dex2dex_json_info()
std::vector< std::unique_ptr< Class > > classes_list_t
Definition OAT/Binary.hpp:50
it_const_methods methods() const
Iterator over LIEF::OAT::Method.
std::vector< std::unique_ptr< DexFile > > oat_dex_files_t
Definition OAT/Binary.hpp:54
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:62
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:35
Definition OAT/Header.hpp:36
Class to parse an OAT file to produce an OAT::Binary.
Definition OAT/Parser.hpp:38
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:224
Iterator which returns reference on container's values.
Definition iterators.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:32
#define LIEF_API
Definition visibility.h:41