crextractor 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Vitaly Gashkov <vitalygashkov@vk.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Crextractor
2
+
3
+ Utility for extracting secrets from Crunchyroll mobile app
4
+
5
+ ## Prerequisites
6
+
7
+ - [Node.js](https://nodejs.org/en)
8
+ - [jadx](https://github.com/skylot/jadx)
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm i crextractor
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ #### Library
19
+
20
+ ```js
21
+ import { extractSecrets } from 'crextractor';
22
+
23
+ const { id, secret, encoded, header } = await extractSecrets();
24
+
25
+ // Do something with the extracted secrets
26
+ ```
27
+
28
+ #### Command-line interface
29
+
30
+ ```bash
31
+ npx crextractor
32
+ ```
33
+
34
+ > Results will be printed to the console and saved to `secrets.json` file
35
+
36
+ ## License
37
+
38
+ MIT
package/bin/cli.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { extractSecrets } = require('../crextractor');
4
+
5
+ extractSecrets({ output: 'secrets.json' });
@@ -0,0 +1,10 @@
1
+ export function extractSecrets(): Promise<{
2
+ // Crunchyroll app ID
3
+ id: string;
4
+ // Crunchyroll app secret
5
+ secret: string;
6
+ // Base64 encoded `id:secret` string
7
+ encoded: string;
8
+ // HTTP header with Basic Authorization to access Crunchyroll mobile APIs
9
+ authorization: string;
10
+ }>;
package/crextractor.js ADDED
@@ -0,0 +1,94 @@
1
+ const { execSync } = require('node:child_process');
2
+ const { join } = require('node:path');
3
+ const { readdir, readFile, writeFile, rm } = require('node:fs/promises');
4
+ const { download } = require('molnia');
5
+
6
+ const downloadLatestApk = async () => {
7
+ const source = 'https://apkcombo.com/crunchyroll/com.crunchyroll.crunchyroid/download/apk';
8
+ const page = await fetch(source);
9
+ const html = await page.text();
10
+ const route = '/r2' + html.split('/r2')[1]?.split('"')[0];
11
+ const url = `https://apkcombo.com${route}`;
12
+ const filepath = join(process.cwd(), 'crunchyroll.xapk');
13
+ await download(url, {
14
+ output: filepath,
15
+ onError: (error) => console.error(error),
16
+ });
17
+ return filepath;
18
+ };
19
+
20
+ const decompileApk = (apkPath) => {
21
+ try {
22
+ execSync(`jadx ${apkPath}`, { stdio: 'inherit' });
23
+ } catch (error) {}
24
+ return apkPath.replace('.xapk', '');
25
+ };
26
+
27
+ const findConfigurationImpl = async (sourcesDir) => {
28
+ const entries = await readdir(sourcesDir, { withFileTypes: true });
29
+ for (const entry of entries) {
30
+ if (!entry.isDirectory()) continue;
31
+ const moduleDir = join(sourcesDir, entry.name);
32
+ const moduleEntries = await readdir(moduleDir, { withFileTypes: true });
33
+ for (const moduleFile of moduleEntries) {
34
+ if (moduleFile.isDirectory()) continue;
35
+ const moduleFilePath = join(moduleDir, moduleFile.name);
36
+ const moduleContents = await readFile(moduleFilePath, 'utf8');
37
+ if (moduleContents.includes(' ConfigurationImpl.kt')) {
38
+ return moduleContents;
39
+ }
40
+ }
41
+ }
42
+ };
43
+
44
+ const parseSecrets = (contents) => {
45
+ const lines = contents.split('\n');
46
+ const startIndex = lines.findIndex((line) => line.includes('https://sso.crunchyroll.com'));
47
+ const endIndex = lines.findIndex((line) => line.includes('CR-AndroidMobile-SSAI-Prod'));
48
+ const results = lines
49
+ .slice(startIndex, endIndex)
50
+ .map((line) => line.replaceAll(';', ''))
51
+ .map((line) => line.replaceAll('"', ''))
52
+ .map((line) => line.split('= ')[1])
53
+ .map((line) => line.trim());
54
+ const [, , id, secret] = results;
55
+ const encoded = Buffer.from(`${id}:${secret}`).toString('base64');
56
+ const authorization = `Basic ${encoded}`;
57
+ return { id, secret, encoded, authorization };
58
+ };
59
+
60
+ const extractSecrets = async ({ output, cleanup = true } = {}) => {
61
+ console.log('Downloading latest APK...');
62
+ const apkPath = await downloadLatestApk();
63
+
64
+ console.log('Decompiling APK...');
65
+ const decompiledDir = decompileApk(apkPath);
66
+
67
+ console.log('Searching for secrets...');
68
+ const sourcesDir = join(decompiledDir, 'sources');
69
+ const manifest = require(join(decompiledDir, 'resources', 'manifest.json'));
70
+ const version = manifest.version_name;
71
+ const configurationImpl = await findConfigurationImpl(sourcesDir);
72
+ if (!configurationImpl) throw new Error('Could not find ConfigurationImpl.kt');
73
+
74
+ console.log('Parsing secrets...');
75
+ const { id, secret, encoded, authorization } = parseSecrets(configurationImpl);
76
+
77
+ console.log(`Cleaning up files...`);
78
+ if (cleanup) await rm(apkPath, { recursive: true, force: true });
79
+ if (cleanup) await rm(decompiledDir, { recursive: true, force: true });
80
+
81
+ console.log(`Version: ${version}`);
82
+ console.log(`ID: ${id}`);
83
+ console.log(`Secret: ${secret}`);
84
+ console.log(`Encoded ID with secret: ${encoded}`);
85
+ console.log(`Authorization: ${authorization}`);
86
+
87
+ if (output) {
88
+ await writeFile(output, JSON.stringify({ version, id, secret, encoded, authorization }, null, 2));
89
+ }
90
+
91
+ return { version, id, secret, encoded, authorization };
92
+ };
93
+
94
+ module.exports = { extractSecrets };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "crextractor",
3
+ "version": "1.1.0",
4
+ "description": "Utility for extracting secrets from Crunchyroll mobile app",
5
+ "main": "crextractor.js",
6
+ "bin": {
7
+ "crextractor": "bin/cli.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "crextractor.d.ts",
12
+ "crextractor.js"
13
+ ],
14
+ "types": "crextractor.d.ts",
15
+ "type": "commonjs",
16
+ "scripts": {
17
+ "start": "node bin/cli.js",
18
+ "test": "echo \"Error: no test specified\" && exit 1"
19
+ },
20
+ "keywords": [
21
+ "crunchyroll"
22
+ ],
23
+ "author": "Vitaly Gashkov <vitalygashkov@vk.com>",
24
+ "license": "MIT",
25
+ "readmeFilename": "README.md",
26
+ "funding": [
27
+ {
28
+ "type": "individual",
29
+ "url": "https://t.me/tribute/app?startapp=dqW2"
30
+ }
31
+ ],
32
+ "engines": {
33
+ "node": ">=20"
34
+ },
35
+ "dependencies": {
36
+ "molnia": "^0.1.5"
37
+ },
38
+ "devDependencies": {
39
+ "typescript": "^5.9.2"
40
+ }
41
+ }