28 RebaseOpcodes.size() + BindOpcodes.size() + WeakBindOpcodes.size() +
29 LazyBindOpcodes.size() + ExportTrie.Children.size() +
30 NameList.size() + StringTable.size();
37 auto Len = strnlen(&Val[0], 16);
42 size_t CopySize = 16 >= Scalar.
size() ? 16 : Scalar.
size();
43 memcpy((
void *)Val, Scalar.
data(), CopySize);
45 if (Scalar.
size() < 16) {
46 memset((
void *)&Val[Scalar.
size()], 0, 16 - Scalar.
size());
56 for (
int Idx = 0; Idx < 16; ++Idx) {
57 Out <<
format(
"%02" PRIX32, Val[Idx]);
58 if (Idx == 3 || Idx == 5 || Idx == 7 || Idx == 9)
65 for (
size_t Idx = 0; Idx < Scalar.
size(); ++Idx) {
66 if (Scalar[Idx] ==
'-' || OutIdx >= 16)
68 unsigned long long TempInt;
70 return "invalid number";
72 return "out of range number";
73 Val[OutIdx] =
static_cast<uint8_t
>(TempInt);
103 IO.
mapTag(
"!mach-o",
true);
134 static_cast<llvm::yaml::Hex32>(0));
141 IO.
mapTag(
"!fat-mach-o",
true);
200 template <
typename StructType>
204 void mapLoadCommandData<MachO::segment_command>(
210 void mapLoadCommandData<MachO::segment_command_64>(
216 void mapLoadCommandData<MachO::dylib_command>(
222 void mapLoadCommandData<MachO::rpath_command>(
228 void mapLoadCommandData<MachO::dylinker_command>(
236 LoadCommand.
Data.load_command_data.cmd);
238 LoadCommand.
Data.load_command_data.cmd = TempCmd;
241 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
242 case MachO::LCName: \
243 MappingTraits<MachO::LCStruct>::mapping(IO, \
244 LoadCommand.Data.LCStruct##_data); \
245 mapLoadCommandData<MachO::LCStruct>(IO, LoadCommand); \
248 switch (LoadCommand.
Data.load_command_data.cmd) {
249 #include "llvm/Support/MachO.def"
297 void MappingTraits<MachO::dylinker_command>::mapping(
300 IO.mapRequired(
"name", LoadCommand.
name);
303 void MappingTraits<MachO::dysymtab_command>::mapping(
304 IO &IO, MachO::dysymtab_command &LoadCommand) {
306 IO.mapRequired(
"ilocalsym", LoadCommand.ilocalsym);
307 IO.mapRequired(
"nlocalsym", LoadCommand.nlocalsym);
308 IO.mapRequired(
"iextdefsym", LoadCommand.iextdefsym);
309 IO.mapRequired(
"nextdefsym", LoadCommand.nextdefsym);
310 IO.mapRequired(
"iundefsym", LoadCommand.iundefsym);
311 IO.mapRequired(
"nundefsym", LoadCommand.nundefsym);
312 IO.mapRequired(
"tocoff", LoadCommand.tocoff);
313 IO.mapRequired(
"ntoc", LoadCommand.ntoc);
314 IO.mapRequired(
"modtaboff", LoadCommand.modtaboff);
315 IO.mapRequired(
"nmodtab", LoadCommand.nmodtab);
316 IO.mapRequired(
"extrefsymoff", LoadCommand.extrefsymoff);
317 IO.mapRequired(
"nextrefsyms", LoadCommand.nextrefsyms);
318 IO.mapRequired(
"indirectsymoff", LoadCommand.indirectsymoff);
319 IO.mapRequired(
"nindirectsyms", LoadCommand.nindirectsyms);
320 IO.mapRequired(
"extreloff", LoadCommand.extreloff);
321 IO.mapRequired(
"nextrel", LoadCommand.nextrel);
322 IO.mapRequired(
"locreloff", LoadCommand.locreloff);
323 IO.mapRequired(
"nlocrel", LoadCommand.nlocrel);
326 void MappingTraits<MachO::encryption_info_command>::mapping(
327 IO &IO, MachO::encryption_info_command &LoadCommand) {
329 IO.mapRequired(
"cryptoff", LoadCommand.cryptoff);
330 IO.mapRequired(
"cryptsize", LoadCommand.cryptsize);
331 IO.mapRequired(
"cryptid", LoadCommand.cryptid);
334 void MappingTraits<MachO::encryption_info_command_64>::mapping(
335 IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
337 IO.mapRequired(
"cryptoff", LoadCommand.cryptoff);
338 IO.mapRequired(
"cryptsize", LoadCommand.cryptsize);
339 IO.mapRequired(
"cryptid", LoadCommand.cryptid);
340 IO.mapRequired(
"pad", LoadCommand.pad);
343 void MappingTraits<MachO::entry_point_command>::mapping(
344 IO &IO, MachO::entry_point_command &LoadCommand) {
346 IO.mapRequired(
"entryoff", LoadCommand.entryoff);
347 IO.mapRequired(
"stacksize", LoadCommand.stacksize);
350 void MappingTraits<MachO::fvmfile_command>::mapping(
351 IO &IO, MachO::fvmfile_command &LoadCommand) {
353 IO.mapRequired(
"name", LoadCommand.name);
354 IO.mapRequired(
"header_addr", LoadCommand.header_addr);
369 void MappingTraits<MachO::ident_command>::mapping(
372 void MappingTraits<MachO::linkedit_data_command>::mapping(
373 IO &IO, MachO::linkedit_data_command &LoadCommand) {
375 IO.mapRequired(
"dataoff", LoadCommand.dataoff);
376 IO.mapRequired(
"datasize", LoadCommand.datasize);
379 void MappingTraits<MachO::linker_option_command>::mapping(
380 IO &IO, MachO::linker_option_command &LoadCommand) {
382 IO.mapRequired(
"count", LoadCommand.count);
385 void MappingTraits<MachO::prebind_cksum_command>::mapping(
386 IO &IO, MachO::prebind_cksum_command &LoadCommand) {
388 IO.mapRequired(
"cksum", LoadCommand.cksum);
391 void MappingTraits<MachO::load_command>::mapping(
392 IO &IO, MachO::load_command &LoadCommand) {}
394 void MappingTraits<MachO::prebound_dylib_command>::mapping(
395 IO &IO, MachO::prebound_dylib_command &LoadCommand) {
397 IO.mapRequired(
"name", LoadCommand.name);
398 IO.mapRequired(
"nmodules", LoadCommand.nmodules);
399 IO.mapRequired(
"linked_modules", LoadCommand.linked_modules);
402 void MappingTraits<MachO::routines_command>::mapping(
403 IO &IO, MachO::routines_command &LoadCommand) {
405 IO.mapRequired(
"init_address", LoadCommand.init_address);
406 IO.mapRequired(
"init_module", LoadCommand.init_module);
407 IO.mapRequired(
"reserved1", LoadCommand.reserved1);
408 IO.mapRequired(
"reserved2", LoadCommand.reserved2);
409 IO.mapRequired(
"reserved3", LoadCommand.reserved3);
410 IO.mapRequired(
"reserved4", LoadCommand.reserved4);
411 IO.mapRequired(
"reserved5", LoadCommand.reserved5);
412 IO.mapRequired(
"reserved6", LoadCommand.reserved6);
415 void MappingTraits<MachO::routines_command_64>::mapping(
416 IO &IO, MachO::routines_command_64 &LoadCommand) {
418 IO.mapRequired(
"init_address", LoadCommand.init_address);
419 IO.mapRequired(
"init_module", LoadCommand.init_module);
420 IO.mapRequired(
"reserved1", LoadCommand.reserved1);
421 IO.mapRequired(
"reserved2", LoadCommand.reserved2);
422 IO.mapRequired(
"reserved3", LoadCommand.reserved3);
423 IO.mapRequired(
"reserved4", LoadCommand.reserved4);
424 IO.mapRequired(
"reserved5", LoadCommand.reserved5);
425 IO.mapRequired(
"reserved6", LoadCommand.reserved6);
428 void MappingTraits<MachO::rpath_command>::mapping(
429 IO &IO, MachO::rpath_command &LoadCommand) {
431 IO.mapRequired(
"path", LoadCommand.path);
478 void MappingTraits<MachO::segment_command_64>::mapping(
481 IO.mapRequired(
"segname", LoadCommand.
segname);
482 IO.mapRequired(
"vmaddr", LoadCommand.
vmaddr);
483 IO.mapRequired(
"vmsize", LoadCommand.
vmsize);
484 IO.mapRequired(
"fileoff", LoadCommand.
fileoff);
485 IO.mapRequired(
"filesize", LoadCommand.
filesize);
486 IO.mapRequired(
"maxprot", LoadCommand.
maxprot);
487 IO.mapRequired(
"initprot", LoadCommand.
initprot);
488 IO.mapRequired(
"nsects", LoadCommand.
nsects);
489 IO.mapRequired(
"flags", LoadCommand.
flags);
492 void MappingTraits<MachO::source_version_command>::mapping(
493 IO &IO, MachO::source_version_command &LoadCommand) {
495 IO.mapRequired(
"version", LoadCommand.version);
498 void MappingTraits<MachO::sub_client_command>::mapping(
499 IO &IO, MachO::sub_client_command &LoadCommand) {
501 IO.mapRequired(
"client", LoadCommand.client);
504 void MappingTraits<MachO::sub_framework_command>::mapping(
505 IO &IO, MachO::sub_framework_command &LoadCommand) {
507 IO.mapRequired(
"umbrella", LoadCommand.umbrella);
510 void MappingTraits<MachO::sub_library_command>::mapping(
511 IO &IO, MachO::sub_library_command &LoadCommand) {
513 IO.mapRequired(
"sub_library", LoadCommand.sub_library);
516 void MappingTraits<MachO::sub_umbrella_command>::mapping(
517 IO &IO, MachO::sub_umbrella_command &LoadCommand) {
519 IO.mapRequired(
"sub_umbrella", LoadCommand.sub_umbrella);
522 void MappingTraits<MachO::symseg_command>::mapping(
523 IO &IO, MachO::symseg_command &LoadCommand) {
525 IO.mapRequired(
"offset", LoadCommand.offset);
526 IO.mapRequired(
"size", LoadCommand.size);
529 void MappingTraits<MachO::symtab_command>::mapping(
530 IO &IO, MachO::symtab_command &LoadCommand) {
532 IO.mapRequired(
"symoff", LoadCommand.symoff);
533 IO.mapRequired(
"nsyms", LoadCommand.nsyms);
534 IO.mapRequired(
"stroff", LoadCommand.stroff);
535 IO.mapRequired(
"strsize", LoadCommand.strsize);
538 void MappingTraits<MachO::thread_command>::mapping(
539 IO &IO, MachO::thread_command &LoadCommand) {}
541 void MappingTraits<MachO::twolevel_hints_command>::mapping(
542 IO &IO, MachO::twolevel_hints_command &LoadCommand) {
544 IO.mapRequired(
"offset", LoadCommand.offset);
545 IO.mapRequired(
"nhints", LoadCommand.nhints);
548 void MappingTraits<MachO::uuid_command>::mapping(
549 IO &IO, MachO::uuid_command &LoadCommand) {
551 IO.mapRequired(
"uuid", LoadCommand.uuid);
554 void MappingTraits<MachO::version_min_command>::mapping(
555 IO &IO, MachO::version_min_command &LoadCommand) {
557 IO.mapRequired(
"version", LoadCommand.version);
558 IO.mapRequired(
"sdk", LoadCommand.sdk);
void mapOptional(const char *Key, T &Val)
std::vector< Object > Slices
std::vector< MachOYAML::ExportEntry > Children
std::vector< llvm::yaml::Hex8 > PayloadBytes
ExportEntry encapsulates the current-state-of-the-walk used when doing a non-recursive walk of the tr...
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
std::vector< int64_t > SLEBExtraData
bool needsQuotes(StringRef S)
std::vector< MachOYAML::RebaseOpcode > RebaseOpcodes
llvm::yaml::Hex32 cputype
static const bool IsLittleEndianHost
llvm::yaml::Hex32 cpusubtype
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
std::vector< yaml::Hex64 > ExtraData
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
std::vector< LoadCommand > LoadCommands
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
virtual bool mapTag(StringRef Tag, bool Default=false)=0
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
llvm::yaml::Hex64 Address
std::vector< MachOYAML::BindOpcode > WeakBindOpcodes
MachOYAML::ExportEntry ExportTrie
std::vector< yaml::Hex64 > ULEBExtraData
MachO::RebaseOpcode Opcode
std::vector< MachOYAML::BindOpcode > BindOpcodes
std::vector< FatArch > FatArchs
This class should be specialized by type that requires custom conversion to/from a yaml scalar...
This file declares classes for handling the YAML representation of Mach-O.
llvm::yaml::Hex32 reserved3
std::vector< NListEntry > NameList
void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand)
llvm::yaml::Hex32 reserved2
virtual bool outputting()=0
This class implements an extremely fast bulk output stream that can only output to a stream...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
std::vector< StringRef > StringTable
StringRef - Represent a constant reference to a string, i.e.
void mapRequired(const char *Key, T &Val)
llvm::MachO::macho_load_command Data
llvm::yaml::Hex32 reserved
std::vector< MachOYAML::BindOpcode > LazyBindOpcodes
uint32_t compatibility_version
llvm::yaml::Hex32 reserved1