LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
Type.hpp
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:
62 Type();
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
79 array_t& array();
80
83 PRIMITIVES& primitive();
84
87 size_t dim() const;
88
91 Type& underlying_array_type();
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};
106 array_t* array_;
107 PRIMITIVES* basic_;
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 Type.hpp:33
Class & cls()
IF the current type is a TYPES::CLASS, return the associated DEX::CLASS. Otherwise the returned value...
size_t dim() const
Return the array dimension if the current type is an array. Otherwise it returns 0.
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...
TYPES type() const
Whether it is a primitive type, a class, ...
Definition Object.hpp:25
Definition Visitor.hpp:219
LIEF namespace.
Definition Abstract/Binary.hpp:32