Changeset 217 for trunk/Cocoa/F-Script Anywhere/Source/bytesex.c
- Timestamp:
- 05/09/06 05:56:05 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/F-Script Anywhere/Source/bytesex.c
r7 r217 1 1 /* 2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 2 * Copyright (c) 2004, Apple Computer, Inc. All rights reserved. 5 3 * 6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights 7 * Reserved. This file contains Original Code and/or Modifications of 8 * Original Code as defined in and that are subject to the Apple Public 9 * Source License Version 1.1 (the "License"). You may not use this file 10 * except in compliance with the License. Please obtain a copy of the 11 * License at http://www.apple.com/publicsource and read it before using 12 * this file. 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 13 * its contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 13 15 * 14 * The Original Code and all software distributed under the License are 15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the 19 * License for the specific language governing rights and limitations 20 * under the License. 21 * 22 * @APPLE_LICENSE_HEADER_END@ 16 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 23 27 */ 24 28 /* byte_sex.c */ 25 29 #include <string.h> 30 #include "stuff/target_arch.h" 26 31 #include <mach-o/fat.h> 27 32 #include <mach-o/loader.h> 28 #import <mach/m68k/thread_status.h> 29 #import <mach/ppc/thread_status.h> 30 #import <mach/m88k/thread_status.h> 31 #import <mach/i860/thread_status.h> 32 #import <mach/i386/thread_status.h> 33 #import <mach/hppa/thread_status.h> 34 #import <mach/sparc/thread_status.h> 33 #include <mach/m68k/thread_status.h> 34 #undef MACHINE_THREAD_STATE /* need to undef these to avoid warnings */ 35 #undef MACHINE_THREAD_STATE_COUNT 36 #include <mach/ppc/thread_status.h> 37 #undef MACHINE_THREAD_STATE /* need to undef these to avoid warnings */ 38 #undef MACHINE_THREAD_STATE_COUNT 39 #include <mach/m88k/thread_status.h> 40 #include <mach/i860/thread_status.h> 41 #include <mach/i386/thread_status.h> 42 #include <mach/hppa/thread_status.h> 43 #include <mach/sparc/thread_status.h> 35 44 #include <mach-o/nlist.h> 36 45 #include <mach-o/reloc.h> … … 38 47 #include "stuff/bool.h" 39 48 #include "stuff/bytesex.h" 49 50 __private_extern__ 51 long long 52 SWAP_LONG_LONG( 53 long long ll) 54 { 55 union { 56 char c[8]; 57 long long ll; 58 } in, out; 59 in.ll = ll; 60 out.c[0] = in.c[7]; 61 out.c[1] = in.c[6]; 62 out.c[2] = in.c[5]; 63 out.c[3] = in.c[4]; 64 out.c[4] = in.c[3]; 65 out.c[5] = in.c[2]; 66 out.c[6] = in.c[1]; 67 out.c[7] = in.c[0]; 68 return(out.ll); 69 } 40 70 41 71 __private_extern__ … … 150 180 __private_extern__ 151 181 void 182 swap_mach_header_64( 183 struct mach_header_64 *mh, 184 enum byte_sex target_byte_sex) 185 { 186 #ifdef __MWERKS__ 187 enum byte_sex dummy; 188 dummy = target_byte_sex; 189 #endif 190 mh->magic = SWAP_LONG(mh->magic); 191 mh->cputype = SWAP_LONG(mh->cputype); 192 mh->cpusubtype = SWAP_LONG(mh->cpusubtype); 193 mh->filetype = SWAP_LONG(mh->filetype); 194 mh->ncmds = SWAP_LONG(mh->ncmds); 195 mh->sizeofcmds = SWAP_LONG(mh->sizeofcmds); 196 mh->flags = SWAP_LONG(mh->flags); 197 mh->reserved = SWAP_LONG(mh->reserved); 198 } 199 200 __private_extern__ 201 void 152 202 swap_load_command( 153 203 struct load_command *lc, … … 187 237 __private_extern__ 188 238 void 239 swap_segment_command_64( 240 struct segment_command_64 *sg, 241 enum byte_sex target_byte_sex) 242 { 243 #ifdef __MWERKS__ 244 enum byte_sex dummy; 245 dummy = target_byte_sex; 246 #endif 247 /* segname[16] */ 248 sg->cmd = SWAP_LONG(sg->cmd); 249 sg->cmdsize = SWAP_LONG(sg->cmdsize); 250 sg->vmaddr = SWAP_LONG_LONG(sg->vmaddr); 251 sg->vmsize = SWAP_LONG_LONG(sg->vmsize); 252 sg->fileoff = SWAP_LONG_LONG(sg->fileoff); 253 sg->filesize = SWAP_LONG_LONG(sg->filesize); 254 sg->maxprot = SWAP_LONG(sg->maxprot); 255 sg->initprot = SWAP_LONG(sg->initprot); 256 sg->nsects = SWAP_LONG(sg->nsects); 257 sg->flags = SWAP_LONG(sg->flags); 258 } 259 260 __private_extern__ 261 void 189 262 swap_section( 190 263 struct section *s, … … 203 276 s[i].addr = SWAP_LONG(s[i].addr); 204 277 s[i].size = SWAP_LONG(s[i].size); 278 s[i].offset = SWAP_LONG(s[i].offset); 279 s[i].align = SWAP_LONG(s[i].align); 280 s[i].reloff = SWAP_LONG(s[i].reloff); 281 s[i].nreloc = SWAP_LONG(s[i].nreloc); 282 s[i].flags = SWAP_LONG(s[i].flags); 283 s[i].reserved1 = SWAP_LONG(s[i].reserved1); 284 s[i].reserved2 = SWAP_LONG(s[i].reserved2); 285 } 286 } 287 288 __private_extern__ 289 void 290 swap_section_64( 291 struct section_64 *s, 292 unsigned long nsects, 293 enum byte_sex target_byte_sex) 294 { 295 unsigned long i; 296 #ifdef __MWERKS__ 297 enum byte_sex dummy; 298 dummy = target_byte_sex; 299 #endif 300 301 for(i = 0; i < nsects; i++){ 302 /* sectname[16] */ 303 /* segname[16] */ 304 s[i].addr = SWAP_LONG_LONG(s[i].addr); 305 s[i].size = SWAP_LONG_LONG(s[i].size); 205 306 s[i].offset = SWAP_LONG(s[i].offset); 206 307 s[i].align = SWAP_LONG(s[i].align); … … 542 643 cpu->ctr = SWAP_LONG(cpu->ctr); 543 644 cpu->mq = SWAP_LONG(cpu->mq); 544 cpu->pad = SWAP_LONG(cpu->pad); 645 cpu->vrsave = SWAP_LONG(cpu->vrsave); 646 } 647 648 __private_extern__ 649 void 650 swap_ppc_thread_state64_t( 651 ppc_thread_state64_t *cpu, 652 enum byte_sex target_byte_sex) 653 { 654 cpu->srr0 = SWAP_LONG_LONG(cpu->srr0); 655 cpu->srr1 = SWAP_LONG_LONG(cpu->srr1); 656 cpu->r0 = SWAP_LONG_LONG(cpu->r0); 657 cpu->r1 = SWAP_LONG_LONG(cpu->r1); 658 cpu->r2 = SWAP_LONG_LONG(cpu->r2); 659 cpu->r3 = SWAP_LONG_LONG(cpu->r3); 660 cpu->r4 = SWAP_LONG_LONG(cpu->r4); 661 cpu->r5 = SWAP_LONG_LONG(cpu->r5); 662 cpu->r6 = SWAP_LONG_LONG(cpu->r6); 663 cpu->r7 = SWAP_LONG_LONG(cpu->r7); 664 cpu->r8 = SWAP_LONG_LONG(cpu->r8); 665 cpu->r9 = SWAP_LONG_LONG(cpu->r9); 666 cpu->r10 = SWAP_LONG_LONG(cpu->r10); 667 cpu->r11 = SWAP_LONG_LONG(cpu->r11); 668 cpu->r12 = SWAP_LONG_LONG(cpu->r12); 669 cpu->r13 = SWAP_LONG_LONG(cpu->r13); 670 cpu->r14 = SWAP_LONG_LONG(cpu->r14); 671 cpu->r15 = SWAP_LONG_LONG(cpu->r15); 672 cpu->r16 = SWAP_LONG_LONG(cpu->r16); 673 cpu->r17 = SWAP_LONG_LONG(cpu->r17); 674 cpu->r18 = SWAP_LONG_LONG(cpu->r18); 675 cpu->r19 = SWAP_LONG_LONG(cpu->r19); 676 cpu->r20 = SWAP_LONG_LONG(cpu->r20); 677 cpu->r21 = SWAP_LONG_LONG(cpu->r21); 678 cpu->r22 = SWAP_LONG_LONG(cpu->r22); 679 cpu->r23 = SWAP_LONG_LONG(cpu->r23); 680 cpu->r24 = SWAP_LONG_LONG(cpu->r24); 681 cpu->r25 = SWAP_LONG_LONG(cpu->r25); 682 cpu->r26 = SWAP_LONG_LONG(cpu->r26); 683 cpu->r27 = SWAP_LONG_LONG(cpu->r27); 684 cpu->r28 = SWAP_LONG_LONG(cpu->r28); 685 cpu->r29 = SWAP_LONG_LONG(cpu->r29); 686 cpu->r30 = SWAP_LONG_LONG(cpu->r30); 687 cpu->r31 = SWAP_LONG_LONG(cpu->r31); 688 cpu->cr = SWAP_LONG(cpu->cr); 689 cpu->xer = SWAP_LONG_LONG(cpu->xer); 690 cpu->lr = SWAP_LONG_LONG(cpu->lr); 691 cpu->ctr = SWAP_LONG_LONG(cpu->ctr); 692 cpu->vrsave = SWAP_LONG(cpu->vrsave); 545 693 } 546 694 … … 1690 1838 __private_extern__ 1691 1839 void 1840 swap_routines_command_64( 1841 struct routines_command_64 *r_cmd, 1842 enum byte_sex target_byte_sex) 1843 { 1844 #ifdef __MWERKS__ 1845 enum byte_sex dummy; 1846 dummy = target_byte_sex; 1847 #endif 1848 r_cmd->cmd = SWAP_LONG(r_cmd->cmd); 1849 r_cmd->cmdsize = SWAP_LONG(r_cmd->cmdsize); 1850 r_cmd->init_address = SWAP_LONG_LONG(r_cmd->init_address); 1851 r_cmd->init_module = SWAP_LONG_LONG(r_cmd->init_module); 1852 r_cmd->reserved1 = SWAP_LONG_LONG(r_cmd->reserved1); 1853 r_cmd->reserved2 = SWAP_LONG_LONG(r_cmd->reserved2); 1854 r_cmd->reserved3 = SWAP_LONG_LONG(r_cmd->reserved3); 1855 r_cmd->reserved4 = SWAP_LONG_LONG(r_cmd->reserved4); 1856 r_cmd->reserved5 = SWAP_LONG_LONG(r_cmd->reserved5); 1857 r_cmd->reserved6 = SWAP_LONG_LONG(r_cmd->reserved6); 1858 } 1859 1860 __private_extern__ 1861 void 1692 1862 swap_twolevel_hints_command( 1693 1863 struct twolevel_hints_command *hints_cmd, … … 1777 1947 symbols[i].n_desc = SWAP_SHORT(symbols[i].n_desc); 1778 1948 symbols[i].n_value = SWAP_LONG(symbols[i].n_value); 1949 } 1950 } 1951 1952 __private_extern__ 1953 void 1954 swap_nlist_64( 1955 struct nlist_64 *symbols, 1956 unsigned long nsymbols, 1957 enum byte_sex target_byte_sex) 1958 { 1959 unsigned long i; 1960 #ifdef __MWERKS__ 1961 enum byte_sex dummy; 1962 dummy = target_byte_sex; 1963 #endif 1964 1965 for(i = 0; i < nsymbols; i++){ 1966 symbols[i].n_un.n_strx = SWAP_LONG(symbols[i].n_un.n_strx); 1967 /* n_type */ 1968 /* n_sect */ 1969 symbols[i].n_desc = SWAP_SHORT(symbols[i].n_desc); 1970 symbols[i].n_value = SWAP_LONG_LONG(symbols[i].n_value); 1779 1971 } 1780 1972 } … … 1963 2155 __private_extern__ 1964 2156 void 2157 swap_dylib_module_64( 2158 struct dylib_module_64 *mods, 2159 unsigned long nmods, 2160 enum byte_sex target_byte_sex) 2161 { 2162 unsigned long i; 2163 #ifdef __MWERKS__ 2164 enum byte_sex dummy; 2165 dummy = target_byte_sex; 2166 #endif 2167 2168 for(i = 0; i < nmods; i++){ 2169 mods[i].module_name = SWAP_LONG(mods[i].module_name); 2170 mods[i].iextdefsym = SWAP_LONG(mods[i].iextdefsym); 2171 mods[i].nextdefsym = SWAP_LONG(mods[i].nextdefsym); 2172 mods[i].irefsym = SWAP_LONG(mods[i].irefsym); 2173 mods[i].nrefsym = SWAP_LONG(mods[i].nrefsym); 2174 mods[i].ilocalsym = SWAP_LONG(mods[i].ilocalsym); 2175 mods[i].nlocalsym = SWAP_LONG(mods[i].nlocalsym); 2176 mods[i].iextrel = SWAP_LONG(mods[i].iextrel); 2177 mods[i].nextrel = SWAP_LONG(mods[i].nextrel); 2178 mods[i].iinit_iterm = SWAP_LONG(mods[i].iinit_iterm); 2179 mods[i].ninit_nterm = SWAP_LONG(mods[i].ninit_nterm); 2180 mods[i].objc_module_info_addr = 2181 SWAP_LONG_LONG(mods[i].objc_module_info_addr); 2182 mods[i].objc_module_info_size = 2183 SWAP_LONG_LONG(mods[i].objc_module_info_size); 2184 } 2185 } 2186 2187 __private_extern__ 2188 void 1965 2189 swap_dylib_table_of_contents( 1966 2190 struct dylib_table_of_contents *tocs,
Note:
See TracChangeset
for help on using the changeset viewer.