macho.h (2427B)
1 typedef struct Macho Macho; 2 typedef struct MachoCmd MachoCmd; 3 typedef struct MachoSeg MachoSeg; 4 typedef struct MachoSect MachoSect; 5 typedef struct MachoRel MachoRel; 6 typedef struct MachoSymtab MachoSymtab; 7 typedef struct MachoSym MachoSym; 8 typedef struct MachoDysymtab MachoDysymtab; 9 10 enum 11 { 12 MachoCpuVax = 1, 13 MachoCpu68000 = 6, 14 MachoCpu386 = 7, 15 MachoCpuAmd64 = 0x1000007, 16 MachoCpuMips = 8, 17 MachoCpu98000 = 10, 18 MachoCpuHppa = 11, 19 MachoCpuArm = 12, 20 MachoCpu88000 = 13, 21 MachoCpuSparc = 14, 22 MachoCpu860 = 15, 23 MachoCpuAlpha = 16, 24 MachoCpuPower = 18, 25 26 MachoCmdSegment = 1, 27 MachoCmdSymtab = 2, 28 MachoCmdSymseg = 3, 29 MachoCmdThread = 4, 30 MachoCmdDysymtab = 11, 31 MachoCmdSegment64 = 25, 32 33 MachoFileObject = 1, 34 MachoFileExecutable = 2, 35 MachoFileFvmlib = 3, 36 MachoFileCore = 4, 37 MachoFilePreload = 5 38 }; 39 40 struct MachoSeg 41 { 42 char name[16+1]; 43 uint64 vmaddr; 44 uint64 vmsize; 45 uint32 fileoff; 46 uint32 filesz; 47 uint32 maxprot; 48 uint32 initprot; 49 uint32 nsect; 50 uint32 flags; 51 MachoSect *sect; 52 }; 53 54 struct MachoSect 55 { 56 char name[16+1]; 57 char segname[16+1]; 58 uint64 addr; 59 uint64 size; 60 uint32 offset; 61 uint32 align; 62 uint32 reloff; 63 uint32 nreloc; 64 uint32 flags; 65 66 MachoRel *rel; 67 }; 68 69 struct MachoRel 70 { 71 uint32 addr; 72 uint32 symnum; 73 uint8 pcrel; 74 uint8 length; 75 uint8 extrn; 76 uint8 type; 77 }; 78 79 struct MachoSymtab 80 { 81 uint32 symoff; 82 uint32 nsym; 83 uint32 stroff; 84 uint32 strsize; 85 86 char *str; 87 MachoSym *sym; 88 }; 89 90 struct MachoSym 91 { 92 char *name; 93 uint8 type; 94 uint8 sectnum; 95 uint16 desc; 96 char kind; 97 uint64 value; 98 }; 99 100 struct MachoDysymtab 101 { 102 uint32 ilocalsym; 103 uint32 nlocalsym; 104 uint32 iextdefsym; 105 uint32 nextdefsym; 106 uint32 iundefsym; 107 uint32 nundefsym; 108 uint32 tocoff; 109 uint32 ntoc; 110 uint32 modtaboff; 111 uint32 nmodtab; 112 uint32 extrefsymoff; 113 uint32 nextrefsyms; 114 uint32 indirectsymoff; 115 uint32 nindirectsyms; 116 uint32 extreloff; 117 uint32 nextrel; 118 uint32 locreloff; 119 uint32 nlocrel; 120 }; 121 122 struct MachoCmd 123 { 124 int type; 125 uint32 off; 126 uint32 size; 127 MachoSeg seg; 128 MachoSymtab sym; 129 MachoDysymtab dsym; 130 }; 131 132 struct Macho 133 { 134 int fd; 135 int is64; 136 uint cputype; 137 uint subcputype; 138 uint32 filetype; 139 uint32 flags; 140 MachoCmd *cmd; 141 uint ncmd; 142 uint16 (*e2)(uchar*); 143 uint32 (*e4)(uchar*); 144 uint64 (*e8)(uchar*); 145 int (*coreregs)(Macho*, uchar**); 146 }; 147 148 Macho *machoopen(char*); 149 Macho *machoinit(int); 150 void machoclose(Macho*); 151 int coreregsmachopower(Macho*, uchar**); 152 int macholoadrel(Macho*, MachoSect*); 153 int macholoadsym(Macho*, MachoSymtab*);