9#ifndef KUNAI_DEX_PARSER_TYPES_HPP
10#define KUNAI_DEX_PARSER_TYPES_HPP
12#include "Kunai/Utils/kunaistream.hpp"
13#include "Kunai/DEX/parser/strings.hpp"
16#include <unordered_map>
49 : type(type), raw_type(raw_type)
78 using dvmtype_t = std::unique_ptr<DVMType>;
105 const std::unordered_map<fundamental_e, std::string> fundamental_s =
107 {BOOLEAN,
"boolean"},
122 DVMType(FUNDAMENTAL, name), f_type(f_type), name(name)
139 return "Fundamental";
154 return fundamental_s.at(type);
168 return fundamental_s.at(f_type);
178 std::string pretty_name;
229 dvmtype_t array_type;
231 std::string pretty_name;
237 DVMArray(std::string raw,
size_t depth, dvmtype_t& array) :
238 DVMType(
ARRAY, raw), depth(depth), array_type(std::move(array))
262 return array_type.get();
307 std::vector<dvmtype_t> ordered_types;
309 std::unordered_map<std::uint32_t, DVMType*> types_by_id;
311 std::uint32_t number_of_types;
313 std::uint32_t offset;
328 std::uint32_t number_of_types,
329 std::uint32_t types_offset
336 return ordered_types;
360 return number_of_types;
384 dvmtype_t parse_type(std::string& name);
Class that represent the array types.
Definition types.hpp:223
DVMArray(std::string raw, size_t depth, dvmtype_t &array)
Constructor of DVMArray.
Definition types.hpp:237
std::string print_type() const override
Return the string representation of the type.
Definition types.hpp:253
type_e get_type() const override
Return the type in this case an Array type.
Definition types.hpp:246
~DVMArray()=default
Destructor of DVMArray.
size_t get_depth() const
Get the depth of the array specified as [[.
Definition types.hpp:267
const DVMType * get_array_type() const
Return a pointer to the type of the array.
Definition types.hpp:260
const std::string & pretty_print() override
Pretty print the name of the type.
Classes of the DVM.
Definition types.hpp:174
type_e get_type() const override
get type_e enum value for Class object.
Definition types.hpp:192
std::string & get_name()
Return a reference to the name.
Definition types.hpp:213
DVMClass(std::string name)
constructor of DVM class with the name of the class
Definition types.hpp:183
std::string print_type() const override
get the type in string format
Definition types.hpp:199
const std::string & pretty_print() override
Pretty print the name of the type.
~DVMClass()=default
default destructor of DVMClass
const std::string & get_name() const
Get the name of the class.
Definition types.hpp:206
Fundamental types from the DVM, these are the common from many other languages.
Definition types.hpp:83
~DVMFundamental()=default
Destructor of the fundamental.
const std::string & print_fundamental_type(fundamental_e type) const
Return a reference to a string with the fundamental type.
Definition types.hpp:152
DVMFundamental(fundamental_e f_type, std::string name)
Constructor of the DVMFundamental.
Definition types.hpp:121
type_e get_type() const override
get the type of the object
Definition types.hpp:130
const std::string & pretty_print() override
Get a pretty printed version of the name.
Definition types.hpp:166
fundamental_e get_fundamental_type() const
get the stored fundamental type
Definition types.hpp:144
fundamental_e
enum with the fundamental types
Definition types.hpp:87
const std::string & get_name() const
Return a reference to the fundamental name.
Definition types.hpp:159
std::string print_type() const override
Return a string with the name of the type.
Definition types.hpp:137
Represents the base class of a Type in the DVM we have different types.
Definition types.hpp:26
virtual type_e get_type() const =0
Virtual method to return the type.
type_e
Types of the DVM we have by default fundamental, classes and array types.
Definition types.hpp:31
@ CLASS
fundamental type (int, float...)
Definition types.hpp:33
@ ARRAY
user defined class
Definition types.hpp:34
@ UNKNOWN
an array type
Definition types.hpp:35
virtual const std::string & pretty_print()
Pretty print the name of the type.
Definition types.hpp:72
DVMType(type_e type, std::string raw_type)
Constructor of DVMType.
Definition types.hpp:48
std::string & get_raw()
get raw string from the type object
Definition types.hpp:65
virtual std::string print_type() const =0
Get the type on its string representation.
virtual ~DVMType()=default
Destructor of DVMType.
Storage class for all the strings of the DEX file.
Definition strings.hpp:34
void to_xml(std::ofstream &xml_file)
Dump the types to an xml file.
std::uint32_t get_number_of_types() const
Get the number of types stored.
Definition types.hpp:358
friend std::ostream & operator<<(std::ostream &os, const Types &entry)
Pretty printer for Types.
const std::vector< dvmtype_t > & get_ordered_types() const
Get a reference to the vector with all the types.
Definition types.hpp:334
DVMType * get_type_by_id(std::uint32_t type_id)
Get a type given its string ID.
std::uint32_t get_offset() const
Get the offset where types are stored.
Definition types.hpp:365
DVMType * get_type_from_order(std::uint32_t pos)
Get a type given position.
Types()=default
Constructor of the Types object, nothing for initialization.
~Types()=default
Destructor of Types.
const std::unordered_map< std::uint32_t, DVMType * > & get_types_by_id() const
Get the types with the map of string id - type.
Definition types.hpp:341
void parse_types(stream::KunaiStream *stream, Strings *strings, std::uint32_t number_of_types, std::uint32_t types_offset)
Parse the types and store them in the class.
In case something unknown is found, we categorize it.
Definition types.hpp:277
~Unknown()=default
Destructor of unknown type.
Unknown(std::string raw)
Constructor of unknown type.
Definition types.hpp:282
type_e get_type() const override
Get Unkown type.
Definition types.hpp:291
std::string print_type() const override
Get Unkown type as a string.
Definition types.hpp:298
Class to manage an input file stream given for the analysis.
Definition kunaistream.hpp:20
utilities
Definition analysis.hpp:23