Skip to content

Commit

Permalink
fix #123
Browse files Browse the repository at this point in the history
v3.0.25
  • Loading branch information
ChiChou committed Aug 18, 2023
1 parent 724a5b2 commit 4daad0f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
11 changes: 1 addition & 10 deletions index.js
Expand Up @@ -140,19 +140,10 @@ export class BagBak extends EventEmitter {
this.emit('sshBegin');
await this.#copyToLocal(remoteRoot, parent);

// exclude SC_Info, etc.
const exclude = ['SC_Info', 'iTunesMetadata.plist', 'embedded.mobileprovision', '_CodeSignature'];
for (const name of exclude) {
await rm(join(localRoot, name), { recursive: true, force: true })
.catch(() => { });
}

this.emit('sshFinish');

const visitor = new AppBundleVisitor(localRoot);
// find all encrypted binaries.
// side effects: it will also remove some unwanted files
// todo: refactor to 2 passes
await visitor.removeUnwanted();
const map = await visitor.encryptedBinaries();

debug('encrypted binaries', map);
Expand Down
56 changes: 34 additions & 22 deletions lib/scan.js
Expand Up @@ -32,14 +32,6 @@ const exclude = {
files: new Set(['iTunesMetadata.plist', 'embedded.mobileprovision'])
};

/**
*
* @param {PathLike} dir
*/
function unlink(dir) {
return rm(dir, { recursive: true, force: true }).catch(() => { });
}

export class AppBundleVisitor {
#root;

Expand All @@ -60,11 +52,6 @@ export class AppBundleVisitor {
if (item.endsWith('.appex')) {
const fullname = path.join(pluginsDir, item);
const scope = fullname;

for (const item of exclude.dirs) {
await unlink(path.join(fullname, item));
}

yield* this.#visit(scope, fullname);
}
}
Expand All @@ -79,15 +66,9 @@ export class AppBundleVisitor {
const info = await stat(fullname);

if (info.isFile()) {
if (exclude.files.has(item)) {
await unlink(fullname);
} else {
yield* this.#visitFile(this.#root, fullname);
}
yield* this.#visitFile(this.#root, fullname);
} else if (info.isDirectory()) {
if (exclude.dirs.has(item)) {
await unlink(fullname);
} else if (item === 'PlugIns' || item === 'Extensions') {
if (item === 'PlugIns' || item === 'Extensions') {
yield* this.#visitPlugins(fullname);
} else {
yield* this.#visit(this.#root, fullname);
Expand Down Expand Up @@ -137,7 +118,6 @@ export class AppBundleVisitor {
}

/**
* Warning: this function has side effects: it will remove some files in the app bundle
* @returns {Promise<Map<import('fs').PathLike, [import('fs').PathLike, import('./macho.js').MachO][]>>}
*/
async encryptedBinaries() {
Expand Down Expand Up @@ -167,4 +147,36 @@ export class AppBundleVisitor {

return result;
}

/**
* @returns {Promise<void>}
*/
async removeUnwanted() {
/**
* @param {PathLike} dir
* @returns {Promise<void>}
*/
async function visit(dir) {
console.log('dir', dir)
for (const item of await readdir(dir)) {
const fullname = path.join(dir, item);
const info = await stat(fullname);
if (!info.isDirectory()) {
continue;
}

if (exclude.dirs.has(item)) {
await rm(fullname, { recursive: true, force: true }).catch(() => { });
} else {
await visit(fullname);
}
}
}

for (const name of exclude.files) {
await rm(path.join(this.#root, name), { force: true }).catch(() => { });
}

return visit(this.#root);
}
}
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
@@ -1,6 +1,6 @@
{
"name": "bagbak",
"version": "3.0.23",
"version": "3.0.25",
"description": "Dump iOS app from a jailbroken device, based on frida.re",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4daad0f

Please sign in to comment.