Shared library modules under lib/
Overview
The lib/ tree contains reusable Android/Kotlin extension libraries rather than source-specific code. Most modules expose either a small helper API that an extension calls while building Page objects, an OkHttp Interceptor that rewrites synthetic image URLs into displayable responses, or both. Reader libraries such as lib/speedbinb, lib/publus, lib/clipstudioreader, and lib/e4p follow a common pattern: fetch a vendor manifest/configuration, encode per-page decode state into the image URL fragment, then require the extension's OkHttpClient to include the matching interceptor so the image response is descrambled or decrypted at load time.
Networking support is centered on lib/cronet and lib/cronetruntime. lib/…/Cronet.kt adds OkHttpClient.Builder.cronet(), which swaps OkHttp's network call for a Cronet-backed one only when running on Android and only when the client has not customized TLS, proxy, DNS-affecting settings, or authentication that Cronet cannot honor. lib/…/RuntimeLoader.kt loads a generated assets/cronet-runtime.apk into a process-wide DexClassLoader; that asset is produced by lib/…/build.gradle.kts from the separate application module lib/cronetruntime. The runtime entry point lib/…/CronetRuntime.java prefers platform HttpEngine, falls back to Play Services Cronet, and exposes an OkHttp Interceptor implemented by lib/…/CronetServer.java.
Utility modules provide self-contained primitives used by extensions when a site exposes custom encodings. lib/aessiv implements AES-SIV and AES-GCM-SIV decryption. lib/ece implements RFC 8188 aes128gcm payload decryption, HKDF, and raw P-256 public-key conversion. lib/secretstream ports libsodium-style XChaCha20-Poly1305 secretstream pull support plus a BigInteger X25519 helper. lib/lzstring reimplements lz-string Base64 compression/decompression, lib/unpacker unpacks Dean Edwards packer-compressed JavaScript, and lib/synchrony runs the bundled Synchrony JavaScript deobfuscator through QuickJS.
Image and text adapters bridge nonstandard page payloads into images the host app can render. lib/…/DataImageInterceptor.kt turns data:image attributes into loopback fake URLs and serves decoded bytes. lib/…/TextInterceptor.kt renders title/body text URLs generated by TextInterceptorHelper.createUrl() into PNG pages, with optional APK-bundled fallback fonts. lib/…/ImageDecoder.kt chooses between Mihon, Tachiyomi, and Android decoders at runtime, dropping unavailable host decoders after linkage failures.
Library catalog
- lib/…/AesSiv.kt decrypts RFC 5297 AES-SIV ciphertexts in
tag || ciphertextformat with one or more AAD byte arrays. lib/…/AesGcmSiv.kt decrypts RFC 8452 AES-GCM-SIVciphertext || tagpayloads using AES-ECB blocks because Android only exposesAES/GCM-SIV/NoPaddingon newer APIs. - lib/…/ClipStudioReader.kt extracts pages from Clip Studio Reader comic and EPUB viewers. For comics it obtains a time key, face XML, page XML URLs, grid dimensions, spread halves, and fragments beginning with
csr-page; for EPUBs it fetches viewer API config, a bearer token, OPF image entries, optional XOR image key, and fragments beginning withcsr-epub. lib/…/ClipStudioReaderInterceptor.kt consumes those fragments, sets required referer/bearer headers, unscrambles comic grids, crops spread halves, and XOR-deobfuscates EPUB image headers when needed. DTOs are in lib/…/ClipStudioReaderDto.kt. lib/cronetprovides the extension-facing OkHttp integration. Cronet.kt rebuilds the remaining interceptor chain around CronetChain.kt, injects aTransportProtocol(Protocol.HTTP_2)tag, handles redirects/retries through FollowUpInterceptor.kt, and exposesResponse.isCronet. RuntimeLoader.kt is responsible for process-wide dynamic loading of the runtime APK asset.lib/cronetruntimeis the embedded runtime APK shipped bylib/cronet. CronetRuntime.java selects and initializes the actual Cronet engine; CronetServer.java adapts Cronet's asyncUrlRequestAPI to OkHttp responses, upload bodies, timeouts, cancellation, response headers, decoded-content handling, and streamingResponseBodyreads. Theorg/chromium/net/*files are the API surface used by Play Services/HttpEngine Cronet.- lib/…/DataImageInterceptor.kt exposes Jsoup
Element.dataImageAsUrl()anddataImageAsUrlOrNull()helpers and an interceptor for fakehttps://127.0.0.1/?image...URLs. It decodes Base64 or raw data URI payloads and returns an image response. lib/e4psupports E4P/QSC manifests and XEBP image decryption. E4PManifestReader.kt reads encrypted or plain protobuf manifests, picks the highest-height image variant, preserves auth query parameters, and embeds XEBP decryption data in URL fragments. E4PInterceptor.kt reads the QSC directory via an HTTP Range request, fetches the selected file range, strips plain XEBP containers to WebP, or calls XebpDecoder.kt when fragment decryption context is present. E4PDecoder.kt unwraps TDRM/CDRM manifest wrappers with RC4, custom Blowfish, Blake2-derived keys, and ChaCha8; TiffDecoder.kt decodes the TIFF patch image used by XebpDecoder.kt; protobuf DTOs live in E4PManifestDto.kt.- lib/…/Ece.kt decrypts RFC 8188
aes128gcmencrypted content, exposes HKDF, and converts P-256 public keys between JavaECPublicKeyand raw uncompressed0x04 || X || Yform while checking curve membership. - lib/…/Intl.kt loads UTF-8
.propertiesbundles fromassets/i18n/messages_<language>.properties, chooses a requested language only if present in the supplied set, falls back to the base language per key, exposes locale-aware formatting, and provides a locale collator/display-name helper. - lib/…/ImageDecoder.kt decodes image bytes through host-provided Mihon or Tachiyomi decoders before falling back to
BitmapFactory. It catchesLinkageErrorand removes decoders that the current host app does not ship. - lib/…/LZString.kt implements
compressToBase64()anddecompressFromBase64()compatible with the JavaScriptlz-stringlibrary. lib/publusparses Publus configurations and performs image filename generation/auth/unscrambling. PublusPages.kt fetches configuration_pack.json, decrypts packed config data throughDecoderin Publus.kt, builds image URLs throughPublusImage.generateFilename(), and stores page decode state in a JSON fragment. PublusInterceptor.kt parses that fragment and usesPublusImage.unscramble()orunscrambleNoKeys()to rebuild JPEG pages. PublusAuth.kt models CloudFront/book auth query parameters and caches per-chapter auth with refresh support. DTOs and fragment parsing are in PublusDto.kt.lib/secretstreamcontains Java ports of ChaCha20, Poly1305, Core HChaCha20,State, andSecretStreampull-mode decryption derived from libsodium, plus X25519.kt for one-shot shared-secret derivation.SecretStream.pull()verifies Poly1305 tags, decrypts chunks, updates/rekeys stream state, and returns a message/tag pair.lib/speedbinbsupports SpeedBinb/PTBinB readers. SpeedBinbReader.kt extracts page lists from reader HTML or thebibGetCntntInfoAPI, decodes scramble tables via Crypto.kt, constructs image URLs for Direct/REST/SBC servers, and storesptbinbkey pairs in URL fragments. SpeedBinbInterceptor.kt routes synthetic text pages throughTextInterceptor, fetches .ptimg.json metadata images, selectsPtImgDescrambler,PtBinbDescramblerA, orPtBinbDescramblerF, and recompresses descrambled bitmaps as JPEG. DTOs are in Models.kt, and the shared bitmap move logic is in descrambler/SpeedBinbDescrambler.kt.- lib/…/Deobfuscator.kt loads assets/synchrony-v2.4.5.1.js, rewrites its ESM export into globals QuickJS can evaluate, JSON-quotes the source script, and returns Synchrony's deobfuscated JavaScript source.
- lib/…/TextInterceptor.kt serves generated
http://tachiyomi-lib-textinterceptor/<title>/<body>URLs as rendered PNG pages. It uses Android text layout/canvas APIs, HTML entity cleanup, and optional per-character fallback font spans. - lib/…/Unpacker.kt expands Dean Edwards packer output by extracting the packed data/dictionary and replacing radix-62 tokens. SubstringExtractor.kt is its cursor-style delimiter helper.
Notable APIs and flows
- Cronet request flow: an extension adds
OkHttpClient.Builder.cronet()from lib/…/Cronet.kt. The interceptor loadsCronetRuntime.server(Context)from the runtime APK, checks for unsupported client settings, reconstructs OkHttp's bridge/cache/network interceptors, and ends the chain withCronetServer. CronetServer.java turns a single OkHttp request into a CronetUrlRequest, copies allowed headers, buffers upload bodies, maps RFC 9218 Priority to Cronet priorities, waits for response headers with OkHttp timeout/cancellation semantics, and exposes body reads through an OkioSource. - Fragment-driven image post-processing: ClipStudioReader.kt, SpeedBinbReader.kt, PublusPages.kt, and E4PManifestReader.kt all embed decode parameters in URL fragments rather than external state. Their interceptors (ClipStudioReaderInterceptor.kt, SpeedBinbInterceptor.kt, PublusInterceptor.kt, E4PInterceptor.kt) parse those fragments after the network response and return a normal image response to the app. If an extension calls the page-fetch helper but forgets to install the corresponding interceptor, the app will request the raw vendor URL and see scrambled, encrypted, or XML/JSON payloads.
- Synthetic page URLs: DataImageInterceptor.kt and TextInterceptor.kt intentionally create non-site URLs that OkHttp can route through an interceptor.
dataImageAsUrl()useshttps://127.0.0.1/?...for data URIs, whileTextInterceptorHelper.createUrl()uses the fixed hosttachiyomi-lib-textinterceptor. These URLs are not intended to reach the network. - E4P/XEBP page flow: E4PManifestReader.kt fetches an E4P ticket/protobuf manifest, E4PDecoder.kt decrypts/decompresses it, and the reader appends a fragment containing the QSC entry name plus optional XEBP IV/content/consumer/PBEX seed. E4PInterceptor.kt uses the fragment entry name to range-read the file out of the QSC archive and calls XebpDecoder.kt to decrypt a TIFF watermark patch and composite it over the VP8 WebP base image.
- Publus auth and fragment flow:
PublusAuthInfo.toAuth()converts API auth blocks into query parameters;PublusAuthHandlercan refresh stale signed auth during a reading session.fetchPages()stores page attributes, keys, and optional sessionextrainPublusFragment, whilePublusInterceptorreads that fragment to decide whether and how to unscramble.
Coupling
- If lib/…/CronetRuntime.java changes the signature or behavior of
server(Context), also bumpKEYin lib/…/RuntimeLoader.kt; otherwise an already-loaded class loader may serve an incompatible runtime class for the process. - If the Gradle asset wiring in lib/…/build.gradle.kts or the consumable APK configuration in lib/…/build.gradle.kts changes, verify RuntimeLoader.kt can still find
assets/cronet-runtime.apk; the Cronet extension API degrades silently to OkHttp when the runtime asset cannot be loaded. - If page fragment formats change in lib/…/ClipStudioReader.kt, lib/…/SpeedBinbReader.kt, lib/…/PublusPages.kt, or lib/…/E4PManifestReader.kt, update the matching interceptor parser in the same module at the same time; these are string/JSON fragments with no shared schema enforcement beyond the DTOs they manually parse.
- If lib/…/SpeedBinbInterceptor.kt changes its handling of text pages, verify lib/…/build.gradle.kts still depends on
:lib:textinterceptorand that SpeedBinbReader.kt still usesTextInterceptorHelper.createUrl()for purchase-link pages. - If lib/…/Intl.kt is reused by a new extension, ensure the extension packages its bundles at
assets/i18n/messages_<snake_case_language>.propertiesor passes a custom filename factory; missing bundles are loaded throughclassLoader.getResourceAsStream()and fail at runtime. - If host image decoder dependencies move or are renamed, update lib/…/ImageDecoder.kt; it imports both Mihon and Tachiyomi decoder classes directly and only handles absence at linkage time.
Risks
- lib/…/Cronet.kt reflectively constructs OkHttp internal
BridgeInterceptorandCacheInterceptorclasses. If OkHttp changes those class names or constructor shapes, Cronet requests fall back to normal OkHttp, and only the once-per-message log in Cronet.kt shows why. - lib/…/CronetServer.java buffers the entire request body into memory before installing a Cronet
UploadDataProvider. Large uploads through a Cronet-enabled client can increase memory pressure even though response bodies are streamed. - lib/…/E4PDecoder.kt, lib/…/XebpDecoder.kt, and lib/…/TiffDecoder.kt encode reverse-engineered DRM/container constants and binary layout assumptions. A site-side update to E4P ticket types, XEBP chunks, PBEX seeds, or TIFF patch format will fail as manifest decode errors, QSC lookup errors, or corrupted image output.
- lib/…/SpeedBinbReader.kt explicitly works around Jsoup behavior by parsing only the first
<t-case>because malformed TTX can nest fallbacks after 128 pages. Changes to that parsing can drop pages or include fallback markup as pages. - lib/…/X25519.kt states that its BigInteger scalar multiplication is not constant-time. It is intended for fresh one-shot private scalars only; reusing long-lived private keys through this helper would expose timing-risky key material.