KUNAI Static Analyzer
Kunai is a library for doing static binary analysis of Dalvik.
Loading...
Searching...
No Matches
annotations.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 annotations.hpp
7// @brief Manage the annotations from the DEX file
8
9#ifndef KUNAI_DEX_PARSER_ANNOTATIONS_HPP
10#define KUNAI_DEX_PARSER_ANNOTATIONS_HPP
11
12#include "Kunai/Utils/kunaistream.hpp"
13#include "Kunai/DEX/parser/fields.hpp"
14#include "Kunai/DEX/parser/methods.hpp"
15
16#include <memory>
17#include <vector>
18#include <unordered_map>
19
20namespace KUNAI
21{
22namespace DEX
23{
26 {
28 std::uint32_t method_idx;
30 std::uint32_t annotations_off;
31 public:
35 ParameterAnnotation(std::uint32_t method_idx, std::uint32_t annotations_off)
36 : method_idx(method_idx), annotations_off(annotations_off)
37 {}
38
41
44 std::uint32_t get_method_idx() const
45 {
46 return method_idx;
47 }
48
51 std::uint32_t get_annotations_off() const
52 {
53 return annotations_off;
54 }
55 };
56
57 using parameterannotation_t = std::unique_ptr<ParameterAnnotation>;
58
61 {
63 std::uint32_t method_idx;
65 std::uint32_t annotations_off;
66 public:
70 MethodAnnotation(std::uint32_t method_idx, std::uint32_t annotations_off)
71 : method_idx(method_idx), annotations_off(annotations_off)
72 {}
74 ~MethodAnnotation() = default;
75
78 std::uint32_t get_method_idx() const
79 {
80 return method_idx;
81 }
84 std::uint32_t get_annotations_off() const
85 {
86 return annotations_off;
87 }
88 };
89
90 using methodannotation_t = std::unique_ptr<MethodAnnotation>;
91
94 {
96 std::uint32_t field_idx;
98 std::uint32_t annotations_off;
99 public:
100
104 FieldAnnotation(std::uint32_t field_idx, std::uint32_t annotations_off)
105 : field_idx(field_idx), annotations_off(annotations_off)
106 {}
107
109 ~FieldAnnotation() = default;
110
113 std::uint32_t get_field_idx() const
114 {
115 return field_idx;
116 }
117
120 std::uint32_t get_annotations_off() const
121 {
122 return annotations_off;
123 }
124 };
125
126 using fieldannotation_t = std::unique_ptr<FieldAnnotation>;
127
130 {
132 std::uint32_t class_annotations_off;
134 std::vector<fieldannotation_t> field_annotations;
136 std::unordered_map<std::uint32_t, FieldAnnotation*> field_annotations_by_id;
138 std::vector<methodannotation_t> method_annotations;
140 std::unordered_map<std::uint32_t, MethodAnnotation*> method_annotations_by_id;
142 std::vector<parameterannotation_t> parameter_annotations;
144 std::unordered_map<std::uint32_t, ParameterAnnotation*> parameter_annotations_by_id;
145 public:
153
157 const std::vector<fieldannotation_t>& get_field_annotations() const
158 {
159 return field_annotations;
160 }
161
165 std::vector<fieldannotation_t>& get_field_annotations()
166 {
167 return field_annotations;
168 }
169
174
178 const std::vector<methodannotation_t>& get_method_annotations() const
179 {
180 return method_annotations;
181 }
182
186 std::vector<methodannotation_t>& get_method_annotations()
187 {
188 return method_annotations;
189 }
190
195
199 const std::vector<parameterannotation_t>& get_parameter_annotations() const
200 {
201 return parameter_annotations;
202 }
203
207 std::vector<parameterannotation_t>& get_parameter_annotations()
208 {
209 return parameter_annotations;
210 }
211
216 };
217} // namespace DEX
218} // namespace KUNAI
219
220
221#endif
Class with all the previos annotations.
Definition annotations.hpp:130
std::vector< methodannotation_t > & get_method_annotations()
Get a reference to all method annotations from the annotation directory.
Definition annotations.hpp:186
AnnotationDirectoryItem()=default
Constructor of AnnotationDirectoryItem.
std::vector< fieldannotation_t > & get_field_annotations()
Get a reference to all the field annotations from the annotation directory.
Definition annotations.hpp:165
MethodAnnotation * get_method_annotation_by_id(std::uint32_t idx)
Get a pointer to method annotation.
const std::vector< fieldannotation_t > & get_field_annotations() const
Get a constant reference to all the field annotations from the annotation directory.
Definition annotations.hpp:157
~AnnotationDirectoryItem()=default
Destructor of AnnotationDirectoryItem.
FieldAnnotation * get_field_annotation_by_id(std::uint32_t idx)
Get a pointer to a field annotation.
void parse_annotation_directory_item(stream::KunaiStream *stream)
Parse the annotation directory item.
std::vector< parameterannotation_t > & get_parameter_annotations()
Get a reference to all the parameter annotations from the annotation directory.
Definition annotations.hpp:207
ParameterAnnotation * get_parameter_annotation_by_id(std::uint32_t idx)
Get a pointer to a parameter annotation.
const std::vector< parameterannotation_t > & get_parameter_annotations() const
Get a constant reference to all the parameter annotations from the annotation directory.
Definition annotations.hpp:199
const std::vector< methodannotation_t > & get_method_annotations() const
Get a constant reference to all method annotations from the annotation directory.
Definition annotations.hpp:178
Information for the list of annotations for the fields.
Definition annotations.hpp:94
~FieldAnnotation()=default
Destructor of FieldAnnotation.
std::uint32_t get_field_idx() const
Get the field idx of the annotation.
Definition annotations.hpp:113
std::uint32_t get_annotations_off() const
Get the offset of the annotation.
Definition annotations.hpp:120
FieldAnnotation(std::uint32_t field_idx, std::uint32_t annotations_off)
Constructor of FieldAnnotation.
Definition annotations.hpp:104
Information for the list of annotations for the methods.
Definition annotations.hpp:61
MethodAnnotation(std::uint32_t method_idx, std::uint32_t annotations_off)
Constructor of MethodAnnotations.
Definition annotations.hpp:70
std::uint32_t get_annotations_off() const
Obtain the offset of the annotations.
Definition annotations.hpp:84
std::uint32_t get_method_idx() const
Obtain the method idx of the current method annotation.
Definition annotations.hpp:78
~MethodAnnotation()=default
Destructor of the method annotations.
Information for the list of annotations for the parameters.
Definition annotations.hpp:26
~ParameterAnnotation()=default
Destructor of ParameterAnnotation.
ParameterAnnotation(std::uint32_t method_idx, std::uint32_t annotations_off)
Constructor of ParameterAnnotation.
Definition annotations.hpp:35
std::uint32_t get_annotations_off() const
Get the offset to the annotations.
Definition annotations.hpp:51
std::uint32_t get_method_idx() const
Get the MethodIDX value.
Definition annotations.hpp:44
Class to manage an input file stream given for the analysis.
Definition kunaistream.hpp:20
utilities
Definition analysis.hpp:23