How frida/frida-gum works
Project type and purpose
• Type: Open-source C library (instrumentation & introspection).
• Purpose: Provide cross-platform inline hooking (Interceptor), code tracing (Stalker), memory monitoring, process/module introspection, code generation/relocation, plus helper libs for heap tracking & profiling.
• Consumers: frida-core (via GumJS), standalone C/C++ projects (via devkit), language bindings.
File structure
• Top-level “gum/”: Core C API (gum.c, guminterceptor.h, gumstalker.h, etc.).
• “gum/arch-*” & “gum/backend-*”: Architecture-specific code generators & interceptors (x86, ARM, MIPS, ARM64).
• “bindings/gumjs/”: JavaScript runtime binding layer (QuickJS, V8).
• “libs/gum/heap” & “libs/gum/prof”: Helper libraries for heap instrumentation & profiling.
• “ext/” & “subprojects/”: External dependencies (libffi, V8, QuickJS, OpenSSL, etc.) managed by Meson.
• “tests/”: Comprehensive test suites for core, arch, heap, prof, gumjs, gumpp.
• “tools/”: Utility scripts for versioning, grafting, symbolication.
README for architecture clues
• Core capabilities listed under “Provides:” section.
• Links to individual components (Interceptor, Stalker, MemoryAccessMonitor).
• Mentions devkit for static linking, out-of-process dynamic linker (Darwin).
• Highlights codegen & relocation modules per architecture.
a. Main components
• Core C API: gum.c / gum.h – provides public hooks (Interceptor, Stalker, MemoryAccessMonitor, introspection APIs).
• Arch-specific modules: arch-*/ backends produce machine code generators, relocators, readers, writers.
• Platform backends: backend-linux, backend-windows, backend-darwin, etc. – implement process, memory, symbol lookups per OS.
• Devkit: static library release for consumer integration.
• JS Bindings: bindings/gumjs – exposes C API to JS runtimes (QuickJS, V8).
• Helper libs: libs/gum/heap (allocation tracking), libs/gum/prof (profilers).
• External deps: subprojects (QuickJS, V8, libffi, SQLite, Capstone).
• Tests & Tools: validation & utility layers.
b. Relationships & interactions
• Core C API calls into arch-modules and platform backends via well-defined headers.
• JS Binding Layer invokes Core C API through generate-bindings.py runtime wrappers.
• Helper libs consume Core instrumentation hooks (e.g., Stalker events) to track allocations or sample performance.
• Tests drive the Core API, arch backends and helper libs, verifying behavior on each architecture and OS.
• Build system (Meson/Makefile) orchestrates compilation of core, subprojects, tests and bindings.
c. Architectural patterns & design principles
• Plugin-style: arch and backend modules register themselves at runtime.
• Layered: Core API → Architecture codegen/relocation → Platform abstraction → Consumer bindings.
• Extensible: New architectures or OS backends can be added under gum/arch-* or gum/backend-*.
• Build isolation: Subprojects embedded via Meson wraps, enabling reproducible builds.
d. Key technologies
• Language: C99, C++ (in some modules & bindings).
• Build: Meson, Ninja, Make.
• JS engines: QuickJS, V8.
• Subproject management: Meson wraps.
• Testing: C fixtures, Python scripts, shell runners.