Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dyldcache parsing for iOS 18 beta changes #23033

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions libr/bin/format/mach0/dsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,15 @@ static const RDSCField dsc_header_fields[] = {
{ "i", "imagesOffset" },
{ "i", "imagesCount" },
{ "i", "cacheSubType" },
{ "i", "padding" },
{ "l", "objcOptsOffset" },
{ "l", "objcOptsSize" },
{ "l", "cacheAtlasOffset" },
{ "l", "cacheAtlasSize" },
{ "l", "dynamicDataOffset" },
{ "l", "dynamicDataMaxSize" },
{ "i", "maybePointsToLinkeditMapAtTheEndOfSubCachesArray" },
{ "i", "previousPointerMakesSense" },
{ NULL, NULL }
};

Expand Down
2 changes: 1 addition & 1 deletion libr/bin/format/mach0/mach0.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ struct MACH0_(obj_t) {
bool libs_loaded;
RPVector libs_cache;
int nlibs;
int size;
ut64 size;
ut64 baddr;
ut64 entry;
bool big_endian;
Expand Down
25 changes: 20 additions & 5 deletions libr/io/p/io_dsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static int r_io_dsc_object_read(RIO *io, RIODesc *fd, ut8 *buf, int count);
static ut64 r_io_dsc_object_seek(RIO *io, RIODscObject *dsc, ut64 offset, int whence);

static bool r_io_dsc_object_dig_slices(RIODscObject * dsc);
static bool r_io_dsc_detect_subcache_format(int fd, ut32 sc_offset, ut32 sc_count, ut64 size, ut64 * out_entry_size, RDscSubcacheFormat * out_format);
static bool r_io_dsc_detect_subcache_format(int fd, ut32 sc_offset, ut32 sc_count, ut32 array_end, ut64 size, ut64 * out_entry_size, RDscSubcacheFormat * out_format);
static bool r_io_dsc_dig_subcache(RIODscObject * dsc, const char * filename, ut64 start, ut8 * check_uuid, ut64 * out_size);
static bool r_io_dsc_object_dig_one_slice(RIODscObject * dsc, int fd, ut64 start, ut64 end, ut8 * check_uuid, RDSCHeader * header, bool walk_monocache);
static RIODscSlice * r_io_dsc_object_get_slice(RIODscObject * dsc, ut64 off_global);
Expand Down Expand Up @@ -343,7 +343,11 @@ static bool r_io_dsc_object_dig_slices(RIODscObject * dsc) {
RDscSubcacheFormat sc_format = SUBCACHE_FORMAT_UNDEFINED;

if (subCacheArrayCount) {
if (!r_io_dsc_detect_subcache_format(fd, subCacheArrayOffset, subCacheArrayCount, next_or_end, &sc_entry_size, &sc_format)) {
ut32 array_end = 0;

dsc_header_get_u32 (header, "maybePointsToLinkeditMapAtTheEndOfSubCachesArray", &array_end);

if (!r_io_dsc_detect_subcache_format(fd, subCacheArrayOffset, subCacheArrayCount, array_end, next_or_end, &sc_entry_size, &sc_format)) {
R_LOG_ERROR ("Could not detect subcache entry format");
goto error;
}
Expand Down Expand Up @@ -440,12 +444,21 @@ static bool r_io_dsc_object_dig_slices(RIODscObject * dsc) {
return false;
}

static bool r_io_dsc_detect_subcache_format(int fd, ut32 sc_offset, ut32 sc_count, ut64 size, ut64 * out_entry_size, RDscSubcacheFormat * out_format) {
static bool r_io_dsc_detect_subcache_format(int fd, ut32 sc_offset, ut32 sc_count, ut32 array_end, ut64 size, ut64 * out_entry_size, RDscSubcacheFormat * out_format) {
RDscSubcacheFormat sc_format = SUBCACHE_FORMAT_UNDEFINED;
ut64 sc_entry_size = 0;
ut64 array_size_v2 = sizeof (RDscSubcacheEntryV2) * sc_count;

if (array_end) {
if (array_end == sc_offset + array_size_v2) {
sc_format = SUBCACHE_FORMAT_V2;
sc_entry_size = sizeof (RDscSubcacheEntryV2);
goto beach;
}
}

if (sc_count != 0) {
ut64 array_size_v1 = sizeof (RDscSubcacheEntryV1) * sc_count;
ut64 array_size_v2 = sizeof (RDscSubcacheEntryV2) * sc_count;
char test_v1, test_v2;

if (array_size_v1 + 1 >= size || array_size_v2 + 1 >= size) {
Expand Down Expand Up @@ -473,7 +486,7 @@ static bool r_io_dsc_detect_subcache_format(int fd, ut32 sc_offset, ut32 sc_coun
sc_entry_size = sizeof (RDscSubcacheEntryV2);
}
}

beach:
*out_entry_size = sc_entry_size;
*out_format = sc_format;

Expand Down Expand Up @@ -1214,6 +1227,7 @@ static bool get_rebase_infos(RIODscSlice * slice, int fd, ut64 start, RDSCHeader
info->info = get_rebase_info (fd, slideInfoOffset, slideInfoSize, info->start, 0);
if (!info->info) {
R_LOG_ERROR ("Failed to get rebase info");
return false;
}
}
}
Expand Down Expand Up @@ -1242,6 +1256,7 @@ static bool get_rebase_infos(RIODscSlice * slice, int fd, ut64 start, RDSCHeader
info->info = get_rebase_info (fd, slideInfoOffset, slideInfoSize, info->start, 0);
if (!info->info) {
R_LOG_ERROR ("Failed to get rebase info");
return false;
}
}
}
Expand Down
Loading