LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
DEX/Method.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_METHOD_H
17#define LIEF_DEX_METHOD_H
18
19#include <string_view>
20#include <climits>
21#include <vector>
22
23#include "LIEF/Object.hpp"
24#include "LIEF/visibility.h"
25
26#include "LIEF/DEX/CodeInfo.hpp"
27#include "LIEF/DEX/deopt.hpp"
28#include "LIEF/DEX/enums.hpp"
29
30
31namespace LIEF::DEX {
32class Parser;
33class Class;
34class Prototype;
35
37class LIEF_API Method : public Object {
38 friend class Parser;
39
40 public:
41 using access_flags_list_t = std::vector<ACCESS_FLAGS>;
42
43 public:
44 using bytecode_t = std::vector<uint8_t>;
46 Method(std::string name, Class* parent = nullptr);
47
48 Method(const Method&);
50
52 std::string_view name() const;
53
55 bool has_class() const;
56
59 const Class* cls() const;
61
63 uint64_t code_offset() const;
64
66 const bytecode_t& bytecode() const;
67
69 size_t index() const;
70
73 bool is_virtual() const;
74
76 const Prototype* prototype() const;
78
79 void insert_dex2dex_info(uint32_t pc, uint32_t index);
80
81 void accept(Visitor& visitor) const override;
82
84
86 bool has(ACCESS_FLAGS f) const;
87
90
91 // CodeInfo to get additional data about a method i.e. argument count
92 const CodeInfo& code_info() const;
93
94 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Method& mtd);
95
96 ~Method() override;
97
98 private:
99 void set_virtual(bool v);
100
101 private:
102 std::string name_;
103 Class* parent_ = nullptr;
104 Prototype* prototype_ = nullptr;
105 uint32_t access_flags_ = ACCESS_FLAGS::ACC_UNKNOWN;
106 uint32_t original_index_ = UINT_MAX;
107 bool is_virtual_ = false;
108
109 uint64_t code_offset_ = 0;
110 std::vector<uint8_t> bytecode_;
111
112 CodeInfo code_info_;
113
114 dex2dex_method_info_t dex2dex_info_;
115};
116
117} // Namespace DEX
118// Namespace LIEF
119#endif
Class which represents a DEX Class (i.e. a Java/Kotlin class).
Definition DEX/Class.hpp:37
Definition CodeInfo.hpp:33
std::string_view name() const
Name of the Method.
void accept(Visitor &visitor) const override
std::vector< uint8_t > bytecode_t
Definition DEX/Method.hpp:44
friend std::ostream & operator<<(std::ostream &os, const Method &mtd)
const dex2dex_method_info_t & dex2dex_info() const
Method(std::string name, Class *parent=nullptr)
~Method() override
Method(const Method &)
std::vector< ACCESS_FLAGS > access_flags_list_t
Definition DEX/Method.hpp:41
void insert_dex2dex_info(uint32_t pc, uint32_t index)
const bytecode_t & bytecode() const
Dalvik Bytecode as bytes.
Prototype * prototype()
bool is_virtual() const
True if this method is a virtual one. i.e. not static, private, final or constructor.
Method & operator=(const Method &)
const Class * cls() const
DEX::Class associated with this Method or a nullptr if not resolved.
access_flags_list_t access_flags() const
ACCESS_FLAGS as an std::set.
bool has(ACCESS_FLAGS f) const
Check if the current method has the given ACCESS_FLAGS.
size_t index() const
Index in the DEX Methods pool.
const CodeInfo & code_info() const
const Prototype * prototype() const
Method's prototype or a nullptr if it is not resolved.
friend class Parser
Definition DEX/Method.hpp:38
bool has_class() const
True if a class is associated with this method.
uint64_t code_offset() const
Offset to the Dalvik Bytecode.
Class which parses a DEX file to produce a DEX::File object.
Definition DEX/Parser.hpp:38
Class which represents a DEX method prototype.
Definition Prototype.hpp:29
Definition Visitor.hpp:212
Definition DEX/Class.hpp:31
ACCESS_FLAGS
Definition DEX/enums.hpp:22
@ ACC_UNKNOWN
Definition DEX/enums.hpp:23
std::unordered_map< uint32_t, uint32_t > dex2dex_method_info_t
Definition deopt.hpp:27
#define LIEF_API
Definition visibility.h:45