Files
crextractor/crextractor.js
T

95 lines
3.5 KiB
JavaScript
Raw Normal View History

const { execSync } = require('node:child_process');
2025-08-23 21:14:56 +05:00
const { join } = require('node:path');
const { readdir, readFile, writeFile, rm } = require('node:fs/promises');
const { download } = require('molnia');
2025-03-26 13:19:45 +05:00
const downloadLatestApk = async () => {
2025-08-23 21:14:56 +05:00
const source = 'https://apkcombo.com/crunchyroll/com.crunchyroll.crunchyroid/download/apk';
2025-03-26 13:19:45 +05:00
const page = await fetch(source);
const html = await page.text();
2025-08-23 21:14:56 +05:00
const route = '/r2' + html.split('/r2')[1]?.split('"')[0];
const url = `https://apkcombo.com${route}`;
const filepath = join(process.cwd(), 'crunchyroll.xapk');
await download(url, {
output: filepath,
onError: (error) => console.error(error),
});
return filepath;
2025-03-26 13:19:45 +05:00
};
const decompileApk = (apkPath) => {
try {
execSync(`jadx ${apkPath}`, { stdio: 'inherit' });
} catch (error) {}
2025-03-26 13:19:45 +05:00
return apkPath.replace('.xapk', '');
};
const findConfigurationImpl = async (sourcesDir) => {
const entries = await readdir(sourcesDir, { withFileTypes: true });
for (const entry of entries) {
if (!entry.isDirectory()) continue;
const moduleDir = join(sourcesDir, entry.name);
const moduleEntries = await readdir(moduleDir, { withFileTypes: true });
for (const moduleFile of moduleEntries) {
if (moduleFile.isDirectory()) continue;
const moduleFilePath = join(moduleDir, moduleFile.name);
const moduleContents = await readFile(moduleFilePath, 'utf8');
if (moduleContents.includes(' ConfigurationImpl.kt')) {
return moduleContents;
}
}
}
};
const parseSecrets = (contents) => {
const lines = contents.split('\n');
const startIndex = lines.findIndex((line) => line.includes('https://sso.crunchyroll.com'));
const endIndex = lines.findIndex((line) => line.includes('CR-AndroidMobile-SSAI-Prod'));
const results = lines
.slice(startIndex, endIndex)
.map((line) => line.replaceAll(';', ''))
.map((line) => line.replaceAll('"', ''))
.map((line) => line.split('= ')[1])
.map((line) => line.trim());
const [, , id, secret] = results;
const encoded = Buffer.from(`${id}:${secret}`).toString('base64');
2025-08-23 21:14:56 +05:00
const authorization = `Basic ${encoded}`;
return { id, secret, encoded, authorization };
2025-03-26 13:19:45 +05:00
};
2025-08-23 21:14:56 +05:00
const extractSecrets = async ({ output, cleanup = true } = {}) => {
2025-03-26 13:19:45 +05:00
console.log('Downloading latest APK...');
const apkPath = await downloadLatestApk();
console.log('Decompiling APK...');
const decompiledDir = decompileApk(apkPath);
console.log('Searching for secrets...');
const sourcesDir = join(decompiledDir, 'sources');
const manifest = require(join(decompiledDir, 'resources', 'manifest.json'));
2025-08-23 21:14:56 +05:00
const version = manifest.version_name;
2025-03-26 13:19:45 +05:00
const configurationImpl = await findConfigurationImpl(sourcesDir);
2025-08-23 21:14:56 +05:00
if (!configurationImpl) throw new Error('Could not find ConfigurationImpl.kt');
2025-03-26 13:19:45 +05:00
console.log('Parsing secrets...');
2025-08-23 21:14:56 +05:00
const { id, secret, encoded, authorization } = parseSecrets(configurationImpl);
2025-03-26 13:19:45 +05:00
console.log(`Cleaning up files...`);
if (cleanup) await rm(apkPath, { recursive: true, force: true });
if (cleanup) await rm(decompiledDir, { recursive: true, force: true });
2025-08-23 21:14:56 +05:00
console.log(`Version: ${version}`);
2025-03-26 13:19:45 +05:00
console.log(`ID: ${id}`);
console.log(`Secret: ${secret}`);
console.log(`Encoded ID with secret: ${encoded}`);
2025-08-23 21:14:56 +05:00
console.log(`Authorization: ${authorization}`);
if (output) {
await writeFile(output, JSON.stringify({ version, id, secret, encoded, authorization }, null, 2));
}
2025-03-26 13:19:45 +05:00
2025-08-23 21:14:56 +05:00
return { version, id, secret, encoded, authorization };
2025-03-26 13:19:45 +05:00
};
module.exports = { extractSecrets };