00001 /* 00002 * HT Editor 00003 * htmach-o.h 00004 * 00005 * Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de) 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License version 2 as 00009 * published by the Free Software Foundation. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 #ifndef __HTMACHO_H__ 00022 #define __HTMACHO_H__ 00023 00024 #include "machostruc.h" 00025 #include "formats.h" 00026 #include "htendian.h" 00027 #include "htformat.h" 00028 00029 #define DESC_MACHO "Mach-O - Mach exe/link format" 00030 #define DESC_MACHO_HEADER "Mach-O/header" 00031 /*#define DESC_MACHO_SECTION_HEADERS "elf/section headers" 00032 #define DESC_MACHO_PROGRAM_HEADERS "elf/program headers" 00033 #define DESC_MACHO_SYMTAB "elf/symbol table %s (%d)" 00034 #define DESC_MACHO_RELOCTAB "elf/relocation table %s (%d)"*/ 00035 #define DESC_MACHO_IMAGE "Mach-O/image" 00036 00037 extern format_viewer_if htmacho_if; 00038 00039 /* 00040 #define ATOM_ELF_CLASS 0x454c4600 00041 #define ATOM_ELF_CLASS_STR "454c4600" 00042 00043 #define ATOM_ELF_DATA 0x454c4601 00044 #define ATOM_ELF_DATA_STR "454c4601" 00045 00046 #define ATOM_ELF_OS_ABI 0x454c4602 00047 #define ATOM_ELF_OS_ABI_STR "454c4602" 00048 00049 #define ATOM_ELF_TYPE 0x454c4603 00050 #define ATOM_ELF_TYPE_STR "454c4603" 00051 00052 #define ATOM_ELF_MACHINE 0x454c4604 00053 #define ATOM_ELF_MACHINE_STR "454c4604" 00054 00055 #define ATOM_ELF_SH_TYPE 0x454c4605 00056 #define ATOM_ELF_SH_TYPE_STR "454c4605" 00057 00058 #define ATOM_ELF_SH_FLAGS 0x454c4606 00059 #define ATOM_ELF_SH_FLAGS_STR "454c4606" 00060 00061 #define ATOM_ELF_PH_TYPE 0x454c4607 00062 #define ATOM_ELF_PH_TYPE_STR "454c4607" 00063 00064 #define ATOM_ELF_PH_FLAGS 0x454c4608 00065 #define ATOM_ELF_PH_FLAGS_STR "454c4608" 00066 00067 #define ATOM_ELF_ST_BIND 0x454c4609 00068 #define ATOM_ELF_ST_BIND_STR "454c4609" 00069 00070 #define ATOM_ELF_ST_TYPE 0x454c460a 00071 #define ATOM_ELF_ST_TYPE_STR "454c460a" 00072 00073 #define ATOM_ELF_R_386_TYPE 0x454c460b 00074 #define ATOM_ELF_R_386_TYPE_STR "454c460b" 00075 00076 union macho_segment_header { 00077 ELF_SECTION_HEADER32 sheaders32; 00078 ELF_SECTION_HEADER64 sheaders64; 00079 }; 00080 00081 struct elf_program_headers { 00082 UINT count; 00083 union { 00084 ELF_PROGRAM_HEADER32 *pheaders32; 00085 ELF_PROGRAM_HEADER64 *pheaders64; 00086 }; 00087 }; 00088 00089 struct ht_elf_reloc_section { 00090 elf32_addr address; 00091 UINT reloc_shidx; 00092 }; 00093 */ 00094 struct macho_commands { 00095 UINT count; 00096 MACHO_COMMAND_U **cmds; 00097 }; 00098 00099 struct macho_sections { 00100 UINT count; 00101 MACHO_SECTION *sections; 00102 }; 00103 00104 struct ht_macho_shared_data { 00105 FILEOFS header_ofs; 00106 MACHO_HEADER header; 00107 macho_commands cmds; 00108 macho_sections sections; 00109 endianess image_endianess; 00110 /* ELF_HEADER ident; 00111 endianess byte_order; 00112 union { 00113 ELF_HEADER32 header32; 00114 ELF_HEADER64 header64; 00115 }; 00116 elf_section_headers sheaders; 00117 char **shnames; 00118 elf_program_headers pheaders; 00119 UINT symtables; 00120 UINT reloctables; 00121 ht_format_viewer *v_image; 00122 ht_elf_reloc_section *htrelocs; 00123 UINT fake_undefined_section;*/ 00124 }; 00125 00126 /* 00127 * CLASS ht_macho 00128 */ 00129 00130 class ht_macho: public ht_format_group { 00131 public: 00132 void init(bounds *b, ht_streamfile *file, format_viewer_if **ifs, ht_format_group *format_group, FILEOFS header_ofs, endianess image_endianess); 00133 virtual void done(); 00134 }; 00135 00136 typedef uint32 MACHOAddress; 00137 00138 bool macho_phys_and_mem_section(MACHO_SECTION *s, UINT machoclass); 00139 bool macho_valid_section(MACHO_SECTION *s, UINT machoclass); 00140 00141 bool macho_addr_to_section(macho_sections *section_headers, UINT machoclass, MACHOAddress addr, int *section); 00142 bool macho_addr_to_ofs(macho_sections *section_headers, UINT machoclass, MACHOAddress addr, dword *ofs); 00143 bool macho_addr_is_valid(macho_sections *section_headers, UINT machoclass, MACHOAddress addr); 00144 00145 bool macho_ofs_to_addr(macho_sections *section_headers, UINT machoclass, dword ofs, MACHOAddress *addr); 00146 bool macho_ofs_to_section(macho_sections *section_headers, UINT machoclass, dword ofs, dword *section); 00147 00148 #endif /* !__HTMACHO_H__ */