]>
git.saurik.com Git - apple/system_cmds.git/blob - kpgo.tproj/kpgo.c
2 * Copyright (c) 2014 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.0 (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
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
22 * @APPLE_LICENSE_HEADER_END@
34 static void usage(char **argv
)
36 fprintf (stderr
, "usage: %s [-H] [-m] [-w] [uuid] >datafile\n", argv
[0]);
37 fprintf (stderr
, " uuid : the UUID of a kext\n");
38 fprintf (stderr
, " -H : grab data for the HIB segment\n");
39 fprintf (stderr
, " -w : wait for the kext to be unloaded\n");
40 fprintf (stderr
, " -m : request metadata\n");
44 int main(int argc
, char **argv
)
52 while ((c
= getopt(argc
, argv
, "hHwm")) != EOF
) {
58 flags
|= PGO_METADATA
;
61 data_flags
|= PGO_WAIT_FOR_UNLOAD
;
73 if (optind
== argc
- 1 &&
74 0 == uuid_parse(argv
[optind
], uuid
))
82 ssize_t size
= grab_pgo_data(uuidp
, flags
, NULL
, 0);
86 perror("grab_pgo_data");
91 fprintf (stderr
, "size = %ld\n", (long) size
);
93 unsigned char *buffer
= valloc(size
);
100 ssize_t r
= grab_pgo_data(uuidp
, flags
| data_flags
, buffer
, size
);
105 perror("grab_pgo_data");
109 if (isatty(STDOUT_FILENO
)) {
110 fprintf (stderr
, "%s: refusing to write binary data to a tty!\n", argv
[0]);
116 r
= write(STDOUT_FILENO
, buffer
, size
);