DEX

Utilities

Warning

doxygenfunction: Unable to resolve multiple matches for function “LIEF::DEX::is_dex” with arguments (const std::string&) in doxygen xml output for project “lief” from directory: /tmp/LIEF/LIEF/build/doc/doxygen/xml. Potential matches:

- bool is_dex(const std::string &file)
- bool is_dex(const std::vector<uint8_t> &raw)

Warning

doxygenfunction: Unable to resolve multiple matches for function “LIEF::DEX::is_dex” with arguments (const std::vector<uint8_t>&) in doxygen xml output for project “lief” from directory: /tmp/LIEF/LIEF/build/doc/doxygen/xml. Potential matches:

- bool is_dex(const std::string &file)
- bool is_dex(const std::vector<uint8_t> &raw)

Warning

doxygenfunction: Unable to resolve multiple matches for function “LIEF::DEX::version” with arguments (const std::string&) in doxygen xml output for project “lief” from directory: /tmp/LIEF/LIEF/build/doc/doxygen/xml. Potential matches:

- dex_version_t version(const std::string &file)
- dex_version_t version(const std::vector<uint8_t> &raw)

Warning

doxygenfunction: Unable to resolve multiple matches for function “LIEF::DEX::version” with arguments (const std::vector<uint8_t>&) in doxygen xml output for project “lief” from directory: /tmp/LIEF/LIEF/build/doc/doxygen/xml. Potential matches:

- dex_version_t version(const std::string &file)
- dex_version_t version(const std::vector<uint8_t> &raw)

Parser

class LIEF::DEX::Parser

Class which parse a DEX file and transform into a DEX::File object.

Public Functions

Parser &operator=(const Parser &copy) = delete
Parser(const Parser &copy) = delete

Public Static Functions

std::unique_ptr<File> parse(const std::string &file)
std::unique_ptr<File> parse(const std::vector<uint8_t> &data, const std::string &name = "")

File

class LIEF::DEX::File : public LIEF::Object

Public Functions

File &operator=(const File &copy) = delete
File(const File &copy) = delete
dex_version_t version(void) const

Version of the current DEX file.

const std::string &name(void) const

Name of this file.

void name(const std::string &name)
const std::string &location(void) const

Location of this file.

void location(const std::string &location)
const Header &header(void) const

DEX header.

Header &header(void)
it_const_classes classes(void) const

All classes used in the DEX file

it_classes classes(void)
bool has_class(const std::string &class_name) const

Check if the given class name exists.

const Class &get_class(const std::string &class_name) const

Return the DEX::Class object associated with the given name.

Class &get_class(const std::string &class_name)
const Class &get_class(size_t index) const

Return the DEX::Class object associated with the given index.

Class &get_class(size_t index)
dex2dex_info_t dex2dex_info(void) const

De-optimize information.

std::string dex2dex_json_info(void)

De-optimize information as JSON.

it_const_methods methods(void) const

All Methods used in this DEX

it_methods methods(void)
it_const_strings strings(void) const

String pool.

it_strings strings(void)
it_const_types types(void) const

Type pool.

it_types types(void)
it_const_protypes prototypes(void) const

Prototype pool.

it_protypes prototypes(void)
const MapList &map(void) const

DEX Map.

MapList &map(void)
std::string save(const std::string path = "", bool deoptimize = true) const

Extract the current dex file and deoptimize it.

std::vector<uint8_t> raw(bool deoptimize = true) const
void accept(Visitor &visitor) const override
bool operator==(const File &rhs) const
bool operator!=(const File &rhs) const
~File(void)

Friends

friend std::ostream &operator<<(std::ostream &os, const File &file)


Method

class LIEF::DEX::Method : public LIEF::Object

Public Types

using access_flags_list_t = std::vector<ACCESS_FLAGS>
using bytecode_t = std::vector<uint8_t>

Public Functions

Method(void)
Method(const std::string &name, Class *parent = nullptr)
Method(const Method&)
Method &operator=(const Method&)
const std::string &name(void) const

Name of the Method.

bool has_class(void) const

True if a class is associated with this method.

const Class &cls(void) const

Class associated with this Method.

Class &cls(void)
uint64_t code_offset(void) const

Offset to the Dalvik Bytecode.

const bytecode_t &bytecode(void) const

Dalvik Bytecode.

size_t index(void) const

Index in the DEX Methods pool.

bool is_virtual(void) const

True if this method is a virtual one. i.e. not static, private, finale or constructor

const Prototype &prototype(void) const

Method’s prototype.

Prototype &prototype(void)
void insert_dex2dex_info(uint32_t pc, uint32_t index)
void accept(Visitor &visitor) const override
const dex2dex_method_info_t &dex2dex_info(void) const
bool has(ACCESS_FLAGS f) const
access_flags_list_t access_flags(void) const
bool operator==(const Method &rhs) const
bool operator!=(const Method &rhs) const
~Method(void)

Friends

friend std::ostream &operator<<(std::ostream &os, const Method &mtd)

Class

class LIEF::DEX::Class : public LIEF::Object

Public Types

using access_flags_list_t = std::vector<ACCESS_FLAGS>

Public Functions

Class(void)
Class(const Class&)
Class &operator=(const Class&)
Class(const std::string &fullname, uint32_t access_flags = ACCESS_FLAGS::ACC_UNKNOWN, Class *parent = nullptr, const std::string &source_filename = "")
const std::string &fullname(void) const

Mangled class name (e.g. Lcom/example/android/MyActivity;)

std::string package_name(void) const

Package Name.

std::string name(void) const

Class name.

std::string pretty_name(void) const

Demangled class name.

bool has(ACCESS_FLAGS f) const

Check if the class has the given access flag.

access_flags_list_t access_flags(void) const

Access flags used by this class.

const std::string &source_filename(void) const

Filename associated with this class (if any)

bool has_parent(void) const

True if the current class extends another one.

const Class &parent(void) const

Parent class.

Class &parent(void)
it_const_methods methods(void) const

Methods implemented in this class.

it_methods methods(void)
it_methods methods(const std::string &name)

Return Methods having the given name.

it_const_methods methods(const std::string &name) const
dex2dex_class_info_t dex2dex_info(void) const

De-optimize information.

size_t index(void) const

Original index in the DEX class pool.

void accept(Visitor &visitor) const override
bool operator==(const Class &rhs) const
bool operator!=(const Class &rhs) const
~Class(void)

Public Static Functions

std::string package_normalized(const std::string &pkg_name)
std::string fullname_normalized(const std::string &pkg_cls)
std::string fullname_normalized(const std::string &pkg, const std::string &cls_name)

Friends

friend std::ostream &operator<<(std::ostream &os, const Class &cls)

Code Info

class LIEF::DEX::CodeInfo : public LIEF::Object

Public Functions

CodeInfo(void)
CodeInfo(const code_item *codeitem)
CodeInfo(const CodeInfo&)
CodeInfo &operator=(const CodeInfo&)
void accept(Visitor &visitor) const override
bool operator==(const CodeInfo &rhs) const
bool operator!=(const CodeInfo &rhs) const
~CodeInfo(void)

Friends

friend std::ostream &operator<<(std::ostream &os, const CodeInfo &cinfo)

Prototype

class LIEF::DEX::Prototype : public LIEF::Object

Public Types

using parameters_type_t = std::vector<Type*>
using it_params = ref_iterator<parameters_type_t>
using it_const_params = const_ref_iterator<const parameters_type_t>

Public Functions

Prototype(void)
Prototype(const Prototype &other)
const Type &return_type(void) const

Type returned.

Type &return_type(void)
it_const_params parameters_type(void) const

Types of the parameters.

it_params parameters_type(void)
void accept(Visitor &visitor) const override
bool operator==(const Prototype &rhs) const
bool operator!=(const Prototype &rhs) const
~Prototype(void)

Friends

friend std::ostream &operator<<(std::ostream &os, const Prototype &type)

Type

class LIEF::DEX::Type : public LIEF::Object

Public Types

enum TYPES

Values:

enumerator UNKNOWN = 0
enumerator PRIMITIVE = 1
enumerator CLASS = 2
enumerator ARRAY = 3
enum PRIMITIVES

Values:

enumerator VOID_T = 0x01
enumerator BOOLEAN = 0x02
enumerator BYTE = 0x03
enumerator SHORT = 0x04
enumerator CHAR = 0x05
enumerator INT = 0x06
enumerator LONG = 0x07
enumerator FLOAT = 0x08
enumerator DOUBLE = 0x09
using array_t = std::vector<Type>

Public Functions

Type(void)
Type(const std::string &mangled)
Type(const Type &other)
TYPES type(void) const
const Class &cls(void) const
const array_t &array(void) const
const PRIMITIVES &primitive(void) const
Class &cls(void)
array_t &array(void)
PRIMITIVES &primitive(void)
size_t dim(void) const

Return the array dimension if the current is an array. Otherwise it returns 0

const Type &underlying_array_type(void) const
Type &underlying_array_type(void)
void accept(Visitor &visitor) const override
bool operator==(const Type &rhs) const
bool operator!=(const Type &rhs) const
~Type(void)

Public Members

Class *cls_ = {nullptr}
array_t *array_
PRIMITIVES *basic_

Public Static Functions

std::string pretty_name(PRIMITIVES p)

Friends

friend std::ostream &operator<<(std::ostream &os, const Type &type)

MapList

class LIEF::DEX::MapList : public LIEF::Object

Public Types

using items_t = std::map<MapItem::TYPES, MapItem>
using it_items_t = ref_iterator<std::vector<MapItem*>>
using it_const_items_t = const_ref_iterator<std::vector<MapItem*>>

Public Functions

MapList(void)
MapList(const MapList&)
MapList &operator=(const MapList&)
it_items_t items(void)

Iterator over LIEF::DEX::MapItem.

it_const_items_t items(void) const
bool has(MapItem::TYPES type) const

Check if the given type exists.

const MapItem &get(MapItem::TYPES type) const

Return the LIEF::DEX::MapItem associated with the given type.

MapItem &get(MapItem::TYPES type)

Return the LIEF::DEX::MapItem associated with the given type.

const MapItem &operator[](MapItem::TYPES type) const

Return the LIEF::DEX::MapItem associated with the given type.

MapItem &operator[](MapItem::TYPES type)

Return the LIEF::DEX::MapItem associated with the given type.

void accept(Visitor &visitor) const override
bool operator==(const MapList &rhs) const
bool operator!=(const MapList &rhs) const
~MapList(void)

Friends

friend std::ostream &operator<<(std::ostream &os, const MapList &mtd)

MapItem

class LIEF::DEX::MapItem : public LIEF::Object

Public Types

enum TYPES

Values:

enumerator HEADER = 0x0000
enumerator STRING_ID = 0x0001
enumerator TYPE_ID = 0x0002
enumerator PROTO_ID = 0x0003
enumerator FIELD_ID = 0x0004
enumerator METHOD_ID = 0x0005
enumerator CLASS_DEF = 0x0006
enumerator CALL_SITE_ID = 0x0007
enumerator METHOD_HANDLE = 0x0008
enumerator MAP_LIST = 0x1000
enumerator TYPE_LIST = 0x1001
enumerator ANNOTATION_SET_REF_LIST = 0x1002
enumerator ANNOTATION_SET = 0x1003
enumerator CLASS_DATA = 0x2000
enumerator CODE = 0x2001
enumerator STRING_DATA = 0x2002
enumerator DEBUG_INFO = 0x2003
enumerator ANNOTATION = 0x2004
enumerator ENCODED_ARRAY = 0x2005
enumerator ANNOTATIONS_DIRECTORY = 0x2006

Public Functions

MapItem(void)
MapItem(TYPES type, uint32_t offset, uint32_t size, uint16_t reserved = 0)
MapItem(const MapItem&)
MapItem &operator=(const MapItem&)
TYPES type(void) const
uint16_t reserved(void) const
uint32_t size(void) const
uint32_t offset(void) const
void accept(Visitor &visitor) const override
bool operator==(const MapItem &rhs) const
bool operator!=(const MapItem &rhs) const
~MapItem(void)

Friends

friend std::ostream &operator<<(std::ostream &os, const MapItem &item)