Skip to content

Commit

Permalink
Document dependency on and check existence of zip and unzipon Linux
Browse files Browse the repository at this point in the history
Closes #57
  • Loading branch information
niklashigi committed Jun 26, 2021
1 parent 76e5bca commit d0202a8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You can now install the `example-patched.apk` file on your Android device and us

### Patching App Bundles

You can also patch apps using [Android App Bundle](android-app-bundle) with `apk-mitm` by providing it with a `*.xapk` file (for example from [APKPure][apkpure]) or a `*.apks` file (which you can export yourself using [SAI][sai]).
You can also patch apps using [Android App Bundle](android-app-bundle) with `apk-mitm` by providing it with a `*.xapk` file (for example from [APKPure][apkpure]) or a `*.apks` file (which you can export yourself using [SAI][sai]). If you're doing this on Linux, make sure that both `zip` and `unzip` are installed.

### Making manual changes

Expand Down
5 changes: 5 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type TaskOptions = {
uberApkSigner: UberApkSigner
tmpDir: string
wait: boolean
isAppBundle: boolean
debuggable: boolean
}

Expand Down Expand Up @@ -55,17 +56,20 @@ async function main() {
const outputName = `${baseName}-patched${fileExtension}`
const outputPath = path.resolve(path.dirname(inputPath), outputName)

let isAppBundle = false
let taskFunction: (options: TaskOptions) => Listr

switch (fileExtension) {
case '.apk':
taskFunction = patchApk
break
case '.xapk':
isAppBundle = true
taskFunction = patchXapkBundle
break
case '.apks':
case '.zip':
isAppBundle = true
taskFunction = patchApksBundle
break
default:
Expand All @@ -92,6 +96,7 @@ async function main() {
uberApkSigner,
wait: args.wait,
skipPatches: args.skipPatches,
isAppBundle,
debuggable: args.debuggable,
})
.run()
Expand Down
24 changes: 24 additions & 0 deletions src/tasks/check-prerequisites.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import execa = require('execa')
import Listr = require('listr')

import { TaskOptions } from '../cli'
Expand Down Expand Up @@ -25,13 +26,36 @@ export default function checkPrerequisites(options: TaskOptions) {
throw new VersionError('Java', MIN_JAVA_VERSION, majorVersion)
},
},
{
title: 'Checking additional tools',
task: async () => {
if (options.isAppBundle && process.platform !== 'win32')
await ensureZipUlitiesAvailable()
},
},
{
title: 'Downloading tools',
task: () => downloadTools(options),
},
])
}

/**
* Ensure that `zip` and `unzip` are installed on Linux or macOS. Both are used
* (through the `cross-zip` package) when patching App Bundles.
*/
async function ensureZipUlitiesAvailable() {
try {
await execa('unzip', ['-v'])
await execa('zip', ['-v'])
} catch {
throw new Error(
'apk-mitm requires the commands "unzip" and "zip" to be installed when patching App Bundles.' +
" Make sure they're both installed and try again!",
)
}
}

class VersionError extends Error {
constructor(tool: string, minVersion: number, currentVersion: number) {
super(
Expand Down

0 comments on commit d0202a8

Please sign in to comment.