LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
DEX/Type.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_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
33class LIEF_API Type : public Object {
34 friend class Parser;
35
36 public:
37 enum class TYPES {
38 UNKNOWN = 0,
39 PRIMITIVE = 1,
40 CLASS = 2,
41 ARRAY = 3,
42 };
43
44 enum class PRIMITIVES {
45 VOID_T = 0x01,
46 BOOLEAN = 0x02,
47 BYTE = 0x03,
48 SHORT = 0x04,
49 CHAR = 0x05,
50 INT = 0x06,
51 LONG = 0x07,
52 FLOAT = 0x08,
53 DOUBLE = 0x09,
54 };
55
56 using array_t = std::vector<Type>;
57
58 public:
59 static std::string pretty_name(PRIMITIVES p);
60
61 public:
63 Type(const std::string& mangled);
64 Type(const Type& other);
65
67 TYPES type() const;
68
69 const Class& cls() const;
70 const array_t& array() const;
71 const PRIMITIVES& primitive() const;
72
76
80
84
87 size_t dim() const;
88
92
93 void accept(Visitor& visitor) const override;
94
95
96 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Type& type);
97
98 ~Type() override;
99
100 private:
101 void parse(const std::string& type);
102
103 TYPES type_{TYPES::UNKNOWN};
104 union {
105 Class* cls_{nullptr};
108 };
109};
110
111} // Namespace DEX
112} // Namespace LIEF
113#endif
Class which represents a DEX Class (i.e. a Java/Kotlin class)
Definition DEX/Class.hpp:35
Class which parses a DEX file to produce a DEX::File object.
Definition DEX/Parser.hpp:38
Class which represents a DEX type as described in the format specifications: https://source....
Definition DEX/Type.hpp:33
Class & cls()
IF the current type is a TYPES::CLASS, return the associated DEX::CLASS. Otherwise the returned value...
const PRIMITIVES & primitive() const
PRIMITIVES
Definition DEX/Type.hpp:44
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:106
std::vector< Type > array_t
Definition DEX/Type.hpp:56
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:107
Type(const Type &other)
const Class & cls() const
static std::string pretty_name(PRIMITIVES p)
Type & underlying_array_type()
const array_t & array() const
TYPES
Definition DEX/Type.hpp:37
TYPES type() const
Whether it is a primitive type, a class, ...
Definition Object.hpp:25
Definition Visitor.hpp:224
LIEF namespace.
Definition Abstract/Binary.hpp:32
#define LIEF_API
Definition visibility.h:41