Skip to content

Commit

Permalink
Remove "I: " prefix from Apktool logs
Browse files Browse the repository at this point in the history
  • Loading branch information
shroudedcode committed Oct 12, 2019
1 parent d14c1c7 commit 0cb553e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
14 changes: 4 additions & 10 deletions src/index.ts
Expand Up @@ -11,7 +11,6 @@ const { version } = require('../package.json')
import modifyManifest from './tasks/modify-manifest'
import modifyNetworkSecurityConfig from './tasks/modify-netsec-config'
import disableCertificatePinning from './tasks/disable-certificate-pinning'
import observeProcess from './utils/observe-process'

import apktool from './tools/apktool'
import uberApkSigner from './tools/uber-apk-signer'
Expand Down Expand Up @@ -39,9 +38,7 @@ export default async function prepareApk(apkPath: string) {
await new Listr([
{
title: 'Decoding APK file',
task: () => observeProcess(
apktool.decode(apkPath, decodeDir),
),
task: () => apktool.decode(apkPath, decodeDir),
},
{
title: 'Modifying app manifest',
Expand All @@ -60,18 +57,15 @@ export default async function prepareApk(apkPath: string) {
},
{
title: 'Encoding patched APK file',
task: () => observeProcess(
apktool.encode(decodeDir, unsignedApkPath),
),
task: () => apktool.encode(decodeDir, unsignedApkPath),
},
{
title: 'Signing patched APK file',
task: () => {
return new Observable(subscriber => {
(async () => {
await observeProcess(
uberApkSigner.sign(unsignedApkPath),
).forEach(line => subscriber.next(line))
await uberApkSigner.sign(unsignedApkPath)
.forEach(line => subscriber.next(line))

await fs.copyFile(
path.join(tmpDir, 'unsigned-aligned-debugSigned.apk'),
Expand Down
19 changes: 13 additions & 6 deletions src/tools/apktool.ts
@@ -1,17 +1,24 @@
import { ExecaChildProcess } from 'execa'
import * as path from 'path'
import { map } from 'rxjs/operators'

import executeJar from '../utils/execute-jar'
import observeProcess from '../utils/observe-process'

const jar = path.join(__dirname, '../../jar/apktool.jar')

const apktool = {
decode(inputPath: string, outputPath: string) {
return executeJar(jar, ['decode', inputPath, '--output', outputPath])
},
encode(inputPath: string, outputPath: string) {
return executeJar(jar, ['build', inputPath, '--output', outputPath, '--use-aapt2'])
},
decode: (inputPath: string, outputPath: string) => observeApktool(
executeJar(jar, ['decode', inputPath, '--output', outputPath]),
),
encode: (inputPath: string, outputPath: string) => observeApktool(
executeJar(jar, ['build', inputPath, '--output', outputPath, '--use-aapt2']),
),
version: 'v2.4.1 SNAPSHOT@197d46',
}

function observeApktool(process: ExecaChildProcess) {
return map((line: string) => line.replace(/I: /g, ''))(observeProcess(process))
}

export default apktool
7 changes: 4 additions & 3 deletions src/tools/uber-apk-signer.ts
@@ -1,13 +1,14 @@
import * as path from 'path'

import executeJar from '../utils/execute-jar'
import observeProcess from '../utils/observe-process'

const jar = path.join(__dirname, '../../jar/uber-apk-signer.jar')

const uberApkSigner = {
sign(inputPath: string) {
return executeJar(jar, ['--apks', inputPath])
},
sign: (inputPath: string) => observeProcess(
executeJar(jar, ['--apks', inputPath]),
),
version: 'v1.1.0',
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/observe-process.ts
@@ -1,7 +1,7 @@
import { ExecaChildProcess } from 'execa'
import { Observable } from 'rxjs'

export default function observeProcess(process: ExecaChildProcess) {
export default function observeProcess(process: ExecaChildProcess): Observable<string> {
return new Observable(subscriber => {
process
.then(() => subscriber.complete())
Expand Down

0 comments on commit 0cb553e

Please sign in to comment.