From 3dadf3ee4ac02b4542f12a8d7eb6fcc4ee6f4a2b Mon Sep 17 00:00:00 2001 From: Niklas Higi Date: Tue, 6 Jul 2021 10:25:43 +0200 Subject: [PATCH] Fix App Bundle APKs not being properly signed on Windows Fixes #55 --- src/patch-app-bundle.ts | 3 ++- src/tasks/disable-certificate-pinning.ts | 10 +++------- src/utils/build-glob.ts | 11 +++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 src/utils/build-glob.ts diff --git a/src/patch-app-bundle.ts b/src/patch-app-bundle.ts index fa060bf..8e27ea3 100644 --- a/src/patch-app-bundle.ts +++ b/src/patch-app-bundle.ts @@ -7,6 +7,7 @@ import Listr = require('listr') import patchApk from './patch-apk' import { TaskOptions } from './cli' import observeAsync from './utils/observe-async' +import buildGlob from './utils/build-glob' export function patchXapkBundle(options: TaskOptions) { return patchAppBundle(options, { isXapk: true }) @@ -55,7 +56,7 @@ function patchAppBundle(options: TaskOptions, { isXapk }: { isXapk: boolean }) { title: 'Signing APKs', task: () => observeAsync(async log => { - const apkFiles = await globby(path.join(bundleDir, '**/*.apk')) + const apkFiles = await globby(buildGlob(bundleDir, '**/*.apk')) await uberApkSigner .sign(apkFiles, { zipalign: false }) diff --git a/src/tasks/disable-certificate-pinning.ts b/src/tasks/disable-certificate-pinning.ts index 9a52b70..f4c9ad6 100644 --- a/src/tasks/disable-certificate-pinning.ts +++ b/src/tasks/disable-certificate-pinning.ts @@ -1,25 +1,21 @@ -import * as path from 'path' import globby = require('globby') import { ListrTaskWrapper } from 'listr' import observeAsync from '../utils/observe-async' import processSmaliFile from './smali/process-file' +import buildGlob from '../utils/build-glob' export default async function disableCertificatePinning( directoryPath: string, task: ListrTaskWrapper, ) { return observeAsync(async log => { - // Convert Windows path (using backslashes) to POSIX path (using slashes) - const directoryPathPosix = directoryPath - .split(path.sep) - .join(path.posix.sep) - const globPattern = path.posix.join(directoryPathPosix, 'smali*/**/*.smali') + const smaliGlob = buildGlob(directoryPath, 'smali*/**/*.smali') let pinningFound = false log('Scanning Smali files...') - for await (const filePathChunk of globby.stream(globPattern)) { + for await (const filePathChunk of globby.stream(smaliGlob)) { // Required because Node.js streams are not typed as generics const filePath = filePathChunk as string diff --git a/src/utils/build-glob.ts b/src/utils/build-glob.ts new file mode 100644 index 0000000..e3c5822 --- /dev/null +++ b/src/utils/build-glob.ts @@ -0,0 +1,11 @@ +import * as path from 'path' + +/** Build a glob pattern that works on POSIX and Windows. */ +export default function buildGlob(...components: string[]) { + // Convert Windows path (using backslashes) to POSIX path (using slashes) + const unixComponents = components.map(component => + component.split(path.sep).join(path.posix.sep), + ) + + return path.posix.join(...unixComponents) +}