Chameleon

Chameleon Commit Details

Date:2012-10-26 15:51:20 (6 years 8 months ago)
Author:Evan Lojewski
Commit:2072
Parents: 2071
Message:Add new segsize program to be used in future commit
Changes:
A/trunk/i386/util/segsize.c
M/trunk/i386/util/Makefile

File differences

trunk/i386/util/segsize.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* Source License Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <mach/mach.h>
#include <mach/mach_error.h>
#include <sys/file.h>
#include <mach-o/loader.h>
#include <libkern/OSByteOrder.h>
#include <unistd.h>
intinfile;
struct mach_headermh;
void *cmds;
static boolswap_ends;
static unsigned long swap(
unsigned long x
)
{
if (swap_ends)
return OSSwapInt32(x);
else
return x;
}
int
main(int argc, char *argv[])
{
intnc, ncmds;
char *cp;
if (argc == 3) {
infile = open(argv[1], O_RDONLY);
if (infile < 0)
goto usage;
}
else {
usage:
fprintf(stderr, "usage: segsize segment\n");
exit(1);
}
nc = read(infile, &mh, sizeof (mh));
if (nc < 0) {
perror("read mach header");
exit(1);
}
if (nc < (int)sizeof (mh)) {
fprintf(stderr, "read mach header: premature EOF %d\n", nc);
exit(1);
}
if (mh.magic == MH_MAGIC)
swap_ends = false;
else if (mh.magic == MH_CIGAM)
swap_ends = true;
else {
fprintf(stderr, "bad magic number %lx\n", (unsigned long)mh.magic);
exit(1);
}
cmds = calloc(swap(mh.sizeofcmds), sizeof (char));
if (cmds == 0) {
fprintf(stderr, "alloc load commands: no memory\n");
exit(1);
}
nc = read(infile, cmds, swap(mh.sizeofcmds));
if (nc < 0) {
perror("read load commands");
exit(1);
}
if (nc < (int)swap(mh.sizeofcmds)) {
fprintf(stderr, "read load commands: premature EOF %d\n", nc);
exit(1);
}
for (ncmds = swap(mh.ncmds), cp = cmds;
ncmds > 0; ncmds--) {
// boolisDATA;
// unsignedvmsize;
#define lcp((struct load_command *)cp)
switch(swap(lcp->cmd)) {
case LC_SEGMENT:
#define scp((struct segment_command *)cp)
if(strcmp(scp->segname, argv[2]) == 0)
{
printf("%ld\n", swap(scp->vmsize));
#if 0
if (isDATA)
vmsize = swap(scp->filesize);
else
vmsize = swap(scp->vmsize);
#endif
}
break;
}
cp += swap(lcp->cmdsize);
}
exit(0);
}
trunk/i386/util/Makefile
1616
1717
1818
19
20
19
20
2121
2222
2323
DIR = util
include ${SRCROOT}/Make.rules
PROGRAMS = machOconv dyldsymboltool
OBJS = dyldsymboltool.o32 dyldsymboltool.o64 machOconv.o32 machOconv.o64
PROGRAMS = machOconv dyldsymboltool segsize
OBJS = dyldsymboltool.o32 dyldsymboltool.o64 machOconv.o32 machOconv.o64 segsize.o32 segsize.o64
ifeq (${CONFIG_BDMESG}, y)

Archive Download the corresponding diff file

Revision: 2072