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 - 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#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;
34class 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*>;
43 using it_methods = ref_iterator<methods_t&>;
44 using it_const_methods = const_ref_iterator<const methods_t&>;
45
46 using fields_t = std::vector<Field*>;
47 using it_fields = ref_iterator<fields_t&>;
48 using it_const_fields = const_ref_iterator<const fields_t&>;
49
50 using it_named_methods = filter_iterator<methods_t&>;
51 using it_const_named_methods = const_filter_iterator<const methods_t&>;
52
53 using it_named_fields = filter_iterator<fields_t&>;
54 using it_const_named_fields = const_filter_iterator<const fields_t&>;
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
65 Class(std::string fullname, uint32_t access_flags = ACCESS_FLAGS::ACC_UNKNOWN,
66 Class* parent = nullptr, std::string source_filename = "");
67 const std::string& fullname() const;
70 std::string package_name() const;
73 std::string name() const;
76 std::string pretty_name() const;
79 bool has(ACCESS_FLAGS f) const;
82 access_flags_list_t access_flags() const;
85 const std::string& source_filename() const;
88 bool has_parent() const;
91 const Class* parent() const;
94 Class* parent();
95 it_const_methods methods() const;
98 it_methods methods();
99 it_named_methods methods(const std::string& name);
102 it_const_named_methods methods(const std::string& name) const;
103 it_const_fields fields() const;
106 it_fields fields();
107 it_named_fields fields(const std::string& name);
110 it_const_named_fields fields(const std::string& name) const;
114 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
Class which represents a DEX Class (i.e. a Java/Kotlin class)
Definition DEX/Class.hpp:36
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
access_flags_list_t access_flags() const
Access flags used by this class.
it_const_methods methods() const
Methods implemented in this class.
static std::string package_normalized(const std::string &pkg_name)
it_methods methods()
~Class() override
it_fields fields()
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.
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.
const std::string & fullname() const
Mangled class name (e.g. Lcom/example/android/MyActivity;)
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)
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 DEX/Class.hpp:30
std::unordered_map< Method *, dex2dex_method_info_t > dex2dex_class_info_t
Definition deopt.hpp:28
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41