LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
ART/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_ART_PARSER_H
17#define LIEF_ART_PARSER_H
18#include <string_view>
19#include <memory>
20#include <vector>
21
22#include "LIEF/ART/types.hpp"
23#include "LIEF/path.hpp"
24#include "LIEF/visibility.h"
25
26namespace LIEF {
27class BinaryStream;
28namespace ART {
29class File;
30
31
34 public:
35 static std::unique_ptr<File> parse(std::string_view file);
36
39 template<class PathT, enable_if_path_t<PathT> = 0>
40 static std::unique_ptr<File> parse(const PathT& file) {
41 return parse(file.string());
42 }
43
44 static std::unique_ptr<File> parse(std::vector<uint8_t> data,
45 std::string_view name = "");
46
47 Parser& operator=(const Parser& copy) = delete;
48 Parser(const Parser& copy) = delete;
49
50 private:
51 Parser();
52 Parser(std::string_view file);
53 Parser(std::vector<uint8_t> data);
54 ~Parser();
55
56 void init(std::string_view name, art_version_t version);
57
58 template<typename ART_T>
59 void parse_file();
60
61 template<typename ART_T>
62 size_t parse_header();
63
64 template<typename ART_T, typename PTR_T>
65 void parse_sections();
66
67 template<typename ART_T, typename PTR_T>
68 void parse_roots();
69
70 template<typename ART_T, typename PTR_T>
71 void parse_methods();
72
73 // Section parsing
74 template<typename ART_T, typename PTR_T>
75 void parse_objects(size_t offset, size_t size);
76
77 template<typename ART_T, typename PTR_T>
78 void parse_art_fields(size_t offset, size_t size);
79
80 template<typename ART_T, typename PTR_T>
81 void parse_art_methods(size_t offset, size_t size);
82
83 template<typename ART_T, typename PTR_T>
84 void parse_interned_strings(size_t offset, size_t size);
85
86 // Parse an **Array** of java.lang.DexCache objects
87 template<typename ART_T, typename PTR_T>
88 void parse_dex_caches(size_t offset, size_t size);
89
90 // Parse a **Single** java.lang.DexCache object
91 template<typename ART_T, typename PTR_T>
92 void parse_dex_cache(size_t object_offset);
93
94 // Parse an **Array** of java.lang.Class objects
95 template<typename ART_T, typename PTR_T>
96 void parse_class_roots(size_t offset, size_t size);
97
98 // Parse java.lang.Class objects
99 template<typename ART_T, typename PTR_T>
100 void parse_class(size_t offset);
101
102 // Parse java.lang.String objects
103 template<typename ART_T, typename PTR_T>
104 void parse_jstring(size_t offset);
105
106
108 // template<typename ART_T, typename PTR_T>
109 // void parse_class_roots(size_t object_offset);
110
111 std::unique_ptr<File> file_;
112 std::unique_ptr<BinaryStream> stream_;
113 uint32_t imagebase_ = 0;
114};
115}
116}
117#endif
Definition ART/File.hpp:29
static std::unique_ptr< File > parse(std::string_view file)
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 ART/Parser.hpp:40
Parser & operator=(const Parser &copy)=delete
Parser(const Parser &copy)=delete
static std::unique_ptr< File > parse(std::vector< uint8_t > data, std::string_view name="")
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:35
Definition ART/enums.hpp:21
art_version_t version(std::string_view file)
Return the ART version of the given file.
uint32_t art_version_t
Definition ART/types.hpp:24
LIEF namespace.
Definition Abstract/Binary.hpp:41
#define LIEF_API
Definition visibility.h:45