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