entinyGramAndroid patchset

#Source map

Where the code lives, and where to read it when these pages are not enough. The plugin system is open source in three places: the SDK and the plugins in one repository, the app side in the entinyGram client, and the original engine upstream in Inugram.

#The three repositories

RepositoryWhat is in it
entinyGram/pluginsthe SDK (typings, command line tool, @entiny/sdk), the official plugins, the catalog and the build scripts
entaytion/entinyGramthe entinyGram client: the patchset and the Kotlin code that hosts plugins inside the app
teidesu/inugramInugram, the project entinyGram is built on. The plugin engine, the API and the original docs come from here

#The plugins repository

Everything a plugin author touches is in entinyGram/plugins.

#sdk/types: the typings

sdk/types is the package @inugram/plugin-types. It is the most important thing to read: every call is documented there, with its grant, its limits and whether it is experimental.

FileContents
common.d.tsthe core of the API: inu, accounts, messages, inu.ui, inu.icons, inu.utils, interceptors
android.d.tsinu.android: the current screen, bundles, native views
android.jvm.d.tsinu.jvm: reflection, handles, defineClass, routines
android.xposed.d.tsinu.xposed: hooks
android.notification-center.d.tsthe app's internal event bus (unsafe.notificationCenter)
android.tl.d.tsevery Telegram TL type, method and update
canvas.d.tsinu.canvas
fs.d.tsinu.fs
dom.d.tsthe web-like globals: fetch, Blob, localStorage, timers
grants.jsonthe grant catalogue: every permission, its scopes and its level
grants.d.tsthe same grants as types
tl-names.txtthe names of TL methods and updates a grant scope can use

#sdk/cli: the inu command line tool

sdk/cli is @inugram/cli. Read it to see exactly what a command does.

PathContents
src/commandsone file per command: build, check, dev, eval, init, list, push, remove, verify
src/utils/config.tsthe inu.config.ts schema and how it is loaded
src/utils/manifest.tsthe manifest schema, how the header is written, and the grant validation
src/utils/device.tshow the tool talks to the phone over adb
src/routinesthe routine compiler: finding calls, captures, bytecode
src/templatesthe starter project inu init creates

#sdk/docs: the original guides

sdk/docs holds the plugin guides as they come from Inugram: getting started, engine, grants, ui, telegram, interception, io, canvas, jvm, xposed and routines. The pages you are reading explain the same ideas, with entinyGram's additions.

#sdk/entiny: @entiny/sdk

sdk/entiny is the package a plugin imports to use the entinyGram SDK.

PathContents
src/index.tswithEntiny, the @requires rule, the placement types, SDK_VERSION
src/embed.tsthe embed function and its row types, the contract with the SDK plugin
src/slots.tsthe typed list of places a setting can go
slots.jsonthe same list as data: every screen, section, item and picker
README.mdshort notes on placement

#plugins: the official plugins

plugins/ has one folder per plugin, each with an inu.config.ts and a src. They are the best examples of real code: see Worked examples.

The SDK plugin is in plugins/entiny-sdk/src:

FileContents
index.tsthe Marketplace pages: Home, Plugins, Settings, the plugin page, install
channel.tsreading a Telegram channel as a catalog, and the post parser
sources.tsthe list of sources and what is stored about them
catalog.tsthe catalog types, and how a channel file is addressed
navbar.tsthe native bottom bar
embed/engine.tsthe engine that draws other plugins' rows into the app's screens
iconsthe tab icons, plain SVG files
i18n.tsthe texts, in English, Ukrainian and Russian

#The catalog and the scripts

PathContents
index.jsonthe catalog the Marketplace reads for official plugins
plugins/distevery published version of every official plugin, never changed once published
user-pluginsthe second GitHub catalog, for community bundles
scripts/build-plugin-index.tsbuilds the plugins, hashes them and refreshes the catalog
scripts/build-user-index.tsthe same for community bundles
scripts/pack-release.tspacks named release files
scripts/generate-slots.tsregenerates the slot list from the app's strings

#The client

The plugin host inside the app is Kotlin, in src/fork of the client repository. Read it when you want to know what happens on the other side of a call.

PathContents
helpers/pluginsthe host: loading, permissions, sessions, the Telegram and JVM bridges, icons and UI
helpers/plugins/PluginManager.ktinstalling, enabling, updating and the dependency checks
helpers/plugins/PluginImportHelper.ktthe import and permission sheet
helpers/plugins/ui/PluginUi.kthow declarative pages become native screens
helpers/entiny/EntinyMarketBridge.ktthe small bridge the Marketplace uses to list and install plugins
ui/settings/PluginsActivity.ktthe plugin list in the settings
ui/settings/PluginSettingsActivity.ktthe generic host of a plugin's settings page

The user facing list of what entinyGram adds is FEATURES.md.

#Inugram upstream

The plugin engine, the inu API and the command line tool were written in Inugram. Its sdk folder holds the same three parts you saw above: cli, docs and types.

#Finding what to hook

When you hook the app, you need the name of a class and a method. The app is Telegram for Android with a patchset, so almost every class has the stock name:

  1. Read the original source: DrKLO/Telegram. The classes you will see most are AndroidUtilities, LocaleController, MessagesController, ChatActivity, DialogCell and ChatMessageCell.
  2. For the entinyGram and Inugram classes, such as desu.inugram.InuConfig, read the client repository above.
  3. To see the exact names and signatures in the build you target, decompile the APK with jadx.
  4. Hook a method with its descriptor, such as formapMapUrl(IDDIIZII)Ljava/lang/String;, so the right overload is chosen. See Method hooks.

#Other references