📄 p_mach.h
字号:
static void compileTimeAssertions() { BeLePolicy::compileTimeAssertions(); }};} // namespace N_Machtypedef N_Mach::MachClass_32<N_BELE_CTP::HostPolicy> MachClass_Host32;typedef N_Mach::MachClass_64<N_BELE_CTP::HostPolicy> MachClass_Host64;typedef N_Mach::MachClass_32<N_BELE_CTP::BEPolicy> MachClass_BE32;typedef N_Mach::MachClass_64<N_BELE_CTP::BEPolicy> MachClass_BE64;typedef N_Mach::MachClass_32<N_BELE_CTP::LEPolicy> MachClass_LE32;typedef N_Mach::MachClass_64<N_BELE_CTP::LEPolicy> MachClass_LE64;// shortcutstypedef MachClass_Host32::Mach_segment_command Mach32_segment_command;typedef MachClass_Host32::Mach_section_command Mach32_section_command;typedef MachClass_Host64::Mach_segment_command Mach64_segment_command;typedef MachClass_Host64::Mach_section_command Mach64_section_command;typedef MachClass_BE32::Mach_segment_command MachBE32_segment_command;typedef MachClass_BE32::Mach_section_command MachBE32_section_command;typedef MachClass_BE64::Mach_segment_command MachBE64_segment_command;typedef MachClass_BE64::Mach_section_command MachBE64_section_command;typedef MachClass_LE32::Mach_segment_command MachLE32_segment_command;typedef MachClass_LE32::Mach_section_command MachLE32_section_command;typedef MachClass_LE64::Mach_segment_command MachLE64_segment_command;typedef MachClass_LE64::Mach_section_command MachLE64_section_command;typedef MachClass_BE32::Mach_ppc_thread_state Mach_ppc_thread_state;typedef MachClass_LE32::Mach_i386_thread_state Mach_i386_thread_state;#include "p_unix.h"template <class TMachClass>class PackMachBase : public PackUnix{ typedef PackUnix super;protected: typedef TMachClass MachClass; typedef typename MachClass::BeLePolicy BeLePolicy; typedef typename MachClass::MachITypes MachITypes; // integral types typedef typename MachClass::U16 U16; typedef typename MachClass::U32 U32; typedef typename MachClass::U64 U64; typedef typename MachClass::Addr Addr; // Mach types typedef typename MachClass::Mach_header Mach_header; typedef typename MachClass::Mach_segment_command Mach_segment_command; typedef typename MachClass::Mach_section_command Mach_section_command;public: PackMachBase(InputFile *, unsigned cpuid, unsigned t_flavor, unsigned ts_word_cnt, unsigned tc_size); virtual ~PackMachBase(); virtual int getVersion() const { return 13; } virtual const int *getCompressionMethods(int method, int level) const; // called by the generic pack() virtual void pack1(OutputFile *, Filter &); // generate executable header virtual void pack2(OutputFile *, Filter &); // append compressed data virtual void pack3(OutputFile *, Filter &) = 0; // append loader virtual void pack4(OutputFile *, Filter &) = 0; // append PackHeader virtual void pack1_setup_threado(OutputFile *const fo) = 0; virtual void unpack(OutputFile *fo); virtual bool canPack(); virtual unsigned find_SEGMENT_gap(unsigned const k);protected: virtual void patchLoader(); virtual void patchLoaderChecksum(); virtual void updateLoader(OutputFile *); virtual void buildMachLoader( upx_byte const *const proto, unsigned const szproto, upx_byte const *const fold, unsigned const szfold, Filter const *ft ); virtual void defineSymbols(Filter const *); virtual void addStubEntrySections(Filter const *); static int __acc_cdecl_qsort compare_segment_command(void const *aa, void const *bb); unsigned my_cputype; unsigned my_thread_flavor; unsigned my_thread_state_word_count; unsigned my_thread_command_size; unsigned n_segment; unsigned sz_segment; unsigned sz_mach_headers; Mach_segment_command *rawmseg; // as input, with sections Mach_segment_command *msegcmd; // LC_SEGMENT first, without sections Mach_header mhdri; Mach_header mhdro; Mach_segment_command segcmdo; struct b_info { // 12-byte header before each compressed block U32 sz_unc; // uncompressed_size U32 sz_cpr; // compressed_size unsigned char b_method; // compression algorithm unsigned char b_ftid; // filter id unsigned char b_cto8; // filter parameter unsigned char b_unused; } __attribute_packed; struct l_info { // 12-byte trailer in header for loader U32 l_checksum; LE32 l_magic; U16 l_lsize; unsigned char l_version; unsigned char l_format; } __attribute_packed; struct p_info { // 12-byte packed program header U32 p_progid; U32 p_filesize; U32 p_blocksize; } __attribute_packed; struct l_info linfo;};class PackMachPPC32 : public PackMachBase<MachClass_BE32>{ typedef PackMachBase<MachClass_BE32> super;public: PackMachPPC32(InputFile *f) : super(f, Mach_header::CPU_TYPE_POWERPC, Mach_thread_command::PPC_THREAD_STATE, sizeof(Mach_ppc_thread_state)>>2, sizeof(threado)) { } virtual int getFormat() const { return UPX_F_MACH_PPC32; } virtual const char *getName() const { return "Mach/ppc32"; } virtual const char *getFullName(const options_t *) const { return "powerpc-darwin.macho"; } virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); } virtual unsigned get_native32(const void *b) const { return get_be32(b); } virtual unsigned get_native16(const void *b) const { return get_be16(b); } virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); } virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); } virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }protected: virtual const int *getFilters() const; virtual void pack1_setup_threado(OutputFile *const fo); virtual void pack3(OutputFile *, Filter &); // append loader virtual void pack4(OutputFile *, Filter &); // append PackHeader virtual Linker* newLinker() const; virtual void buildLoader(const Filter *ft); struct Mach_thread_command { BE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */ BE32 cmdsize; /* total size of this command */ BE32 flavor; BE32 count; /* sizeof(following_thread_state)/4 */ Mach_ppc_thread_state state; #define WANT_MACH_THREAD_ENUM #include "p_mach_enum.h" } __attribute_packed; Mach_thread_command threado;};class PackMachI386 : public PackMachBase<MachClass_LE32>{ typedef PackMachBase<MachClass_LE32> super;public: PackMachI386(InputFile *f) : super(f, Mach_header::CPU_TYPE_I386, (unsigned)Mach_thread_command::i386_THREAD_STATE, sizeof(Mach_i386_thread_state)>>2, sizeof(threado)) { } virtual int getFormat() const { return UPX_F_MACH_i386; } virtual const char *getName() const { return "Mach/i386"; } virtual const char *getFullName(const options_t *) const { return "i386-darwin.macho"; }protected: virtual const int *getFilters() const; virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); } virtual unsigned get_native32(const void *b) const { return get_le32(b); } virtual unsigned get_native16(const void *b) const { return get_le16(b); } virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); } virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); } virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); } virtual void pack1_setup_threado(OutputFile *const fo); virtual void pack3(OutputFile *, Filter &); // append loader virtual void pack4(OutputFile *, Filter &); // append PackHeader virtual Linker* newLinker() const; virtual void buildLoader(const Filter *ft); virtual void addStubEntrySections(Filter const *); struct Mach_thread_command { LE32 cmd; /* LC_THREAD or LC_UNIXTHREAD */ LE32 cmdsize; /* total size of this command */ LE32 flavor; LE32 count; /* sizeof(following_thread_state)/4 */ Mach_i386_thread_state state; #define WANT_MACH_THREAD_ENUM #include "p_mach_enum.h" } __attribute_packed; Mach_thread_command threado;};class PackMachFat : public Packer{ typedef Packer super;public: PackMachFat(InputFile *f); virtual ~PackMachFat(); virtual int getVersion() const { return 13; } virtual int getFormat() const { return UPX_F_MACH_FAT; } virtual const char *getName() const { return "Mach/fat"; } virtual const char *getFullName(const options_t *) const { return "fat-darwin.macho"; } virtual const int *getCompressionMethods(int method, int level) const; virtual const int *getFilters() const;protected: // implementation virtual void pack(OutputFile *fo); virtual void unpack(OutputFile *fo); virtual void list();public: virtual bool canPack(); virtual int canUnpack();protected: // loader core virtual void buildLoader(const Filter *ft); virtual Linker* newLinker() const;#if (ACC_CC_BORLANDC)public:#endif enum { N_FAT_ARCH = 5 };protected: struct Fat_head { struct Mach_fat_header fat; struct Mach_fat_arch arch[N_FAT_ARCH]; } __attribute_packed; Fat_head fat_head; // UI handler UiPacker *uip; // linker Linker *linker;#define WANT_MACH_HEADER_ENUM#include "p_mach_enum.h"};#endif /* already included *//*vi:ts=4:et*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -