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