Skip to content

Commit

Permalink
bugfix: wrong offset of cryptid
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiChou committed Jun 16, 2023
1 parent 33d8b54 commit d7121f0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
6 changes: 5 additions & 1 deletion agent/tiny.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ rpc.exports = {
fileOffset += HIGH_WATER_MARK;
send({ event: 'trunk', fileOffset, name: relative }, p.readByteArray(remain));
recv('ack').wait();

const zeroFilled = new ArrayBuffer(12); // cryptoff, cryptsize, cryptid
send({ event: 'trunk', fileOffset: info.encCmdOffset + 8, name: relative }, zeroFilled);
recv('ack').wait();
}
}

send({ event: 'end', name: relative, flagOffset: info.encCmdOffset + 16 });
send({ event: 'end', name: relative});
recv('ack').wait();
}

Expand Down
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ export class BagBak extends EventEmitter {
} else if (payload.event === 'trunk') {
await fileHandles.get(key).write(data, 0, data.byteLength, payload.fileOffset);
} else if (payload.event === 'end') {
const fd = fileHandles.get(key);
// remove cryptid
const zeroFilled = Buffer.alloc(4).fill(0);
fd.write(zeroFilled, 0, 4, payload.flagOffset);
await fileHandles.get(key).close();
fileHandles.delete(key);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/macho.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const MH_DYLIB = 0x6;
export const MH_DYLINKER = 0x7;
export const MH_BUNDLE = 0x8;

const LC_ENCRYPTION_INFO_64 = 0x2c;

/**
*
* @param {PathLike} file
Expand Down Expand Up @@ -94,8 +96,7 @@ export async function parse(file) {
for (let offset = 0, i = 0; offset + 8 < buffer.length, i < ncmds; i++) {
const cmd = buffer.readUInt32LE(offset);
const cmdsize = buffer.readUInt32LE(offset + 4);
if (cmd === 0x2c) {
// LC_ENCRYPTION_INFO_64
if (cmd === LC_ENCRYPTION_INFO_64) {
const cryptoff = buffer.readUInt32LE(offset + 4 * 2);
const cryptsize = buffer.readUInt32LE(offset + 4 * 3);
const cryptid = buffer.readUInt32LE(offset + 4 * 4);
Expand All @@ -106,7 +107,7 @@ export async function parse(file) {
id: cryptid,
};

result.encCmdOffset = offset;
result.encCmdOffset = offset + HEADER_SIZE_64;
}
offset += cmdsize;
}
Expand Down
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.9",
"version": "3.0.10",
"description": "Dump iOS app from a jailbroken device, based on frida.re",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit d7121f0

Please sign in to comment.