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

A lightweight handle to a single DEX method. More...

#include <analysis/method.hpp>

Public Member Functions

std::string_view name () const
 Simple name of the method (e.g. "<init>", "main").
 
ClassRef declaring_class () const
 ClassRef for the class that defines this method.
 
MethodId id () const
 The method's identity: its class, name and prototype.
 
std::string_view proto () const
 The prototype: the parameter types inside parentheses, then the return type, e.g. "(Ljava/lang/String;I)V".
 
std::string_view return_type () const
 Descriptor of the return type, from the prototype: "V" for void, "I", "Ljava/lang/String;", "[B" and so on.
 
std::vector< std::string_view > parameters () const
 Descriptors of the parameter types, in declaration order; empty for a method without parameters.
 
AccessFlags access_flags () const
 
bool has_code () const
 True iff this method has a bytecode body (i.e. is neither abstract nor native).
 
bool is_constructor () const
 Returns true for <init> and <clinit> methods.
 
bool is_static () const
 
bool is_public () const
 
bool is_private () const
 
bool is_abstract () const
 
bool is_native () const
 
std::span< const Instruction > instructions () const
 Decoded bytecode for this method, as a view into a per-context cache.
 
const Cfg & cfg () const
 Control-flow graph for this method's bytecode.
 
uint16_t register_count () const
 Total size of the method's register frame (registers_size), or 0 for abstract / native methods (which have no code item).
 
std::vector< ParameterRegister > parameter_registers () const
 Incoming parameters mapped to their entry registers, in declaration order (with this first for instance methods).
 
std::vector< MethodCall > calls () const
 Forward references — what this method's body reaches out to.
 
std::vector< FieldAccess > field_accesses () const
 
std::vector< StringLoad > string_loads () const
 
std::vector< TypeUse > type_uses () const
 
std::vector< TryBlock > try_blocks () const
 Try regions and their handlers, in DEX order.
 
std::vector< Annotation > annotations () const
 Annotations attached to this method, resolved.
 
bool operator== (const Method &) const =default
 Two handles are equal when they come from the same analysis (one AnalysisContext, or copies of it) and point at the same method of the same DEX file.
 

Friends

struct std::hash< Method >
 
class Class
 
class CallGraph
 
class Xrefs
 

Detailed Description

A lightweight handle to a single DEX method.

Get one from Class::methods(), CallGraph::method_for() or Xrefs::referrer_method(). The handle keeps shared ownership of the analysis, so it remains valid after every AnalysisContext wrapper has been destroyed. It stores the absolute method_ids index plus the access flags and code offset that come from the EncodedMethod entry in class_data_item (not from the MethodIdItem itself).

Member Function Documentation

◆ name()

std::string_view dex::Method::name ( ) const

Simple name of the method (e.g. "<init>", "main").

◆ declaring_class()

ClassRef dex::Method::declaring_class ( ) const

ClassRef for the class that defines this method.

◆ id()

MethodId dex::Method::id ( ) const

The method's identity: its class, name and prototype.

It is the identity the call graph and the cross-references use, so a Method can be looked up in them with it.

◆ proto()

std::string_view dex::Method::proto ( ) const

The prototype: the parameter types inside parentheses, then the return type, e.g. "(Ljava/lang/String;I)V".

It is the proto of id(). The view stays valid for the lifetime of the AnalysisContext.

◆ return_type()

std::string_view dex::Method::return_type ( ) const

Descriptor of the return type, from the prototype: "V" for void, "I", "Ljava/lang/String;", "[B" and so on.

The view stays valid for the lifetime of the AnalysisContext.

◆ parameters()

std::vector< std::string_view > dex::Method::parameters ( ) const

Descriptors of the parameter types, in declaration order; empty for a method without parameters.

The views stay valid for the lifetime of the AnalysisContext.

◆ access_flags()

AccessFlags dex::Method::access_flags ( ) const
inline

◆ has_code()

bool dex::Method::has_code ( ) const
inline

True iff this method has a bytecode body (i.e. is neither abstract nor native).

Equivalent to !instructions().empty() but cheaper.

◆ is_constructor()

bool dex::Method::is_constructor ( ) const

Returns true for <init> and <clinit> methods.

◆ is_static()

bool dex::Method::is_static ( ) const
inline

◆ is_public()

bool dex::Method::is_public ( ) const
inline

◆ is_private()

bool dex::Method::is_private ( ) const
inline

◆ is_abstract()

bool dex::Method::is_abstract ( ) const
inline

◆ is_native()

bool dex::Method::is_native ( ) const
inline

◆ instructions()

std::span< const Instruction > dex::Method::instructions ( ) const

Decoded bytecode for this method, as a view into a per-context cache.

Repeated calls return the same span; the underlying storage stays alive for as long as this Method (and any other handle into the same context). Returns an empty span for abstract/native methods (code_off == 0).

◆ cfg()

const Cfg & dex::Method::cfg ( ) const

Control-flow graph for this method's bytecode.

Cached per-context; repeated calls return the same reference. Returns an empty Cfg for abstract/native methods.

◆ register_count()

uint16_t dex::Method::register_count ( ) const

Total size of the method's register frame (registers_size), or 0 for abstract / native methods (which have no code item).

◆ parameter_registers()

std::vector< ParameterRegister > dex::Method::parameter_registers ( ) const

Incoming parameters mapped to their entry registers, in declaration order (with this first for instance methods).

Empty for abstract / native methods, where no register frame exists.

◆ calls()

std::vector< MethodCall > dex::Method::calls ( ) const

Forward references — what this method's body reaches out to.

Each walks the decoded instruction stream (cheap; instructions are cached) and resolves constant-pool indices to identities. Empty for abstract / native methods. This is the per-method "xref-to" complement of the whole-program reverse index in AnalysisContext::xrefs().

◆ field_accesses()

std::vector< FieldAccess > dex::Method::field_accesses ( ) const

◆ string_loads()

std::vector< StringLoad > dex::Method::string_loads ( ) const

◆ type_uses()

std::vector< TypeUse > dex::Method::type_uses ( ) const

◆ try_blocks()

std::vector< TryBlock > dex::Method::try_blocks ( ) const

Try regions and their handlers, in DEX order.

Empty when the method has no try blocks (or is abstract / native).

◆ annotations()

std::vector< Annotation > dex::Method::annotations ( ) const

Annotations attached to this method, resolved.

Parsed on demand.

◆ operator==()

bool dex::Method::operator== ( const Method &  ) const
default

Two handles are equal when they come from the same analysis (one AnalysisContext, or copies of it) and point at the same method of the same DEX file.

Handles from two contexts that loaded the same file are not equal. std::hash<Method> is consistent with it.

Friends And Related Symbol Documentation

◆ std::hash< Method >

friend struct std::hash< Method >
friend

◆ Class

friend class Class
friend

◆ CallGraph

friend class CallGraph
friend

◆ Xrefs

friend class Xrefs
friend

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