📄 p_mach.h
字号:
/* p_mach.h -- This file is part of the UPX executable compressor. Copyright (C) 1996-2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 1996-2007 Laszlo Molnar All Rights Reserved. UPX and the UCL library are free software; you can redistribute them and/or modify them under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Markus F.X.J. Oberhumer Laszlo Molnar markus@oberhumer.com ml1050@users.sourceforge.net */#ifndef __UPX_P_MACHO_H#define __UPX_P_MACHO_Hstruct Mach_fat_header { BE32 magic; enum { // note conflict with java bytecode PackLinuxI386 FAT_MAGIC = 0xcafebabe, FAT_MAGIC_SWAB = 0xbebafeca }; BE32 nfat_arch; // Number of Mach_fat_arch which follow.}__attribute_packed;struct Mach_fat_arch { BE32 cputype; BE32 cpusubtype; BE32 offset; BE32 size; BE32 align; /* shift count; log base 2 */}__attribute_packed;/*************************************************************************// Mach Mach Object executable; all structures are target-endian// 'otool' is the Mach analog of 'readelf' (convert executable file to ASCII).**************************************************************************/namespace N_Mach {// integral typestemplate <class TWord, class TXword, class TAddr, class TOff>struct MachITypes{ typedef TWord Word; typedef TXword Xword; typedef TAddr Addr; typedef TOff Off;};template <class TMachITypes>struct Mach_header{ typedef typename TMachITypes::Word Word; Word magic; Word cputype; Word cpysubtype; Word filetype; Word ncmds; Word sizeofcmds; Word flags;#define WANT_MACH_HEADER_ENUM 1#include "p_mach_enum.h"}__attribute_packed;template <class TMachITypes>struct Mach_header64{ // only difference is padding to 0 mod 8 typedef typename TMachITypes::Word Word; Word magic; Word cputype; Word cpysubtype; Word filetype; Word ncmds; Word sizeofcmds; Word flags; Word reserved; // pad to 0 mod 8#define WANT_MACH_HEADER_ENUM 1#include "p_mach_enum.h"}__attribute_packed;template <class TMachITypes>struct Mach_segment_command{ typedef typename TMachITypes::Word Word; typedef typename TMachITypes::Addr Addr; typedef typename TMachITypes::Off Off; Word cmd; Word cmdsize; char segname[16]; Addr vmaddr; Addr vmsize; Off fileoff; Off filesize; Word maxprot; Word initprot; Word nsects; Word flags;#define WANT_MACH_SEGMENT_ENUM 1#include "p_mach_enum.h"}__attribute_packed;template <class TMachITypes>struct Mach_section_command{ typedef typename TMachITypes::Word Word; typedef typename TMachITypes::Addr Addr; typedef typename TMachITypes::Off Off; char sectname[16]; char segname[16]; Addr addr; /* memory address */ Addr size; /* size in bytes */ Word offset; /* file offset */ // FIXME: 64 bit? Word align; /* power of 2 */ Word reloff; /* file offset of relocation entries */ Word nreloc; /* number of relocation entries */ Word flags; /* section type and attributes */ Word reserved1; Word reserved2;#define WANT_MACH_SECTION_ENUM 1#include "p_mach_enum.h"}__attribute_packed;template <class TMachITypes>struct Mach_ppc_thread_state{ typedef typename TMachITypes::Addr Addr; Addr srr0; /* Instruction address register (PC; entry addr) */ Addr srr1; /* Machine state register (supervisor) */ Addr r0, r1, r2, r3, r4, r5, r6, r7; Addr r8, r9,r10,r11,r12,r13,r14,r15; Addr r16,r17,r18,r19,r20,r21,r22,r23; Addr r24,r25,r26,r27,r28,r29,r30,r31; Addr cr; /* Condition register */ // FIXME: Word? Addr xer; /* User's integer exception register */ Addr lr; /* Link register */ Addr ctr; /* Count register */ Addr mq; /* MQ register (601 only) */ Addr vrsave; /* Vector Save Register */}__attribute_packed;template <class TMachITypes>struct Mach_i386_thread_state{ typedef typename TMachITypes::Word Word; Word eax, ebx, ecx, edx; Word edi, esi, ebp; Word esp, ss; Word eflags; Word eip, cs; Word ds, es, fs, gs;}__attribute_packed;template <class TMachITypes>struct Mach_i386_new_thread_state{ typedef typename TMachITypes::Word Word; Word gs, fs, es, ds; Word edi, esi, ebp, esp; Word ebx, edx, ecx, eax; Word eip, cs, efl; Word uesp, ss;}__attribute_packed;} // namespace N_Machnamespace N_Mach32 {} // namespace N_Mach32namespace N_Mach64 {template <class TMachITypes>struct Mach_ppc_thread_state64{ typedef typename TMachITypes::Word Word; typedef typename TMachITypes::Xword Xword; Xword srr0; /* Instruction address register (PC; entry addr) */ Xword srr1; /* Machine state register (supervisor) */ Xword r0, r1, r2, r3, r4, r5, r6, r7; Xword r8, r9,r10,r11,r12,r13,r14,r15; Xword r16,r17,r18,r19,r20,r21,r22,r23; Xword r24,r25,r26,r27,r28,r29,r30,r31; Word cr; /* Condition register */ // FIXME: Xword? Xword xer; /* User's integer exception register */ Xword lr; /* Link register */ Xword ctr; /* Count register */ Word vrsave; /* Vector Save Register */}__attribute_packed;} // namespace N_Mach64namespace N_Mach {template <class TP>struct MachClass_32{ typedef TP BeLePolicy; // integral types typedef typename TP::U16 U16; typedef typename TP::U32 U32; typedef typename TP::U64 U64; typedef N_Mach::MachITypes<U32, U64, U32, U32> MachITypes;#if (ACC_CC_BORLANDC) typedef U32 Addr;#else typedef typename MachITypes::Addr Addr;#endif // Mach types typedef N_Mach::Mach_header<MachITypes> Mach_header; typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command; typedef N_Mach::Mach_section_command<MachITypes> Mach_section_command; typedef N_Mach::Mach_ppc_thread_state<MachITypes> Mach_ppc_thread_state; typedef N_Mach::Mach_i386_thread_state<MachITypes> Mach_i386_thread_state; static void compileTimeAssertions() { BeLePolicy::compileTimeAssertions(); COMPILE_TIME_ASSERT(sizeof(Addr) == 4) }};template <class TP>struct MachClass_64{ typedef TP BeLePolicy; // integral types typedef typename TP::U16 U16; typedef typename TP::U32 U32; typedef typename TP::U64 U64; typedef N_Mach::MachITypes<U32, U64, U64, U64> MachITypes; // Mach types typedef N_Mach::Mach_header64<MachITypes> Mach_header; typedef N_Mach::Mach_segment_command<MachITypes> Mach_segment_command; typedef N_Mach::Mach_section_command<MachITypes> Mach_section_command;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -