Skip to main content

Crate asc_engine

Crate asc_engine 

Source
Expand description

The asc-rs engine: stateless, zero-preprocessing queries against an APK.

  • Engine::get_class_dex inflates the DEX entries in parallel (smallest first) and stops as soon as one defines the requested class.
  • Engine::find_refs runs a reference search over every DEX entry in parallel and streams results back as each DEX completes.
  • Engine::get_class rebuilds a minimal DEX containing only the target class and renders it as smali.
  • Engine::list_classes lists the classes of every DEX entry in order.
  • Engine::manifest_xml decodes the binary AndroidManifest.xml.

Optionally the engine keeps inflated DEX entries in an on-disk cache (shared across processes) and/or an in-memory LRU together with the locator tables built for them, so repeated queries skip inflation and table builds. The disk cache also keeps the locator tables (L2, mapped by later processes instead of rebuilt) and find_refs results (L3); see asc_cache for the tiers. Disk writes happen on a background thread so a query never waits on them; Engine::flush_cache_writes waits for them to land and Engine::close_cache_writes (run on drop) additionally stops queueing new ones.

Re-exports§

pub use asc_arsc;
pub use asc_cache;

Modules§

condition
The condition language of findrefs rules and callgraph endpoints.
config
The user’s configuration of threads, memory and the disk cache: one table of settings (Config::KEYS), each taken from (first wins) a command-line flag, its environment variable, the config file (Config::file_path), or its default. auto defaults follow the machine (Device) and the user’s other busy processes.
hints
What to tell an agent when a lookup comes up empty: that a class belongs to the framework, the classes or members it probably meant, why a search found nothing. Only computed on those paths, so it may scan the APK.
names
Class-name normalisation shared by the CLI and MCP.
text
The text form shared by every tool: one record per line, | between columns, strings quoted and escaped as JSON does (asc_arsc::quote).

Structs§

Application
Busy
Marks this process busy in the user’s process registry while a request (an MCP tool call, a daemon command) runs, so the others split the CPUs with it from its first moment (auto_threads) and take them back as soon as it ends. Nested and concurrent requests count once.
CacheConfig
Cache configuration for an Engine.
CacheStats
Cache activity counters.
CachedEntry
A cached inflated entry.
CallQuery
A call graph query.
CallRow
One line of the tree, in depth-first order.
CallTree
Result of Engine::call_graph.
Claim
One entry’s part in a DexDedup.
ClassHit
A DEX (possibly one logical DEX of a 041 container) that defines a class.
ClassListing
A class definition and the (logical) DEX that defines it.
ClassQuery
Class part of a member query.
ClassSource
Result of a full getclass.
CompiledQuery
A Query with every regular expression it needs compiled up front.
Component
DataSpec
Device
The machine’s memory and CPUs, as the automatic budgets see them.
DexClasses
The classes one logical DEX defines, in class_def order.
DexDedup
Content keys claimed by the entries of one sweep.
Engine
Engine over one APK.
EntryClasses
The classes of one DEX entry: its logical DEXes, or why it could not be read.
FindOptions
Options of Engine::find_refs_opts.
HierarchyQuery
A hierarchy query.
HierarchyRow
One line of the tree, in depth-first order.
HierarchyTree
Result of Engine::hierarchy.
InflateLimits
Caps on what reading an APK may inflate, against zip bombs. The default only rejects what Deflate cannot produce; Limits::guarded is for sweeping untrusted APKs in bulk.
IntentFilter
LogicalDex
One logical DEX of a cached entry with its lazily built locator tables. The tables are shared with the entry that replaces this one once its bytes are remapped from the disk cache (same bytes, so still valid).
ManifestSummary
MatchingMethods
The methods whose code matches each query of a Engine::matching_methods call, and its notes.
MemberQuery
Method or field query: at least one of class / name must be set.
MemoryPolicy
How a memory cache follows the machine: a share of the memory the user’s resident hosts could hold together, split between them.
Permission
PrebuildReport
What Engine::prebuild did.
RefBatch
Results for one DEX, delivered as soon as its search completes.
RefResult
One aggregated reference result: a method and what it references.
RefSite
One instruction behind a RefResult.
RefSummary
Summary of a whole find_refs run.
ResourceRow
One resource matching a Engine::search_resources query.
SearchTarget
An APK opened for a search whose DEX entries are scheduled by the caller, e.g. across many APKs at once (Engine::search_target).
SharedCache
A cache several Engines share, so a process serving many APKs keeps one memory budget (the LRU is keyed by APK) and one disk-writer thread. Engines attached with Engine::with_shared_cache leave queued disk writes alone when dropped; dropping the SharedCache flushes them and stops queueing (as dropping a private engine does).
SmaliOptions
Rendering options.
TextRows
Rows of one DEX entry as text, one per line, each ending in \n: what RefResult::line would print for them, in the same order.

Enums§

CallRoots
Where a call graph starts.
ClassRelation
How a class relates to the target of an Extends / Implements query.
Direction
Which way to walk.
EngineError
FieldAccess
How a Dalvik field instruction uses its referenced field.
Lineage
Which way to walk the hierarchy.
Matched
A constant a RefResult matched.
RefContext
How much code to return with each findrefs row.
ResourceField
What Engine::search_resources matches against.
Threads
Worker threads of a search.

Constants§

DEFAULT_FAN_OUT
Most classes of the program that may define a supertype’s method for a dispatch set to follow the calls naming it (Query::Virtual’s fan_out). An AIDL interface has its Stub, Stub.Proxy, Default and a service or two; an abstract base a handful of subclasses. A functional interface (Runnable, Kotlin’s FunctionN) or a lifecycle callback has hundreds to thousands, and its calls say nothing about which of them runs.
MAPPED_CHARGE_DIVISOR
The memory cache charges file-backed bytes (mapped from the disk cache or the APK) at this fraction of their size, heap bytes in full.

Functions§

archive_of
The archive of a program a DEX of it comes from, by the DEX’s name (app/Tele.apk for app/Tele.apk/classes2.dex, also as a logical DEX ...classes2.dex!classes1.dex); None for a lone archive’s.
auto_threads
Worker threads of a search whose caller fixed none: this machine’s CPUs split between this process and the user’s other busy registered ones (auto_threads_for). Re-read at most once per [THREADS_EVERY], so a sweep follows the others starting and finishing their scans (crate::Threads::wait_turn).
auto_threads_for
[OVERSUBSCRIBE] x cpus workers split evenly between this process and busy_others, at most cpus and at least 2 (where there are 2): a scan on one thread gives up its overlap of inflating one entry while searching another. Up to 4 busy processes each keep every CPU.
available_memory
Bytes of memory available to this process: on Linux MemAvailable, lowered to the headroom left under a cgroup v2 memory.max; on Apple systems the free, speculative and inactive pages. None elsewhere.
compile_rules
Compile every rule; the first invalid one fails them all.
decompile_dex_class
Rebuild descriptor out of buf and disassemble it.
decompile_dex_class_method
decompile_dex_class rendering only method (name(params)ret) when given.
dex_classes
Enumerate the classes of one logical DEX whose descriptor starts with prefix (a descriptor prefix, used as is; None keeps every class). Unreadable class_defs are counted and skipped.
find_refs_in_dex
Run a reference search over one DEX buffer and return structured results.
find_refs_in_dex_opts
find_refs_in_dex with a context.
find_refs_lines
Python AscHandler.findrefs equivalent: formatted lines for one DEX.
parse_id
0x7f0d0001 / 7f0d0001 / @0x7f0d0001.
protection_level_name
android:protectionLevel flags as text (signature|privileged).
results_from_hits
Turn raw hits into display results (grouped per method when aggregate).
total_memory
Physical memory, lowered to a cgroup v2 memory.max. None where it cannot be read.

Type Aliases§

DexBytes
Shared inflated bytes of a DEX (possibly one logical DEX of a container).
Result