10#ifndef KUNAI_DEX_ANALYSIS_DEX_ANALYSIS_HPP
11#define KUNAI_DEX_ANALYSIS_DEX_ANALYSIS_HPP
13#include "Kunai/DEX/analysis/analysis.hpp"
14#include "Kunai/DEX/DVM/dex_disassembler.hpp"
23 std::vector<Parser*> parsers;
27 std::unordered_map<std::string,
28 std::unique_ptr<ClassAnalysis>> classes;
33 std::unordered_map<std::string,
34 std::unique_ptr<ExternalClass>> external_classes;
38 std::unordered_map<std::string,
39 std::unique_ptr<StringAnalysis>> strings;
43 std::unordered_map<std::string,
44 std::unique_ptr<MethodAnalysis>> methods;
48 std::unordered_map<std::string,
49 std::unique_ptr<ExternalMethod>> external_methods;
52 std::unordered_map<std::string, MethodAnalysis*> methods_hashes;
55 std::unordered_map<std::string,
58 std::vector<FieldAnalysis*> all_fields;
64 bool created_xrefs =
false;
75 void _create_xrefs(
ClassDef * current_class);
84 std::string & method_name, std::string & method_descriptor);
112 auto it = classes.find(class_name);
114 if (it != classes.end())
115 return it->second.get();
122 const std::unordered_map<std::string, std::unique_ptr<ClassAnalysis>>&
130 std::unordered_map<std::string, std::unique_ptr<ClassAnalysis>>&
138 const std::unordered_map<std::string, std::unique_ptr<ExternalClass>>&
141 return external_classes;
146 std::unordered_map<std::string, std::unique_ptr<ExternalClass>>&
149 return external_classes;
157 std::string method_key;
159 if (method.index() == 0)
160 method_key = std::get<EncodedMethod*>(method)->getMethodID()->pretty_method();
162 method_key = std::get<ExternalMethod*>(method)->pretty_method_name();
164 auto it = methods.find(method_key);
166 if (it == methods.end())
169 return it->second.get();
178 std::string &method_name,
179 std::string &method_descriptor)
181 std::string m_hash = class_name+method_name+method_descriptor;
183 auto it = method_hashes.find(m_hash);
185 if (it == method_hashes.end())
197 std::string &method_name,
198 std::string &method_descriptor)
202 if (m_a && (!m_a->external()))
203 return std::get<EncodedMethod*>(m_a->get_encoded_method())->getMethodID();
210 const std::unordered_map<std::string, std::unique_ptr<MethodAnalysis>>&
218 std::unordered_map<std::string, std::unique_ptr<MethodAnalysis>>&
226 const std::unordered_map<std::string, std::unique_ptr<ExternalMethod>>&
229 return external_methods;
234 std::unordered_map<std::string, std::unique_ptr<ExternalMethod>>&
237 return external_methods;
248 return class_analysis->get_field_analysis(field);
259 const std::unordered_map<std::string,
267 std::unordered_map<std::string,
279 std::vector<ClassAnalysis*>
find_classes(std::string& name,
bool no_external);
290 std::string& method_name,
291 std::string& descriptor,
292 std::string& accessflags,
308 std::string& field_name,
309 std::string& field_type,
310 std::string& accessflags);
Definition dex_analysis.hpp:21
const std::unordered_map< std::string, std::unique_ptr< ExternalMethod > > & get_external_methods() const
Return a constant reference to the ExternalMethods.
Definition dex_analysis.hpp:227
FieldAnalysis * get_field_analysis(EncodedField *field)
Get a field given an encoded field.
Definition dex_analysis.hpp:243
const std::unordered_map< std::string, std::unique_ptr< ClassAnalysis > > & get_classes() const
Get a constant reference to the classes.
Definition dex_analysis.hpp:123
ClassAnalysis * get_class_analysis(std::string &class_name)
Get a ClassAnalysis object by the class name.
Definition dex_analysis.hpp:110
void add(Parser *parser)
Add all the classes and methods from a parser to the analysis class.
void create_xrefs()
Create class, method, string and field cross references if you are using multiple DEX files,...
std::vector< MethodAnalysis * > find_methods(std::string &class_name, std::string &method_name, std::string &descriptor, std::string &accessflags, bool no_external)
Find MethodAnalysis object by name with regular expression. This time is necessary to specify more va...
std::unordered_map< std::string, std::unique_ptr< ExternalClass > > & get_external_classes()
Get a reference to external classes.
Definition dex_analysis.hpp:147
const std::unordered_map< std::string, std::unique_ptr< MethodAnalysis > > & get_methods() const
Return a constant reference to the method analysis.
Definition dex_analysis.hpp:211
std::vector< ClassAnalysis * > find_classes(std::string &name, bool no_external)
Find classes by name with regular expression, the method returns a list of ClassAnalysis object that ...
std::vector< FieldAnalysis * > find_fields(std::string &class_name, std::string &field_name, std::string &field_type, std::string &accessflags)
Find FieldAnalysis objects using regular expressions find those that are in classes.
std::vector< StringAnalysis * > find_strings(std::string &str)
Find the strings that match a provided regular expression.
std::unordered_map< std::string, std::unique_ptr< ExternalMethod > > & get_external_methods()
Return a reference to the ExternalMethods.
Definition dex_analysis.hpp:235
std::unordered_map< std::string, std::unique_ptr< MethodAnalysis > > & get_methods()
Return a reference to the method analysis.
Definition dex_analysis.hpp:219
const std::unordered_map< std::string, std::unique_ptr< ExternalClass > > & get_external_classes() const
Get a constant reference to external classes.
Definition dex_analysis.hpp:139
MethodID * get_method_id_by_name(std::string &class_name, std::string &method_name, std::string &method_descriptor)
Obtain a MethodID by different values.
Definition dex_analysis.hpp:196
std::vector< FieldAnalysis * > & get_fields()
Get all the fields from all the classes.
MethodAnalysis * get_method(std::variant< EncodedMethod *, ExternalMethod * > method)
Get a MethodAnalysis pointer given an Encoded or External Method.
Definition dex_analysis.hpp:155
std::unordered_map< std::string, std::unique_ptr< StringAnalysis > > & get_string_analysis()
Get a reference to the StringAnalysis map.
Definition dex_analysis.hpp:268
MethodAnalysis * get_method_analysis_by_name(std::string &class_name, std::string &method_name, std::string &method_descriptor)
Obtain a method anaylsis by different values.
Definition dex_analysis.hpp:177
std::unordered_map< std::string, std::unique_ptr< ClassAnalysis > > & get_classes()
Get a reference to the classes.
Definition dex_analysis.hpp:131
const std::unordered_map< std::string, std::unique_ptr< StringAnalysis > > & get_string_analysis() const
Get a constant reference to the StringAnalysis objects.
Definition dex_analysis.hpp:260
Specification of the class analysis, this class contains fields, strings, methods....
Definition analysis.hpp:765
Definition of class with all the ids and offsets for all the other data.
Definition classes.hpp:152
Classes of the DVM.
Definition types.hpp:174
const std::string & get_name() const
Get the name of the class.
Definition types.hpp:206
Disassembler for DEX data.
Definition dex_disassembler.hpp:27
Class that represent field information it contains a FieldID and also the access flags.
Definition encoded.hpp:266
const FieldID * get_field() const
Get a constant pointer to the FieldID.
Definition encoded.hpp:288
specification of a field analysis
Definition analysis.hpp:379
const DVMType * get_class() const
Get a constant pointer to the class where field is.
Definition fields.hpp:65
Specification of the method analysis, a method contains instructions, exceptions data,...
Definition analysis.hpp:491
MethodID represents a single method from DEX file.
Definition methods.hpp:28
utilities
Definition analysis.hpp:23