ios-kernel-patch/nm.c

52 lines
1.3 KiB
C
Raw Normal View History

2011-06-05 05:17:21 +07:00
#include <data/mach-o/binary.h>
2011-06-27 09:11:21 +07:00
#include <data/dyldcache/binary.h>
2011-06-05 05:17:21 +07:00
#include <stdio.h>
#include <stdlib.h>
static void usage() {
2011-09-02 07:36:29 +07:00
fprintf(stderr, "Usage: nm [-ixp] [-c subfile] binary [symbol]\n");
2011-06-05 05:17:21 +07:00
exit(1);
}
int main(int argc, char **argv) {
int flags = 0;
2011-06-27 09:11:21 +07:00
const char *subfile = NULL;
2011-06-05 05:17:21 +07:00
int c;
2011-06-27 09:11:21 +07:00
while((c = getopt(argc, argv, "ixpc:")) != -1) switch(c) {
2011-06-05 05:17:21 +07:00
case 'i': flags |= IMPORTED_SYM; break;
case 'x': flags |= TO_EXECUTE; break;
case 'p': flags |= PRIVATE_SYM; break;
2011-06-27 09:11:21 +07:00
case 'c': subfile = optarg; break;
2011-06-05 05:17:21 +07:00
default: usage();
}
if(!argv[optind] || (argv[optind + 1] && argv[optind + 2])) usage();
struct binary binary;
b_init(&binary);
2011-06-27 09:11:21 +07:00
if(subfile) {
struct binary other;
b_init(&other);
b_load_dyldcache(&other, argv[optind]);
b_dyldcache_load_macho(&other, subfile, &binary);
} else {
b_load_macho(&binary, argv[optind]);
}
2011-06-05 05:17:21 +07:00
if(argv[optind + 1]) {
printf("%8x\n", b_sym(&binary, argv[optind + 1], flags));
} else {
struct data_sym *syms;
uint32_t nsyms;
b_copy_syms(&binary, &syms, &nsyms, flags);
while(nsyms--) {
printf("%8x %s\n", syms->address, syms->name);
syms++;
}
}
return 0;
}