LIEF: Library to Instrument Executable Formats
Version 2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
lief-install
x86_64
static
include
LIEF
DEX
DEX/Parser.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_DEX_PARSER_H
17
#define LIEF_DEX_PARSER_H
18
19
#include <string_view>
20
#include <unordered_map>
21
#include <memory>
22
#include <string>
23
#include <vector>
24
25
#include "
LIEF/DEX/types.hpp
"
26
#include "
LIEF/path.hpp
"
27
#include "
LIEF/visibility.h
"
28
29
namespace
LIEF
{
30
class
VectorStream
;
31
32
namespace
DEX
{
33
class
Class
;
34
class
Method
;
35
class
Field
;
36
class
File
;
37
class
Type
;
38
40
class
LIEF_API
Parser
{
41
public
:
43
static
std::unique_ptr<File>
parse
(std::string_view file);
44
47
template
<
class
PathT, enable_if_path_t<PathT> = 0>
48
static
std::unique_ptr<File>
parse
(
const
PathT& file) {
49
return
parse
(file.string());
50
}
51
52
static
std::unique_ptr<File>
parse
(std::vector<uint8_t> data,
53
std::string_view name =
""
);
54
55
Parser
&
operator=
(
const
Parser
& copy) =
delete
;
56
Parser
(
const
Parser
& copy) =
delete
;
57
58
private
:
59
Parser
();
60
Parser
(std::string_view file);
61
Parser
(std::vector<uint8_t> data);
62
~Parser
();
63
64
void
init(std::string_view name,
dex_version_t
version
);
65
66
template
<
typename
DEX_T>
67
void
parse_file();
68
69
template
<
typename
DEX_T>
70
void
parse_header();
71
72
template
<
typename
DEX_T>
73
void
parse_map();
74
75
template
<
typename
DEX_T>
76
void
parse_strings();
77
78
template
<
typename
DEX_T>
79
void
parse_types();
80
81
template
<
typename
DEX_T>
82
void
parse_fields();
83
84
template
<
typename
DEX_T>
85
void
parse_prototypes();
86
87
template
<
typename
DEX_T>
88
void
parse_methods();
89
90
template
<
typename
DEX_T>
91
void
parse_classes();
92
93
template
<
typename
DEX_T>
94
void
parse_class_data(uint32_t offset,
Class
& cls);
95
96
template
<
typename
DEX_T>
97
void
parse_field(
size_t
index,
Class
& cls,
bool
is_static);
98
99
template
<
typename
DEX_T>
100
void
parse_method(
size_t
index,
Class
& cls,
bool
is_virtual);
101
102
template
<
typename
DEX_T>
103
void
parse_code_info(uint32_t offset,
Method
& method);
104
105
void
resolve_inheritance();
106
107
void
resolve_external_methods();
108
109
void
resolve_external_fields();
110
111
void
resolve_types();
112
113
std::unique_ptr<File> file_;
114
115
// Map of inheritance relationship when parsing classes ('parse_classes')
116
// The key is the parent class name of the value
117
std::unordered_multimap<std::string, Class*> inheritance_;
118
119
// Map of method/class relationship when parsing methods ('parse_methods')
120
// The key is the Class name in which the method is defined
121
std::unordered_multimap<std::string, Method*> class_method_map_;
122
123
// Map of field/class relationship when parsing fields ('parse_fields')
124
// The key is the Class name in which the field is defined
125
std::unordered_multimap<std::string, Field*> class_field_map_;
126
127
std::unordered_multimap<std::string, Type*> class_type_map_;
128
129
std::unique_ptr<VectorStream> stream_;
130
};
131
132
}
133
}
134
#endif
types.hpp
LIEF::DEX::Class
Class which represents a DEX Class (i.e. a Java/Kotlin class).
Definition
DEX/Class.hpp:37
LIEF::DEX::Field
Class which represents a DEX Field.
Definition
Field.hpp:35
LIEF::DEX::File
Class that represents a DEX file.
Definition
DEX/File.hpp:40
LIEF::DEX::Method
Class which represents a DEX::Method.
Definition
DEX/Method.hpp:37
LIEF::DEX::Parser::Parser
Parser(const Parser ©)=delete
LIEF::DEX::Parser::parse
static std::unique_ptr< File > parse(std::vector< uint8_t > data, std::string_view name="")
LIEF::DEX::Parser::parse
static std::unique_ptr< File > parse(const PathT &file)
Same as parse(std::string_view) but the file is given as a std::filesystem::path.
Definition
DEX/Parser.hpp:48
LIEF::DEX::Parser::parse
static std::unique_ptr< File > parse(std::string_view file)
Parse the DEX file from the file path given in parameter.
LIEF::DEX::Parser::operator=
Parser & operator=(const Parser ©)=delete
LIEF::DEX::Type
Class which represents a DEX type as described in the format specifications: https://source....
Definition
DEX/Type.hpp:34
LIEF::VectorStream
Definition
VectorStream.hpp:29
LIEF::DEX
Definition
DEX/Class.hpp:31
LIEF::DEX::version
dex_version_t version(std::string_view file)
Return the DEX version of the given file.
LIEF::DEX::dex_version_t
uint32_t dex_version_t
Definition
DEX/types.hpp:23
LIEF
LIEF namespace.
Definition
Abstract/Binary.hpp:41
path.hpp
visibility.h
LIEF_API
#define LIEF_API
Definition
visibility.h:45
Generated by
1.18.0