KUNAI Static Analyzer
Kunai is a library for doing static binary analysis of Dalvik.
Loading...
Searching...
No Matches
disassembler.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 disassembler.hpp
7// @brief Utilities of the disassembler to use by the different disassembly
8// algorithms.
9
10#ifndef KUNAI_DEX_DVM_DISASSEMBLER_HPP
11#define KUNAI_DEX_DVM_DISASSEMBLER_HPP
12
13#include "Kunai/DEX/DVM/dalvik_instructions.hpp"
14
15#include <memory>
16#include <iostream>
17#include <any>
18
19#include <unordered_map>
20#include <map>
21#include <utility>
22
23
24namespace KUNAI
25{
26namespace DEX
27{
28
30 {
31 public:
35 typedef struct _handler_data
36 {
37 DVMType* handler_type;
38 std::uint64_t handler_start_addr;
40
43 typedef struct _exceptions_data
44 {
45 std::uint64_t try_value_start_addr;
46 std::uint64_t try_value_end_addr;
47 std::vector<handler_data> handler;
49
54 using instructions_t = std::unordered_map
56 std::vector<std::unique_ptr<Instruction>>>;
57
58 private:
60 Parser * parser;
63 Instruction * last_instr;
65 DVMClass throwable_class{"Ljava/lang/Throwable;"};
66
67 public:
68
70 Disassembler() = default;
71
74 void set_parser(Parser * parser)
75 {
76 this->parser = parser;
77 }
78
84 std::unique_ptr<Instruction> disassemble_instruction(
85 std::uint32_t opcode,
86 std::vector<uint8_t> & bytecode,
87 std::size_t index
88 );
89
101 std::vector<std::int64_t> determine_next(Instruction * instruction, std::uint64_t curr_idx);
102
110 std::vector<std::int64_t> determine_next(std::uint64_t curr_idx);
111
117
123
128 std::vector<exceptions_data> determine_exception(EncodedMethod * method);
129 };
130} // namespace DEX
131} // namespace KUNAI
132
133
134#endif
Classes of the DVM.
Definition types.hpp:174
Represents the base class of a Type in the DVM we have different types.
Definition types.hpp:26
Definition disassembler.hpp:30
std::unique_ptr< Instruction > disassemble_instruction(std::uint32_t opcode, std::vector< uint8_t > &bytecode, std::size_t index)
Get an instruction object from the op.
std::vector< exceptions_data > determine_exception(EncodedMethod *method)
Retrieve information from possible exception code inside of a method.
struct KUNAI::DEX::Disassembler::_exceptions_data exceptions_data
Information for the exceptions in the code.
std::int16_t get_conditional_jump_target(Instruction *instr)
Given an instruction check if it is a conditional jump and retrieve in that case the target of the ju...
Disassembler()=default
Constructor of the internal Disassembler for Dalvik.
void set_parser(Parser *parser)
Set the parser for the disassembler.
Definition disassembler.hpp:74
std::vector< std::int64_t > determine_next(Instruction *instruction, std::uint64_t curr_idx)
Determine given the last instruction the next instruction to run, the bytecode is retrieved from a :c...
std::int32_t get_unconditional_jump_target(Instruction *instr)
Given an instruction check if it is an unconditional jump and retrieve in that case the target of the...
std::vector< std::int64_t > determine_next(std::uint64_t curr_idx)
Same as the other determine_next but the instruction we give is the instruction last_instr that Disas...
std::unordered_map< EncodedMethod *, std::vector< std::unique_ptr< Instruction > > > instructions_t
For those who just want the full set of instructions it is possible to retrieve a vector with all the...
Definition disassembler.hpp:56
struct KUNAI::DEX::Disassembler::_handler_data handler_data
Information for the handler of exceptions, handler type, the start address of it and basic blocks.
Class that represent the information from a Method.
Definition encoded.hpp:635
Base class for the Instructions of the Dalvik Bytecode.
Definition dalvik_instructions.hpp:69
Definition parser.hpp:29
utilities
Definition analysis.hpp:23
Information for the exceptions in the code.
Definition disassembler.hpp:44
Information for the handler of exceptions, handler type, the start address of it and basic blocks.
Definition disassembler.hpp:36