Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/arch/i386/libsaio/load.c

Source at commit 1302 created 12 years 8 months ago.
By meklort, Clean up libsaio
1/*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 2.0 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * load.c - Functions for decoding a Mach-o Kernel.
24 *
25 * Copyright (c) 1998-2003 Apple Computer, Inc.
26 *
27 */
28
29#include <mach-o/fat.h>
30#include <mach-o/loader.h>
31#include <mach/machine/thread_status.h>
32
33
34cpu_type_t archCpuType=CPU_TYPE_I386;
35
36// Public Functions
37
38long ThinFatFile(void **binary, unsigned long *length)
39{
40 unsigned long nfat, swapped, size = 0;
41 struct fat_header *fhp = (struct fat_header *)*binary;
42 struct fat_arch *fap =
43 (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header));
44 cpu_type_t fapcputype;
45 uint32_t fapoffset;
46 uint32_t fapsize;
47
48 if (fhp->magic == FAT_MAGIC) {
49 nfat = fhp->nfat_arch;
50 swapped = 0;
51 } else if (fhp->magic == FAT_CIGAM) {
52 nfat = OSSwapInt32(fhp->nfat_arch);
53 swapped = 1;
54 } else {
55 return -1;
56 }
57
58 for (; nfat > 0; nfat--, fap++) {
59 if (swapped) {
60 fapcputype = OSSwapInt32(fap->cputype);
61 fapoffset = OSSwapInt32(fap->offset);
62 fapsize = OSSwapInt32(fap->size);
63 }
64else
65{
66fapcputype = fap->cputype;
67fapoffset = fap->offset;
68fapsize = fap->size;
69}
70
71 if (fapcputype == archCpuType) {
72 *binary = (void *) ((unsigned long)*binary + fapoffset);
73 size = fapsize;
74 break;
75 }
76 }
77
78 if (length != 0) *length = size;
79
80 return 0;
81}

Archive Download this file

Revision: 1302