Skip to content

Commit

Permalink
Fix dyldcache deps carving logic ##bin
Browse files Browse the repository at this point in the history
The dyldcache-specific logic which parses library-loading Mach-O load
commands to carve dependencies in order to filter them was wrongly
assuming the path of the loaded library is always at offset 24 instead
of looking up the right offset from the command itself.

While this was working 99.99% of the times, when it didn't it broke the
deps carving logic and produced weird-looking "alien dep" errors.
  • Loading branch information
mrmacete authored and trufae committed Jun 17, 2024
1 parent b5cb854 commit 4f1d5be
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libr/bin/p/bin_dyldcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,18 @@ static void carve_deps_at_address(RDyldCache *cache, cache_img_t *img, HtSU *pat
while (cursor < end) {
ut32 cmd = r_read_le32 (cursor);
ut32 cmdsize = r_read_le32 (cursor + sizeof (ut32));
ut8 *cmd_end = cursor + cmdsize;
if (cmd == LC_LOAD_DYLIB ||
cmd == LC_LOAD_WEAK_DYLIB ||
cmd == LC_REEXPORT_DYLIB ||
cmd == LC_LOAD_UPWARD_DYLIB) {
ut32 path_offset = r_read_le32 (cursor + 2 * sizeof (ut32));
bool found;
if (cursor + 24 >= end) {
break;
if (cursor + path_offset >= cmd_end) {
R_LOG_ERROR ("Malformed load command");
goto nextcmd;
}
const char *key = (const char *) cursor + 24;
const char *key = (const char *) cursor + path_offset;
size_t dep_index = (size_t)ht_su_find (path_to_idx, key, &found);
if (!found || dep_index >= cache->hdr->imagesCount) {
R_LOG_WARN ("alien dep '%s'", key);
Expand Down

0 comments on commit 4f1d5be

Please sign in to comment.