LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
OAT/Parser.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_PARSER_H
17#define LIEF_OAT_PARSER_H
18#include <memory>
19
20#include "LIEF/visibility.h"
21#include "LIEF/ELF/Parser.hpp"
22
23namespace LIEF {
24
25namespace VDEX {
26class File;
27}
28
29namespace DEX {
30class Class;
31}
32
33namespace OAT {
34class Binary;
35class Class;
36class LIEF_API Parser : public ELF::Parser {
39 public: static std::unique_ptr<Binary> parse(const std::string& oat_file);
42 static std::unique_ptr<Binary> parse(const std::string& oat_file,
43 const std::string& vdex_file);
44
45 static std::unique_ptr<Binary> parse(std::vector<uint8_t> data);
46
47 Parser& operator=(const Parser& copy) = delete;
48 Parser(const Parser& copy) = delete;
49
50 protected:
51 Parser();
52 Parser(const std::string& oat_file);
53 Parser(std::vector<uint8_t> data);
54 ~Parser() override;
55
56 Binary& oat_binary() {
57 // The type of the parent binary_ is guaranteed by the constructor
58 return *reinterpret_cast<Binary*>(binary_.get());
59 }
60
61 bool has_vdex() const;
62 void set_vdex(std::unique_ptr<VDEX::File> file);
63
64 template<typename OAT_T>
65 void parse_binary();
66
67 template<typename OAT_T>
68 void parse_header();
69
70 template<typename OAT_T>
71 void parse_header_keys();
72
73 template<typename OAT_T>
74 void parse_dex_files();
75
76 template<typename OAT_T>
77 void parse_type_lookup_table();
78
79 template<typename OAT_T>
80 void parse_oat_classes();
81
82 template<typename OAT_T>
83 void parse_oat_methods(uint64_t methods_offsets, Class& clazz, const DEX::Class& dex_class);
84
85 void init();
86
87 std::unique_ptr<LIEF::VDEX::File> vdex_file_;
88
89 uint64_t data_address_ = 0;
90 uint64_t data_size_ = 0;
91
92 uint64_t exec_start_ = 0;
93 uint64_t exec_size_ = 0;
94};
95
96} // namespace OAT
97} // namespace LIEF
98#endif
Class which represents a DEX Class (i.e. a Java/Kotlin class)
Definition DEX/Class.hpp:36
Definition OAT/Binary.hpp:41
Definition OAT/Class.hpp:36
Class to parse an OAT file to produce an OAT::Binary.
Definition OAT/Parser.hpp:38
static std::unique_ptr< Binary > parse(const std::string &oat_file, const std::string &vdex_file)
static std::unique_ptr< Binary > parse(const std::string &oat_file)
Parse an OAT file.
static std::unique_ptr< Binary > parse(std::vector< uint8_t > data)
Parser & operator=(const Parser &copy)=delete
Parser(const Parser &copy)=delete
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