# mustime/adrill architecture

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

- Interactive diagram: https://gitdiagram.com/mustime/adrill
- Repository: https://github.com/mustime/adrill

## Overview

##### Main Components
- Main Executable:
- Represented by source/main.cc. This is the entry point of the application where command-line arguments are parsed (options like --pid, --pname, and --libpath).
- It directs the flow, triggering the injection process.
- Injection Core:
- Found in files like source/call_procedure.cc/h, which likely encapsulate the injection logic.
- This component will orchestrate the injection sequence.
- Architecture-Specific Backends:
- Located in source/backend with subdirectories arm, arm64, x64, and x86.
- Each backend (e.g., call_procedure-arm.cc, call_procedure-x86.cc) implements architecture-specific procedures for function calls or memory operations.
- Ptrace Interface:
- Implemented in source/ptrace_wrapper.cc/h.
- Responsible for interfacing with the operating system to attach and control target processes.
- Dynamic Linking and ELF Handling:
- Handled by source/elf_dlfcn.cc/h.
- This module manages ELF file interactions and dynamic loading necessary for injection.
- Utility and Support Modules:
- File utilities in file_utils.cc/h.
- Logging via logger.h and macros for internal debugging.
- Other supportive code modules like sdk_code.cc/h and selinux.cc/h for additional control and error handling.
- Configuration:
- The file config.h.in shows that some configurable parameters are provided—these might affect how the injection is set up.

##### Diagramming the Component Relationships
- Entry Point (main executable): Mark this as the starting node.
▸ The Injection Core (calling into call_procedure).
▸ The Ptrace Interface: This component is essential for process control.
- Beneath the Injection Core, expand to show:
- A branch for Architecture-Specific Backends:
- A connection from these backends to the “Dynamic Linking/ELF Handling” module, emphasizing that injection involves manipulation of library loading.
- Incorporate Utility Functions:
- External Interactions:
- You might also label a note or external dependency: “Requires Root Privilege” for execution, which is crucial context.

##### Architectural Patterns and Design Principles
- Abstraction: The main injection logic is abstracted away from low-level operations (ptrace, ELF handling), meaning each component should be drawn so that responsibilities are clearly segmented.
- Extensibility: The use of separate directories for each backend architecture highlights an extensible design to support additional architectures if needed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Adrill Injector"
        MA["Main Application (main.cc)"]:::core
        IC["Injection Core (call_procedure.cc)"]:::core
        PI["Ptrace Interface (ptrace_wrapper.cc)"]:::core

        MA -->|"triggers"| IC
        MA -->|"attaches"| PI

        subgraph "Architecture-Specific Backends"
            ARM["Backend - ARM (call_procedure-arm.cc)"]:::backend
            ARM64["Backend - ARM64 (call_procedure-arm64.cc)"]:::backend
            X86["Backend - x86 (call_procedure-x86.cc)"]:::backend
            X64["Backend - x86_64 (call_procedure-x64.cc)"]:::backend
        end

        IC -->|"delegates"| ARM
        IC -->|"delegates"| ARM64
        IC -->|"delegates"| X86
        IC -->|"delegates"| X64

        dynamic["Dynamic Linking/ELF Handling (elf_dlfcn.cc)"]:::core
        ARM -->|"utilizes"| dynamic
        ARM64 -->|"utilizes"| dynamic
        X86 -->|"utilizes"| dynamic
        X64 -->|"utilizes"| dynamic

        fileUtil["File Utilities (file_utils.cc)"]:::util
        log["Logging (logger.h)"]:::util
        sdk["SDK Support (sdk_code.cc)"]:::util
        selinux["SELinux Handling (selinux.cc)"]:::util
        config["Configuration (config.h.in)"]:::util

        MA ---|"supports"| fileUtil
        IC ---|"logs_via"| log
        IC ---|"uses"| sdk
        IC ---|"handles"| selinux

        PI -->|"attaches_target"| target["Target Android Process"]:::external
        IC -->|"injects_into"| target
    end

    note["Requires Root Privilege"]:::note

    click MA "https://github.com/mustime/adrill/blob/main/source/main.cc"
    click IC "https://github.com/mustime/adrill/blob/main/source/call_procedure.cc"
    click PI "https://github.com/mustime/adrill/blob/main/source/ptrace_wrapper.cc"
    click ARM "https://github.com/mustime/adrill/blob/main/source/backend/arm/call_procedure-arm.cc"
    click ARM64 "https://github.com/mustime/adrill/blob/main/source/backend/arm64/call_procedure-arm64.cc"
    click X86 "https://github.com/mustime/adrill/blob/main/source/backend/x86/call_procedure-x86.cc"
    click X64 "https://github.com/mustime/adrill/blob/main/source/backend/x64/call_procedure-x64.cc"
    click dynamic "https://github.com/mustime/adrill/blob/main/source/elf_dlfcn.cc"
    click fileUtil "https://github.com/mustime/adrill/blob/main/source/file_utils.cc"
    click log "https://github.com/mustime/adrill/blob/main/source/logger.h"
    click config "https://github.com/mustime/adrill/blob/main/source/config.h.in"
    click sdk "https://github.com/mustime/adrill/blob/main/source/sdk_code.cc"
    click selinux "https://github.com/mustime/adrill/blob/main/source/selinux.cc"

    classDef core fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef util fill:#FFFFE0,stroke:#DAA520,stroke-width:2px;
    classDef external fill:#F08080,stroke:#8B0000,stroke-width:2px;
    classDef note fill:#FFFACD,stroke:#BDB76B,stroke-width:2px,stroke-dasharray: 5 5;
```
