LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
DEX/Method.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_DEX_METHOD_H
17#define LIEF_DEX_METHOD_H
18
19#include <climits>
20#include <vector>
21
22#include "LIEF/visibility.h"
23#include "LIEF/Object.hpp"
24
25#include "LIEF/DEX/enums.hpp"
26#include "LIEF/DEX/CodeInfo.hpp"
27#include "LIEF/DEX/deopt.hpp"
28
29namespace LIEF {
30namespace DEX {
31class Parser;
32class Class;
33class Prototype;
34class LIEF_API Method : public Object {
37 friend class Parser;
38 public:
39 using access_flags_list_t = std::vector<ACCESS_FLAGS>;
40
41 public:
42 using bytecode_t = std::vector<uint8_t>;
44 Method(std::string name, Class* parent = nullptr);
45
46 Method(const Method&);
47 Method& operator=(const Method&);
48 const std::string& name() const;
51 bool has_class() const;
54 const Class* cls() const;
58 Class* cls();
59 uint64_t code_offset() const;
62 const bytecode_t& bytecode() const;
65 size_t index() const;
68 bool is_virtual() const;
72 const Prototype* prototype() const;
75 Prototype* prototype();
76
77 void insert_dex2dex_info(uint32_t pc, uint32_t index);
78
79 void accept(Visitor& visitor) const override;
80
82 bool has(ACCESS_FLAGS f) const;
85 access_flags_list_t access_flags() const;
88
89
90 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Method& mtd);
91
92 ~Method() override;
93
94 private:
95 void set_virtual(bool v);
96
97 private:
98 std::string name_;
99 Class* parent_ = nullptr;
100 Prototype* prototype_ = nullptr;
101 uint32_t access_flags_ = ACCESS_FLAGS::ACC_UNKNOWN;
102 uint32_t original_index_ = UINT_MAX;
103 bool is_virtual_ = false;
104
105 uint64_t code_offset_ = 0;
106 std::vector<uint8_t> bytecode_;
107
108 CodeInfo code_info_;
109
110 dex2dex_method_info_t dex2dex_info_;
111
112};
113
114} // Namespace DEX
115} // Namespace LIEF
116#endif
Class which represents a DEX Class (i.e. a Java/Kotlin class)
Definition DEX/Class.hpp:36
Class which represents a DEX::Method.
Definition DEX/Method.hpp:36
void accept(Visitor &visitor) const override
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 &)
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, finale or constructor.
const std::string & name() const
Name of the Method.
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 Prototype * prototype() const
Method's prototype or a nullptr if it is not resolved.
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 DEX/Class.hpp:30
std::unordered_map< uint32_t, uint32_t > dex2dex_method_info_t
Definition deopt.hpp:27
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41