C++¶
Utilities¶
- bool LIEF::DEX::is_dex(const std::string &file)¶
Check if the given file is a DEX.
- bool LIEF::DEX::is_dex(const std::vector<uint8_t> &raw)¶
Check if the given raw data is a DEX.
- dex_version_t LIEF::DEX::version(const std::string &file)¶
Return the DEX version of the given file.
- dex_version_t LIEF::DEX::version(const std::vector<uint8_t> &raw)¶
Return the DEX version of the raw data.
Parser¶
File¶
- class File : public LIEF::Object¶
Class that represents a DEX file.
Public Types
- using it_classes = ref_iterator<classes_list_t&, Class*>¶
- using it_const_classes = const_ref_iterator<const classes_list_t&, const Class*>¶
- using it_methods = ref_iterator<methods_t&, Method*>¶
- using it_const_methods = const_ref_iterator<const methods_t&, const Method*>¶
- using strings_t = std::vector<std::unique_ptr<std::string>>¶
- using it_strings = ref_iterator<strings_t&, std::string*>¶
- using it_const_strings = const_ref_iterator<const strings_t&, const std::string*>¶
- using it_types = ref_iterator<types_t&, Type*>¶
- using it_const_types = const_ref_iterator<const types_t&, const Type*>¶
- using it_prototypes = ref_iterator<prototypes_t&, Prototype*>¶
- using it_const_prototypes = const_ref_iterator<const prototypes_t&, const Prototype*>¶
- using it_fields = ref_iterator<fields_t&, Field*>¶
- using it_const_fields = const_ref_iterator<const fields_t&, const Field*>¶
Public Functions
- dex_version_t version() const¶
Version of the current DEX file.
- std::string_view name() const¶
Name of this file.
- void name(const std::string &name)¶
- std::string_view location() const¶
Location of this file.
- void location(const std::string &location)¶
- it_const_classes classes() const¶
All classes used in the DEX file
- it_classes classes()¶
- 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.
- const Class *get_class(size_t index) const¶
Return the DEX::Class object associated with the given index.
- dex2dex_info_t dex2dex_info() const¶
De-optimize information.
- std::string dex2dex_json_info() const¶
De-optimize information as JSON.
- it_const_methods methods() const¶
Return an iterator over all the DEX::Method used in this DEX file.
- it_methods methods()¶
- it_const_fields fields() const¶
Return an iterator over all the DEX::Field used in this DEX file.
- it_const_strings strings() const¶
String pool.
- it_strings strings()¶
- it_const_types types() const¶
Type pool.
- it_prototypes prototypes()¶
Prototype pool.
- it_const_prototypes prototypes() const¶
- 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¶
- virtual void accept(Visitor &visitor) const override¶
- ~File() override¶
- using it_classes = ref_iterator<classes_list_t&, Class*>¶
Header¶
- class Header : public LIEF::Object¶
Class which represents the DEX header. This is the first structure that begins the DEX format.
The official documentation is provided here: https://source.android.com/devices/tech/dalvik/dex-format#header-item
Public Types
- using location_t = std::pair<uint32_t, uint32_t>¶
- using magic_t = std::array<uint8_t, 8>¶
- using signature_t = std::array<uint8_t, 20>¶
Public Functions
- Header()¶
- uint32_t checksum() const¶
The file checksum.
- signature_t signature() const¶
SHA-1 DEX signature (which is not really used as a signature).
- uint32_t file_size() const¶
Size of the entire file (including the current the header).
- uint32_t header_size() const¶
Size of this header. It should be 0x70.
- uint32_t map() const¶
Offset from the start of the file to the map list (see: DEX::MapList).
- location_t strings() const¶
Offset and size of the string pool.
- location_t link() const¶
- location_t types() const¶
- location_t prototypes() const¶
- location_t fields() const¶
- location_t methods() const¶
- location_t classes() const¶
- location_t data() const¶
- uint32_t nb_classes() const¶
- uint32_t nb_methods() const¶
- virtual void accept(Visitor &visitor) const override¶
- ~Header() override¶
- using location_t = std::pair<uint32_t, uint32_t>¶
Method¶
- class Method : public LIEF::Object¶
Class which represents a DEX::Method.
Public Types
- using access_flags_list_t = std::vector<ACCESS_FLAGS>¶
- using bytecode_t = std::vector<uint8_t>¶
Public Functions
- Method()¶
- bool has_class() const¶
True if a class is associated with this method.
- const Class *cls() const¶
DEX::Class associated with this Method or a nullptr if not resolved.
- uint64_t code_offset() const¶
Offset to the Dalvik Bytecode.
- const bytecode_t &bytecode() const¶
Dalvik Bytecode as bytes.
- size_t index() const¶
Index in the DEX Methods pool.
- bool is_virtual() const¶
True if this method is a virtual one. i.e. not static, private, final or constructor.
- void insert_dex2dex_info(uint32_t pc, uint32_t index)¶
- virtual void accept(Visitor &visitor) const override¶
- const dex2dex_method_info_t &dex2dex_info() const¶
- bool has(ACCESS_FLAGS f) const¶
Check if the current method has the given ACCESS_FLAGS.
- access_flags_list_t access_flags() const¶
ACCESS_FLAGS as an std::set.
- ~Method() override¶
- using access_flags_list_t = std::vector<ACCESS_FLAGS>¶
Class¶
- class Class : public LIEF::Object¶
Class which represents a DEX Class (i.e. a Java/Kotlin class).
Public Types
- using access_flags_list_t = std::vector<ACCESS_FLAGS>¶
- using it_methods = ref_iterator<methods_t&>¶
- using it_const_methods = const_ref_iterator<const methods_t&>¶
- using it_fields = ref_iterator<fields_t&>¶
- using it_const_fields = const_ref_iterator<const fields_t&>¶
- using it_named_methods = filter_iterator<methods_t&>¶
- using it_const_named_methods = const_filter_iterator<const methods_t&>¶
- using it_named_fields = filter_iterator<fields_t&>¶
- using it_const_named_fields = const_filter_iterator<const fields_t&>¶
Public Functions
- Class()¶
- Class(std::string fullname, uint32_t access_flags = ACCESS_FLAGS::ACC_UNKNOWN, Class *parent = nullptr, std::string source_filename = "")¶
- std::string_view fullname() const¶
Mangled class name (e.g.
Lcom/example/android/MyActivity;).
- std::string package_name() const¶
Package Name.
- std::string pretty_name() 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() const¶
Access flags used by this class.
- std::string_view source_filename() const¶
Filename associated with this class (if any).
- bool has_parent() const¶
True if the current class extends another one.
- it_const_methods methods() const¶
Methods implemented in this class.
- it_methods methods()¶
- it_named_methods methods(const std::string &name)¶
Return Methods having the given name.
- it_const_named_methods methods(const std::string &name) const¶
- it_const_fields fields() const¶
Fields implemented in this class.
- it_named_fields fields(const std::string &name)¶
Return Fields having the given name.
- it_const_named_fields fields(const std::string &name) const¶
- dex2dex_class_info_t dex2dex_info() const¶
De-optimize information.
- size_t index() const¶
Original index in the DEX class pool.
- virtual void accept(Visitor &visitor) const override¶
- ~Class() override¶
- using access_flags_list_t = std::vector<ACCESS_FLAGS>¶
Field¶
- class Field : public LIEF::Object¶
Class which represents a DEX Field.
Public Types
- using access_flags_list_t = std::vector<ACCESS_FLAGS>¶
Public Functions
- Field()¶
- bool has_class() const¶
True if a class is associated with this field (which should be the case).
- size_t index() const¶
Index in the DEX Fields pool.
- bool is_static() const¶
True if this field is a static one.
- virtual void accept(Visitor &visitor) const override¶
- bool has(ACCESS_FLAGS f) const¶
Check if the field has the given ACCESS_FLAGS.
- access_flags_list_t access_flags() const¶
ACCESS_FLAGS as a list.
- ~Field() override¶
- using access_flags_list_t = std::vector<ACCESS_FLAGS>¶
Code Info¶
Prototype¶
- class Prototype : public LIEF::Object¶
Class which represents a DEX method prototype.
Public Types
- using it_params = ref_iterator<parameters_type_t>¶
- using it_const_params = const_ref_iterator<const parameters_type_t>¶
Public Functions
- Prototype()¶
- it_const_params parameters_type() const¶
Types of the parameters.
- virtual void accept(Visitor &visitor) const override¶
- ~Prototype() override¶
- using it_params = ref_iterator<parameters_type_t>¶
Type¶
- class Type : public LIEF::Object¶
Class which represents a DEX type as described in the format specifications: https://source.android.com/devices/tech/dalvik/dex-format#typedescriptor.
Public Types
- enum class TYPES¶
Values:
- enumerator UNKNOWN = 0¶
- enumerator PRIMITIVE = 1¶
- enumerator CLASS = 2¶
- enumerator ARRAY = 3¶
- enumerator UNKNOWN = 0¶
Public Functions
- Type()¶
- Type(const std::string &mangled)¶
- const PRIMITIVES &primitive() const¶
- Class &cls()¶
IF the current type is a TYPES::CLASS, return the associated DEX::CLASS. Otherwise the returned value is undefined.
- array_t &array()¶
IF the current type is a TYPES::ARRAY, return the associated array. Otherwise the returned value is undefined.
- PRIMITIVES &primitive()¶
IF the current type is a TYPES::PRIMITIVE, return the associated PRIMITIVES. Otherwise the returned value is undefined.
- size_t dim() const¶
Return the array dimension if the current type is an array. Otherwise it returns 0.
- const Type &underlying_array_type() const¶
In the case of a TYPES::ARRAY, return the array’s type.
- virtual void accept(Visitor &visitor) const override¶
- ~Type() override¶
Public Static Functions
- static std::string pretty_name(PRIMITIVES p)¶
- enum class TYPES¶
MapList¶
- class MapList : public LIEF::Object¶
Class which represents the
map_liststructure that follows the main DEX header.This MapList aims at referencing the location of other DEX structures as described in https://source.android.com/devices/tech/dalvik/dex-format#map-item
Public Types
- using it_items_t = ref_iterator<std::vector<MapItem*>>¶
- using it_const_items_t = const_ref_iterator<std::vector<MapItem*>>¶
Public Functions
- MapList()¶
- it_items_t items()¶
Iterator over LIEF::DEX::MapItem.
- it_const_items_t items() const¶
- 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.
- virtual void accept(Visitor &visitor) const override¶
- ~MapList() override¶
- using it_items_t = ref_iterator<std::vector<MapItem*>>¶
MapItem¶
- class MapItem : public LIEF::Object¶
Class which represents an element of the MapList object.
Public Types
- enum class TYPES : uint16_t¶
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¶
- enumerator HEADER = 0x0000¶
Public Functions
- MapItem()¶
- uint16_t reserved() const¶
Reserved value (likely for alignment purpose).
- uint32_t size() const¶
The number of elements (the real meaning depends on the type).
- uint32_t offset() const¶
Offset from the start of the DEX file to the items associated with the underlying TYPES.
- virtual void accept(Visitor &visitor) const override¶
- ~MapItem() override¶
- enum class TYPES : uint16_t¶