Skip to content

Commit 5c70c8a

Browse files
committed
Fix some issues with 0x0-based MH_FILSETs and improve fallback arch/plat detection. This allows SKE filesets to load now, but more work should be done for improved support for these
1 parent 567537d commit 5c70c8a

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

view/kernelcache/core/KernelCacheView.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ void KernelCacheViewType::Register()
2525
}
2626

2727
Ref<BinaryView> KernelCacheViewType::Create(BinaryView* data)
28-
{uint32_t magic;
28+
{
29+
uint32_t magic;
2930
data->Read(&magic, data->GetStart(), 4);
3031
if (magic != MH_CIGAM_64 && magic != MH_MAGIC_64) // FIXME 32 bit
3132
{
@@ -133,7 +134,7 @@ Ref<Settings> KernelCacheViewType::GetLoadSettingsForData(BinaryView* data)
133134
R"({
134135
"title" : "Image Auto-Load Regex Pattern",
135136
"type" : "string",
136-
"default" : ".*libsystem_c.dylib",
137+
"default" : "",
137138
"description" : "A regex pattern to auto load matching images at the end of view init, defaults to the system_c image only."
138139
})");
139140

@@ -318,9 +319,16 @@ bool KernelCacheView::Init()
318319
}
319320
if (!foundBuildVersion)
320321
{
321-
LogError("Failed to find LC_BUILD_VERSION in subheader");
322-
SetDefaultArchitecture(Architecture::GetByName("aarch64"));
323-
SetDefaultPlatform(Platform::GetByName("macos-kernel-aarch64"));
322+
// FIXME: Is it in-spec to have LC_BUILD_VERSION only in the super header?
323+
// This is sufficient as a fallback but source should be referenced here.
324+
LogWarn("Failed to find LC_BUILD_VERSION in subheader. Assuming macOS platform.");
325+
std::map<std::string, Ref<Metadata>> metadataMap = {
326+
{"machoplatform", new Metadata((uint64_t) MACHO_PLATFORM_MACOS)},
327+
};
328+
Ref<Metadata> metadata = new Metadata(metadataMap);
329+
Ref<Platform> plat = g_kcViewType->RecognizePlatform(cpuType, GetDefaultEndianness(), this, metadata);
330+
SetDefaultArchitecture(plat->GetArchitecture());
331+
SetDefaultPlatform(plat);
324332
}
325333
}
326334
else
@@ -329,13 +337,6 @@ bool KernelCacheView::Init()
329337
return false;
330338
}
331339

332-
if (textSegOffset == 0)
333-
{
334-
LogError("Failed to find __TEXT segment");
335-
return false;
336-
}
337-
338-
339340
// Add Mach-O file header type info
340341
EnumerationBuilder cpuTypeBuilder;
341342
cpuTypeBuilder.AddMemberWithValue("CPU_TYPE_ANY", MACHO_CPU_TYPE_ANY);

0 commit comments

Comments
 (0)