LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
DEX/Class.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_CLASS_H
17#define LIEF_DEX_CLASS_H
18
19#include <climits>
20
21#include "LIEF/visibility.h"
22#include "LIEF/Object.hpp"
23#include "LIEF/iterators.hpp"
24
25#include "LIEF/DEX/enums.hpp"
26#include "LIEF/DEX/deopt.hpp"
27
28namespace LIEF {
29namespace DEX {
30class Parser;
31class Field;
32class Method;
33
35class LIEF_API Class : public Object {
36 friend class Parser;
37
38 public:
39 using access_flags_list_t = std::vector<ACCESS_FLAGS>;
40
41 using methods_t = std::vector<Method*>;
44
45 using fields_t = std::vector<Field*>;
48
51
54
55 public:
56 static std::string package_normalized(const std::string& pkg_name);
57 static std::string fullname_normalized(const std::string& pkg_cls);
58 static std::string fullname_normalized(const std::string& pkg, const std::string& cls_name);
59
60 Class();
61 Class(const Class&) = delete;
62 Class& operator=(const Class&) = delete;
63
64 Class(std::string fullname, uint32_t access_flags = ACCESS_FLAGS::ACC_UNKNOWN,
65 Class* parent = nullptr, std::string source_filename = "");
66
68 const std::string& fullname() const;
69
71 std::string package_name() const;
72
74 std::string name() const;
75
77 std::string pretty_name() const;
78
80 bool has(ACCESS_FLAGS f) const;
81
83 access_flags_list_t access_flags() const;
84
86 const std::string& source_filename() const;
87
89 bool has_parent() const;
90
92 const Class* parent() const;
93 Class* parent();
94
97 it_methods methods();
98
100 it_named_methods methods(const std::string& name);
101 it_const_named_methods methods(const std::string& name) const;
102
105 it_fields fields();
106
108 it_named_fields fields(const std::string& name);
109 it_const_named_fields fields(const std::string& name) const;
110
112 dex2dex_class_info_t dex2dex_info() const;
113
115 size_t index() const;
116
117 void accept(Visitor& visitor) const override;
118
119
120 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Class& cls);
121
122 ~Class() override;
123
124 private:
125 std::string fullname_;
126 uint32_t access_flags_ = ACCESS_FLAGS::ACC_UNKNOWN;
127 Class* parent_ = nullptr;
128 methods_t methods_;
129 fields_t fields_;
130 std::string source_filename_;
131
132 uint32_t original_index_ = UINT_MAX;
133};
134
135} // Namespace DEX
136} // Namespace LIEF
137#endif
Class which represents a DEX Class (i.e. a Java/Kotlin class)
Definition DEX/Class.hpp:35
size_t index() const
Original index in the DEX class pool.
access_flags_list_t access_flags() const
Access flags used by this class.
it_const_methods methods() const
Methods implemented in this class.
bool has_parent() const
True if the current class extends another one.
std::string pretty_name() const
Demangled class name.
bool has(ACCESS_FLAGS f) const
Check if the class has the given access flag.
it_named_fields fields(const std::string &name)
Return Fields having the given name.
it_named_methods methods(const std::string &name)
Return Methods having the given name.
std::string name() const
Class name.
dex2dex_class_info_t dex2dex_info() const
De-optimize information.
const std::string & fullname() const
Mangled class name (e.g. Lcom/example/android/MyActivity;)
it_const_fields fields() const
Fields implemented in this class.
const Class * parent() const
Parent class.
std::string package_name() const
Package Name.
const std::string & source_filename() const
Filename associated with this class (if any)
Class which parses a DEX file to produce a DEX::File object.
Definition DEX/Parser.hpp:38
Definition Object.hpp:25
Definition Visitor.hpp:219
Iterator which return a ref on container's values given predicates.
Definition iterators.hpp:265
Iterator which returns reference on container's values.
Definition iterators.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:32