diff --git a/src/cli.ts b/src/cli.ts index 8c42284..100d314 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -24,6 +24,7 @@ export type TaskOptions = { wait: boolean isAppBundle: boolean debuggable: boolean + skipDecode: boolean } interface PatchingError extends Error { @@ -57,11 +58,11 @@ async function main() { const fileExtension = path.extname(input) const baseName = path.basename(input, fileExtension) const outputName = `${baseName}-patched${fileExtension}` - const outputPath = path.resolve(path.dirname(inputPath), outputName) + let outputPath = path.resolve(path.dirname(inputPath), outputName) + let skipDecode = false let isAppBundle = false let taskFunction: (options: TaskOptions) => Listr - switch (fileExtension) { case '.apk': taskFunction = patchApk @@ -75,6 +76,11 @@ async function main() { isAppBundle = true taskFunction = patchApksBundle break + case '': + taskFunction = patchApk + skipDecode = true + outputPath += '.apk' + break default: showSupportedExtensions() } @@ -102,7 +108,13 @@ async function main() { const uberApkSigner = new UberApkSigner() showVersions({ apktool, uberApkSigner }) - console.log(chalk.dim(` Using temporary directory:\n ${tmpDir}\n`)) + if (skipDecode) { + console.log( + chalk.dim(` Patching from decoded apktool directory:\n ${inputPath}\n`), + ) + } else { + console.log(chalk.dim(` Using temporary directory:\n ${tmpDir}\n`)) + } taskFunction({ inputPath, @@ -115,6 +127,7 @@ async function main() { skipPatches: args.skipPatches, isAppBundle, debuggable: args.debuggable, + skipDecode, }) .run() .then(async context => { @@ -190,7 +203,7 @@ function formatCommandError(error: string, { tmpDir }: { tmpDir: string }) { function showHelp() { console.log(chalk` - $ {bold apk-mitm} + $ {bold apk-mitm} {blue {dim.bold *} Optional flags:} {dim {bold --wait} Wait for manual changes before re-encoding} diff --git a/src/patch-apk.ts b/src/patch-apk.ts index 72f169e..0b41b97 100644 --- a/src/patch-apk.ts +++ b/src/patch-apk.ts @@ -12,7 +12,9 @@ import checkPrerequisites from './tasks/check-prerequisites' export default function patchApk(options: TaskOptions) { const { apktool, uberApkSigner } = options - const decodeDir = path.join(options.tmpDir, 'decode') + const decodeDir = options.skipDecode + ? options.inputPath + : path.join(options.tmpDir, 'decode') const tmpApkPath = path.join(options.tmpDir, 'tmp.apk') let fallBackToAapt = false @@ -24,6 +26,7 @@ export default function patchApk(options: TaskOptions) { }, { title: 'Decoding APK file', + skip: () => options.skipDecode, task: () => apktool.decode(options.inputPath, decodeDir), }, {