40 auto Len = strnlen(&Val[0], 16);
45 size_t CopySize = 16 >= Scalar.
size() ? 16 : Scalar.
size();
46 memcpy((
void *)Val, Scalar.
data(), CopySize);
48 if (Scalar.
size() < 16) {
49 memset((
void *)&Val[Scalar.
size()], 0, 16 - Scalar.
size());
58 for (
int Idx = 0; Idx < 16; ++Idx) {
59 Out <<
format(
"%02" PRIX32, Val[Idx]);
60 if (Idx == 3 || Idx == 5 || Idx == 7 || Idx == 9)
67 for (
size_t Idx = 0; Idx < Scalar.
size(); ++Idx) {
68 if (Scalar[Idx] ==
'-' || OutIdx >= 16)
70 unsigned long long TempInt;
72 return "invalid number";
74 return "out of range number";
75 Val[OutIdx] =
static_cast<uint8_t
>(TempInt);
105 IO.
mapTag(
"!mach-o",
true);
136 static_cast<llvm::yaml::Hex32>(0));
143 IO.
mapTag(
"!fat-mach-o",
true);
202 template <
typename StructType>
206 void mapLoadCommandData<MachO::segment_command>(
212 void mapLoadCommandData<MachO::segment_command_64>(
218 void mapLoadCommandData<MachO::dylib_command>(
224 void mapLoadCommandData<MachO::rpath_command>(
230 void mapLoadCommandData<MachO::dylinker_command>(
236 void mapLoadCommandData<MachO::build_version_command>(
244 LoadCommand.
Data.load_command_data.cmd);
246 LoadCommand.
Data.load_command_data.cmd = TempCmd;
249 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
250 case MachO::LCName: \
251 MappingTraits<MachO::LCStruct>::mapping(IO, \
252 LoadCommand.Data.LCStruct##_data); \
253 mapLoadCommandData<MachO::LCStruct>(IO, LoadCommand); \
256 switch (LoadCommand.
Data.load_command_data.cmd) {
257 #include "llvm/BinaryFormat/MachO.def"
311 void MappingTraits<MachO::dylinker_command>::mapping(
313 IO.mapRequired(
"name", LoadCommand.
name);
316 void MappingTraits<MachO::dysymtab_command>::mapping(
317 IO &IO, MachO::dysymtab_command &LoadCommand) {
318 IO.mapRequired(
"ilocalsym", LoadCommand.ilocalsym);
319 IO.mapRequired(
"nlocalsym", LoadCommand.nlocalsym);
320 IO.mapRequired(
"iextdefsym", LoadCommand.iextdefsym);
321 IO.mapRequired(
"nextdefsym", LoadCommand.nextdefsym);
322 IO.mapRequired(
"iundefsym", LoadCommand.iundefsym);
323 IO.mapRequired(
"nundefsym", LoadCommand.nundefsym);
324 IO.mapRequired(
"tocoff", LoadCommand.tocoff);
325 IO.mapRequired(
"ntoc", LoadCommand.ntoc);
326 IO.mapRequired(
"modtaboff", LoadCommand.modtaboff);
327 IO.mapRequired(
"nmodtab", LoadCommand.nmodtab);
328 IO.mapRequired(
"extrefsymoff", LoadCommand.extrefsymoff);
329 IO.mapRequired(
"nextrefsyms", LoadCommand.nextrefsyms);
330 IO.mapRequired(
"indirectsymoff", LoadCommand.indirectsymoff);
331 IO.mapRequired(
"nindirectsyms", LoadCommand.nindirectsyms);
332 IO.mapRequired(
"extreloff", LoadCommand.extreloff);
333 IO.mapRequired(
"nextrel", LoadCommand.nextrel);
334 IO.mapRequired(
"locreloff", LoadCommand.locreloff);
335 IO.mapRequired(
"nlocrel", LoadCommand.nlocrel);
338 void MappingTraits<MachO::encryption_info_command>::mapping(
339 IO &IO, MachO::encryption_info_command &LoadCommand) {
340 IO.mapRequired(
"cryptoff", LoadCommand.cryptoff);
341 IO.mapRequired(
"cryptsize", LoadCommand.cryptsize);
342 IO.mapRequired(
"cryptid", LoadCommand.cryptid);
345 void MappingTraits<MachO::encryption_info_command_64>::mapping(
346 IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
347 IO.mapRequired(
"cryptoff", LoadCommand.cryptoff);
348 IO.mapRequired(
"cryptsize", LoadCommand.cryptsize);
349 IO.mapRequired(
"cryptid", LoadCommand.cryptid);
350 IO.mapRequired(
"pad", LoadCommand.pad);
353 void MappingTraits<MachO::entry_point_command>::mapping(
354 IO &IO, MachO::entry_point_command &LoadCommand) {
355 IO.mapRequired(
"entryoff", LoadCommand.entryoff);
356 IO.mapRequired(
"stacksize", LoadCommand.stacksize);
359 void MappingTraits<MachO::fvmfile_command>::mapping(
360 IO &IO, MachO::fvmfile_command &LoadCommand) {
361 IO.mapRequired(
"name", LoadCommand.name);
362 IO.mapRequired(
"header_addr", LoadCommand.header_addr);
376 void MappingTraits<MachO::ident_command>::mapping(
379 void MappingTraits<MachO::linkedit_data_command>::mapping(
380 IO &IO, MachO::linkedit_data_command &LoadCommand) {
381 IO.mapRequired(
"dataoff", LoadCommand.dataoff);
382 IO.mapRequired(
"datasize", LoadCommand.datasize);
385 void MappingTraits<MachO::linker_option_command>::mapping(
386 IO &IO, MachO::linker_option_command &LoadCommand) {
387 IO.mapRequired(
"count", LoadCommand.count);
390 void MappingTraits<MachO::prebind_cksum_command>::mapping(
391 IO &IO, MachO::prebind_cksum_command &LoadCommand) {
392 IO.mapRequired(
"cksum", LoadCommand.cksum);
395 void MappingTraits<MachO::load_command>::mapping(
396 IO &IO, MachO::load_command &LoadCommand) {}
398 void MappingTraits<MachO::prebound_dylib_command>::mapping(
399 IO &IO, MachO::prebound_dylib_command &LoadCommand) {
400 IO.mapRequired(
"name", LoadCommand.name);
401 IO.mapRequired(
"nmodules", LoadCommand.nmodules);
402 IO.mapRequired(
"linked_modules", LoadCommand.linked_modules);
405 void MappingTraits<MachO::routines_command>::mapping(
406 IO &IO, MachO::routines_command &LoadCommand) {
407 IO.mapRequired(
"init_address", LoadCommand.init_address);
408 IO.mapRequired(
"init_module", LoadCommand.init_module);
409 IO.mapRequired(
"reserved1", LoadCommand.reserved1);
410 IO.mapRequired(
"reserved2", LoadCommand.reserved2);
411 IO.mapRequired(
"reserved3", LoadCommand.reserved3);
412 IO.mapRequired(
"reserved4", LoadCommand.reserved4);
413 IO.mapRequired(
"reserved5", LoadCommand.reserved5);
414 IO.mapRequired(
"reserved6", LoadCommand.reserved6);
417 void MappingTraits<MachO::routines_command_64>::mapping(
418 IO &IO, MachO::routines_command_64 &LoadCommand) {
419 IO.mapRequired(
"init_address", LoadCommand.init_address);
420 IO.mapRequired(
"init_module", LoadCommand.init_module);
421 IO.mapRequired(
"reserved1", LoadCommand.reserved1);
422 IO.mapRequired(
"reserved2", LoadCommand.reserved2);
423 IO.mapRequired(
"reserved3", LoadCommand.reserved3);
424 IO.mapRequired(
"reserved4", LoadCommand.reserved4);
425 IO.mapRequired(
"reserved5", LoadCommand.reserved5);
426 IO.mapRequired(
"reserved6", LoadCommand.reserved6);
429 void MappingTraits<MachO::rpath_command>::mapping(
430 IO &IO, MachO::rpath_command &LoadCommand) {
431 IO.mapRequired(
"path", LoadCommand.path);
477 void MappingTraits<MachO::segment_command_64>::mapping(
479 IO.mapRequired(
"segname", LoadCommand.
segname);
480 IO.mapRequired(
"vmaddr", LoadCommand.
vmaddr);
481 IO.mapRequired(
"vmsize", LoadCommand.
vmsize);
482 IO.mapRequired(
"fileoff", LoadCommand.
fileoff);
483 IO.mapRequired(
"filesize", LoadCommand.
filesize);
484 IO.mapRequired(
"maxprot", LoadCommand.
maxprot);
485 IO.mapRequired(
"initprot", LoadCommand.
initprot);
486 IO.mapRequired(
"nsects", LoadCommand.
nsects);
487 IO.mapRequired(
"flags", LoadCommand.
flags);
490 void MappingTraits<MachO::source_version_command>::mapping(
491 IO &IO, MachO::source_version_command &LoadCommand) {
492 IO.mapRequired(
"version", LoadCommand.version);
495 void MappingTraits<MachO::sub_client_command>::mapping(
496 IO &IO, MachO::sub_client_command &LoadCommand) {
497 IO.mapRequired(
"client", LoadCommand.client);
500 void MappingTraits<MachO::sub_framework_command>::mapping(
501 IO &IO, MachO::sub_framework_command &LoadCommand) {
502 IO.mapRequired(
"umbrella", LoadCommand.umbrella);
505 void MappingTraits<MachO::sub_library_command>::mapping(
506 IO &IO, MachO::sub_library_command &LoadCommand) {
507 IO.mapRequired(
"sub_library", LoadCommand.sub_library);
510 void MappingTraits<MachO::sub_umbrella_command>::mapping(
511 IO &IO, MachO::sub_umbrella_command &LoadCommand) {
512 IO.mapRequired(
"sub_umbrella", LoadCommand.sub_umbrella);
515 void MappingTraits<MachO::symseg_command>::mapping(
516 IO &IO, MachO::symseg_command &LoadCommand) {
517 IO.mapRequired(
"offset", LoadCommand.offset);
518 IO.mapRequired(
"size", LoadCommand.size);
521 void MappingTraits<MachO::symtab_command>::mapping(
522 IO &IO, MachO::symtab_command &LoadCommand) {
523 IO.mapRequired(
"symoff", LoadCommand.symoff);
524 IO.mapRequired(
"nsyms", LoadCommand.nsyms);
525 IO.mapRequired(
"stroff", LoadCommand.stroff);
526 IO.mapRequired(
"strsize", LoadCommand.strsize);
529 void MappingTraits<MachO::thread_command>::mapping(
530 IO &IO, MachO::thread_command &LoadCommand) {}
532 void MappingTraits<MachO::twolevel_hints_command>::mapping(
533 IO &IO, MachO::twolevel_hints_command &LoadCommand) {
534 IO.mapRequired(
"offset", LoadCommand.offset);
535 IO.mapRequired(
"nhints", LoadCommand.nhints);
538 void MappingTraits<MachO::uuid_command>::mapping(
539 IO &IO, MachO::uuid_command &LoadCommand) {
540 IO.mapRequired(
"uuid", LoadCommand.uuid);
543 void MappingTraits<MachO::version_min_command>::mapping(
544 IO &IO, MachO::version_min_command &LoadCommand) {
545 IO.mapRequired(
"version", LoadCommand.version);
546 IO.mapRequired(
"sdk", LoadCommand.sdk);
549 void MappingTraits<MachO::note_command>::mapping(
550 IO &IO, MachO::note_command &LoadCommand) {
551 IO.mapRequired(
"data_owner", LoadCommand.data_owner);
552 IO.mapRequired(
"offset", LoadCommand.offset);
553 IO.mapRequired(
"size", LoadCommand.size);
556 void MappingTraits<MachO::build_version_command>::mapping(
557 IO &IO, MachO::build_version_command &LoadCommand) {
558 IO.mapRequired(
"platform", LoadCommand.platform);
559 IO.mapRequired(
"minos", LoadCommand.minos);
560 IO.mapRequired(
"sdk", LoadCommand.sdk);
561 IO.mapRequired(
"ntools", LoadCommand.ntools);
void mapOptional(const char *Key, T &Val)
std::vector< Object > Slices
std::vector< MachOYAML::ExportEntry > Children
std::vector< llvm::yaml::Hex8 > PayloadBytes
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