Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lara/kexploit/decrypt.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void set_progress_callback(progress_callback_t callback) {
uint64_t text_fileoff;
uint64_t text_filesize;
uint64_t binary_size;
uint64_t fat_offset;
bool is_64;
uint32_t ncmds;
};
Expand Down Expand Up @@ -139,8 +140,16 @@ static int parse_macho(uint8_t *buf, uint64_t size, struct macho_ctx *ctx) {
if (OSSwapBigToHostInt32(archs[i].cputype) == CPU_TYPE_ARM64) {
uint32_t offset = OSSwapBigToHostInt32(archs[i].offset);
uint32_t arch_size = OSSwapBigToHostInt32(archs[i].size);
if (offset + arch_size <= size)
return parse_macho(buf + offset, arch_size, ctx);
if (offset + arch_size <= size) {
int ret = parse_macho(buf + offset, arch_size, ctx);
if (ret == 0) {
ctx->cryptoff += offset;
ctx->text_fileoff += offset;
ctx->binary_size = size;
ctx->fat_offset = offset;
}
return ret;
}
}
}
return -1;
Expand Down Expand Up @@ -388,7 +397,7 @@ static int decrypt_to_output(const char *binaryPath, pid_t pid, uint8_t *file_bu
progupdate((double)pages_done / total_pages);
}

uint64_t crypto_off = ctx->is_64 ? sizeof(struct mach_header_64) : sizeof(struct mach_header);
uint64_t crypto_off = ctx->fat_offset + (ctx->is_64 ? sizeof(struct mach_header_64) : sizeof(struct mach_header));
for (uint32_t i = 0; i < ctx->ncmds; i++) {
if (crypto_off + sizeof(struct load_command) > file_size) break;
struct load_command *lc = (struct load_command *)(decrypted + crypto_off);
Expand Down Expand Up @@ -461,5 +470,3 @@ int decrypt_app(const char *bundlePath, const char *executableName, const char *
snprintf(execPath, sizeof(execPath), "%s/%s", bundlePath, executableName);
return decrypt_binary(execPath, executableName, outputPath);
}


Loading