dex++ 0.3.1
C++ and C API reference
Loading...
Searching...
No Matches
dex::apk::ResourceTable Class Reference

#include <apk/resources.hpp>

Public Member Functions

std::optional< ResourceName > name_of (uint32_t id) const
 Name of the resource with id id, or nullopt if not present.
 
std::optional< std::string_view > resolve_string (uint32_t id) const
 Value of a string-typed resource id, resolved through the global value pool.
 
std::optional< bool > resolve_bool (uint32_t id) const
 Value of resource id as a boolean: a <bool> resource, or any integer-typed value (nonzero is true), as Android's TypedArray.getBoolean reads it.
 
std::optional< int64_t > resolve_int (uint32_t id) const
 Value of resource id as an integer: an <integer> resource, or any other integer-typed value (a boolean, a color), read as its signed 32-bit data, as Android's TypedArray.getInt reads it.
 
std::optional< uint32_t > id_of (std::string_view type, std::string_view entry) const
 Reverse lookup: the id of type / entry (first package that defines it), or nullopt.
 
bool empty () const
 

Static Public Member Functions

static std::expected< ResourceTable, Error > parse (std::span< const uint8_t > buf)
 Decode a resources.arsc image.
 

Member Function Documentation

◆ parse()

static std::expected< ResourceTable, Error > dex::apk::ResourceTable::parse ( std::span< const uint8_t >  buf)
static

Decode a resources.arsc image.

Fails with ErrorCode::InvalidResources when buf is not a resource table, or holds neither a package nor a string.

◆ name_of()

std::optional< ResourceName > dex::apk::ResourceTable::name_of ( uint32_t  id) const

Name of the resource with id id, or nullopt if not present.

◆ resolve_string()

std::optional< std::string_view > dex::apk::ResourceTable::resolve_string ( uint32_t  id) const

Value of a string-typed resource id, resolved through the global value pool.

nullopt if the id is absent or its value is not a string.

This and the other resolve_* functions follow a resource whose value is a reference to another resource (<bool name="a">@bool/b</bool>) to the end of the chain. Like Android, they give up after 20 steps, which also stops a reference loop. The value used is the default configuration's; see the comment at the top of this file.

◆ resolve_bool()

std::optional< bool > dex::apk::ResourceTable::resolve_bool ( uint32_t  id) const

Value of resource id as a boolean: a <bool> resource, or any integer-typed value (nonzero is true), as Android's TypedArray.getBoolean reads it.

nullopt if the id is absent or its value is of another type, such as a string.

◆ resolve_int()

std::optional< int64_t > dex::apk::ResourceTable::resolve_int ( uint32_t  id) const

Value of resource id as an integer: an <integer> resource, or any other integer-typed value (a boolean, a color), read as its signed 32-bit data, as Android's TypedArray.getInt reads it.

(aapt2 writes a true boolean as -1.) nullopt if the id is absent or its value is of another type, such as a string.

◆ id_of()

std::optional< uint32_t > dex::apk::ResourceTable::id_of ( std::string_view  type,
std::string_view  entry 
) const

Reverse lookup: the id of type / entry (first package that defines it), or nullopt.

Linear in the table; intended for tooling.

◆ empty()

bool dex::apk::ResourceTable::empty ( ) const
inline

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