9#ifndef KUNAI_DEX_DVM_DALVIK_INSTRUCTIONS_HPP
10#define KUNAI_DEX_DVM_DALVIK_INSTRUCTIONS_HPP
12#include "Kunai/Utils/kunaistream.hpp"
13#include "Kunai/DEX/parser/parser.hpp"
14#include "Kunai/DEX/DVM/dvm_types.hpp"
15#include "Kunai/DEX/DVM/dalvik_opcodes.hpp"
29 enum class dexinsttype_t
71 dexinsttype_t instruction_type;
89 Instruction(std::vector<uint8_t> &bytecode, std::size_t index, dexinsttype_t instruction_type)
94 Instruction(std::vector<uint8_t> &bytecode, std::size_t index, dexinsttype_t instruction_type, std::uint32_t
length)
100 op_codes = {bytecode.begin() + index, bytecode.begin() + index +
length};
116 return instruction_type;
174 if (operation == TYPES::Operation::CONDITIONAL_BRANCH_DVM_OPCODE ||
175 operation == TYPES::Operation::UNCONDITIONAL_BRANCH_DVM_OPCODE ||
176 operation == TYPES::Operation::RET_BRANCH_DVM_OPCODE ||
177 operation == TYPES::Operation::MULTI_BRANCH_DVM_OPCODE)
257 return TYPES::Operand::REGISTER;
264 return TYPES::Operand::REGISTER;
272 "v" + std::to_string(vA) +
", " +
273 "v" + std::to_string(vB);
281 "v" + std::to_string(vA) +
", " +
282 "v" + std::to_string(vB);
299 std::uint8_t get_destination()
const
304 std::int8_t get_source()
const
309 TYPES::Operand get_destination_type()
const
311 return TYPES::Operand::REGISTER;
314 TYPES::Operand get_source_type()
const
316 return TYPES::Operand::LITERAL;
324 "v" + std::to_string(vA) +
", " +
333 "v" + std::to_string(vA) +
", " +
360 return TYPES::Operand::REGISTER;
368 "v" + std::to_string(vAA);
376 "v" + std::to_string(vAA);
401 return TYPES::Operand::OFFSET;
409 std::to_string((nAA*2) +
static_cast<std::int64_t
>(
address));
417 std::to_string((nAA*2) +
static_cast<std::int64_t
>(
address));
442 return TYPES::Operand::OFFSET;
450 std::to_string((nAAAA*2) +
static_cast<std::int64_t
>(
address));
458 std::to_string((nAAAA*2) +
static_cast<std::int64_t
>(
address));
485 return TYPES::Operand::LITERAL;
495 TYPES::Operand get_index_operand_type()
const
497 return TYPES::Operand::LITERAL;
505 std::to_string(nAA) +
", kind@" + std::to_string(nBBBB);
513 std::to_string(nAA) +
", kind@" + std::to_string(nBBBB);
541 return TYPES::Operand::REGISTER;
555 return TYPES::Operand::REGISTER;
563 "v" + std::to_string(vAA) +
", v" +
564 std::to_string(vBBBB);
572 "v" + std::to_string(vAA) +
", v" +
573 std::to_string(vBBBB);
602 return TYPES::Operand::REGISTER;
616 return TYPES::Operand::OFFSET;
624 std::to_string(vAA) +
", " +
625 std::to_string(nBBBB);
633 std::to_string(vAA) +
", " +
634 std::to_string(nBBBB);
663 return TYPES::Operand::REGISTER;
677 return TYPES::Operand::LITERAL;
685 std::to_string(vAA) +
", " +
686 std::to_string(nBBBB);
694 std::to_string(vAA) +
", " +
695 std::to_string(nBBBB);
723 return TYPES::Operand::REGISTER;
737 return TYPES::Operand::LITERAL;
745 std::to_string(vAA) +
", " +
746 std::to_string(nBBBB);
754 std::to_string(vAA) +
", " +
755 std::to_string(nBBBB);
766 bool is_type =
false;
768 bool is_fundamental =
false;
769 bool is_array =
false;
770 bool is_class =
false;
771 bool is_unknown =
false;
774 bool is_field =
false;
776 bool is_method =
false;
778 bool is_proto =
false;
785 std::string source_str;
804 return TYPES::Operand::REGISTER;
819 return TYPES::Operand::KIND;
868 return reinterpret_cast<DVMClass *
>(
878 return reinterpret_cast<DVMArray *
>(
915 std::to_string(vAA) +
", " +
916 source_str +
" (" + std::to_string(iBBBB) +
")";
924 std::to_string(vAA) +
", " +
925 source_str +
" (" + std::to_string(iBBBB) +
")";
954 return TYPES::Operand::REGISTER;
968 return TYPES::Operand::REGISTER;
982 return TYPES::Operand::REGISTER;
990 std::to_string(vAA) +
", v" +
991 std::to_string(vBB) +
", v" +
1000 std::to_string(vAA) +
", v" +
1001 std::to_string(vBB) +
", v" +
1002 std::to_string(vCC);
1033 return TYPES::Operand::REGISTER;
1047 return TYPES::Operand::REGISTER;
1061 return TYPES::Operand::LITERAL;
1069 std::to_string(vAA) +
", v" +
1070 std::to_string(vBB) +
", " +
1071 std::to_string(nCC);
1079 std::to_string(vAA) +
", v" +
1080 std::to_string(vBB) +
", " +
1081 std::to_string(nCC);
1110 return TYPES::Operand::REGISTER;
1124 return TYPES::Operand::REGISTER;
1138 return TYPES::Operand::OFFSET;
1146 std::to_string(vA) +
", v" +
1147 std::to_string(vB) +
", " +
1148 std::to_string(nCCCC);
1156 std::to_string(vA) +
", v" +
1157 std::to_string(vB) +
", " +
1158 std::to_string(nCCCC);
1189 return TYPES::Operand::REGISTER;
1203 return TYPES::Operand::REGISTER;
1217 return TYPES::Operand::LITERAL;
1225 std::to_string(vA) +
", v" +
1226 std::to_string(vB) +
", " +
1227 std::to_string(nCCCC);
1235 std::to_string(vA) +
", v" +
1236 std::to_string(vB) +
", " +
1237 std::to_string(nCCCC);
1253 std::uint16_t iCCCC;
1255 std::string iCCCC_str;
1259 bool is_type =
false;
1261 bool is_field =
false;
1277 return TYPES::Operand::REGISTER;
1291 return TYPES::Operand::REGISTER;
1305 return TYPES::Operand::KIND;
1338 std::to_string(vA) +
", v" + std::to_string(vB) +
", " +
1339 iCCCC_str +
" (" + std::to_string(iCCCC) +
")";
1347 std::to_string(vA) +
", v" + std::to_string(vB) +
", " +
1348 iCCCC_str +
" (" + std::to_string(iCCCC) +
")";
1362 std::uint16_t iCCCC;
1364 std::string iCCCC_str;
1366 bool is_field =
false;
1384 return TYPES::Operand::REGISTER;
1398 return TYPES::Operand::REGISTER;
1412 return TYPES::Operand::KIND;
1436 std::to_string(vA) +
", v" + std::to_string(vB) +
", " +
1437 iCCCC_str +
" (" + std::to_string(iCCCC) +
")";
1445 std::to_string(vA) +
", v" + std::to_string(vB) +
", " +
1446 iCCCC_str +
" (" + std::to_string(iCCCC) +
")";
1455 std::int32_t nAAAAAAAA;
1471 return TYPES::Operand::OFFSET;
1485 os << DalvikOpcodes::get_instruction_name(op) + std::to_string((nAAAAAAAA*2) + static_cast<std::int64_t>(
address));
1494 std::uint16_t vAAAA;
1496 std::uint16_t vBBBB;
1511 return TYPES::Operand::REGISTER;
1525 return TYPES::Operand::REGISTER;
1533 std::to_string(vAAAA) +
", v" + std::to_string(vBBBB);
1541 std::to_string(vAAAA) +
", v" + std::to_string(vBBBB);
1553 std::uint32_t nBBBBBBBB;
1568 return TYPES::Operand::REGISTER;
1582 return TYPES::Operand::LITERAL;
1590 std::to_string(vAA) +
", " + std::to_string(nBBBBBBBB);
1598 std::to_string(vAA) +
", " + std::to_string(nBBBBBBBB);
1625 std::int32_t nBBBBBBBB;
1648 return TYPES::Operand::REGISTER;
1662 return TYPES::Operand::OFFSET;
1670 return type_of_switch;
1677 return packed_switch;
1684 return sparse_switch;
1691 this->packed_switch = packed_switch;
1698 this->sparse_switch = sparse_switch;
1706 std::to_string(vAA) +
", " + std::to_string(nBBBBBBBB);
1714 std::to_string(vAA) +
", " + std::to_string(nBBBBBBBB);
1726 std::uint32_t iBBBBBBBB;
1728 std::string str_value;
1743 return TYPES::Operand::REGISTER;
1757 return TYPES::Operand::OFFSET;
1772 std::to_string(vAA) +
", \"" + str_value +
"\" (" + std::to_string(iBBBBBBBB) +
")";
1780 std::to_string(vAA) +
", " + str_value +
" (" + std::to_string(iBBBBBBBB) +
")";
1791 std::uint8_t array_size;
1793 std::uint16_t type_index;
1795 bool is_type =
false;
1797 bool is_method =
false;
1799 std::string type_str;
1801 std::vector<std::uint8_t> registers;
1825 return TYPES::Operand::REGISTER;
1846 return TYPES::Operand::KIND;
1871 for(
const auto reg : registers)
1873 instruction +=
"v" + std::to_string(reg) +
", ";
1876 if (registers.size() > 0)
1877 instruction = instruction.substr(0, instruction.size()-2);
1879 instruction +=
"}, " + type_str;
1901 std::uint8_t array_size;
1903 std::uint16_t index;
1905 bool is_method =
false;
1907 bool is_type =
false;
1909 std::string index_str;
1912 std::vector<std::uint16_t> registers;
1918 std::uint8_t get_registers_size()
const
1923 std::uint16_t get_index_value()
const
1928 TYPES::Operand get_index_type()
const
1930 return TYPES::Operand::KIND;
1933 const std::vector<std::uint16_t>& get_registers()
const
1938 std::vector<std::uint16_t>& get_registers()
1943 DVMType * get_operand_dvmtype()
1960 std::uint16_t> get_operand()
1970 const std::string& get_operand_str()
const
1981 for(
const auto reg : registers)
1983 instruction +=
"v" + std::to_string(reg) +
", ";
1986 if (registers.size() > 0)
1987 instruction = instruction.substr(0, instruction.size()-2);
1989 instruction +=
"}, " + index_str;
2011 std::uint8_t reg_count;
2013 std::vector<std::uint8_t> registers;
2015 std::uint16_t method_reference;
2019 std::uint16_t prototype_reference;
2025 std::uint8_t get_number_of_registers()
const
2030 const std::vector<std::uint8_t>& get_registers()
const
2035 std::vector<std::uint8_t>& get_registers()
2040 std::uint16_t get_method_reference()
const
2042 return method_reference;
2045 std::uint16_t get_prototype_reference()
const
2047 return prototype_reference;
2066 for(
const auto reg : registers)
2068 instruction +=
"v" + std::to_string(reg) +
", ";
2071 if (registers.size() > 0)
2072 instruction = instruction.substr(0, instruction.size()-2);
2074 instruction +=
"}, ";
2100 std::uint8_t reg_count;
2102 std::vector<std::uint16_t> registers;
2104 std::uint16_t method_reference;
2108 std::uint16_t prototype_reference;
2114 std::uint8_t get_number_of_registers()
const
2119 const std::vector<std::uint16_t>& get_registers()
const
2124 std::vector<std::uint16_t>& get_registers()
2129 std::uint16_t get_method_reference()
const
2131 return method_reference;
2139 std::uint16_t get_prototype_reference()
const
2141 return prototype_reference;
2146 return prototype_id;
2155 for(
const auto reg : registers)
2157 instruction +=
"v" + std::to_string(reg) +
", ";
2160 if (registers.size() > 0)
2161 instruction = instruction.substr(0, instruction.size()-2);
2163 instruction +=
"}, ";
2190 std::int64_t nBBBBBBBBBBBBBBBB;
2194 std::uint8_t get_first_register()
const
2199 TYPES::Operand get_first_register_type()
const
2201 return TYPES::Operand::REGISTER;
2204 std::uint8_t get_second_register()
const
2209 TYPES::Operand get_second_register_type()
const
2211 return TYPES::Operand::REGISTER;
2214 std::int64_t get_wide_value()
const
2216 return nBBBBBBBBBBBBBBBB;
2219 TYPES::Operand get_wide_value_type()
const
2221 return TYPES::Operand::LITERAL;
2229 ", v" + std::to_string(vBB) +
"}, " + std::to_string(nBBBBBBBBBBBBBBBB);
2237 ", v" + std::to_string(vBB) +
"}, " + std::to_string(nBBBBBBBBBBBBBBBB);
2248 std::int32_t first_key;
2250 std::vector<std::int32_t> targets;
2254 std::uint16_t get_number_of_targets()
const
2259 std::int32_t get_first_key()
const
2264 const std::vector<std::int32_t>& get_targets()
const
2269 std::vector<std::int32_t>& get_targets()
2278 std::stringstream output;
2281 std::to_string(size) +
" (first/last key)" + std::to_string(first_key) +
"[";
2283 for (
const auto target : targets)
2284 output <<
"0x" << std::hex << target <<
",";
2287 output.seekp(-1, output.cur);
2290 return output.str();
2298 std::to_string(size) +
" (first/last key)" + std::to_string(first_key) +
"[";
2300 for (
const auto target : targets)
2301 os <<
"0x" << std::hex << target <<
",";
2304 os.seekp(-1, os.cur);
2318 std::vector<std::tuple<std::int32_t, std::int32_t>> keys_targets;
2322 std::uint16_t get_size_of_targets()
const
2327 const std::vector<std::tuple<std::int32_t, std::int32_t>>& get_keys_targets()
const
2329 return keys_targets;
2332 std::vector<std::tuple<std::int32_t, std::int32_t>>& get_keys_targets()
2334 return keys_targets;
2341 std::stringstream output;
2345 for (
const auto& key_target : keys_targets)
2347 auto key = std::get<0>(key_target);
2348 auto target = std::get<1>(key_target);
2351 output <<
"-0x" << std::hex << key <<
":";
2353 output <<
"0x" << std::hex << key <<
":";
2356 output <<
"-0x" << std::hex << target <<
":";
2358 output <<
"0x" << std::hex << target <<
":";
2364 output.seekp(-1, output.cur);
2368 return output.str();
2377 for (
const auto& key_target : keys_targets)
2379 auto key = std::get<0>(key_target);
2380 auto target = std::get<1>(key_target);
2383 os <<
"-0x" << std::hex << key <<
":";
2385 os <<
"0x" << std::hex << key <<
":";
2388 os <<
"-0x" << std::hex << target <<
":";
2390 os <<
"0x" << std::hex << target <<
":";
2394 os.seekp(-1, os.cur);
2403 std::uint16_t element_width;
2405 std::vector<std::uint8_t> data;
2409 std::uint16_t get_element_width()
const
2411 return element_width;
2414 std::uint32_t get_size_of_data()
const
2419 const std::vector<std::uint8_t>& get_data()
const
2424 std::vector<std::uint8_t>& get_data()
2433 std::stringstream output;
2435 output <<
"(width)" << element_width <<
" (size)" << size <<
" [";
2437 for (
auto byte : data)
2439 output <<
"0x" << std::hex << static_cast<std::uint32_t>(
byte) <<
",";
2443 output.seekp(-1, output.cur);
2447 return output.str();
2454 os <<
"(width)" << element_width <<
" (size)" << size <<
" [";
2456 for (
auto byte : data)
2458 os <<
"0x" << std::hex << static_cast<std::uint32_t>(
byte) <<
",";
2462 os.seekp(-1, os.cur);
2483 std::stringstream stream;
2485 stream <<
"DalvikInvalidInstruction [length: " <<
length <<
"][Opcodes: ";
2488 stream << std::hex << val <<
" ";
2490 stream.seekp(-1, stream.cur);
2494 return stream.str();
2501 os <<
"DalvikInvalidInstruction [length: " <<
length <<
"][Opcodes: ";
2504 os << std::hex << val <<
" ";
2506 os.seekp(-1, os.cur);
Class that represent the array types.
Definition types.hpp:223
Classes of the DVM.
Definition types.hpp:174
Fundamental types from the DVM, these are the common from many other languages.
Definition types.hpp:83
Represents the base class of a Type in the DVM we have different types.
Definition types.hpp:26
In case there is an incorrect instruction this one holds all the opcodes and the length of previous i...
Definition dalvik_instructions.hpp:2472
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:2481
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:2499
static const std::string & get_instruction_name(std::uint32_t instruction)
Find the instruction opcode in a map to obtain the instruction name.
static TYPES::Operation get_instruction_operation(std::uint32_t instruction)
Find the instruction operation given an instruction opcode.
static TYPES::Kind get_instruction_type(std::uint32_t instruction)
Find the instruction type given an instruction opcode.
FieldID represent one of the fields from the DEX file.
Definition fields.hpp:28
FieldID * get_field(std::uint32_t pos)
Get one of the fields by its position.
Class present in methods which uses array data.
Definition dalvik_instructions.hpp:2402
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:2452
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:2431
Useless instruction with opcode of 00 no instruction represents this, it's not either a nop.
Definition dalvik_instructions.hpp:194
Instruction00x(std::vector< uint8_t > &bytecode, std::size_t index, Parser *parser)
Constructor of Instruction00x this instruction does nothing.
Definition dalvik_instructions.hpp:199
Unconditional jump instruction. An offset is given to know where to jump.
Definition dalvik_instructions.hpp:383
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:406
std::int8_t get_jump_offset() const
Get offset of the jump.
Definition dalvik_instructions.hpp:392
TYPES::Operand get_operand_type() const
Get type of operand in this case an offset.
Definition dalvik_instructions.hpp:399
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:414
Instruction for wasting cycles. It represents a nop, it has a length of 2.
Definition dalvik_instructions.hpp:207
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:213
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:220
Instruction for moving a given literal, the instruction has a register and a literal value,...
Definition dalvik_instructions.hpp:290
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:330
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:321
Move single, double-words or objects from invoke results, also save caught exception into given regis...
Definition dalvik_instructions.hpp:342
TYPES::Operand get_destination_type() const
Get the type of operand for the destination.
Definition dalvik_instructions.hpp:358
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:373
std::uint8_t get_destination() const
Get destination register index of the operation.
Definition dalvik_instructions.hpp:351
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:365
Move the contents of one register to another length of the instruction is 2 bytes,...
Definition dalvik_instructions.hpp:230
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:278
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:269
TYPES::Operand get_source_type() const
Get the operand type of the source.
Definition dalvik_instructions.hpp:262
std::uint8_t get_source() const
Get the index of the source register.
Definition dalvik_instructions.hpp:248
TYPES::Operand get_destination_type() const
Get the operand type of the destination.
Definition dalvik_instructions.hpp:255
std::uint8_t get_destination() const
Get the index of the destination register.
Definition dalvik_instructions.hpp:241
opAA, kind@BBBB, where AA indicates a type of error and BBBB and index into the appropiate table
Definition dalvik_instructions.hpp:465
TYPES::Operand get_error_operand_type() const
Get the type of operand for the error operand.
Definition dalvik_instructions.hpp:483
std::uint16_t get_index_into_table() const
Get the index to the appropiate table of the instruction...
Definition dalvik_instructions.hpp:490
std::uint8_t get_type_of_error_data() const
Get the index of the type of error.
Definition dalvik_instructions.hpp:476
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:510
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:502
Another unconditional jump with a bigger offset of 2 bytes for the offset.
Definition dalvik_instructions.hpp:424
TYPES::Operand get_operand_type() const
Get the type of the operand of this instruction (jump)
Definition dalvik_instructions.hpp:440
std::int16_t get_offset() const
Get the offset where to jump with an unconditional jump.
Definition dalvik_instructions.hpp:433
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:455
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:447
Move a reference to a register from a string, type, etc example instruction: const-string vAA,...
Definition dalvik_instructions.hpp:762
std::uint16_t get_source() const
Get the index used as source operand, this is an index to a string, type, etc...
Definition dalvik_instructions.hpp:810
DVMFundamental * get_source_dvmfundamental() const
Check if source is a DVMFundamental and return a pointer.
Definition dalvik_instructions.hpp:855
TYPES::Operand get_destination_type() const
Get the type of the destination.
Definition dalvik_instructions.hpp:802
bool is_source_string() const
Check if source is a string.
Definition dalvik_instructions.hpp:831
std::uint8_t get_destination() const
Get the index of the register for destination.
Definition dalvik_instructions.hpp:795
TYPES::Operand get_source_type() const
Get the type of the source, this time is a KIND the KIND can be various things.
Definition dalvik_instructions.hpp:817
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:912
MethodID * get_source_method() const
check if source is a MethodID and return a pointer
Definition dalvik_instructions.hpp:903
const std::string & pretty_print_source() const
Print a string version of the source.
Definition dalvik_instructions.hpp:824
std::string & get_source_str()
get reference of the string this should be called only if is_str == true
Definition dalvik_instructions.hpp:839
FieldID * get_source_field() const
check if source is a FieldID and return a pointer
Definition dalvik_instructions.hpp:885
DVMArray * get_source_dvmarray() const
check if source is a DVMArray and return a pointer
Definition dalvik_instructions.hpp:875
DVMClass * get_source_dvmclass() const
check if source is a DVMClass and return a pointer
Definition dalvik_instructions.hpp:865
ProtoID * get_source_proto() const
Check if source is a ProtoID and return a pointer.
Definition dalvik_instructions.hpp:894
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:921
DVMType * get_source_dvmtype() const
Check if source is a DVMType and return a pointer.
Definition dalvik_instructions.hpp:846
Move given literal value into specified register. Example: const/high16 vAA, #+BBBB0000 where vAA is ...
Definition dalvik_instructions.hpp:703
TYPES::Operand get_source_type() const
Get the source type of the instruction.
Definition dalvik_instructions.hpp:735
std::uint8_t get_destination() const
Get the index of the destination register.
Definition dalvik_instructions.hpp:714
std::int64_t get_source() const
Get the source value of the instruction.
Definition dalvik_instructions.hpp:728
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:751
TYPES::Operand get_destination_type() const
Get the destination type of the instruction.
Definition dalvik_instructions.hpp:721
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:742
Move given literal value into specified register. Example of instruction: const/16 vAA,...
Definition dalvik_instructions.hpp:643
std::int16_t get_source() const
Get the source value of the instruction.
Definition dalvik_instructions.hpp:668
TYPES::Operand get_destination_type() const
Get the destination type of the instruction.
Definition dalvik_instructions.hpp:661
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:691
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:682
TYPES::Operand get_source_type() const
Get the source type of the instruction.
Definition dalvik_instructions.hpp:675
std::uint8_t get_destination() const
Get the index of the destination register.
Definition dalvik_instructions.hpp:654
Branch to the given destination if the given register's value compares with 0 as specified....
Definition dalvik_instructions.hpp:582
TYPES::Operand get_offset_type() const
Get the type of the offset of the jump.
Definition dalvik_instructions.hpp:614
TYPES::Operand get_check_reg_type() const
Get the type of the checked register.
Definition dalvik_instructions.hpp:600
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:621
std::uint8_t get_check_reg() const
Get the register used for the check in the jump.
Definition dalvik_instructions.hpp:593
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:630
std::int16_t get_jump_offset() const
Get the offset of the jump.
Definition dalvik_instructions.hpp:607
Perform indicated binary operation on the indicated register and literal value, storing result in des...
Definition dalvik_instructions.hpp:1011
std::int8_t get_second_operand() const
Get the value of the second operand.
Definition dalvik_instructions.hpp:1052
std::uint8_t get_destination() const
Get the index value of the destination register.
Definition dalvik_instructions.hpp:1024
TYPES::Operand get_destination_type() const
Get the type of the destination.
Definition dalvik_instructions.hpp:1031
TYPES::Operand get_first_operand_type() const
Get the type of the first operand.
Definition dalvik_instructions.hpp:1045
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1076
TYPES::Operand get_second_operand_type() const
Get the type of the second operand.
Definition dalvik_instructions.hpp:1059
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1066
std::uint8_t get_first_operand() const
Get the first operand of the instruction.
Definition dalvik_instructions.hpp:1038
Store in the given destination 1 if the register provided contains an instance of the given type/fiel...
Definition dalvik_instructions.hpp:1247
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1335
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1344
std::uint8_t get_operand() const
Get the operand checked in the instruction.
Definition dalvik_instructions.hpp:1282
TYPES::Operand get_operand_type() const
Get the type of the operand of the instruction.
Definition dalvik_instructions.hpp:1289
TYPES::Operand get_checked_id_type() const
Get the type of the checked ID.
Definition dalvik_instructions.hpp:1303
std::uint16_t get_checked_id() const
Get the ID of the checked Type/Field.
Definition dalvik_instructions.hpp:1296
DVMType * get_checked_dvmtype() const
Check if checked value is a DVMType and get a pointer.
Definition dalvik_instructions.hpp:1317
std::uint8_t get_destination() const
Get the destination operand for the instruction.
Definition dalvik_instructions.hpp:1268
TYPES::Operand get_destination_type() const
Get the destination operand type.
Definition dalvik_instructions.hpp:1275
const std::string & get_checked_value_str() const
Get a pretty-printed version of the checked value.
Definition dalvik_instructions.hpp:1310
FieldID * get_checked_field()
Check if checked value is a FieldID and get a pointer.
Definition dalvik_instructions.hpp:1326
Format suggested for statically linked field access instructions or Types. Example: op vA,...
Definition dalvik_instructions.hpp:1356
TYPES::Operand get_register_B_type() const
Get the type for the register B.
Definition dalvik_instructions.hpp:1396
std::uint16_t get_field_offset() const
Get the offset for the field.
Definition dalvik_instructions.hpp:1403
FieldID * get_field() const
Check if the idx is from a field and return a FieldID.
Definition dalvik_instructions.hpp:1424
const std::string & get_field_string() const
Get a string representation of the Field.
Definition dalvik_instructions.hpp:1417
TYPES::Operand get_register_A_type() const
Get the type for the register A.
Definition dalvik_instructions.hpp:1382
std::uint8_t get_register_A() const
Get the index of the first register used in the instruction.
Definition dalvik_instructions.hpp:1375
TYPES::Operand get_field_offset_type() const
Get the type for the offset, probably KIND.
Definition dalvik_instructions.hpp:1410
std::uint8_t get_register_B() const
Get the index of the second register used in the instruction.
Definition dalvik_instructions.hpp:1389
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1433
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1442
Perform indicated binary operation on the operands storing finally the result in the destination regi...
Definition dalvik_instructions.hpp:1167
TYPES::Operand get_destination_type() const
Get the type of the operand used for destination.
Definition dalvik_instructions.hpp:1187
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1232
std::uint8_t get_first_operand() const
Get the first operand of the instruction.
Definition dalvik_instructions.hpp:1194
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1222
TYPES::Operand get_first_operand_type() const
Get the type of the first operand of the instruction.
Definition dalvik_instructions.hpp:1201
TYPES::Operand get_second_operand_type() const
Get the type of the second operand of the instruction.
Definition dalvik_instructions.hpp:1215
std::int16_t get_second_operand() const
Get the second operand of the instruction.
Definition dalvik_instructions.hpp:1208
std::uint8_t get_destination() const
Get the destination of the operation.
Definition dalvik_instructions.hpp:1180
Branch to given offset after comparison of two registers. Example if-test vA, vB, +CCCC.
Definition dalvik_instructions.hpp:1088
std::uint8_t get_first_operand() const
Get the first operand of the check.
Definition dalvik_instructions.hpp:1101
TYPES::Operand get_offset_type() const
Get the type of the offset for the jump.
Definition dalvik_instructions.hpp:1136
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1153
std::uint8_t get_second_operand() const
Get the second operand of the check.
Definition dalvik_instructions.hpp:1115
TYPES::Operand get_second_operand_type() const
Get the type of the second operand of the comparison.
Definition dalvik_instructions.hpp:1122
TYPES::Operand get_first_operand_type() const
Get the type of the first operand of the comparison.
Definition dalvik_instructions.hpp:1108
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1143
std::int16_t get_offset() const
Get the offset of the jump in case this is taken.
Definition dalvik_instructions.hpp:1129
Move the contents of one non-object register to another. an instruction like move/from16 vAA,...
Definition dalvik_instructions.hpp:521
TYPES::Operand get_source_type() const
Get the type of operand from the source.
Definition dalvik_instructions.hpp:553
TYPES::Operand get_destination_type() const
Get the type of operand from the destination.
Definition dalvik_instructions.hpp:539
std::uint16_t get_source() const
Get the index of the register of the source.
Definition dalvik_instructions.hpp:546
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:569
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:560
std::uint8_t get_destination() const
Get index of the register of destination.
Definition dalvik_instructions.hpp:532
Perform indicated floating point or long comparison Example: cmpkind vAA, vBB, vCC.
Definition dalvik_instructions.hpp:932
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:997
TYPES::Operand get_second_source_type() const
Get the type of the second source.
Definition dalvik_instructions.hpp:980
std::uint8_t get_destination() const
Get the register for the destination.
Definition dalvik_instructions.hpp:945
TYPES::Operand get_first_source_type() const
Get the type of the first source.
Definition dalvik_instructions.hpp:966
std::uint8_t get_second_source() const
Get the register for the second source.
Definition dalvik_instructions.hpp:973
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:987
TYPES::Operand get_destination_type() const
Get the type of the destination.
Definition dalvik_instructions.hpp:952
std::uint8_t get_first_source() const
Get the register for the first source.
Definition dalvik_instructions.hpp:959
Unconditional jump to indicated offset Example: goto/32 +AAAAAAAA.
Definition dalvik_instructions.hpp:1453
std::int32_t get_offset() const
Get the offset of the jump.
Definition dalvik_instructions.hpp:1462
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1476
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1483
TYPES::Operand get_offset_type() const
Get the type of the offset.
Definition dalvik_instructions.hpp:1469
Move a reference to string specified by given index into the specified register. Example: const-strin...
Definition dalvik_instructions.hpp:1722
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1777
TYPES::Operand get_string_idx_type() const
Get the type from the string operand.
Definition dalvik_instructions.hpp:1755
std::uint32_t get_string_idx() const
Get the index of the string operand.
Definition dalvik_instructions.hpp:1748
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1769
const std::string & get_string_value() const
Get the value from the string pointed in the instruction.
Definition dalvik_instructions.hpp:1762
std::uint8_t get_destination() const
Get the destination register for the string.
Definition dalvik_instructions.hpp:1734
TYPES::Operand get_destination_type() const
Get the destination type of the operand.
Definition dalvik_instructions.hpp:1741
Instructions between a register and a literal value of 32 bits. Example: const vAA,...
Definition dalvik_instructions.hpp:1549
TYPES::Operand get_source_type() const
Get the source operand type of the instruction.
Definition dalvik_instructions.hpp:1580
TYPES::Operand get_destination_type() const
Get the destination operand type of the instruction.
Definition dalvik_instructions.hpp:1566
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1587
std::uint8_t get_destination() const
Get the destination operand of the instruction.
Definition dalvik_instructions.hpp:1559
std::uint32_t get_source() const
Get the source operand of the instruction.
Definition dalvik_instructions.hpp:1573
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1595
Fill given array with indicated data. Reference must be an array of primitives. Also used for specify...
Definition dalvik_instructions.hpp:1611
SparseSwitch * get_sparse_switch()
Get the pointer to sparse switch in case it exists.
Definition dalvik_instructions.hpp:1682
void set_sparse_switch(SparseSwitch *sparse_switch)
Set the pointer to the SparseSwitch.
Definition dalvik_instructions.hpp:1696
std::uint8_t get_ref_register() const
get the register used as reference for switch/array
Definition dalvik_instructions.hpp:1639
TYPES::Operand get_ref_register_type() const
Get the type of the reference register.
Definition dalvik_instructions.hpp:1646
PackedSwitch * get_packed_switch()
Get the pointer to a packed switch in case it exists.
Definition dalvik_instructions.hpp:1675
type_of_switch_t get_type_of_switch() const
Get the type of switch in case the instruction is a switch.
Definition dalvik_instructions.hpp:1668
TYPES::Operand get_offset_type() const
Return the type of the offset.
Definition dalvik_instructions.hpp:1660
std::int32_t get_offset() const
Return the offset to the table with packed data.
Definition dalvik_instructions.hpp:1653
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1703
type_of_switch_t
Enum specifying the type of switch for the data table.
Definition dalvik_instructions.hpp:1616
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1711
void set_packed_switch(PackedSwitch *packed_switch)
Set the pointer to the PackedSwitch.
Definition dalvik_instructions.hpp:1689
Binary operation between registers of 16 bits Example: move/16 vAAAA, vBBBB.
Definition dalvik_instructions.hpp:1492
TYPES::Operand get_source_type() const
Get the type of the source operand.
Definition dalvik_instructions.hpp:1523
TYPES::Operand get_destination_type() const
Get the type of the destination operand.
Definition dalvik_instructions.hpp:1509
std::uint16_t get_source() const
Get the source operand of the instruction.
Definition dalvik_instructions.hpp:1516
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1530
std::uint16_t get_destination() const
Get the destination operand of the instruction.
Definition dalvik_instructions.hpp:1502
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1538
Construct array of given type and size, filling it with supplied contents. Type must be an array type...
Definition dalvik_instructions.hpp:1789
const std::vector< std::uint8_t > & get_registers() const
Get a constant reference to the vector with the registers.
Definition dalvik_instructions.hpp:1816
TYPES::Operand get_registers_type()
Get the type of the registers operand.
Definition dalvik_instructions.hpp:1823
std::vector< std::uint8_t > & get_registers()
Get a reference to the vector with the registers.
Definition dalvik_instructions.hpp:1830
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1886
DVMType * get_dvmtype()
Get the DVMType of the array type.
Definition dalvik_instructions.hpp:1851
std::uint8_t get_number_of_registers() const
Get the number of registers from the instruction.
Definition dalvik_instructions.hpp:1809
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1867
std::uint16_t get_type_idx() const
Get the idx of the type.
Definition dalvik_instructions.hpp:1837
TYPES::Operand get_array_type() const
Get the type of the array.
Definition dalvik_instructions.hpp:1844
Construct array of given type and size, filling it with supplied contents. Example instructions: op {...
Definition dalvik_instructions.hpp:1899
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:1996
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:1977
Invoke indicated signature polymorphic method. The result (if any) may be stored with an appropiate m...
Definition dalvik_instructions.hpp:2009
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:2062
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:2086
Invoke the method handle indicated, this time it can provide with a range of arguments given by a siz...
Definition dalvik_instructions.hpp:2098
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:2175
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:2151
Move given literal value into specified register pair Example: const-wide vAA, #+BBBBBBBBBBBBBBBB.
Definition dalvik_instructions.hpp:2184
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:2234
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:2226
Base class for the Instructions of the Dalvik Bytecode.
Definition dalvik_instructions.hpp:69
virtual ~Instruction()=default
Destructor of the instruction.
virtual std::uint32_t get_instruction_length() const
Get the length of the instruction.
Definition dalvik_instructions.hpp:121
virtual std::uint64_t get_address() const
Get the address of the instruction.
Definition dalvik_instructions.hpp:142
virtual dexinsttype_t get_instruction_type() const
Get the instruction type from the enum.
Definition dalvik_instructions.hpp:114
virtual TYPES::Kind get_kind() const
Get the kind of instruction, use a DalvikOpcodes function.
Definition dalvik_instructions.hpp:108
Instruction(std::vector< uint8_t > &bytecode, std::size_t index, dexinsttype_t instruction_type)
Constructor of the Instruction, here is applied the parsing of the opcodes.
Definition dalvik_instructions.hpp:89
virtual std::uint32_t get_instruction_opcode() const
Get the opcode of the instruction.
Definition dalvik_instructions.hpp:128
virtual bool has_side_effects() const
Instruction has or can have some side effect.
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:156
std::uint32_t op
op code from the instruction
Definition dalvik_instructions.hpp:79
std::uint64_t address
address of the instruction
Definition dalvik_instructions.hpp:81
std::uint32_t length
Length of the instruction.
Definition dalvik_instructions.hpp:77
virtual void set_address(std::uint64_t address)
Set the address of the instruction.
Definition dalvik_instructions.hpp:135
Instruction(std::vector< uint8_t > &bytecode, std::size_t index, dexinsttype_t instruction_type, std::uint32_t length)
Definition dalvik_instructions.hpp:94
virtual bool may_throw() const
May throw an exception.
virtual bool is_terminator()
Check if the instruction is a terminator (branch, ret, multibranch)
Definition dalvik_instructions.hpp:170
virtual const std::span< std::uint8_t > & get_opcodes()
Return the op codes in raw from the instruction.
Definition dalvik_instructions.hpp:163
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:149
std::span< std::uint8_t > op_codes
Opcodes of the instruction.
Definition dalvik_instructions.hpp:75
MethodID represents a single method from DEX file.
Definition methods.hpp:28
std::string & pretty_method()
Get a string representation of the method.
MethodID * get_method(std::uint32_t pos)
Get one of the methods by its position.
Packed Switch instruction present in methods which make use of this kind of data.
Definition dalvik_instructions.hpp:2244
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:2295
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:2276
Methods & get_methods()
get a reference to the methods
Definition parser.hpp:153
Fields & get_fields()
get a reference to the fields
Definition parser.hpp:146
Protos & get_protos()
get a reference to the prototypes
Definition parser.hpp:139
Types & get_types()
get a reference to the types object
Definition parser.hpp:125
Store the information of a ProtoID, this is a string with the return type, the list of parameters and...
Definition protos.hpp:54
const std::string & get_shorty_idx() const
Get constant reference to shorty_idx string.
Definition protos.hpp:91
ProtoID * get_proto_by_order(std::uint32_t pos)
Given a position in the vector of protos, return a ProtoID.
Sparse switch instruction present in methods which make use of this kind of data, this contain the ke...
Definition dalvik_instructions.hpp:2314
virtual void print_instruction(std::ostream &os)
Print the instruction on a given stream.
Definition dalvik_instructions.hpp:2373
virtual std::string print_instruction()
Return a string with the representation of the instruction.
Definition dalvik_instructions.hpp:2339
DVMType * get_type_from_order(std::uint32_t pos)
Get a type given position.
utilities
Definition analysis.hpp:23