# lsposed/corepatch architecture

> Architecture diagram of the GitHub repository lsposed/corepatch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lsposed/corepatch
- Repository: https://github.com/lsposed/corepatch

## Overview

##### Main Components
- Android Module (CorePatch): Represent the compiled APK containing both the UI elements (e.g., SettingsActivity, layouts, resources) and the core patch logic.
- Xposed Framework Integration: Display that the module hooks into the Android runtime through the Xposed Framework. Include the “xposed_init” file (located in app/src/main/assets) which is crucial for ensuring that Xposed knows to load this module.
- Hook Components: Identify individual hook classes (such as CorePatchForQ, CorePatchForR, etc.) which target specific Android versions. They are essentially the heart of the patch logic.
- Support Components: Highlight helper classes (e.g., XposedHelper.java) and common utilities (like ReturnConstant.java) that assist in performing the hooks.
- Configuration & Resources: Include the Android Manifest (defining the module’s integration), layout XML files (for the settings UI), and other resources (localized strings, preferences).
- Build System & CI: Add elements for build configuration (Gradle build scripts, settings.gradle.kts, gradle properties) and CI workflows (.github/workflows) that automate the Android CI builds.

##### Relationships & Interactions
- From the Xposed Framework, indicate the loading of the module through the xposed_init file. Then show the initialization of the main hook component (MainHook.java) which in turn directs to specific patch classes based on Android version.
- SettingsActivity as a UI component that interacts with the hook configuration, allowing the user to control or configure behavior.
- Within the hook classes, highlight the internal interaction with system APIs for signature verification and installation procedures.
- Connections to the Gradle/CI pipeline that builds and tests the module.

##### Architectural Patterns & Design Principles
- Version-Based Separation: Emphasize how the patch logic is separated into different classes for specific Android versions (MVC-like separation within the business logic).
- Modularity & Extensibility: Illustrate how the project is organized in a modular fashion, which makes adding new patches easier and allows for maintainability.
- Clear Separation of Responsibilities: The user interface (settings screen) is clearly separated from the core hook logic that interacts with the system.
- Automated Build/Deployment: Include the role of Gradle scripts and GitHub workflows that automate testing and releases.

##### Relevant Technologies & Libraries
- Android Framework & Gradle Kotlin DSL: Represent the Android application as built with Gradle Kotlin DSL files.
- Xposed Framework: Make clear the dependency and integration with the Xposed Framework that performs bytecode manipulation at runtime.
- Java as the main programming language (indicated by the .java files inside the project).
- CI/CD: Illustrate the use of GitHub Actions for Android CI as seen in the .github/workflows directory.

##### Instructing the Principal Software Engineer
- Incorporate annotations detailing dependencies (e.g., usage of specific Android classes, reliance on Xposed APIs) and any important conditional logic based on Android version.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Runtime Behavior: Xposed Hook Integration
    subgraph "Runtime Behavior: Xposed Hook Integration"
        OS["Android OS"]:::os
        XF["Xposed Framework"]:::framework
        Module["Android Module (CorePatch)"]:::module
        Xinit["xposed_init"]:::init
        MH["MainHook"]:::entry
        
        subgraph "Version-Specific Hooks"
            CPQ["CorePatchForQ"]:::patch
            CPR["CorePatchForR"]:::patch
            CPS["CorePatchForS"]:::patch
            CPT["CorePatchForT"]:::patch
            CPU["CorePatchForU"]:::patch
            CPV["CorePatchForV"]:::patch
        end
        
        subgraph "Support Components"
            XH["XposedHelper"]:::support
            RC["ReturnConstant"]:::support
        end
        
        subgraph "UI Components & Configuration"
            SA["SettingsActivity"]:::ui
            SL["Settings Layout (activity_settings.xml)"]:::ui
            AM["AndroidManifest"]:::ui
            RF["Resource Files"]:::ui
        end
    end

    %% Build & CI Pipeline
    subgraph "Build & CI Pipeline"
        GS["Gradle Build Scripts"]:::build
        CI["CI Workflows"]:::ci
        ModuleBuild["Android Module (CorePatch)"]:::module
    end

    %% Build Pipeline Connections
    GS --> ModuleBuild
    CI --> ModuleBuild
    ModuleBuild --> Xinit

    %% Runtime Flow Connections
    OS --> XF
    XF --> Xinit
    Xinit --> MH
    MH --> CPQ
    MH --> CPR
    MH --> CPS
    MH --> CPT
    MH --> CPU
    MH --> CPV
    SA --> MH

    %% Hook Components use Support Components (representative arrows)
    CPQ --> XH
    CPQ --> RC

    %% Styling
    classDef os fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef framework fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef init fill:#f9844a,stroke:#333,stroke-width:2px;
    classDef entry fill:#577590,stroke:#333,stroke-width:2px;
    classDef patch fill:#277da1,stroke:#fff,stroke-width:2px;
    classDef support fill:#f94144,stroke:#333,stroke-width:2px;
    classDef ui fill:#f3722c,stroke:#333,stroke-width:2px;
    classDef build fill:#43aa8b,stroke:#333,stroke-width:2px;
    classDef ci fill:#90e0ef,stroke:#333,stroke-width:2px;
    classDef module fill:#a9d6e5,stroke:#333,stroke-width:2px;

    %% Click Events
    click ModuleBuild "https://github.com/lsposed/corepatch/tree/main/app/"
    click Xinit "https://github.com/lsposed/corepatch/tree/main/app/src/main/assets/xposed_init"
    click CPQ "https://github.com/lsposed/corepatch/blob/main/app/src/main/java/toolkit/coderstory/CorePatchForQ.java"
    click CPR "https://github.com/lsposed/corepatch/blob/main/app/src/main/java/toolkit/coderstory/CorePatchForR.java"
    click CPS "https://github.com/lsposed/corepatch/blob/main/app/src/main/java/toolkit/coderstory/CorePatchForS.java"
    click CPT "https://github.com/lsposed/corepatch/blob/main/app/src/main/java/toolkit/coderstory/CorePatchForT.java"
    click CPU "https://github.com/lsposed/corepatch/blob/main/app/src/main/java/toolkit/coderstory/CorePatchForU.java"
    click CPV "https://github.com/lsposed/corepatch/blob/main/app/src/main/java/toolkit/coderstory/CorePatchForV.java"
    click MH "https://github.com/lsposed/corepatch/blob/main/app/src/main/java/toolkit/coderstory/MainHook.java"
    click XH "https://github.com/lsposed/corepatch/blob/main/app/src/main/java/toolkit/coderstory/XposedHelper.java"
    click RC "https://github.com/lsposed/corepatch/blob/main/app/src/main/java/toolkit/coderstory/ReturnConstant.java"
    click SA "https://github.com/lsposed/corepatch/blob/main/app/src/main/java/toolkit/coderstory/SettingsActivity.java"
    click SL "https://github.com/lsposed/corepatch/blob/main/app/src/main/res/layout/activity_settings.xml"
    click AM "https://github.com/lsposed/corepatch/blob/main/app/src/main/AndroidManifest.xml"
    click RF "https://github.com/lsposed/corepatch/blob/main/app/src/main/res/values/strings.xml"
    click GS "https://github.com/lsposed/corepatch/blob/main/app/build.gradle.kts"
    click CI "https://github.com/lsposed/corepatch/blob/main/.github/workflows/android.yml"
```
