How kimcrowing/iptv works
Project Type and Purpose
• This is a Kotlin-based, Gradle-built library (“ReVanced Patcher”) whose sole responsibility is to patch Android APKs.
• There is no UI layer here—this is a headless engine that powers other tools (CLI, Manager, Library) by exposing a modular patching API.
File‐Structure Analysis
• Top-Level:
• api/ – API descriptor for publishing
• docs/ & README.md – extensive user and developer docs
• src/main/kotlin/app/revanced/patcher – core engine code
• src/main/resources – version properties
• src/test/kotlin – unit tests
• Within src/main/kotlin/app/revanced/patcher:
• Patcher.kt, PatcherConfig.kt, PatcherContext.kt, PatcherResult.kt – façade and orchestration
• Fingerprint.kt, InternalApi.kt, PackageMetadata.kt – APK introspection & loading
• patch/ – core Patch abstraction, contexts (BytecodePatchContext, ResourcePatchContext)
• extensions/ – patch-writing helpers
• util/ – pure utilities (ClassMerger, MethodNavigator, ProxyClassList)
• util/proxy/* – mutable type proxies to build or transform class structures
• util/smali – InlineSmaliCompiler, label support for injecting smali
Key Insights from README
• Core features: disassemble/assemble Dalvik bytecode, decode/build APK resources, read/write arbitrary files.
• Modular patch API: each patch is a self-contained unit that targets bytecode, resources, or files.
• Designed for extensibility: new patches live in the “patch” package and plug into the engine.
Components
a. Main Components
• Consumer (ReVanced‐CLI, ReVanced‐Manager, other host)
• Patcher API (Patcher, PatcherConfig)
• APK Loader & Fingerprinter (InternalApi, Fingerprint, PackageMetadata)
• Patch Manager (loads Patch implementations, Option models)
• Bytecode Engine (BytecodePatchContext + InlineSmaliCompiler)
• Resource Engine (ResourcePatchContext + APK resource decoder/encoder)
• File Patcher (arbitrary file read/write from APK)
• Utility Modules (ClassMerger, MethodNavigator, ProxyClassList & proxies)
• Output Writer (rebuild APK, emit PatcherResult)
b. Relationships & Data Flow
1. Consumer → Patcher API: supply APK path & PatcherConfig
2. Patcher API → APK Loader: load metadata, compute fingerprint
3. Patcher API → Patch Manager: enumerate enabled patches
4. For each Patch:
– Bytecode patches go through Bytecode Engine
– Resource patches go through Resource Engine
– File patches go through File Patcher
– All use Utility Modules as needed
5. Engines emit transformed artifacts back to PatcherContext
6. Patcher API → Output Writer: rebuild patched APK & produce PatcherResult
c. Architectural Patterns & Principles
• Modular Plugin Pattern: patches implement a common Patch interface and register themselves via internal API.
• Facade: Patcher.kt hides complex engine details behind a simple entry point.
• Builder/Configurator: PatcherConfig encapsulates all options for enabling/disabling patches or engines.
• Layered Design: clear separation between API layer, core orchestration, engine implementations, and low-level utilities.
d. Key Technologies & Frameworks
• Kotlin & Gradle/Kotlin DSL
• smali/baksmali integration (InlineSmaliCompiler)
• APK resource decoder/encoder (aapt2 or third-party libs, implied)
• JUnit & Kotlin test libraries for unit tests