Skip to content

Commit

Permalink
feature for #125
Browse files Browse the repository at this point in the history
add a flag to abort when something goes wrong
  • Loading branch information
ChiChou committed Sep 28, 2023
1 parent 7aee759 commit ea91e54
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bin/bagbak.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ async function main() {
.option('-d, --debug', 'enable debug output')
.option('-r, --raw', 'dump raw app bundle to directory (no ipa)')
.option('-o, --output <output>', 'ipa filename or directory to dump to')
.option('--abort-on-error', 'abort on error')
.usage('[bundle id or name]')
.version(await version());

Expand Down Expand Up @@ -139,7 +140,7 @@ async function main() {
})

const saved = program.raw ?
await job.dump(program.output || '.', program.force) :
await job.dump(program.output || '.', program.force, program.abortOnError) :
await job.pack(program.output);

console.log(`Saved to ${chalk.yellow(saved)}`);
Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ export class BagBak extends EventEmitter {
* dump raw app bundle to directory (no ipa)
* @param {import("fs").PathLike} parent path
* @param {boolean} override whether to override existing files
* @param {boolean} abortOnError whether to abort on error
* @returns {Promise<string>}
*/
async dump(parent, override = false) {
async dump(parent, override = false, abortOnError = false) {
if (!await directoryExists(parent))
throw new Error('Output directory does not exist');

Expand Down Expand Up @@ -169,6 +170,8 @@ export class BagBak extends EventEmitter {
try {
pid = await this.#device.spawn(mainExecutable);
} catch(e) {
if (abortOnError) throw e;

console.error(`Failed to spawn executable at ${mainExecutable}, skipping...`);
console.error(`Warning: Unable to dump ${dylibs.map(([path, _]) => path).join('\n')}`);
continue;
Expand All @@ -183,6 +186,8 @@ export class BagBak extends EventEmitter {
try {
session = await this.#device.attach(pid);
} catch(e) {
if (abortOnError) throw e;

console.error(`Failed to attach to pid ${pid}, skipping...`);
console.error(`Warning: Unable to dump ${dylibs.map(([path, _]) => path).join('\n')}`);
continue;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bagbak",
"version": "3.0.26",
"version": "3.0.27",
"description": "Dump iOS app from a jailbroken device, based on frida.re",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit ea91e54

Please sign in to comment.