KUNAI Static Analyzer
Kunai is a library for doing static binary analysis of Dalvik.
Loading...
Searching...
No Matches
fields.hpp
1//--------------------------------------------------------------------*- C++ -*-
2// Kunai-static-analyzer: library for doing analysis of dalvik files
3// @author Farenain <kunai.static.analysis@gmail.com>
4// @author Ernesto Java <javaernesto@gmail.com>
5//
6// @file fields.hpp
7// @brief Manage all the data from the fields from the DEX files.
8#ifndef KUNAI_DEX_PARSER_FIELDS_HPP
9#define KUNAI_DEX_PARSER_FIELDS_HPP
10
11#include "Kunai/DEX/parser/types.hpp"
12#include "Kunai/DEX/parser/strings.hpp"
13#include "Kunai/Utils/kunaistream.hpp"
14
15#include <memory>
16#include <vector>
17
18namespace KUNAI
19{
20namespace DEX
21{
23 class EncodedField;
24
27 class FieldID
28 {
30 DVMType* class_;
32 DVMType* type_;
34 std::string& name_;
36 std::string pretty_name;
38 EncodedField * encoded_field;
39 public:
40
45 FieldID(DVMType* class_, DVMType* type_, std::string& name_)
46 : class_(class_), type_(type_), name_(name_)
47 {
48 }
49
50 void set_encoded_field(EncodedField * encoded_field)
51 {
52 this->encoded_field = encoded_field;
53 }
54
55 EncodedField* get_encoded_field()
56 {
57 return encoded_field;
58 }
59
61 ~FieldID() = default;
62
65 const DVMType* get_class() const
66 {
67 return class_;
68 }
69
73 {
74 return class_;
75 }
76
79 const DVMType* get_type() const
80 {
81 return type_;
82 }
83
87 {
88 return type_;
89 }
90
93 const std::string& get_name() const
94 {
95 return name_;
96 }
97
100 std::string& get_name()
101 {
102 return name_;
103 }
104
107 std::string& pretty_field();
108 };
109
110 using fieldid_t = std::unique_ptr<FieldID>;
111
113 class Fields
114 {
116 std::vector<fieldid_t> fields;
117
119 std::uint32_t fields_size;
120 public:
121
123 Fields() = default;
124
126 ~Fields() = default;
127
135 stream::KunaiStream* stream,
136 Types* types,
137 Strings* strings,
138 std::uint32_t fields_offset,
139 std::uint32_t fields_size
140 );
141
144 const std::vector<fieldid_t>& get_fields() const
145 {
146 return fields;
147 }
148
151 std::vector<fieldid_t>& get_fields()
152 {
153 return fields;
154 }
155
159 FieldID* get_field(std::uint32_t pos);
160
163 std::uint32_t get_number_of_fields() const
164 {
165 return fields_size;
166 }
167
172 friend std::ostream& operator<<(std::ostream& os, const Fields& entry);
173
176 void to_xml(std::ofstream& fos);
177 };
178} // namespace DEX
179} // namespace KUNAI
180
181
182#endif
Represents the base class of a Type in the DVM we have different types.
Definition types.hpp:26
Class that represent field information it contains a FieldID and also the access flags.
Definition encoded.hpp:266
FieldID represent one of the fields from the DEX file.
Definition fields.hpp:28
DVMType * get_class()
Get a pointer to the class where field is.
Definition fields.hpp:72
std::string & pretty_field()
Get a string representation of the field.
~FieldID()=default
Destructor of the FieldID.
const DVMType * get_class() const
Get a constant pointer to the class where field is.
Definition fields.hpp:65
const std::string & get_name() const
Get a constant reference to the name of the field.
Definition fields.hpp:93
const DVMType * get_type() const
Get a constant pointer to the type of the field.
Definition fields.hpp:79
FieldID(DVMType *class_, DVMType *type_, std::string &name_)
Constructor of the FieldID.
Definition fields.hpp:45
DVMType * get_type()
Get a pointer to the type of the field.
Definition fields.hpp:86
std::string & get_name()
Get a reference to the name of the field.
Definition fields.hpp:100
Fields will contain all the FieldID from the DEX file.
Definition fields.hpp:114
friend std::ostream & operator<<(std::ostream &os, const Fields &entry)
Give a pretty print result of the fields.
const std::vector< fieldid_t > & get_fields() const
Get a constant reference to all the fields.
Definition fields.hpp:144
std::vector< fieldid_t > & get_fields()
Get a reference to all the fields.
Definition fields.hpp:151
Fields()=default
Constructor of Fields, default.
~Fields()=default
Destructor of Fields, default.
std::uint32_t get_number_of_fields() const
Get the number of the fields.
Definition fields.hpp:163
void parse_fields(stream::KunaiStream *stream, Types *types, Strings *strings, std::uint32_t fields_offset, std::uint32_t fields_size)
Parse all the field ids objects.
FieldID * get_field(std::uint32_t pos)
Get one of the fields by its position.
void to_xml(std::ofstream &fos)
Print the fields into an XML format.
Storage class for all the strings of the DEX file.
Definition strings.hpp:34
Definition types.hpp:305
Class to manage an input file stream given for the analysis.
Definition kunaistream.hpp:20
utilities
Definition analysis.hpp:23