LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
DEX/Class.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 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#include <string>
21
22#include "LIEF/visibility.h"
23#include "LIEF/Object.hpp"
24#include "LIEF/iterators.hpp"
25
26#include "LIEF/DEX/enums.hpp"
27#include "LIEF/DEX/deopt.hpp"
28
29namespace LIEF {
30namespace DEX {
31class Parser;
32class Field;
33class Method;
34
36class LIEF_API Class : public Object {
37 friend class Parser;
38
39 public:
40 using access_flags_list_t = std::vector<ACCESS_FLAGS>;
41
42 using methods_t = std::vector<Method*>;
45
46 using fields_t = std::vector<Field*>;
49
52
55
56 public:
57 static std::string package_normalized(const std::string& pkg_name);
58 static std::string fullname_normalized(const std::string& pkg_cls);
59 static std::string fullname_normalized(const std::string& pkg, const std::string& cls_name);
60
62 Class(const Class&) = delete;
63 Class& operator=(const Class&) = delete;
64
66 Class* parent = nullptr, std::string source_filename = "");
67
69 const std::string& fullname() const;
70
72 std::string package_name() const;
73
75 std::string name() const;
76
78 std::string pretty_name() const;
79
81 bool has(ACCESS_FLAGS f) const;
82
85
87 const std::string& source_filename() const;
88
90 bool has_parent() const;
91
93 const Class* parent() const;
95
99
101 it_named_methods methods(const std::string& name);
102 it_const_named_methods methods(const std::string& name) const;
103
107
109 it_named_fields fields(const std::string& name);
110 it_const_named_fields fields(const std::string& name) const;
111
114
116 size_t index() const;
117
118 void accept(Visitor& visitor) const override;
119
120
121 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Class& cls);
122
123 ~Class() override;
124
125 private:
126 std::string fullname_;
127 uint32_t access_flags_ = ACCESS_FLAGS::ACC_UNKNOWN;
128 Class* parent_ = nullptr;
129 methods_t methods_;
130 fields_t fields_;
131 std::string source_filename_;
132
133 uint32_t original_index_ = UINT_MAX;
134};
135
136} // Namespace DEX
137} // Namespace LIEF
138#endif
const_filter_iterator< const methods_t & > it_const_named_methods
Definition DEX/Class.hpp:51
ref_iterator< methods_t & > it_methods
Definition DEX/Class.hpp:43
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:40
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:48
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:47
std::vector< Field * > fields_t
Definition DEX/Class.hpp:46
it_methods methods()
~Class() override
it_fields fields()
const_ref_iterator< const methods_t & > it_const_methods
Definition DEX/Class.hpp:44
bool has_parent() const
True if the current class extends another one.
Class(const Class &)=delete
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:53
std::vector< Method * > methods_t
Definition DEX/Class.hpp:42
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:37
const std::string & fullname() const
Mangled class name (e.g. Lcom/example/android/MyActivity;).
const_filter_iterator< const fields_t & > it_const_named_fields
Definition DEX/Class.hpp:54
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:50
static std::string fullname_normalized(const std::string &pkg_cls)
friend std::ostream & operator<<(std::ostream &os, const Class &cls)
const std::string & source_filename() const
Filename associated with this class (if any).
Class which represent a DEX Field.
Definition Field.hpp:34
Class which represents a DEX::Method.
Definition DEX/Method.hpp:36
Class which parses a DEX file to produce a DEX::File object.
Definition DEX/Parser.hpp:38
Definition Visitor.hpp:210
Iterator which return a ref on container's values given predicates.
Definition iterators.hpp:263
Iterator which returns reference on container's values.
Definition iterators.hpp:46
Definition DEX/Class.hpp:30
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
LIEF namespace.
Definition Abstract/Binary.hpp:40
filter_iterator< CT, U, typename decay_t< CT >::const_iterator > const_filter_iterator
Iterator which return a const ref on container's values given predicates.
Definition iterators.hpp:479
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which return const ref on container's values.
Definition iterators.hpp:257
#define LIEF_API
Definition visibility.h:41