KUNAI Static Analyzer
Kunai is a library for doing static binary analysis of Dalvik.
Loading...
Searching...
No Matches
dex_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 dex_disassembler.hpp
7// @brief This class holds the different disassembly algorithms for DEX
8// the user can retrieve any of them and use if for disassembly of the
9// methods, internally dex_disassembler will provide the algorithms with
10// an object of Disassembler class
11
12#ifndef KUNAI_DEX_DVM_DEX_DISASSEMBLER_HPP
13#define KUNAI_DEX_DVM_DEX_DISASSEMBLER_HPP
14
15#include "Kunai/DEX/parser/methods.hpp"
16#include "Kunai/DEX/parser/classes.hpp"
17#include "Kunai/DEX/DVM/disassembler.hpp"
18#include "Kunai/DEX/DVM/linear_sweep_disassembler.hpp"
19#include "Kunai/DEX/DVM/recursive_traversal_disassembler.hpp"
20
21namespace KUNAI
22{
23namespace DEX
24{
27 {
28 public:
32 {
33 LINEAR_SWEEP_ALGORITHM,
34 RECURSIVE_TRAVERSAL_ALGORITHM
35 };
36
37
38 private:
42 disassembly_algorithm algorithm = disassembly_algorithm::LINEAR_SWEEP_ALGORITHM;
45 Disassembler disassembler;
46
49 Parser * parser;
50
52 bool disassembly_correct = false;
53
56 Disassembler::instructions_t dex_instructions;
57
59 LinearSweepDisassembler linear_sweep;
60
62 RecursiveTraversalDisassembler recursive_traversal;
63 public:
64
70 parser(parser)
71 {
72 disassembler.set_parser(parser);
73 linear_sweep.set_internal_disassembler(&disassembler);
74 recursive_traversal.set_internal_disassembler(&disassembler);
75 }
76
81 {
82 this->algorithm = algorithm;
83 }
84
88 {
89 return dex_instructions;
90 }
91
95 {
96 return dex_instructions;
97 }
98
102 {
103 return disassembly_correct;
104 }
105
110
116
121 std::vector<std::unique_ptr<Instruction>>
122 disassembly_buffer(std::vector<std::uint8_t>& buffer);
123
124 DexDisassembler& operator+=(DexDisassembler& other);
125 };
126} // namespace DEX
127} // namespace KUNAI
128
129
130#endif
Disassembler for DEX data.
Definition dex_disassembler.hpp:27
Disassembler::instructions_t & get_dex_instructions()
Get access to all the instructions from a dex.
Definition dex_disassembler.hpp:94
void set_disassembly_algorithm(disassembly_algorithm algorithm)
Set the disassembly algorithm to use in the next calls to the different disassembly methods.
Definition dex_disassembler.hpp:80
bool correct_disassembly() const
Get if the disassembly process was correct or not.
Definition dex_disassembler.hpp:101
const Disassembler::instructions_t & get_dex_instructions() const
Get access to all the instructions from a dex.
Definition dex_disassembler.hpp:87
std::vector< std::unique_ptr< Instruction > > disassembly_buffer(std::vector< std::uint8_t > &buffer)
Disassembly a buffer of bytes, take the buffer of bytes as dalvik instructions.
DexDisassembler(Parser *parser)
Constructor of the DexDisassembler, this should be called only if the parsing was correct.
Definition dex_disassembler.hpp:69
void disassembly_dex()
This is the most important function from the disassembler, this function takes the given parser objec...
disassembly_algorithm
enum of the different algorithms implemented for doing disassembly of DEX file
Definition dex_disassembler.hpp:32
void add_disassembly(DexDisassembler &other)
Add the instructions from another disassembler to the current one, this invalidate the previous one.
Definition disassembler.hpp:30
void set_parser(Parser *parser)
Set the parser for the disassembler.
Definition disassembler.hpp:74
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
LinearSweepDisassembler is one of the DEX disassembly algorithms implemented by Kunai,...
Definition linear_sweep_disassembler.hpp:23
Definition parser.hpp:29
RecursiveTraversalDisassembler is one of the DEX disassembly algorithms implemented by Kunai,...
Definition recursive_traversal_disassembler.hpp:23
utilities
Definition analysis.hpp:23