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