How revanced/revanced-patcher works
1. Repository purpose and role
ReVanced Patcher is a Kotlin library, not an application. Its job is to provide a reusable patching engine for Android APKs, especially Android bytecode and resources. Other ReVanced projects consume it as a dependency, so this repo defines the core patching architecture rather than an end-user workflow.
2. Top-level structure
The repo is centered around a single Kotlin Multiplatform module under patcher/, with shared logic in commonMain and platform-specific code in jvmMain and androidMain. The root Gradle build config and version catalog manage dependency resolution, publication, and test/build execution.
3. Core patching API boundary
The main public surface lives in app.revanced.patcher. Key concepts are Patch, Option, Patching, Matching, and Fingerprint. This is the abstraction layer patch authors use to describe what should be modified and how to locate targets inside an app package.
4. Patch execution contexts
The patching model is split by target type. BytecodePatchContext handles Dalvik/DEX bytecode mutations, while ResourcePatchContext covers Android resource changes. This separation is an important architectural boundary because bytecode and resource patching have different inputs, outputs, and mutation rules.
5. Bytecode and Smali manipulation layer
The repo includes a large set of mutable Dexlib2-backed types under com.android.tools.smali.dexlib2.mutable and ...iface.value. These classes form the low-level mutable model for classes, methods, fields, annotations, and encoded values. This is the layer that actually represents and edits Android bytecode structures before they are written back out.
6. Matching and fingerprinting subsystem
Fingerprint and Matching provide the discovery mechanism used to identify methods/classes to patch. Instead of hard-coding offsets or names, patches can locate targets through structural patterns. That makes the patching engine resilient to app version changes and is a core architectural feature.
7. Utility and navigation helpers
MethodNavigator, ClassMerger, Document, and the extensions/ package support higher-level patch authoring and bytecode traversal. These helpers sit between the public patch API and the mutable Dex model, reducing the amount of low-level bytecode handling patch authors need to perform directly.
8. Proxy and adapter layer
The util/proxy and mutableTypes packages are adaptation layers that map API-facing abstractions to the mutable Dexlib2 model. This suggests the architecture is designed to isolate consumers from implementation details and keep the public API stable even if underlying bytecode representations change.
9. Common vs platform-specific implementations
The commonMain source set contains most of the library logic, while jvmMain and androidMain provide platform-specific replacements for types like File, MutableMap, and Patch. This is a classic multiplatform boundary: shared patching logic is reused everywhere, but filesystem/runtime details are adapted per target environment.
10. Testing strategy
Tests are concentrated in jvmTest, which indicates the library’s behavior is validated on the JVM rather than on-device Android runtime. The tests cover matching, patch behavior, extension utilities, options, and smali helpers, so the repository’s confidence boundary is around patch computation and bytecode model operations.
11. Documentation as part of the architecture
The docs/ directory is substantial and split into setup, patcher intro, patch anatomy, matching, patch structure, and APIs. That suggests the repository is designed around a documented extension model, where the docs are effectively part of the developer-facing architecture for writing patches safely.
12. Release and distribution pipeline
GitHub Actions workflows handle pull request validation, release publishing, and documentation updates. Since the library is meant to be consumed via Gradle coordinates, the CI/release pipeline is part of the delivery architecture: it builds the library, validates changes, and publishes versioned artifacts for downstream ReVanced projects.
Main entry points: build.gradle.kts Patcher module · revanced/patcher JVM tests · revanced/patcher Patch API · workflows CI & release
Components 17
Repository
Build, docs, release, and module orchestration at the repository root.
- Gradle build · Root Gradle configuration and version catalog for dependency and publication management.
build.gradle.kts - Settings · Repository-level Gradle settings and module wiring.
settings.gradle.kts - Patcher module · Single Kotlin Multiplatform library module that exposes the patching engine.
patcher/build.gradle.kts
Shared library
Kotlin Multiplatform code shared across runtimes.
- Patch API · Core patching abstractions: Patch, Option, Patching, Matching, and Fingerprint.
patcher/src/commonMain/kotlin/app/revanced/patcher - Patch contexts · Bytecode and resource patch contexts that separate mutation by target type.
patcher/src/commonMain/kotlin/app/revanced/patcher/patch - Fingerprinting · Structural matching system used to locate app targets without hard-coded offsets.
patcher/src/commonMain/kotlin/app/revanced/patcher/Fingerprint.kt - Bytecode helpers · Method navigation, class merging, document handling, and instruction extensions for patch authors.
patcher/src/commonMain/kotlin/app/revanced/patcher/util - Proxy layer · Adapts API-facing abstractions to mutable Dexlib2-backed types.
patcher/src/commonMain/kotlin/app/revanced/patcher/util/proxy - Mutable Dex model · Mutable class, method, field, annotation, and encoded-value types for Android bytecode editing.
patcher/src/commonMain/kotlin/app/revanced/com/android/tools/smali/dexlib2/mutable - Value model · Mutable encoded-value interfaces and implementations used by the Dex mutation layer.
patcher/src/commonMain/kotlin/app/revanced/com/android/tools/smali/dexlib2/iface/value - Smali tools · Smali-focused utilities and extensions for inspecting and transforming instructions.
patcher/src/commonMain/kotlin/app/revanced/patcher/util/smali - Common helpers · Shared multiplatform wrappers such as File and MutableMap abstractions.
patcher/src/commonMain/kotlin/app/revanced
Platform code
Runtime-specific implementations for JVM and Android.
- JVM impl · JVM-specific replacements for File, MutableMap, and Patch behavior.
patcher/src/jvmMain/kotlin/app/revanced - Android impl · Android-specific replacements for File, MutableMap, and Patch behavior.
patcher/src/androidMain/kotlin/app/revanced
Validation and delivery
Tests, documentation, and CI/release workflows.
- JVM tests · Behavioral tests for matching, patch execution, extensions, options, and smali helpers.
patcher/src/jvmTest/kotlin/app/revanced/patcher - Docs · Guide and API documentation for patch authors and library users.
docs - CI & release · GitHub Actions workflows for validation, release publishing, and documentation updates.
.github/workflows
Connections 19
- Gradle build → Patcher module: configures · Root Gradle build configures the library module.
- Settings → Patcher module: includes · Settings wire the module into the build.
- Patcher module → Patch API: exposes · The module exports the public patching surface.
- Patcher module → Patch contexts: contains · The module defines execution contexts for patching.
- Patcher module → Fingerprinting: contains · The module provides structural target discovery.
- Patcher module → Bytecode helpers: contains · The module includes helper utilities for patch authors.
- Patcher module → Proxy layer: contains · The module adapts public abstractions to mutable internals.
- Patcher module → Mutable Dex model: uses · Bytecode patching operates on the mutable Dex model.
- Patcher module → Value model: uses · Mutable Dex structures depend on encoded-value definitions.
- Patcher module → Smali tools: contains · The module includes smali-oriented utilities.
- Patcher module → Common helpers: contains · Shared Kotlin helpers live in the common source set.
- JVM impl → Patcher module: implements · JVM-specific source set fulfills shared patcher contracts.
- Android impl → Patcher module: implements · Android-specific source set fulfills shared patcher contracts.
- JVM tests → Patch API: verifies · Tests cover the public patching API.
- JVM tests → Fingerprinting: verifies · Tests validate matching and fingerprint behavior.
- JVM tests → Bytecode helpers: verifies · Tests cover extension and smali helper behavior.
- Docs → Patch API: documents · Documentation explains the patching API and patch anatomy.
- CI & release → Patcher module: builds · Workflows validate and publish the library artifacts.
- CI & release → Docs: updates · A workflow keeps documentation in sync.