pattern/macho: Load Commands should include additional specializations (LoadDyLib) (#386)

* add additional command specialization

* address PR feedback
This commit is contained in:
Dhash Shrivathsa
2025-05-10 07:34:01 -04:00
committed by GitHub
parent 3185503be1
commit 0b0eff0cb6

View File

@@ -4,6 +4,7 @@
#pragma MIME application/x-mach-binary #pragma MIME application/x-mach-binary
import type.size; import type.size;
import std.string;
enum Magic : u32 { enum Magic : u32 {
_32BitMagic = 0xFEEDFACE, _32BitMagic = 0xFEEDFACE,
@@ -367,18 +368,44 @@ struct CommandSegment64 {
u8 data[fileSize] @ fileOffset [[sealed]]; u8 data[fileSize] @ fileOffset [[sealed]];
}; };
struct lc_str { // NB: struct as opposed to it's union def in loader.h
u32 offset;
// It's important to note that the `ptr` field is not used in the Mach-O file itself.
// It is only relevant at runtime when the Mach-O file is loaded into memory.
// The Mach-O file uses the `offset` field to locate the string data within the file.
};
struct Dylib {
lc_str name; // always 24
u32 timestamp;
u32 current_version;
u32 compatibility_version;
};
struct LoadDyLib {
Dylib dylib [[inline]];
};
struct LoadCommand { struct LoadCommand {
Command command; Command command;
type::Size<u32> commandSize; type::Size<u32> commandSize;
if (command == Command::UUID) match (command) {
CommandUUID data; (Command::UUID): CommandUUID data;
else if (command == Command::Segment) (Command::Segment): CommandSegment data;
CommandSegment data; (Command::Segment64): CommandSegment64 data;
else if (command == Command::Segment64) (Command::LoadDyLib | Command::IdDyLib | Command::LoadWeakDyLib): {
CommandSegment64 data; LoadDyLib dylib;
else
u8 data[commandSize - 8] [[sealed]]; // always 24 bytes in the struct
std::string::NullString dylib_name;
// the 1 is the size of the string terminator
// not using align here since according to the spec this is computed
padding[commandSize - dylib.dylib.name.offset - 1 - std::string::length(dylib_name)];
}
(_): u8 data[commandSize - 8] [[sealed]];
}
}; };
struct MachO { struct MachO {