KUNAI Static Analyzer
Kunai is a library for doing static binary analysis of Dalvik.
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
KUNAI::DEX::Disassembler Class Reference

Classes

struct  _exceptions_data
 Information for the exceptions in the code. More...
 
struct  _handler_data
 Information for the handler of exceptions, handler type, the start address of it and basic blocks. More...
 

Public Types

typedef struct KUNAI::DEX::Disassembler::_handler_data handler_data
 Information for the handler of exceptions, handler type, the start address of it and basic blocks.
 
typedef struct KUNAI::DEX::Disassembler::_exceptions_data exceptions_data
 Information for the exceptions in the code.
 
using instructions_t = std::unordered_map< EncodedMethod *, std::vector< std::unique_ptr< Instruction > > >
 For those who just want the full set of instructions it is possible to retrieve a vector with all the instructions from the method, it is not needed that these are sorted in any way

 

Public Member Functions

 Disassembler ()=default
 Constructor of the internal Disassembler for Dalvik.
 
void set_parser (Parser *parser)
 Set the parser for the disassembler.
 
std::unique_ptr< Instructiondisassemble_instruction (std::uint32_t opcode, std::vector< uint8_t > &bytecode, std::size_t index)
 Get an instruction object from the op.
 
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 :class:EncodedMethod. The offsets are calculated in number of bytes from the start of the method. Note, the offsets inside the bytecode are denoted in 16 bits units but method returns actual byte offsets.
 
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 Disassembler stores.
 
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 jump.
 
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 jump.
 
std::vector< exceptions_datadetermine_exception (EncodedMethod *method)
 Retrieve information from possible exception code inside of a method.
 

Member Function Documentation

◆ determine_exception()

std::vector< exceptions_data > KUNAI::DEX::Disassembler::determine_exception ( EncodedMethod method)

Retrieve information from possible exception code inside of a method.

Parameters
methodmethod to extract exception data
Returns
exception data in a vector

◆ determine_next() [1/2]

std::vector< std::int64_t > KUNAI::DEX::Disassembler::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 :class:EncodedMethod. The offsets are calculated in number of bytes from the start of the method. Note, the offsets inside the bytecode are denoted in 16 bits units but method returns actual byte offsets.

Parameters
instructioninstruction to obtain the next instructions
curr_idxCurrent idx to calculate the newer one
Returns
list of different offsets where code can go after the current instruction. Instructions like if or switch have more than one target, but throw, return and goto have just one. If entered opcode is not a branch instruction, next instruction is returned.

◆ determine_next() [2/2]

std::vector< std::int64_t > KUNAI::DEX::Disassembler::determine_next ( std::uint64_t  curr_idx)

Same as the other determine_next but the instruction we give is the instruction last_instr that Disassembler stores.

Parameters
curr_idxCurrent idx to calculate the newer one
Returns
list of different offsets where code can go after the current instruction. Instructions like if or switch have more than one target, but throw, return and goto have just one. If entered opcode is not a branch instruction, next instruction is returned.

◆ disassemble_instruction()

std::unique_ptr< Instruction > KUNAI::DEX::Disassembler::disassemble_instruction ( std::uint32_t  opcode,
std::vector< uint8_t > &  bytecode,
std::size_t  index 
)

Get an instruction object from the op.

Parameters
opcodeop code of the instruction to return
bytecodereference to the bytecode for disassembly
indexindex of the current instruction to analyze
Returns
unique pointer to the disassembled Instruction

◆ get_conditional_jump_target()

std::int16_t KUNAI::DEX::Disassembler::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 jump.

Parameters
instrinstruction to retrieve the target of the jump
Returns
target of a conditional jump

◆ get_unconditional_jump_target()

std::int32_t KUNAI::DEX::Disassembler::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 jump.

Parameters
instrinstruction to retrieve the target of the jump
Returns
target of an unconditional jump

◆ set_parser()

void KUNAI::DEX::Disassembler::set_parser ( Parser parser)
inline

Set the parser for the disassembler.

Parameters
parserparser to use in the disassembler

The documentation for this class was generated from the following file: