OLD | NEW |
1 // Copyright (c) 2006, Google Inc. | 1 // Copyright (c) 2006, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // macho_utilties.cc: Utilities for dealing with mach-o files | 30 // macho_utilties.cc: Utilities for dealing with mach-o files |
31 // | 31 // |
32 // Author: Dave Camp | 32 // Author: Dave Camp |
33 | 33 |
34 #include "common/mac/byteswap.h" | 34 #include "common/mac/byteswap.h" |
35 #include "common/mac/macho_utilities.h" | 35 #include "common/mac/macho_utilities.h" |
36 | 36 |
37 void breakpad_swap_uuid_command(struct breakpad_uuid_command *uc, | 37 #include <mach-o/fat.h> |
38 enum NXByteOrder target_byte_order) | 38 #include <mach-o/loader.h> |
39 { | 39 |
| 40 void breakpad_swap_uuid_command(struct breakpad_uuid_command *uc) { |
40 uc->cmd = ByteSwap(uc->cmd); | 41 uc->cmd = ByteSwap(uc->cmd); |
41 uc->cmdsize = ByteSwap(uc->cmdsize); | 42 uc->cmdsize = ByteSwap(uc->cmdsize); |
42 } | 43 } |
43 | 44 |
44 void breakpad_swap_segment_command_64(struct segment_command_64 *sg, | 45 void breakpad_swap_load_command(struct load_command *lc) { |
45 enum NXByteOrder target_byte_order) | 46 lc->cmd = ByteSwap(lc->cmd); |
46 { | 47 lc->cmdsize = ByteSwap(lc->cmdsize); |
| 48 } |
| 49 |
| 50 void breakpad_swap_dylib_command(struct dylib_command *dc) { |
| 51 dc->cmd = ByteSwap(dc->cmd); |
| 52 dc->cmdsize = ByteSwap(dc->cmdsize); |
| 53 |
| 54 dc->dylib.name.offset = ByteSwap(dc->dylib.name.offset); |
| 55 dc->dylib.timestamp = ByteSwap(dc->dylib.timestamp); |
| 56 dc->dylib.current_version = ByteSwap(dc->dylib.current_version); |
| 57 dc->dylib.compatibility_version = ByteSwap(dc->dylib.compatibility_version); |
| 58 } |
| 59 |
| 60 void breakpad_swap_segment_command(struct segment_command *sc) { |
| 61 sc->cmd = ByteSwap(sc->cmd); |
| 62 sc->cmdsize = ByteSwap(sc->cmdsize); |
| 63 |
| 64 sc->vmaddr = ByteSwap(sc->vmaddr); |
| 65 sc->vmsize = ByteSwap(sc->vmsize); |
| 66 sc->fileoff = ByteSwap(sc->fileoff); |
| 67 sc->filesize = ByteSwap(sc->filesize); |
| 68 sc->maxprot = ByteSwap(sc->maxprot); |
| 69 sc->initprot = ByteSwap(sc->initprot); |
| 70 sc->nsects = ByteSwap(sc->nsects); |
| 71 sc->flags = ByteSwap(sc->flags); |
| 72 } |
| 73 |
| 74 void breakpad_swap_segment_command_64(struct segment_command_64 *sg) { |
47 sg->cmd = ByteSwap(sg->cmd); | 75 sg->cmd = ByteSwap(sg->cmd); |
48 sg->cmdsize = ByteSwap(sg->cmdsize); | 76 sg->cmdsize = ByteSwap(sg->cmdsize); |
49 | 77 |
50 sg->vmaddr = ByteSwap(sg->vmaddr); | 78 sg->vmaddr = ByteSwap(sg->vmaddr); |
51 sg->vmsize = ByteSwap(sg->vmsize); | 79 sg->vmsize = ByteSwap(sg->vmsize); |
52 sg->fileoff = ByteSwap(sg->fileoff); | 80 sg->fileoff = ByteSwap(sg->fileoff); |
53 sg->filesize = ByteSwap(sg->filesize); | 81 sg->filesize = ByteSwap(sg->filesize); |
54 | 82 |
55 sg->maxprot = ByteSwap(sg->maxprot); | 83 sg->maxprot = ByteSwap(sg->maxprot); |
56 sg->initprot = ByteSwap(sg->initprot); | 84 sg->initprot = ByteSwap(sg->initprot); |
57 sg->nsects = ByteSwap(sg->nsects); | 85 sg->nsects = ByteSwap(sg->nsects); |
58 sg->flags = ByteSwap(sg->flags); | 86 sg->flags = ByteSwap(sg->flags); |
59 } | 87 } |
60 | 88 |
61 void breakpad_swap_mach_header_64(struct mach_header_64 *mh, | 89 void breakpad_swap_fat_header(struct fat_header *fh) { |
62 enum NXByteOrder target_byte_order) | 90 fh->magic = ByteSwap(fh->magic); |
63 { | 91 fh->nfat_arch = ByteSwap(fh->nfat_arch); |
| 92 } |
| 93 |
| 94 void breakpad_swap_fat_arch(struct fat_arch *fa, uint32_t narchs) { |
| 95 for (uint32_t i = 0; i < narchs; ++i) { |
| 96 fa[i].cputype = ByteSwap(fa[i].cputype); |
| 97 fa[i].cpusubtype = ByteSwap(fa[i].cpusubtype); |
| 98 fa[i].offset = ByteSwap(fa[i].offset); |
| 99 fa[i].size = ByteSwap(fa[i].size); |
| 100 fa[i].align = ByteSwap(fa[i].align); |
| 101 } |
| 102 } |
| 103 |
| 104 void breakpad_swap_mach_header(struct mach_header *mh) { |
64 mh->magic = ByteSwap(mh->magic); | 105 mh->magic = ByteSwap(mh->magic); |
65 mh->cputype = ByteSwap(mh->cputype); | 106 mh->cputype = ByteSwap(mh->cputype); |
66 mh->cpusubtype = ByteSwap(mh->cpusubtype); | 107 mh->cpusubtype = ByteSwap(mh->cpusubtype); |
| 108 mh->filetype = ByteSwap(mh->filetype); |
| 109 mh->ncmds = ByteSwap(mh->ncmds); |
| 110 mh->sizeofcmds = ByteSwap(mh->sizeofcmds); |
| 111 mh->flags = ByteSwap(mh->flags); |
| 112 } |
| 113 |
| 114 void breakpad_swap_mach_header_64(struct mach_header_64 *mh) { |
| 115 mh->magic = ByteSwap(mh->magic); |
| 116 mh->cputype = ByteSwap(mh->cputype); |
| 117 mh->cpusubtype = ByteSwap(mh->cpusubtype); |
67 mh->filetype = ByteSwap(mh->filetype); | 118 mh->filetype = ByteSwap(mh->filetype); |
68 mh->ncmds = ByteSwap(mh->ncmds); | 119 mh->ncmds = ByteSwap(mh->ncmds); |
69 mh->sizeofcmds = ByteSwap(mh->sizeofcmds); | 120 mh->sizeofcmds = ByteSwap(mh->sizeofcmds); |
70 mh->flags = ByteSwap(mh->flags); | 121 mh->flags = ByteSwap(mh->flags); |
71 mh->reserved = ByteSwap(mh->reserved); | 122 mh->reserved = ByteSwap(mh->reserved); |
72 } | 123 } |
73 | 124 |
74 void breakpad_swap_section_64(struct section_64 *s, | 125 void breakpad_swap_section(struct section *s, |
75 uint32_t nsects, | 126 uint32_t nsects) { |
76 enum NXByteOrder target_byte_order) | |
77 { | |
78 for (uint32_t i = 0; i < nsects; i++) { | 127 for (uint32_t i = 0; i < nsects; i++) { |
79 s[i].addr = ByteSwap(s[i].addr); | 128 s[i].addr = ByteSwap(s[i].addr); |
80 s[i].size = ByteSwap(s[i].size); | 129 s[i].size = ByteSwap(s[i].size); |
| 130 |
| 131 s[i].offset = ByteSwap(s[i].offset); |
| 132 s[i].align = ByteSwap(s[i].align); |
| 133 s[i].reloff = ByteSwap(s[i].reloff); |
| 134 s[i].nreloc = ByteSwap(s[i].nreloc); |
| 135 s[i].flags = ByteSwap(s[i].flags); |
| 136 s[i].reserved1 = ByteSwap(s[i].reserved1); |
| 137 s[i].reserved2 = ByteSwap(s[i].reserved2); |
| 138 } |
| 139 } |
| 140 |
| 141 void breakpad_swap_section_64(struct section_64 *s, |
| 142 uint32_t nsects) { |
| 143 for (uint32_t i = 0; i < nsects; i++) { |
| 144 s[i].addr = ByteSwap(s[i].addr); |
| 145 s[i].size = ByteSwap(s[i].size); |
81 | 146 |
82 s[i].offset = ByteSwap(s[i].offset); | 147 s[i].offset = ByteSwap(s[i].offset); |
83 s[i].align = ByteSwap(s[i].align); | 148 s[i].align = ByteSwap(s[i].align); |
84 s[i].reloff = ByteSwap(s[i].reloff); | 149 s[i].reloff = ByteSwap(s[i].reloff); |
85 s[i].nreloc = ByteSwap(s[i].nreloc); | 150 s[i].nreloc = ByteSwap(s[i].nreloc); |
86 s[i].flags = ByteSwap(s[i].flags); | 151 s[i].flags = ByteSwap(s[i].flags); |
87 s[i].reserved1 = ByteSwap(s[i].reserved1); | 152 s[i].reserved1 = ByteSwap(s[i].reserved1); |
88 s[i].reserved2 = ByteSwap(s[i].reserved2); | 153 s[i].reserved2 = ByteSwap(s[i].reserved2); |
89 } | 154 } |
90 } | 155 } |
OLD | NEW |