From 82f62706b67ac29b1e8d6a2a7d30dd717e834ebc Mon Sep 17 00:00:00 2001 From: Vitaly Gashkov Date: Thu, 27 Mar 2025 18:23:20 +0500 Subject: [PATCH] fix: add cli shebang, improve cjs compatibility, exit if target source not found --- crunchys-cli.js | 8 ++++---- crunchys.js | 9 +++++---- package.json | 3 ++- 3 files changed, 11 insertions(+), 9 deletions(-) mode change 100644 => 100755 crunchys-cli.js diff --git a/crunchys-cli.js b/crunchys-cli.js old mode 100644 new mode 100755 index 373e288..e277aaf --- a/crunchys-cli.js +++ b/crunchys-cli.js @@ -1,5 +1,5 @@ -import { extractSecrets } from './crunchys'; +#!/usr/bin/env node -(async () => { - await extractSecrets(); -})(); +const { extractSecrets } = require('./crunchys'); + +extractSecrets(); diff --git a/crunchys.js b/crunchys.js index b4ddf81..ff4e5f3 100644 --- a/crunchys.js +++ b/crunchys.js @@ -25,9 +25,7 @@ const downloadLatestApk = async () => { const decompileApk = (apkPath) => { try { execSync(`jadx ${apkPath}`, { stdio: 'inherit' }); - } catch (error) { - console.error(error); - } + } catch (error) {} return apkPath.replace('.xapk', ''); }; @@ -64,7 +62,7 @@ const parseSecrets = (contents) => { return { id, secret, encoded, header }; }; -export const extractSecrets = async ({ cleanup = true } = {}) => { +const extractSecrets = async ({ cleanup = true } = {}) => { console.log('Downloading latest APK...'); const apkPath = await downloadLatestApk(); @@ -74,6 +72,7 @@ export const extractSecrets = async ({ cleanup = true } = {}) => { console.log('Searching for secrets...'); const sourcesDir = join(decompiledDir, 'sources'); const configurationImpl = await findConfigurationImpl(sourcesDir); + if (!configurationImpl) return console.error('Could not find ConfigurationImpl.kt'); console.log('Parsing secrets...'); const { id, secret, encoded, header } = parseSecrets(configurationImpl); @@ -88,3 +87,5 @@ export const extractSecrets = async ({ cleanup = true } = {}) => { return { id, secret, encoded, header }; }; + +module.exports = { extractSecrets }; diff --git a/package.json b/package.json index 03a55ec..3195b64 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "crunchys", - "version": "1.0.0", + "version": "1.0.1", "description": "A utility to extract secrets from Crunchyroll mobile app", "main": "crunchys.js", "types": "crunchys.d.ts", "bin": "crunchys-cli.js", + "type": "commonjs", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" },