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

Whole-program cross-reference index for an AnalysisContext. More...

#include <analysis/xrefs.hpp>

Public Member Functions

 Xrefs ()=default
 
 Xrefs (const Xrefs &)=delete
 
Xrefs & operator= (const Xrefs &)=delete
 
 Xrefs (Xrefs &&)=default
 
Xrefs & operator= (Xrefs &&)=default
 
std::span< const MethodId > referrers () const
 Identities of every defined method that contains at least one indexed instruction, in discovery order.
 
const MethodId & referrer_id (uint32_t referrer) const
 Identity of one referrer.
 
std::optional< Method > referrer_method (uint32_t referrer) const
 Materialize a Method handle for one referrer.
 
std::span< const MethodXref > method_refs (const MethodId &id) const
 All invoke sites whose declared target is exactly id.
 
std::vector< std::pair< const MethodId *, std::span< const MethodXref > > > method_refs_by_name (std::string_view name) const
 All invoke sites whose declared target has the bare name name, in any class and with any prototype — e.g. every call to "exec" or "loadUrl".
 
std::span< const FieldXref > field_refs (const FieldId &id) const
 All accesses (reads and writes) of the field id.
 
std::vector< FieldXref > field_reads (const FieldId &id) const
 Only the reads (iget* / sget*) of id.
 
std::vector< FieldXref > field_writes (const FieldId &id) const
 Only the writes (iput* / sput*) of id.
 
std::span< const StringXref > string_refs (std::string_view value) const
 All const-string loads of exactly value.
 
std::vector< std::string_view > referenced_strings () const
 Every distinct string value loaded somewhere in the program.
 
std::span< const TypeXref > type_refs (std::string_view descriptor) const
 All type-referencing instructions naming descriptor.
 
bool empty () const
 

Detailed Description

Whole-program cross-reference index for an AnalysisContext.

Answers "who references X" for methods (call sites), fields (reads/writes), strings (const-string loads), and types (const-class / new-instance / check-cast / instance-of / new-array / filled-new-array). Built lazily on first AnalysisContext::xrefs() access and cached on the underlying impl.

Every site records the referrer — the defined method whose bytecode contains the instruction — as an index into referrers(), plus the instruction's code-unit offset. referrer_method() materializes a Method handle on demand.

When a class is defined in more than one loaded DEX file, only the code of its first definition is indexed: the one AnalysisContext::find_class() returns, and the one Android loads. The methods of a later definition never run, so they are not referrers.

Method references are literal: each invoke site is indexed under its declared target MethodId, with no class-hierarchy dispatch (use AnalysisContext::call_graph() — dispatch_targets(), callers() — for virtual dispatch). invoke-custom call sites and const-method-handle/-type operands are not indexed.

All spans and string_views returned by queries point into the index's own storage and stay valid for the lifetime of the AnalysisContext.

Move-only: copying would deep-copy every per-key site vector.

Constructor & Destructor Documentation

◆ Xrefs() [1/3]

dex::Xrefs::Xrefs ( )
default

◆ Xrefs() [2/3]

dex::Xrefs::Xrefs ( const Xrefs &  )
delete

◆ Xrefs() [3/3]

dex::Xrefs::Xrefs ( Xrefs &&  )
default

Member Function Documentation

◆ operator=() [1/2]

Xrefs & dex::Xrefs::operator= ( const Xrefs &  )
delete

◆ operator=() [2/2]

Xrefs & dex::Xrefs::operator= ( Xrefs &&  )
default

◆ referrers()

std::span< const MethodId > dex::Xrefs::referrers ( ) const
inline

Identities of every defined method that contains at least one indexed instruction, in discovery order.

Site referrer fields index here.

◆ referrer_id()

const MethodId & dex::Xrefs::referrer_id ( uint32_t  referrer) const
inline

Identity of one referrer.

Precondition: referrer < referrers().size().

◆ referrer_method()

std::optional< Method > dex::Xrefs::referrer_method ( uint32_t  referrer) const

Materialize a Method handle for one referrer.

Returns nullopt when referrer >= referrers().size().

◆ method_refs()

std::span< const MethodXref > dex::Xrefs::method_refs ( const MethodId &  id) const

All invoke sites whose declared target is exactly id.

◆ method_refs_by_name()

std::vector< std::pair< const MethodId *, std::span< const MethodXref > > > dex::Xrefs::method_refs_by_name ( std::string_view  name) const

All invoke sites whose declared target has the bare name name, in any class and with any prototype — e.g. every call to "exec" or "loadUrl".

Each result pairs the matched target with its sites.

◆ field_refs()

std::span< const FieldXref > dex::Xrefs::field_refs ( const FieldId &  id) const

All accesses (reads and writes) of the field id.

◆ field_reads()

std::vector< FieldXref > dex::Xrefs::field_reads ( const FieldId &  id) const

Only the reads (iget* / sget*) of id.

◆ field_writes()

std::vector< FieldXref > dex::Xrefs::field_writes ( const FieldId &  id) const

Only the writes (iput* / sput*) of id.

◆ string_refs()

std::span< const StringXref > dex::Xrefs::string_refs ( std::string_view  value) const

All const-string loads of exactly value.

◆ referenced_strings()

std::vector< std::string_view > dex::Xrefs::referenced_strings ( ) const

Every distinct string value loaded somewhere in the program.

Useful as the enumeration step before substring/pattern filtering.

◆ type_refs()

std::span< const TypeXref > dex::Xrefs::type_refs ( std::string_view  descriptor) const

All type-referencing instructions naming descriptor.

◆ empty()

bool dex::Xrefs::empty ( ) const
inline

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