OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006, Google Inc. | |
2 // All rights reserved. | |
3 // | |
4 // Redistribution and use in source and binary forms, with or without | |
5 // modification, are permitted provided that the following conditions are | |
6 // met: | |
7 // | |
8 // * Redistributions of source code must retain the above copyright | |
9 // notice, this list of conditions and the following disclaimer. | |
10 // * Redistributions in binary form must reproduce the above | |
11 // copyright notice, this list of conditions and the following disclaimer | |
12 // in the documentation and/or other materials provided with the | |
13 // distribution. | |
14 // * Neither the name of Google Inc. nor the names of its | |
15 // contributors may be used to endorse or promote products derived from | |
16 // this software without specific prior written permission. | |
17 // | |
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
29 | |
30 // macho_utilties.cc: Utilities for dealing with mach-o files | |
31 // | |
32 // Author: Dave Camp | |
33 | |
34 #include "common/mac/macho_utilities.h" | |
35 | |
36 void breakpad_swap_uuid_command(struct breakpad_uuid_command *uc, | |
37 enum NXByteOrder target_byte_order) | |
38 { | |
39 uc->cmd = NXSwapLong(uc->cmd); | |
40 uc->cmdsize = NXSwapLong(uc->cmdsize); | |
41 } | |
42 | |
43 void breakpad_swap_segment_command_64(struct segment_command_64 *sg, | |
44 enum NXByteOrder target_byte_order) | |
45 { | |
46 sg->cmd = NXSwapLong(sg->cmd); | |
47 sg->cmdsize = NXSwapLong(sg->cmdsize); | |
48 | |
49 sg->vmaddr = NXSwapLongLong(sg->vmaddr); | |
50 sg->vmsize = NXSwapLongLong(sg->vmsize); | |
51 sg->fileoff = NXSwapLongLong(sg->fileoff); | |
52 sg->filesize = NXSwapLongLong(sg->filesize); | |
53 | |
54 sg->maxprot = NXSwapLong(sg->maxprot); | |
55 sg->initprot = NXSwapLong(sg->initprot); | |
56 sg->nsects = NXSwapLong(sg->nsects); | |
57 sg->flags = NXSwapLong(sg->flags); | |
58 } | |
59 | |
60 void breakpad_swap_mach_header_64(struct mach_header_64 *mh, | |
61 enum NXByteOrder target_byte_order) | |
62 { | |
63 mh->magic = NXSwapLong(mh->magic); | |
64 mh->cputype = NXSwapLong(mh->cputype); | |
65 mh->cpusubtype = NXSwapLong(mh->cpusubtype); | |
66 mh->filetype = NXSwapLong(mh->filetype); | |
67 mh->ncmds = NXSwapLong(mh->ncmds); | |
68 mh->sizeofcmds = NXSwapLong(mh->sizeofcmds); | |
69 mh->flags = NXSwapLong(mh->flags); | |
70 mh->reserved = NXSwapLong(mh->reserved); | |
71 } | |
72 | |
73 void breakpad_swap_section_64(struct section_64 *s, | |
74 uint32_t nsects, | |
75 enum NXByteOrder target_byte_order) | |
76 { | |
77 for (uint32_t i = 0; i < nsects; i++) { | |
78 s[i].addr = NXSwapLongLong(s[i].addr); | |
79 s[i].size = NXSwapLongLong(s[i].size); | |
80 | |
81 s[i].offset = NXSwapLong(s[i].offset); | |
82 s[i].align = NXSwapLong(s[i].align); | |
83 s[i].reloff = NXSwapLong(s[i].reloff); | |
84 s[i].nreloc = NXSwapLong(s[i].nreloc); | |
85 s[i].flags = NXSwapLong(s[i].flags); | |
86 s[i].reserved1 = NXSwapLong(s[i].reserved1); | |
87 s[i].reserved2 = NXSwapLong(s[i].reserved2); | |
88 } | |
89 } | |
OLD | NEW |