Ignore:
Timestamp:
05/09/06 05:56:05 (18 years ago)
Author:
rchin
Message:
  • Updated to new mach_inject with support for x86
  • Updated nib files to 10.2+ format so that future updates to the f-script framework won't break fsa
  • Adjusted some code to work with the new x86 mach_inject (sends an additional argument)
  • Updates code to work with newer defines in cctools
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/F-Script Anywhere/Source/bytesex.c

    r7 r217  
    11/*
    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.
    53 *
    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.
    1315 *
    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.
    2327 */
    2428/* byte_sex.c */
    2529#include <string.h>
     30#include "stuff/target_arch.h"
    2631#include <mach-o/fat.h>
    2732#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>
    3544#include <mach-o/nlist.h>
    3645#include <mach-o/reloc.h>
     
    3847#include "stuff/bool.h"
    3948#include "stuff/bytesex.h"
     49
     50__private_extern__
     51long long
     52SWAP_LONG_LONG(
     53long 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}
    4070
    4171__private_extern__
     
    150180__private_extern__
    151181void
     182swap_mach_header_64(
     183struct mach_header_64 *mh,
     184enum 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__
     201void
    152202swap_load_command(
    153203struct load_command *lc,
     
    187237__private_extern__
    188238void
     239swap_segment_command_64(
     240struct segment_command_64 *sg,
     241enum 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__
     261void
    189262swap_section(
    190263struct section *s,
     
    203276            s[i].addr = SWAP_LONG(s[i].addr);
    204277            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__
     289void
     290swap_section_64(
     291struct section_64 *s,
     292unsigned long nsects,
     293enum 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);
    205306            s[i].offset = SWAP_LONG(s[i].offset);
    206307            s[i].align = SWAP_LONG(s[i].align);
     
    542643        cpu->ctr = SWAP_LONG(cpu->ctr);
    543644        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__
     649void
     650swap_ppc_thread_state64_t(
     651ppc_thread_state64_t *cpu,
     652enum 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);
    545693}
    546694
     
    16901838__private_extern__
    16911839void
     1840swap_routines_command_64(
     1841struct routines_command_64 *r_cmd,
     1842enum 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__
     1861void
    16921862swap_twolevel_hints_command(
    16931863struct twolevel_hints_command *hints_cmd,
     
    17771947            symbols[i].n_desc = SWAP_SHORT(symbols[i].n_desc);
    17781948            symbols[i].n_value = SWAP_LONG(symbols[i].n_value);
     1949        }
     1950}
     1951
     1952__private_extern__
     1953void
     1954swap_nlist_64(
     1955struct nlist_64 *symbols,
     1956unsigned long nsymbols,
     1957enum 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);
    17791971        }
    17801972}
     
    19632155__private_extern__
    19642156void
     2157swap_dylib_module_64(
     2158struct dylib_module_64 *mods,
     2159unsigned long nmods,
     2160enum 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__
     2188void
    19652189swap_dylib_table_of_contents(
    19662190struct dylib_table_of_contents *tocs,
Note: See TracChangeset for help on using the changeset viewer.