29 #ifndef __UPX_P_MACHO_H 30 #define __UPX_P_MACHO_H 1 33 __packed_struct(Mach_fat_header)
36 FAT_MAGIC = 0xcafebabe,
37 FAT_MAGIC_SWAB = 0xbebafeca
42 __packed_struct(Mach_fat_arch)
58 template <
class TWord,
class TXword,
class TAddr,
class TOff>
67 template <
class TMachITypes>
68 __packed_struct(Mach_header)
69 typedef typename TMachITypes::Word Word;
78 #define WANT_MACH_HEADER_ENUM 1 79 #include "p_mach_enum.h" 82 template <class TMachITypes>
83 __packed_struct(Mach_header64)
85 typedef typename TMachITypes::Word Word;
95 #define WANT_MACH_HEADER_ENUM 1 96 #include "p_mach_enum.h" 99 template <class TMachITypes>
100 __packed_struct(Mach_command)
101 typedef typename TMachITypes::Word Word;
106 #define WANT_MACH_SEGMENT_ENUM 1 107 #include "p_mach_enum.h" 108 __packed_struct_end();
110 template <
class TMachITypes>
111 __packed_struct(Mach_segment_command)
112 typedef typename TMachITypes::Word Word;
113 typedef typename TMachITypes::Addr Addr;
114 typedef typename TMachITypes::Off Off;
127 #define WANT_MACH_SEGMENT_ENUM 1 128 #include "p_mach_enum.h" 129 __packed_struct_end()
131 template <class TMachITypes>
132 __packed_struct(Mach_section_command)
133 typedef typename TMachITypes::Word Word;
134 typedef typename TMachITypes::Addr Addr;
135 typedef typename TMachITypes::Off Off;
148 #define WANT_MACH_SECTION_ENUM 1 149 #include "p_mach_enum.h" 150 __packed_struct_end()
152 template <class TMachITypes>
153 __packed_struct(Mach_section_command_64)
154 typedef typename TMachITypes::Word Word;
155 typedef typename TMachITypes::Addr Addr;
156 typedef typename TMachITypes::Off Off;
157 typedef typename TMachITypes::Word Off32;
158 typedef typename TMachITypes::Xword Xword;
172 #define WANT_MACH_SECTION_ENUM 1 173 #include "p_mach_enum.h" 174 __packed_struct_end()
176 template <class TMachITypes>
177 __packed_struct(Mach_symtab_command)
178 typedef typename TMachITypes::Word Word;
179 typedef typename TMachITypes::Off Off;
180 typedef typename TMachITypes::Word Off32;
188 __packed_struct_end()
190 template <class TMachITypes>
191 __packed_struct(Mach_dysymtab_command)
192 typedef typename TMachITypes::Word Word;
193 typedef typename TMachITypes::Off Off;
194 typedef typename TMachITypes::Word Off32;
210 Off32 indirectsymoff;
216 __packed_struct_end()
218 template <class TMachITypes>
219 __packed_struct(Mach_segsplit_info_command)
220 typedef typename TMachITypes::Word Word;
221 typedef typename TMachITypes::Off Off;
227 __packed_struct_end()
229 template <class TMachITypes>
230 __packed_struct(Mach_routines_command)
231 typedef typename TMachITypes::Word Word;
232 typedef typename TMachITypes::Addr Addr;
244 #define WANT_MACH_SEGMENT_ENUM 1 245 #include "p_mach_enum.h" 246 __packed_struct_end()
248 template <class TMachITypes>
249 __packed_struct(Mach_routines_command_64)
250 typedef typename TMachITypes::Word Word;
251 typedef typename TMachITypes::Addr Addr;
252 typedef typename TMachITypes::Xword Xword;
264 #define WANT_MACH_SEGMENT_ENUM 1 265 #include "p_mach_enum.h" 266 __packed_struct_end()
268 template <class TMachITypes>
269 __packed_struct(Mach_twolevel_hints_command)
270 typedef typename TMachITypes::Word Word;
271 typedef typename TMachITypes::Off Off;
277 #define WANT_MACH_SEGMENT_ENUM 1 278 #include "p_mach_enum.h" 279 __packed_struct_end()
281 template <class TMachITypes>
282 __packed_struct(Mach_linkedit_data_command)
283 typedef typename TMachITypes::Word Word;
289 __packed_struct_end()
291 template <class TMachITypes>
292 __packed_struct(Mach_uuid_command)
293 typedef typename TMachITypes::Word Word;
297 unsigned char uuid[16];
298 __packed_struct_end()
300 template <class TMachITypes, class TMachThreadState>
301 __packed_struct(Mach_thread_command)
302 typedef typename TMachITypes::Word Word;
308 TMachThreadState state;
309 #define WANT_MACH_THREAD_ENUM 1 310 #include "p_mach_enum.h" 311 __packed_struct_end()
313 template <class TMachITypes>
314 __packed_struct(Mach_main_command)
315 typedef typename TMachITypes::Word Word;
316 typedef typename TMachITypes::Xword Xword;
322 __packed_struct_end()
324 template <class TMachITypes>
325 __packed_struct(Mach_source_version_command)
326 typedef typename TMachITypes::Word Word;
331 __packed_struct_end()
333 template <class TMachITypes>
334 __packed_struct(Mach_version_min_command)
335 typedef typename TMachITypes::Word Word;
341 __packed_struct_end()
343 template <class TMachITypes>
344 __packed_struct(Mach_dyld_info_only_command)
345 typedef typename TMachITypes::Word Word;
359 __packed_struct_end()
361 template <class TMachITypes>
362 __packed_struct(Mach_load_dylinker_command)
363 typedef typename TMachITypes::Word Word;
368 __packed_struct_end()
370 template <class TMachITypes>
371 __packed_struct(Mach_dylib)
372 typedef typename TMachITypes::Word Word;
376 Word current_version;
377 Word compatibility_version;
378 __packed_struct_end()
380 template <class TMachITypes>
381 __packed_struct(Mach_load_dylib_command)
382 typedef typename TMachITypes::Word Word;
386 Mach_dylib<TMachITypes> dylib;
387 __packed_struct_end()
389 template <class TMachITypes>
390 __packed_struct(Mach_function_starts_command)
391 typedef typename TMachITypes::Word Word;
397 __packed_struct_end()
399 template <class TMachITypes>
400 __packed_struct(Mach_data_in_code_command)
401 typedef typename TMachITypes::Word Word;
407 __packed_struct_end()
413 template <
class TMachITypes>
414 __packed_struct(Mach_ppc_thread_state)
415 typedef typename TMachITypes::Addr Addr;
419 Addr r0, r1, r2, r3, r4, r5, r6, r7;
420 Addr r8, r9,r10,r11,r12,r13,r14,r15;
421 Addr r16,r17,r18,r19,r20,r21,r22,r23;
422 Addr r24,r25,r26,r27,r28,r29,r30,r31;
431 __packed_struct_end()
433 template <class TMachITypes>
434 __packed_struct(Mach_i386_thread_state)
435 typedef typename TMachITypes::Word Word;
437 Word eax, ebx, ecx, edx;
443 __packed_struct_end()
445 template <class TMachITypes>
446 __packed_struct(Mach_ARM_thread_state)
447 typedef typename TMachITypes::Word Word;
454 __packed_struct_end()
460 template <
class TMachITypes>
461 __packed_struct(Mach_AMD64_thread_state)
462 typedef typename TMachITypes::Xword Xword;
464 Xword rax, rbx, rcx, rdx;
465 Xword rdi, rsi, rbp, rsp;
466 Xword r8, r9, r10, r11;
467 Xword r12, r13, r14, r15;
470 __packed_struct_end()
472 template <class TMachITypes>
473 __packed_struct(Mach_ppc_thread_state64)
474 typedef typename TMachITypes::Word Word;
475 typedef typename TMachITypes::Xword Xword;
479 Xword r0, r1, r2, r3, r4, r5, r6, r7;
480 Xword r8, r9,r10,r11,r12,r13,r14,r15;
481 Xword r16,r17,r18,r19,r20,r21,r22,r23;
482 Xword r24,r25,r26,r27,r28,r29,r30,r31;
490 __packed_struct_end()
492 template <class TMachITypes>
493 __packed_struct(Mach_ppcle_thread_state64)
494 typedef typename TMachITypes::Word Word;
495 typedef typename TMachITypes::Xword Xword;
499 Xword r0, r1, r2, r3, r4, r5, r6, r7;
500 Xword r8, r9,r10,r11,r12,r13,r14,r15;
501 Xword r16,r17,r18,r19,r20,r21,r22,r23;
502 Xword r24,r25,r26,r27,r28,r29,r30,r31;
510 __packed_struct_end()
512 template <class TMachITypes> __packed_struct(Mach_ARM64_thread_state)
513 typedef typename TMachITypes::Xword Xword;
514 typedef typename TMachITypes::Word Word;
516 Xword x0, x1, x2, x3;
517 Xword x4, x5, x6, x7;
518 Xword x8, x9, x10, x11;
519 Xword x12, x13, x14, x15;
520 Xword x16, x17, x18, x19;
521 Xword x20, x21, x22, x23;
522 Xword x24, x25, x26, x27;
523 Xword x28, fp, lr, sp;
526 __packed_struct_end()
535 typedef TP BeLePolicy;
538 typedef typename TP::U16 TE16;
539 typedef typename TP::U32 TE32;
540 typedef typename TP::U64 TE64;
541 typedef N_Mach::MachITypes<TE32, TE64, TE32, TE32> MachITypes;
542 typedef typename MachITypes::Addr Addr;
545 typedef N_Mach::Mach_header<MachITypes> Mach_header;
546 typedef N_Mach::Mach_command<MachITypes> Mach_command;
547 typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command;
548 typedef N_Mach::Mach_section_command<MachITypes> Mach_section_command;
549 typedef N_Mach::Mach_symtab_command<MachITypes> Mach_symtab_command;
550 typedef N_Mach::Mach_dysymtab_command<MachITypes> Mach_dysymtab_command;
551 typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command;
552 typedef N_Mach::Mach_routines_command<MachITypes> Mach_routines_command;
553 typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command;
554 typedef N_Mach::Mach_linkedit_data_command<MachITypes> Mach_linkedit_data_command;
555 typedef N_Mach::Mach_uuid_command<MachITypes> Mach_uuid_command;
556 typedef N_Mach::Mach_data_in_code_command<MachITypes> Mach_data_in_code_command;
557 typedef N_Mach::Mach_function_starts_command<MachITypes> Mach_function_starts_command;
558 typedef N_Mach::Mach_load_dylib_command<MachITypes> Mach_load_dylib_command;
559 typedef N_Mach::Mach_dylib<MachITypes> Mach_dylib;
560 typedef N_Mach::Mach_load_dylinker_command<MachITypes> Mach_load_dylinker_command;
561 typedef N_Mach::Mach_dyld_info_only_command<MachITypes> Mach_dyld_info_only_command;
562 typedef N_Mach::Mach_version_min_command<MachITypes> Mach_version_min_command;
563 typedef N_Mach::Mach_source_version_command<MachITypes> Mach_source_version_command;
564 typedef N_Mach::Mach_main_command<MachITypes> Mach_main_command;
566 typedef N_Mach32::Mach_ppc_thread_state<MachITypes> Mach_ppc_thread_state;
567 typedef N_Mach32::Mach_i386_thread_state<MachITypes> Mach_i386_thread_state;
568 typedef N_Mach32::Mach_ARM_thread_state<MachITypes> Mach_ARM_thread_state;
570 static void compileTimeAssertions() {
571 BeLePolicy::compileTimeAssertions();
572 COMPILE_TIME_ASSERT(
sizeof(Addr) == 4)
579 typedef TP BeLePolicy;
582 typedef typename TP::U16 TE16;
583 typedef typename TP::U32 TE32;
584 typedef typename TP::U64 TE64;
585 typedef N_Mach::MachITypes<TE32, TE64, TE64, TE64> MachITypes;
586 typedef typename MachITypes::Addr Addr;
589 typedef N_Mach::Mach_header64<MachITypes> Mach_header;
590 typedef N_Mach::Mach_command<MachITypes> Mach_command;
591 typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command;
592 typedef N_Mach::Mach_section_command_64<MachITypes> Mach_section_command;
593 typedef N_Mach::Mach_symtab_command<MachITypes> Mach_symtab_command;
594 typedef N_Mach::Mach_dysymtab_command<MachITypes> Mach_dysymtab_command;
595 typedef N_Mach::Mach_segsplit_info_command<MachITypes> Mach_segsplit_info_command;
596 typedef N_Mach::Mach_routines_command_64<MachITypes> Mach_routines_command;
597 typedef N_Mach::Mach_twolevel_hints_command<MachITypes> Mach_twolevel_hints_command;
598 typedef N_Mach::Mach_linkedit_data_command<MachITypes> Mach_linkedit_data_command;
599 typedef N_Mach::Mach_uuid_command<MachITypes> Mach_uuid_command;
600 typedef N_Mach::Mach_data_in_code_command<MachITypes> Mach_data_in_code_command;
601 typedef N_Mach::Mach_function_starts_command<MachITypes> Mach_function_starts_command;
602 typedef N_Mach::Mach_load_dylib_command<MachITypes> Mach_load_dylib_command;
603 typedef N_Mach::Mach_dylib<MachITypes> Mach_dylib;
604 typedef N_Mach::Mach_load_dylinker_command<MachITypes> Mach_load_dylinker_command;
605 typedef N_Mach::Mach_dyld_info_only_command<MachITypes> Mach_dyld_info_only_command;
606 typedef N_Mach::Mach_version_min_command<MachITypes> Mach_version_min_command;
607 typedef N_Mach::Mach_source_version_command<MachITypes> Mach_source_version_command;
608 typedef N_Mach::Mach_main_command<MachITypes> Mach_main_command;
610 typedef N_Mach64::Mach_ppcle_thread_state64<MachITypes> Mach_ppcle_thread_state64;
611 typedef N_Mach64::Mach_AMD64_thread_state<MachITypes> Mach_AMD64_thread_state;
612 typedef N_Mach64::Mach_ARM64_thread_state<MachITypes> Mach_ARM64_thread_state;
614 static void compileTimeAssertions() {
615 BeLePolicy::compileTimeAssertions();
616 COMPILE_TIME_ASSERT(
sizeof(Addr) == 8)
630 typedef MachClass_Host32::Mach_segment_command Mach32_segment_command;
631 typedef MachClass_Host32::Mach_section_command Mach32_section_command;
632 typedef MachClass_Host32::Mach_symtab_command Mach32_symtab_command;
633 typedef MachClass_Host32::Mach_dysymtab_command Mach32_dysymtab_command;
634 typedef MachClass_Host32::Mach_segsplit_info_command Mach32_segsplit_info_command;
635 typedef MachClass_Host32::Mach_routines_command Mach32_routines_command;
636 typedef MachClass_Host32::Mach_twolevel_hints_command Mach32_twolevel_hints_command;
637 typedef MachClass_Host32::Mach_linkedit_data_command Mach32_linkedit_data_command;
638 typedef MachClass_Host32::Mach_uuid_command Mach32_uuid_command;
639 typedef MachClass_Host32::Mach_main_command Mach32_main_command;
640 typedef MachClass_Host32::Mach_data_in_code_command Mach32_data_in_code_command;
641 typedef MachClass_Host32::Mach_function_starts_command Mach32_function_starts_command;
642 typedef MachClass_Host32::Mach_load_dylib_command Mach32_load_dylib_command;
643 typedef MachClass_Host32::Mach_dylib Mach32_dylib;
644 typedef MachClass_Host32::Mach_load_dylinker_command Mach32_load_dylinker_command;
645 typedef MachClass_Host32::Mach_dyld_info_only_command Mach32_dyld_info_only_command;
646 typedef MachClass_Host32::Mach_version_min_command Mach32_version_min_command;
647 typedef MachClass_Host32::Mach_source_version_command Mach32_source_version_command;
649 typedef MachClass_Host64::Mach_segment_command Mach64_segment_command;
650 typedef MachClass_Host64::Mach_section_command Mach64_section_command;
651 typedef MachClass_Host64::Mach_symtab_command Mach64_symtab_command;
652 typedef MachClass_Host64::Mach_dysymtab_command Mach64_dysymtab_command;
653 typedef MachClass_Host64::Mach_segsplit_info_command Mach64_segsplit_info_command;
654 typedef MachClass_Host64::Mach_routines_command Mach64_routines_command;
655 typedef MachClass_Host64::Mach_twolevel_hints_command Mach64_twolevel_hints_command;
656 typedef MachClass_Host64::Mach_linkedit_data_command Mach64_linkedit_data_command;
657 typedef MachClass_Host64::Mach_uuid_command Mach64_uuid_command;
658 typedef MachClass_Host64::Mach_main_command Mach64_main_command;
659 typedef MachClass_Host64::Mach_data_in_code_command Mach64_data_in_code_command;
660 typedef MachClass_Host64::Mach_function_starts_command Mach64_function_starts_command;
661 typedef MachClass_Host64::Mach_load_dylib_command Mach64_load_dylib_command;
662 typedef MachClass_Host64::Mach_dylib Mach64_dylib;
663 typedef MachClass_Host64::Mach_load_dylinker_command Mach64_load_dylinker_command;
664 typedef MachClass_Host64::Mach_dyld_info_only_command Mach64_dyld_info_only_command;
665 typedef MachClass_Host64::Mach_version_min_command Mach64_version_min_command;
666 typedef MachClass_Host64::Mach_source_version_command Mach64_source_version_command;
668 typedef MachClass_BE32::Mach_segment_command MachBE32_segment_command;
669 typedef MachClass_BE32::Mach_section_command MachBE32_section_command;
670 typedef MachClass_BE32::Mach_symtab_command MachBE32_symtab_command;
671 typedef MachClass_BE32::Mach_dysymtab_command MachBE32_dysymtab_command;
672 typedef MachClass_BE32::Mach_segsplit_info_command MachBE32_segsplit_info_command;
673 typedef MachClass_BE32::Mach_routines_command MachBE32_routines_command;
674 typedef MachClass_BE32::Mach_twolevel_hints_command MachBE32_twolevel_hints_command;
675 typedef MachClass_BE32::Mach_linkedit_data_command MachBE32_linkedit_data_command;
676 typedef MachClass_BE32::Mach_uuid_command MachBE32_uuid_command;
677 typedef MachClass_BE32::Mach_main_command MachBE32_main_command;
678 typedef MachClass_BE32::Mach_data_in_code_command MachBE32_data_in_code_command;
679 typedef MachClass_BE32::Mach_function_starts_command MachBE32_function_starts_command;
680 typedef MachClass_BE32::Mach_load_dylib_command MachBE32_load_dylib_command;
681 typedef MachClass_BE32::Mach_dylib MachBE32_dylib;
682 typedef MachClass_BE32::Mach_load_dylinker_command MachBE32_load_dylinker_command;
683 typedef MachClass_BE32::Mach_dyld_info_only_command MachBE32_dyld_info_only_command;
684 typedef MachClass_BE32::Mach_version_min_command MachBE32_version_min_command;
685 typedef MachClass_BE32::Mach_source_version_command MachBE32_source_version_command;
687 typedef MachClass_BE64::Mach_segment_command MachBE64_segment_command;
688 typedef MachClass_BE64::Mach_section_command MachBE64_section_command;
689 typedef MachClass_BE64::Mach_symtab_command MachBE64_symtab_command;
690 typedef MachClass_BE64::Mach_dysymtab_command MachBE64_dysymtab_command;
691 typedef MachClass_BE64::Mach_segsplit_info_command MachBE64_segsplit_info_command;
692 typedef MachClass_BE64::Mach_routines_command MachBE64_routines_command;
693 typedef MachClass_BE64::Mach_twolevel_hints_command MachBE64_twolevel_hints_command;
694 typedef MachClass_BE64::Mach_linkedit_data_command MachBE64_linkedit_data_command;
695 typedef MachClass_BE64::Mach_uuid_command MachBE64_uuid_command;
696 typedef MachClass_BE64::Mach_main_command MachBE64_main_command;
697 typedef MachClass_BE64::Mach_data_in_code_command MachBE64_data_in_code_command;
698 typedef MachClass_BE64::Mach_function_starts_command MachBE64_function_starts_command;
699 typedef MachClass_BE64::Mach_load_dylib_command MachBE64_load_dylib_command;
700 typedef MachClass_BE64::Mach_dylib MachBE64_dylib;
701 typedef MachClass_BE64::Mach_load_dylinker_command MachBE64_load_dylinker_command;
702 typedef MachClass_BE64::Mach_dyld_info_only_command MachBE64_dyld_info_only_command;
703 typedef MachClass_BE64::Mach_version_min_command MachBE64_version_min_command;
704 typedef MachClass_BE64::Mach_source_version_command MachBE64_source_version_command;
706 typedef MachClass_LE32::Mach_segment_command MachLE32_segment_command;
707 typedef MachClass_LE32::Mach_section_command MachLE32_section_command;
708 typedef MachClass_LE32::Mach_symtab_command MachLE32_symtab_command;
709 typedef MachClass_LE32::Mach_dysymtab_command MachLE32_dysymtab_command;
710 typedef MachClass_LE32::Mach_segsplit_info_command MachLE32_segsplit_info_command;
711 typedef MachClass_LE32::Mach_routines_command MachLE32_routines_command;
712 typedef MachClass_LE32::Mach_twolevel_hints_command MachLE32_twolevel_hints_command;
713 typedef MachClass_LE32::Mach_linkedit_data_command MachLE32_linkedit_data_command;
714 typedef MachClass_LE32::Mach_uuid_command MachLE32_uuid_command;
715 typedef MachClass_LE32::Mach_main_command MachLE32_main_command;
716 typedef MachClass_LE32::Mach_data_in_code_command MachLE32_data_in_code_command;
717 typedef MachClass_LE32::Mach_function_starts_command MachLE32_function_starts_command;
718 typedef MachClass_LE32::Mach_load_dylib_command MachLE32_load_dylib_command;
719 typedef MachClass_LE32::Mach_dylib MachLE32_dylib;
720 typedef MachClass_LE32::Mach_load_dylinker_command MachLE32_load_dylinker_command;
721 typedef MachClass_LE32::Mach_dyld_info_only_command MachLE32_dyld_info_only_command;
722 typedef MachClass_LE32::Mach_version_min_command MachLE32_version_min_command;
723 typedef MachClass_LE32::Mach_source_version_command MachLE32_source_version_command;
725 typedef MachClass_LE64::Mach_segment_command MachLE64_segment_command;
726 typedef MachClass_LE64::Mach_section_command MachLE64_section_command;
727 typedef MachClass_LE64::Mach_symtab_command MachLE64_symtab_command;
728 typedef MachClass_LE64::Mach_dysymtab_command MachLE64_dysymtab_command;
729 typedef MachClass_LE64::Mach_segsplit_info_command MachLE64_segsplit_info_command;
730 typedef MachClass_LE64::Mach_routines_command MachLE64_routines_command;
731 typedef MachClass_LE64::Mach_twolevel_hints_command MachLE64_twolevel_hints_command;
732 typedef MachClass_LE64::Mach_linkedit_data_command MachLE64_linkedit_data_command;
733 typedef MachClass_LE64::Mach_uuid_command MachLE64_uuid_command;
734 typedef MachClass_LE64::Mach_main_command MachLE64_main_command;
735 typedef MachClass_LE64::Mach_data_in_code_command MachLE64_data_in_code_command;
736 typedef MachClass_LE64::Mach_function_starts_command MachLE64_function_starts_command;
737 typedef MachClass_LE64::Mach_load_dylib_command MachLE64_load_dylib_command;
738 typedef MachClass_LE64::Mach_dylib MachLE64_dylib;
739 typedef MachClass_LE64::Mach_load_dylinker_command MachLE64_load_dylinker_command;
740 typedef MachClass_LE64::Mach_dyld_info_only_command MachLE64_dyld_info_only_command;
741 typedef MachClass_LE64::Mach_version_min_command MachLE64_version_min_command;
742 typedef MachClass_LE64::Mach_source_version_command MachLE64_source_version_command;
744 typedef MachClass_BE32::Mach_ppc_thread_state Mach_ppc_thread_state;
745 typedef MachClass_LE64::Mach_ppcle_thread_state64 Mach_ppcle_thread_state64;
746 typedef MachClass_LE32::Mach_i386_thread_state Mach_i386_thread_state;
747 typedef MachClass_LE64::Mach_AMD64_thread_state Mach_AMD64_thread_state;
748 typedef MachClass_LE64::Mach_ARM64_thread_state Mach_ARM64_thread_state;
749 typedef MachClass_LE32::Mach_ARM_thread_state Mach_ARM_thread_state;
753 template <
class TMachClass>
758 typedef TMachClass MachClass;
759 typedef typename MachClass::BeLePolicy BeLePolicy;
760 typedef typename MachClass::MachITypes MachITypes;
762 typedef typename MachClass::TE16 TE16;
763 typedef typename MachClass::TE32 TE32;
764 typedef typename MachClass::TE64 TE64;
765 typedef typename MachClass::Addr Addr;
767 typedef typename MachClass::Mach_header Mach_header;
768 typedef typename MachClass::Mach_command Mach_command;
769 typedef typename MachClass::Mach_segment_command Mach_segment_command;
770 typedef typename MachClass::Mach_section_command Mach_section_command;
771 typedef typename MachClass::Mach_symtab_command Mach_symtab_command;
772 typedef typename MachClass::Mach_dysymtab_command Mach_dysymtab_command;
773 typedef typename MachClass::Mach_segsplit_info_command Mach_segsplit_info_command;
774 typedef typename MachClass::Mach_routines_command Mach_routines_command;
775 typedef typename MachClass::Mach_twolevel_hints_command Mach_twolevel_hints_command;
776 typedef typename MachClass::Mach_linkedit_data_command Mach_linkedit_data_command;
777 typedef typename MachClass::Mach_uuid_command Mach_uuid_command;
778 typedef typename MachClass::Mach_main_command Mach_main_command;
779 typedef typename MachClass::Mach_data_in_code_command Mach_data_in_code_command;
780 typedef typename MachClass::Mach_function_starts_command Mach_function_starts_command;
781 typedef typename MachClass::Mach_load_dylib_command Mach_load_dylib_command;
782 typedef typename MachClass::Mach_dylib Mach_dylib;
783 typedef typename MachClass::Mach_load_dylinker_command Mach_load_dylinker_command;
784 typedef typename MachClass::Mach_dyld_info_only_command Mach_dyld_info_only_command;
785 typedef typename MachClass::Mach_version_min_command Mach_version_min_command;
786 typedef typename MachClass::Mach_source_version_command Mach_source_version_command;
790 unsigned t_flavor,
unsigned ts_word_cnt,
unsigned tc_size);
792 virtual int getVersion()
const {
return 13; }
793 virtual const int *getCompressionMethods(
int method,
int level)
const;
803 virtual int threado_size()
const = 0;
804 virtual void threado_setPC(upx_uint64_t pc) = 0;
805 virtual void threado_rewrite(
OutputFile *) = 0;
807 virtual void pack1_setup_threado(
OutputFile *
const fo) = 0;
810 virtual bool canPack();
811 virtual int canUnpack();
812 virtual unsigned find_SEGMENT_gap(
unsigned const k,
unsigned pos_eof);
815 virtual void patchLoader();
816 virtual void patchLoaderChecksum();
818 virtual void buildLoader(
const Filter *ft);
819 virtual void buildMachLoader(
820 upx_byte
const *
const proto,
821 unsigned const szproto,
822 upx_byte
const *
const fold,
823 unsigned const szfold,
825 virtual void defineSymbols(
Filter const *);
826 virtual void addStubEntrySections(
Filter const *);
828 static int __acc_cdecl_qsort compare_segment_command(
void const *aa,
void const *bb);
830 virtual upx_uint64_t threadc_getPC(
void const *) = 0;
832 upx_uint64_t entryVMA;
834 unsigned my_cpusubtype;
835 unsigned my_filetype;
836 unsigned my_thread_flavor;
837 unsigned my_thread_state_word_count;
838 unsigned my_thread_command_size;
842 unsigned sz_mach_headers;
843 unsigned sz_stub_entry;
844 unsigned sz_stub_fold;
845 unsigned sz_stub_main;
846 upx_byte
const *stub_entry;
847 upx_byte
const *stub_fold;
848 upx_byte
const *stub_main;
849 Mach_segment_command *rawmseg;
850 Mach_segment_command *msegcmd;
851 unsigned o_routines_cmd;
852 upx_uint64_t prev_init_address;
856 Mach_segment_command segZERO;
857 Mach_segment_command segXHDR;
858 Mach_section_command secXHDR;
859 Mach_segment_command segTEXT;
860 Mach_section_command secTEXT;
861 Mach_segment_command segLINK;
862 Mach_linkedit_data_command linkitem;
863 Mach_uuid_command cmdUUID;
864 Mach_source_version_command cmdSRCVER;
865 Mach_version_min_command cmdVERMIN;
867 __packed_struct(b_info)
870 unsigned char b_method;
871 unsigned char b_ftid;
872 unsigned char b_cto8;
873 unsigned char b_unused;
874 __packed_struct_end()
876 __packed_struct(l_info)
880 unsigned char l_version;
881 unsigned char l_format;
882 __packed_struct_end()
884 __packed_struct(p_info)
888 __packed_struct_end()
892 static void compileTimeAssertions() {
893 MachClass::compileTimeAssertions();
894 COMPILE_TIME_ASSERT(
sizeof(b_info) == 12)
895 COMPILE_TIME_ASSERT(
sizeof(l_info) == 12)
896 COMPILE_TIME_ASSERT(
sizeof(p_info) == 12)
897 COMPILE_TIME_ASSERT_ALIGNED1(b_info)
898 COMPILE_TIME_ASSERT_ALIGNED1(l_info)
899 COMPILE_TIME_ASSERT_ALIGNED1(p_info)
911 virtual int getFormat()
const {
return UPX_F_MACH_PPC32; }
912 virtual const char *getName()
const {
return "macho/ppc32"; }
913 virtual const char *getFullName(
const options_t *)
const {
return "powerpc-darwin.macho"; }
916 virtual const int *getFilters()
const;
918 virtual void pack1_setup_threado(
OutputFile *
const fo);
919 virtual Linker* newLinker()
const;
920 virtual void addStubEntrySections(
Filter const *);
922 __packed_struct(Mach_thread_command)
927 Mach_ppc_thread_state state;
928 #define WANT_MACH_THREAD_ENUM 1 929 #include "p_mach_enum.h" 930 __packed_struct_end()
932 Mach_thread_command threado;
933 int threado_size()
const {
return sizeof(threado); }
934 void threado_setPC(upx_uint64_t pc) {
935 memset(&threado, 0,
sizeof(threado));
936 threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
937 threado.cmdsize =
sizeof(threado);
938 threado.flavor = my_thread_flavor;
939 threado.count = my_thread_state_word_count;
940 threado.state.srr0 = pc;
942 void threado_rewrite(
OutputFile *fo) { fo->rewrite(&threado,
sizeof(threado)); }
943 void threado_write(
OutputFile *fo) { fo->write(&threado,
sizeof(threado)); }
945 upx_uint64_t threadc_getPC(
void const *ptr) {
946 Mach_thread_command
const *tc = (Mach_thread_command
const *)ptr;
947 if (tc->cmd!=Mach_segment_command::LC_UNIXTHREAD
948 || tc->cmdsize!=
sizeof(threado)
949 || tc->flavor!=my_thread_flavor
950 || tc->count!=my_thread_state_word_count) {
953 return tc->state.srr0;
964 virtual int getFormat()
const {
return UPX_F_MACH_PPC64LE; }
965 virtual const char *getName()
const {
return "macho/ppc64le"; }
966 virtual const char *getFullName(
const options_t *)
const {
return "powerpc64le-darwin.macho"; }
969 virtual const int *getFilters()
const;
971 virtual void pack1_setup_threado(
OutputFile *
const fo);
972 virtual Linker* newLinker()
const;
974 __packed_struct(Mach_thread_command)
979 Mach_ppcle_thread_state64 state64;
980 #define WANT_MACH_THREAD_ENUM 1 981 #include "p_mach_enum.h" 982 __packed_struct_end()
984 Mach_thread_command threado;
985 int threado_size()
const {
return sizeof(threado); }
986 void threado_setPC(upx_uint64_t pc) {
987 memset(&threado, 0,
sizeof(threado));
988 threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
989 threado.cmdsize =
sizeof(threado);
990 threado.flavor = my_thread_flavor;
991 threado.count = my_thread_state_word_count;
992 threado.state64.srr0 = pc;
994 void threado_rewrite(
OutputFile *fo) { fo->rewrite(&threado,
sizeof(threado)); }
995 void threado_write(
OutputFile *fo) { fo->write(&threado,
sizeof(threado)); }
997 upx_uint64_t threadc_getPC(
void const *ptr) {
998 Mach_thread_command
const *tc = (Mach_thread_command
const *)ptr;
999 if (tc->cmd!=Mach_segment_command::LC_UNIXTHREAD
1000 || tc->cmdsize!=
sizeof(threado)
1001 || tc->flavor!=my_thread_flavor
1002 || tc->count!=my_thread_state_word_count) {
1005 return tc->state64.srr0;
1016 virtual int getFormat()
const {
return UPX_F_DYLIB_PPC32; }
1017 virtual const char *getName()
const {
return "dylib/ppc32"; }
1018 virtual const char *getFullName(
const options_t *)
const {
return "powerpc-darwin.dylib"; }
1031 virtual int getFormat()
const {
return UPX_F_DYLIB_PPC64LE; }
1032 virtual const char *getName()
const {
return "dylib/ppc64le"; }
1033 virtual const char *getFullName(
const options_t *)
const {
return "powerpc64le-darwin.dylib"; }
1046 virtual int getFormat()
const {
return UPX_F_MACH_i386; }
1047 virtual const char *getName()
const {
return "macho/i386"; }
1048 virtual const char *getFullName(
const options_t *)
const {
return "i386-darwin.macho"; }
1050 virtual const int *getFilters()
const;
1052 virtual void pack1_setup_threado(
OutputFile *
const fo);
1053 virtual Linker* newLinker()
const;
1054 virtual void addStubEntrySections(
Filter const *);
1056 __packed_struct(Mach_thread_command)
1061 Mach_i386_thread_state state;
1062 #define WANT_MACH_THREAD_ENUM 1 1063 #include "p_mach_enum.h" 1064 __packed_struct_end()
1066 Mach_thread_command threado;
1067 int threado_size()
const {
return sizeof(threado); }
1068 void threado_setPC(upx_uint64_t pc) {
1069 memset(&threado, 0,
sizeof(threado));
1070 threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
1071 threado.cmdsize =
sizeof(threado);
1072 threado.flavor = my_thread_flavor;
1073 threado.count = my_thread_state_word_count;
1074 threado.state.eip = pc;
1076 void threado_rewrite(
OutputFile *fo) { fo->rewrite(&threado,
sizeof(threado)); }
1077 void threado_write(
OutputFile *fo) { fo->write(&threado,
sizeof(threado)); }
1079 upx_uint64_t threadc_getPC(
void const *ptr) {
1080 Mach_thread_command
const *tc = (Mach_thread_command
const *)ptr;
1081 if (tc->cmd!=Mach_segment_command::LC_UNIXTHREAD
1082 || tc->cmdsize!=
sizeof(threado)
1083 || tc->flavor!=my_thread_flavor
1084 || tc->count!=my_thread_state_word_count) {
1087 return tc->state.eip;
1098 virtual int getFormat()
const {
return UPX_F_DYLIB_i386; }
1099 virtual const char *getName()
const {
return "dylib/i386"; }
1100 virtual const char *getFullName(
const options_t *)
const {
return "i386-darwin.dylib"; }
1113 virtual int getFormat()
const {
return UPX_F_MACH_AMD64; }
1114 virtual const char *getName()
const {
return "macho/amd64"; }
1115 virtual const char *getFullName(
const options_t *)
const {
return "amd64-darwin.macho"; }
1117 virtual const int *getFilters()
const;
1119 virtual void pack1_setup_threado(
OutputFile *
const fo);
1120 virtual Linker* newLinker()
const;
1121 virtual void addStubEntrySections(
Filter const *);
1123 __packed_struct(Mach_thread_command)
1124 typedef MachITypes::Word Word;
1129 Mach_AMD64_thread_state state;
1130 #define WANT_MACH_THREAD_ENUM 1 1131 #include "p_mach_enum.h" 1132 __packed_struct_end()
1134 Mach_thread_command threado;
1135 int threado_size()
const {
return sizeof(threado); }
1136 void threado_setPC(upx_uint64_t pc) {
1137 memset(&threado, 0,
sizeof(threado));
1138 threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
1139 threado.cmdsize =
sizeof(threado);
1140 threado.flavor = my_thread_flavor;
1141 threado.count = my_thread_state_word_count;
1142 threado.state.rip = pc;
1144 void threado_rewrite(
OutputFile *fo) { fo->rewrite(&threado,
sizeof(threado)); }
1145 void threado_write(
OutputFile *fo) { fo->write(&threado,
sizeof(threado)); }
1147 upx_uint64_t threadc_getPC(
void const *ptr) {
1148 Mach_thread_command
const *tc = (Mach_thread_command
const *)ptr;
1149 if (tc->cmd!=Mach_segment_command::LC_UNIXTHREAD
1150 || tc->cmdsize!=
sizeof(threado)
1151 || tc->flavor!=my_thread_flavor
1152 || tc->count!=my_thread_state_word_count) {
1155 return tc->state.rip;
1166 virtual int getFormat()
const {
return UPX_F_DYLIB_AMD64; }
1167 virtual const char *getName()
const {
return "dylib/amd64"; }
1168 virtual const char *getFullName(
const options_t *)
const {
return "amd64-darwin.dylib"; }
1181 virtual int getFormat()
const {
return UPX_F_MACH_ARMEL; }
1182 virtual const char *getName()
const {
return "macho/arm"; }
1183 virtual const char *getFullName(
const options_t *)
const {
return "arm-darwin.macho"; }
1185 virtual const int *getCompressionMethods(
int method,
int level)
const;
1186 virtual const int *getFilters()
const;
1188 virtual void pack1_setup_threado(
OutputFile *
const fo);
1189 virtual Linker* newLinker()
const;
1190 virtual void addStubEntrySections(
Filter const *);
1192 __packed_struct(Mach_thread_command)
1197 Mach_ARM_thread_state state;
1198 #define WANT_MACH_THREAD_ENUM 1 1199 #include "p_mach_enum.h" 1200 __packed_struct_end()
1202 Mach_thread_command threado;
1203 int threado_size()
const {
return sizeof(threado); }
1204 void threado_setPC(upx_uint64_t pc) {
1205 memset(&threado, 0,
sizeof(threado));
1206 threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
1207 threado.cmdsize =
sizeof(threado);
1208 threado.flavor = my_thread_flavor;
1209 threado.count = my_thread_state_word_count;
1210 threado.state.pc = pc;
1212 void threado_rewrite(
OutputFile *fo) { fo->rewrite(&threado,
sizeof(threado)); }
1213 void threado_write(
OutputFile *fo) {
return fo->write(&threado,
sizeof(threado)); }
1215 upx_uint64_t threadc_getPC(
void const *ptr) {
1216 Mach_thread_command
const *tc = (Mach_thread_command
const *)ptr;
1217 if (tc->cmd!=Mach_segment_command::LC_UNIXTHREAD
1218 || tc->cmdsize!=
sizeof(threado)
1219 || tc->flavor!=my_thread_flavor
1220 || tc->count!=my_thread_state_word_count) {
1223 return tc->state.pc;
1234 virtual int getFormat()
const {
return UPX_F_MACH_ARM64EL; }
1235 virtual const char *getName()
const {
return "macho/arm64"; }
1236 virtual const char *getFullName(
const options_t *)
const {
return "arm64-darwin.macho"; }
1238 virtual const int *getCompressionMethods(
int method,
int level)
const;
1239 virtual const int *getFilters()
const;
1241 virtual void pack1_setup_threado(
OutputFile *
const fo);
1242 virtual Linker* newLinker()
const;
1243 virtual void addStubEntrySections(
Filter const *);
1245 __packed_struct(Mach_thread_command)
1250 Mach_ARM64_thread_state state;
1251 #define WANT_MACH_THREAD_ENUM 1 1252 #include "p_mach_enum.h" 1253 __packed_struct_end()
1255 Mach_thread_command threado;
1256 int threado_size()
const {
return sizeof(threado); }
1257 void threado_setPC(upx_uint64_t pc) {
1258 memset(&threado, 0,
sizeof(threado));
1259 threado.cmd = Mach_segment_command::LC_UNIXTHREAD;
1260 threado.cmdsize =
sizeof(threado);
1261 threado.flavor = my_thread_flavor;
1262 threado.count = my_thread_state_word_count;
1263 threado.state.pc = pc;
1265 void threado_rewrite(
OutputFile *fo) { fo->rewrite(&threado,
sizeof(threado)); }
1266 void threado_write(
OutputFile *fo) { fo->write(&threado,
sizeof(threado)); }
1268 upx_uint64_t threadc_getPC(
void const *ptr) {
1269 Mach_thread_command
const *tc = (Mach_thread_command
const *)ptr;
1270 if (tc->cmd!=Mach_segment_command::LC_UNIXTHREAD
1271 || tc->cmdsize!=
sizeof(threado)
1272 || tc->flavor!=my_thread_flavor
1273 || tc->count!=my_thread_state_word_count) {
1276 return tc->state.pc;
1287 virtual int getVersion()
const {
return 13; }
1288 virtual int getFormat()
const {
return UPX_F_MACH_FAT; }
1289 virtual const char *getName()
const {
return "macho/fat"; }
1290 virtual const char *getFullName(
const options_t *)
const {
return "fat-darwin.macho"; }
1291 virtual const int *getCompressionMethods(
int method,
int level)
const;
1292 virtual const int *getFilters()
const;
1296 virtual unsigned check_fat_head();
1299 virtual void list();
1302 virtual bool canPack();
1303 virtual int canUnpack();
1307 virtual void buildLoader(
const Filter *ft);
1308 virtual Linker* newLinker()
const;
1310 enum { N_FAT_ARCH = 5 };
1312 __packed_struct(Fat_head)
1313 struct Mach_fat_header fat;
1314 struct Mach_fat_arch arch[N_FAT_ARCH];
1315 __packed_struct_end()
1324 #define WANT_MACH_HEADER_ENUM 1 1325 #include "p_mach_enum.h" Definition: p_mach.h:1280
Definition: p_mach.h:1091
Definition: p_mach.h:1174
Definition: p_mach.h:1024
Definition: p_mach.h:1009
Definition: p_mach.h:1106
Definition: p_mach.h:1227
Definition: p_mach.h:1159
Definition: p_mach.h:1039