KUNAI Static Analyzer
Kunai is a library for doing static binary analysis of Dalvik.
Loading...
Searching...
No Matches
methods.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_METHODS_HPP
9#define KUNAI_DEX_PARSER_METHODS_HPP
10
11#include "Kunai/DEX/parser/protos.hpp"
12#include "Kunai/DEX/parser/strings.hpp"
13#include "Kunai/Utils/kunaistream.hpp"
14
15#include <memory>
16#include <vector>
17
18
19namespace KUNAI
20{
21 namespace DEX
22 {
24 class EncodedMethod;
25
27 class MethodID
28 {
30 DVMType* class_;
32 ProtoID* proto_;
34 std::string& name_;
36 std::string pretty_name;
38 EncodedMethod * encoded_method;
39 public:
40
45 MethodID(DVMType* class_, ProtoID* proto_, std::string& name_)
46 : class_(class_), proto_(proto_), name_(name_)
47 {
48 }
49
51 ~MethodID() = default;
52
56 {
57 return encoded_method;
58 }
59
63 {
64 encoded_method = e;
65 }
66
69 const DVMType* get_class() const
70 {
71 return class_;
72 }
73
77 {
78 return class_;
79 }
80
83 const ProtoID* get_proto() const
84 {
85 return proto_;
86 }
87
91 {
92 return proto_;
93 }
94
97 const std::string& get_name() const
98 {
99 return name_;
100 }
101
104 std::string& get_name()
105 {
106 return name_;
107 }
108
111 std::string& pretty_method();
112 };
113
114 using methodid_t = std::unique_ptr<MethodID>;
115
118 {
120 std::vector<methodid_t> methods;
121
123 std::uint32_t methods_size;
124 public:
125
127 Methods() = default;
128
130 ~Methods() = default;
131
139 stream::KunaiStream* stream,
140 Types* types,
141 Protos* protos,
142 Strings* strings,
143 std::uint32_t methods_offset,
144 std::uint32_t methods_size
145 );
146
149 const std::vector<methodid_t>& get_methods() const
150 {
151 return methods;
152 }
153
156 std::vector<methodid_t>& get_methods()
157 {
158 return methods;
159 }
160
164 MethodID* get_method(std::uint32_t pos);
165
168 std::uint32_t get_number_of_methods() const
169 {
170 return methods_size;
171 }
172
177 friend std::ostream& operator<<(std::ostream& os, const Methods& entry);
178
181 void to_xml(std::ofstream& fos);
182 };
183
184 } // namespace DEX
185} // namespace KUNAI
186
187#endif
Represents the base class of a Type in the DVM we have different types.
Definition types.hpp:26
Class that represent the information from a Method.
Definition encoded.hpp:635
MethodID represents a single method from DEX file.
Definition methods.hpp:28
void set_encoded_method(EncodedMethod *e)
Set the encoded method from this MethodID.
Definition methods.hpp:62
std::string & get_name()
Get a reference to the name of the method.
Definition methods.hpp:104
const std::string & get_name() const
Get a constant reference to the name of the method.
Definition methods.hpp:97
const DVMType * get_class() const
Get a constant pointer to the class where method is.
Definition methods.hpp:69
const ProtoID * get_proto() const
Get a constant pointer to the proto of the method.
Definition methods.hpp:83
~MethodID()=default
Destructor of the MethodID.
ProtoID * get_proto()
Get a pointer to the proto of the method.
Definition methods.hpp:90
DVMType * get_class()
Get a pointer to the class where method is.
Definition methods.hpp:76
MethodID(DVMType *class_, ProtoID *proto_, std::string &name_)
Constructor of the MethodID.
Definition methods.hpp:45
std::string & pretty_method()
Get a string representation of the method.
EncodedMethod * get_encoded_method()
get the encoded method set in this MethodID*
Definition methods.hpp:55
Methods contains all the MethodIDs from the DEX file.
Definition methods.hpp:118
std::vector< methodid_t > & get_methods()
Get a reference to all the methods.
Definition methods.hpp:156
MethodID * get_method(std::uint32_t pos)
Get one of the methods by its position.
void to_xml(std::ofstream &fos)
Print the methods into an XML format.
Methods()=default
Constructor of Methods, default.
~Methods()=default
Destructor of Methods, default.
std::uint32_t get_number_of_methods() const
Get the number of the methods.
Definition methods.hpp:168
friend std::ostream & operator<<(std::ostream &os, const Methods &entry)
Give a pretty print result of the methods.
const std::vector< methodid_t > & get_methods() const
Get a constant reference to all the methods.
Definition methods.hpp:149
void parse_methods(stream::KunaiStream *stream, Types *types, Protos *protos, Strings *strings, std::uint32_t methods_offset, std::uint32_t methods_size)
Parse all the method ids objects.
Store the information of a ProtoID, this is a string with the return type, the list of parameters and...
Definition protos.hpp:54
Class to manage all the ProtoID from the DEX file.
Definition protos.hpp:137
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