LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
DEX/Type.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_TYPE_H
17#define LIEF_DEX_TYPE_H
18
19#include <string_view>
20#include <ostream>
21#include <string>
22#include <vector>
23
24#include "LIEF/Object.hpp"
25#include "LIEF/visibility.h"
26
27
28namespace LIEF::DEX {
29class Parser;
30class Class;
31
35class LIEF_API Type : public Object {
36 friend class Parser;
37
38 public:
39 enum class TYPES {
40 UNKNOWN = 0,
41 PRIMITIVE = 1,
42 CLASS = 2,
43 ARRAY = 3,
44 };
45
46 enum class PRIMITIVES {
47 VOID_T = 0x01,
48 BOOLEAN = 0x02,
49 BYTE = 0x03,
50 SHORT = 0x04,
51 CHAR = 0x05,
52 INT = 0x06,
53 LONG = 0x07,
54 FLOAT = 0x08,
55 DOUBLE = 0x09,
56 };
57
58 using array_t = std::vector<Type>;
59
60 public:
61 static std::string pretty_name(PRIMITIVES p);
62
63 public:
65 Type(std::string_view mangled);
66 Type(const Type& other);
67
69 TYPES type() const;
70
71 const Class& cls() const;
72 const array_t& array() const;
73 const PRIMITIVES& primitive() const;
74
78
82
86
89 size_t dim() const;
90
94
95 void accept(Visitor& visitor) const override;
96
97
98 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Type& type);
99
100 ~Type() override;
101
102 private:
103 void parse(std::string_view type);
104
105 TYPES type_{TYPES::UNKNOWN};
106 union {
107 Class* cls_{nullptr};
108 array_t* array_;
109 PRIMITIVES* basic_;
110 };
111};
112
113} // Namespace DEX
114// Namespace LIEF
115#endif
Class which represents a DEX Class (i.e. a Java/Kotlin class).
Definition DEX/Class.hpp:37
Class which parses a DEX file to produce a DEX::File object.
Definition DEX/Parser.hpp:40
Class & cls()
IF the current type is a TYPES::CLASS, return the associated DEX::CLASS. Otherwise,...
Type(std::string_view mangled)
const PRIMITIVES & primitive() const
PRIMITIVES
Definition DEX/Type.hpp:46
size_t dim() const
Return the array dimension if the current type is an array. Otherwise, it returns 0.
void accept(Visitor &visitor) const override
std::vector< Type > array_t
Definition DEX/Type.hpp:58
const Type & underlying_array_type() const
In the case of a TYPES::ARRAY, return the array's type.
PRIMITIVES & primitive()
IF the current type is a TYPES::PRIMITIVE, return the associated PRIMITIVES. Otherwise,...
array_t & array()
IF the current type is a TYPES::ARRAY, return the associated array. Otherwise, the returned value is ...
Type(const Type &other)
const Class & cls() const
static std::string pretty_name(PRIMITIVES p)
friend class Parser
Definition DEX/Type.hpp:36
const array_t & array() const
TYPES
Definition DEX/Type.hpp:39
@ UNKNOWN
Definition DEX/Type.hpp:40
TYPES type() const
Whether it is a primitive type, a class, ...
Definition Visitor.hpp:212
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DEX/Class.hpp:31
#define LIEF_API
Definition visibility.h:45