11#ifndef KUNAI_DEX_PARSER_ENCODED_HPP
12#define KUNAI_DEX_PARSER_ENCODED_HPP
14#include "Kunai/DEX/parser/strings.hpp"
15#include "Kunai/DEX/parser/fields.hpp"
16#include "Kunai/DEX/parser/fields.hpp"
17#include "Kunai/DEX/parser/methods.hpp"
18#include "Kunai/DEX/DVM/dvm_types.hpp"
19#include "Kunai/Utils/kunaistream.hpp"
31 using encodedvalue_t = std::unique_ptr<EncodedValue>;
37 std::uint64_t array_size;
39 std::vector<encodedvalue_t> values;
76 using encodedarray_t = std::unique_ptr<EncodedArray>;
91 : name(name), value(std::move(value))
112 using annotationelement_t = std::unique_ptr<AnnotationElement>;
124 std::vector<annotationelement_t> elements;
179 TYPES::value_format value_type;
181 std::uint8_t value_args;
184 std::vector<std::uint8_t> values;
270 TYPES::access_flags flags;
278 : field_idx(field_idx), flags(flags)
280 this->field_idx->set_encoded_field(
this);
311 this->initial_value = initial_value;
316 return initial_value;
320 using encodedfield_t = std::unique_ptr<EncodedField>;
334 : type(type), addr(addr)
361 using encodedtypepair_t = std::unique_ptr<EncodedTypePair>;
372 std::vector<encodedtypepair_t> handlers;
375 std::uint64_t catch_all_addr = 0;
378 std::uint64_t offset;
412 return catch_all_addr;
439 using encodedcatchhandler_t = std::unique_ptr<EncodedCatchHandler>;
452 std::uint32_t start_addr;
477 return try_item_struct.start_addr;
495 using tryitem_t = std::unique_ptr<TryItem>;
504 std::uint16_t registers_size;
516 std::vector<std::uint8_t> instructions_raw;
518 std::vector<tryitem_t> try_items;
521 std::uint64_t encoded_catch_handler_list_offset;
523 std::uint64_t encoded_catch_handler_size;
525 std::vector<encodedcatchhandler_t> encoded_catch_handlers;
543 return code_item.registers_size;
585 return instructions_raw;
592 return instructions_raw;
613 return encoded_catch_handler_list_offset;
620 return encoded_catch_handlers;
627 return encoded_catch_handlers;
631 using codeitemstruct_t = std::unique_ptr<CodeItemStruct>;
639 TYPES::access_flags access_flags;
647 : method_id(method_id), access_flags(access_flags)
660 std::uint64_t code_off,
699 using encodedmethod_t = std::unique_ptr<EncodedMethod>;
Annotation element with value and a name this is contained in the EncodedAnnotation class.
Definition encoded.hpp:81
EncodedValue * get_value()
Get the value of the annotation.
Definition encoded.hpp:106
std::string & get_name()
Get the name of the annotation.
Definition encoded.hpp:99
AnnotationElement(std::string &name, encodedvalue_t value)
Constructor of the annotation element.
Definition encoded.hpp:90
~AnnotationElement()=default
Destructor of the annotation element.
Save the information of the code from a Method.
Definition encoded.hpp:499
std::uint64_t get_encoded_catch_handler_offset()
Return the offset where encoded catch handler is read.
Definition encoded.hpp:611
std::vector< tryitem_t > & get_try_items()
Get a reference to the vector of Try Items.
Definition encoded.hpp:604
std::uint16_t get_number_try_items() const
Get the number of try items in the method.
Definition encoded.hpp:562
std::uint16_t get_offset_to_debug_info() const
Get the offset to the debug information.
Definition encoded.hpp:569
const std::vector< encodedcatchhandler_t > & get_encoded_catch_handlers() const
Get a constant reference to the catch handlers vector.
Definition encoded.hpp:618
std::uint16_t get_registers_size() const
Get the number of registers used in a method.
Definition encoded.hpp:541
CodeItemStruct()=default
Constructor of CodeItemStruct.
void parse_code_item_struct(stream::KunaiStream *stream, Types *types)
Parser for the CodeItemStruct.
const std::vector< tryitem_t > & get_try_items() const
Get a constant reference to the vector of Try Items.
Definition encoded.hpp:597
std::uint16_t get_instructions_size() const
Get size of the dalvik instructions (number of opcodes)
Definition encoded.hpp:576
std::uint16_t get_incomings_args() const
Get the number of words incoming arguments to the method.
Definition encoded.hpp:548
std::vector< std::uint8_t > & get_bytecode()
Get a reference to the vector with the bytecode.
Definition encoded.hpp:590
~CodeItemStruct()=default
Destructor of CodeItemStruct.
std::vector< encodedcatchhandler_t > & get_encoded_catch_handlers()
Get a reference to the catch handlers vector.
Definition encoded.hpp:625
const std::vector< std::uint8_t > & get_bytecode() const
Get a constant reference to the vector with the bytecode.
Definition encoded.hpp:583
std::uint16_t get_outgoing_args() const
Get the number of words outgoing argument space required by the code.
Definition encoded.hpp:555
Represents the base class of a Type in the DVM we have different types.
Definition types.hpp:26
Class to parse and create a vector of Annotations.
Definition encoded.hpp:117
EncodedAnnotation()=default
Constructor from EncodedAnnotation.
~EncodedAnnotation()=default
Destructor from EncodedAnnotation.
DVMType * get_annotation_type()
Get the type of the annotations.
Definition encoded.hpp:143
std::uint64_t get_size() const
Get size of annotations.
Definition encoded.hpp:150
AnnotationElement * get_annotation_by_pos(std::uint32_t pos)
Get an annotation element by position.
void parse_encoded_annotation(stream::KunaiStream *stream, Types *types, Strings *strings)
Function to parse an encoded annotation.
std::vector< annotationelement_t > & get_annotations()
Get a reference to all the annotation elements.
Definition encoded.hpp:164
const std::vector< annotationelement_t > & get_annotations() const
Get a constant reference to all the annotation elements.
Definition encoded.hpp:157
Information of an array with encoded values.
Definition encoded.hpp:35
void parse_encoded_array(stream::KunaiStream *stream, Types *types, Strings *strings)
Parse the encoded Array.
const std::vector< encodedvalue_t > & get_values() const
Get constant reference to encoded values.
Definition encoded.hpp:63
~EncodedArray()=default
Destructor of encoded array.
std::uint64_t get_array_size() const
get the size of the array
Definition encoded.hpp:56
EncodedArray()=default
Constructor of the encoded array.
std::vector< encodedvalue_t > & get_values()
Get a reference to encoded values.
Definition encoded.hpp:70
Information of catch handlers.
Definition encoded.hpp:365
std::vector< encodedtypepair_t > & get_handlers()
Get a reference to the vector of EncodedTypePair.
Definition encoded.hpp:424
std::uint64_t get_offset() const
Get the offset where encoded catch handler is.
Definition encoded.hpp:431
std::int64_t get_size() const
Get the size of the EncodedCatchHandler.
Definition encoded.hpp:403
std::uint64_t get_catch_all_addr() const
Return the value from catch_all_addr.
Definition encoded.hpp:410
bool has_explicit_typed_catches() const
Check value of size to test if there are encodedtypepairs.
Definition encoded.hpp:393
~EncodedCatchHandler()=default
Destructor of EncodedCatchHandler.
EncodedCatchHandler()=default
Constructor of EncodedCatchHandler.
void parse_encoded_catch_handler(stream::KunaiStream *stream, Types *types)
Parse all the encoded type pairs.
const std::vector< encodedtypepair_t > & get_handlers() const
Get a constant reference to the vector of EncodedTypePair.
Definition encoded.hpp:417
Class that represent field information it contains a FieldID and also the access flags.
Definition encoded.hpp:266
~EncodedField()=default
Destructor of Encoded Field.
TYPES::access_flags get_access_flags() const
Get the access flags from the Field.
Definition encoded.hpp:302
const FieldID * get_field() const
Get a constant pointer to the FieldID.
Definition encoded.hpp:288
EncodedField(FieldID *field_idx, TYPES::access_flags flags)
Constructor of an encoded field.
Definition encoded.hpp:277
FieldID * get_field()
Get a pointer to the FieldID.
Definition encoded.hpp:295
void set_initial_value(EncodedArray *initial_value)
Those fields that are static contains an initial value.
Definition encoded.hpp:309
Class that represent the information from a Method.
Definition encoded.hpp:635
void parse_encoded_method(stream::KunaiStream *stream, std::uint64_t code_off, Types *types)
Parse the encoded method, this will parse the code item.
MethodID * getMethodID()
Get a pointer to the MethodID of the encoded method.
Definition encoded.hpp:672
EncodedMethod(MethodID *method_id, TYPES::access_flags access_flags)
Constructor of Encoded method.
Definition encoded.hpp:646
const CodeItemStruct & get_code_item() const
Get the code item from the encoded method.
Definition encoded.hpp:686
CodeItemStruct & get_code_item()
Get the code item from the encoded method.
Definition encoded.hpp:693
const MethodID * getMethodID() const
Get a constant pointer to the MethodID of the method.
Definition encoded.hpp:665
TYPES::access_flags get_access_flags() const
Get access flags from the encoded method.
Definition encoded.hpp:679
~EncodedMethod()=default
Destructor of Encoded method.
Type of exception to catch with its address.
Definition encoded.hpp:324
const DVMType * get_exception_type() const
Get a constant pointer to the exception type.
Definition encoded.hpp:348
DVMType * get_exception_type()
Get pointer to exception type.
Definition encoded.hpp:355
EncodedTypePair(DVMType *type, std::uint64_t addr)
Constructor for EncodedTypePair.
Definition encoded.hpp:333
std::uint64_t get_addr() const
Get the bytecode address of the associated exception handler.
Definition encoded.hpp:341
~EncodedTypePair()=default
Destructor of EncodedTypePair.
encoded piece of (nearly) arbitrary hierarchically structured data.
Definition encoded.hpp:177
EncodedArray & get_array()
get a reference to the array in case value is an array
Definition encoded.hpp:243
EncodedValue()=default
Constructor of EncodedValue.
std::uint8_t size_of_value() const
Return the size of the value.
Definition encoded.hpp:215
~EncodedValue()=default
Destructor of EncodedValue.
const EncodedAnnotation & get_annotation() const
get a reference to annotation in case it is annotation
Definition encoded.hpp:250
TYPES::value_format get_value_type() const
Get the enum with the value type.
Definition encoded.hpp:208
const std::vector< std::uint8_t > & get_values() const
Get a constant reference to the values.
Definition encoded.hpp:222
void parse_encoded_value(stream::KunaiStream *stream, Types *types, Strings *strings)
Parse the encoded value.
EncodedAnnotation & get_annotation()
get a reference to annotation in case it is annotation
Definition encoded.hpp:257
std::vector< std::uint8_t > & get_values()
Get a reference to the values.
Definition encoded.hpp:229
const EncodedArray & get_array() const
in case the value is an array return it
Definition encoded.hpp:236
FieldID represent one of the fields from the DEX file.
Definition fields.hpp:28
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
Storage class for all the strings of the DEX file.
Definition strings.hpp:34
Class that specify the information from a try specifies address, number of instructions,...
Definition encoded.hpp:445
~TryItem()=default
Destructor of TryItem.
TryItem()=default
Constructor of TryItem.
std::uint16_t get_handler_off() const
Get offset of handler from try.
Definition encoded.hpp:489
std::uint16_t get_insn_count() const
Get the number of instruction counts from the try.
Definition encoded.hpp:482
std::uint32_t get_start_addr() const
Get the start address of the try block.
Definition encoded.hpp:475
void parse_try_item(stream::KunaiStream *stream)
Parse a try_item_struct_t from stream.
Class to manage an input file stream given for the analysis.
Definition kunaistream.hpp:20
utilities
Definition analysis.hpp:23
Structure with information about a method code.
Definition encoded.hpp:503
std::uint16_t tries_size
Definition encoded.hpp:508
std::uint32_t debug_info_off
number of TryItem, can be 0
Definition encoded.hpp:509
std::uint16_t outs_size
number of words of incoming arguments to the method
Definition encoded.hpp:506
std::uint32_t insns_size
offset to debug_info_item
Definition encoded.hpp:510
std::uint16_t ins_size
number of registers used in the code
Definition encoded.hpp:505
Structure with the information from a Try code.
Definition encoded.hpp:451
std::uint16_t handler_off
number of 16-bit code units covered by this entry.
Definition encoded.hpp:455
std::uint16_t insn_count
Definition encoded.hpp:454