/[gentoo-projects]/pax-utils/scanmacho.c
Gentoo

Diff of /pax-utils/scanmacho.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.13 Revision 1.20
1/* 1/*
2 * Copyright 2008 Gentoo Foundation 2 * Copyright 2008 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2 3 * Distributed under the terms of the GNU General Public License v2
4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanmacho.c,v 1.13 2008/12/30 13:34:46 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanmacho.c,v 1.20 2010/12/08 01:16:01 vapier Exp $
5 * 5 *
6 * based on scanelf by: 6 * based on scanelf by:
7 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org> 7 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org>
8 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org> 8 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org>
9 * for Darwin specific fun: 9 * for Darwin specific fun:
10 * 2008 Fabian Groffen - <grobian@gentoo.org> 10 * 2008-2010 Fabian Groffen - <grobian@gentoo.org>
11 */ 11 */
12 12
13static const char *rcsid = "$Id: scanmacho.c,v 1.13 2008/12/30 13:34:46 vapier Exp $"; 13static const char *rcsid = "$Id: scanmacho.c,v 1.20 2010/12/08 01:16:01 vapier Exp $";
14const char * const argv0 = "scanmacho"; 14const char argv0[] = "scanmacho";
15 15
16#include "paxinc.h" 16#include "paxinc.h"
17 17
18#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 18#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
19 19
70 lcmd = firstloadcmd(fobj); 70 lcmd = firstloadcmd(fobj);
71 lc_load_dylib = MGET(fobj->swapped, LC_LOAD_DYLIB); 71 lc_load_dylib = MGET(fobj->swapped, LC_LOAD_DYLIB);
72 72
73 do { 73 do {
74 if (lcmd->lcmd->cmd == lc_load_dylib) { 74 if (lcmd->lcmd->cmd == lc_load_dylib) {
75 struct dylib_command *dlcmd = (struct dylib_command*)lcmd->data; 75 struct dylib_command *dlcmd = lcmd->data;
76 char *needed; 76 char *needed;
77 needed = (char *)(lcmd->data + MGET(fobj->swapped, dlcmd->dylib.name.offset)); 77 needed = lcmd->data + MGET(fobj->swapped, dlcmd->dylib.name.offset);
78 if (op == 0) { 78 if (op == 0) {
79 if (!be_wewy_wewy_quiet) { 79 if (!be_wewy_wewy_quiet) {
80 if (*found_needed) 80 if (*found_needed)
81 xchrcat(ret, ',', ret_len); 81 xchrcat(ret, ',', ret_len);
82 xstrcat(ret, needed, ret_len); 82 xstrcat(ret, needed, ret_len);
111 lcmd = firstloadcmd(fobj); 111 lcmd = firstloadcmd(fobj);
112 lc_load_dylinker = MGET(fobj->swapped, LC_LOAD_DYLINKER); 112 lc_load_dylinker = MGET(fobj->swapped, LC_LOAD_DYLINKER);
113 113
114 do { 114 do {
115 if (lcmd->lcmd->cmd == lc_load_dylinker) { 115 if (lcmd->lcmd->cmd == lc_load_dylinker) {
116 struct dylinker_command *dlcmd =
117 (struct dylinker_command*)lcmd->data; 116 struct dylinker_command *dlcmd = lcmd->data;
118 char *dylinker; 117 char *dylinker;
119 dylinker = (char *)(lcmd->data + MGET(fobj->swapped, dlcmd->name.offset)); 118 dylinker = lcmd->data + MGET(fobj->swapped, dlcmd->name.offset);
120 *found_interp = 1; 119 *found_interp = 1;
121 free(lcmd); 120 free(lcmd);
122 return (be_wewy_wewy_quiet ? NULL : dylinker); 121 return (be_wewy_wewy_quiet ? NULL : dylinker);
123 } 122 }
124 } while (nextloadcmd(lcmd)); 123 } while (nextloadcmd(lcmd));
137 lcmd = firstloadcmd(fobj); 136 lcmd = firstloadcmd(fobj);
138 lc_id_dylib = MGET(fobj->swapped, LC_ID_DYLIB); 137 lc_id_dylib = MGET(fobj->swapped, LC_ID_DYLIB);
139 138
140 do { 139 do {
141 if (lcmd->lcmd->cmd == lc_id_dylib) { 140 if (lcmd->lcmd->cmd == lc_id_dylib) {
142 struct dylib_command *dlcmd = (struct dylib_command*)lcmd->data; 141 struct dylib_command *dlcmd = lcmd->data;
143 char *soname; 142 char *soname;
144 soname = (char *)(lcmd->data + MGET(fobj->swapped, dlcmd->dylib.name.offset)); 143 soname = lcmd->data + MGET(fobj->swapped, dlcmd->dylib.name.offset);
145 *found_soname = 1; 144 *found_soname = 1;
146 free(lcmd); 145 free(lcmd);
147 return (be_wewy_wewy_quiet ? NULL : soname); 146 return (be_wewy_wewy_quiet ? NULL : soname);
148 } 147 }
149 } while (nextloadcmd(lcmd)); 148 } while (nextloadcmd(lcmd));
150 149
151 return NULL; 150 return NULL;
152} 151}
153 152
154/* scan a macho file and show all the fun stuff */ 153/* scan a macho file and show all the fun stuff */
155#define prints(str) write(fileno(stdout), str, strlen(str)) 154#define prints(str) ({ ssize_t ret = write(fileno(stdout), str, strlen(str)); ret; })
156static int scanmacho_fatobj(fatobj *fobj) 155static int scanmacho_fatobj(fatobj *fobj)
157{ 156{
158 unsigned long i; 157 unsigned long i;
159 char found_needed, found_interp, found_soname, found_lib, found_file; 158 char found_needed, found_interp, found_soname, found_lib, found_file;
160 static char *out_buffer = NULL; 159 static char *out_buffer = NULL;
496 } 495 }
497 496
498 free(path); 497 free(path);
499} 498}
500 499
501/* usage / invocation handling functions */ /* Free Flags: c d e j k l r s t u w x z C G H I J K L P Q T U W X Y */ 500/* usage / invocation handling functions */ /* Free Flags: c d e j k l r s t u w x z G H I J K L P Q T U W X Y */
502#define PARSE_FLAGS "pRmyAnibSN:gE:M:DO:ZaqvF:f:o:BhV" 501#define PARSE_FLAGS "pRmyAnibSN:gE:M:DO:ZaqvF:f:o:CBhV"
503#define a_argument required_argument 502#define a_argument required_argument
504static struct option const long_opts[] = { 503static struct option const long_opts[] = {
505 {"path", no_argument, NULL, 'p'}, 504 {"path", no_argument, NULL, 'p'},
506 {"recursive", no_argument, NULL, 'R'}, 505 {"recursive", no_argument, NULL, 'R'},
507 {"mount", no_argument, NULL, 'm'}, 506 {"mount", no_argument, NULL, 'm'},
522 {"quiet", no_argument, NULL, 'q'}, 521 {"quiet", no_argument, NULL, 'q'},
523 {"verbose", no_argument, NULL, 'v'}, 522 {"verbose", no_argument, NULL, 'v'},
524 {"format", a_argument, NULL, 'F'}, 523 {"format", a_argument, NULL, 'F'},
525 {"from", a_argument, NULL, 'f'}, 524 {"from", a_argument, NULL, 'f'},
526 {"file", a_argument, NULL, 'o'}, 525 {"file", a_argument, NULL, 'o'},
526 {"nocolor", no_argument, NULL, 'C'},
527 {"nobanner", no_argument, NULL, 'B'}, 527 {"nobanner", no_argument, NULL, 'B'},
528 {"help", no_argument, NULL, 'h'}, 528 {"help", no_argument, NULL, 'h'},
529 {"version", no_argument, NULL, 'V'}, 529 {"version", no_argument, NULL, 'V'},
530 {NULL, no_argument, NULL, 0x0} 530 {NULL, no_argument, NULL, 0x0}
531}; 531};
533static const char *opts_help[] = { 533static const char *opts_help[] = {
534 "Scan all directories in PATH environment", 534 "Scan all directories in PATH environment",
535 "Scan directories recursively", 535 "Scan directories recursively",
536 "Don't recursively cross mount points", 536 "Don't recursively cross mount points",
537 "Don't scan symlinks", 537 "Don't scan symlinks",
538 "Scan archives (.a files)", 538 "Scan archives (.a files)\n",
539 "Print LC_LOAD_DYLIB information (ELF: NEEDED)", 539 "Print LC_LOAD_DYLIB information (ELF: NEEDED)",
540 "Print LC_LOAD_DYLINKER information (ELF: INTERP)", 540 "Print LC_LOAD_DYLINKER information (ELF: INTERP)",
541 "Print flags from mach_header (ELF: BIND)", 541 "Print flags from mach_header (ELF: BIND)",
542 "Print LC_ID_DYLIB information (ELF: SONAME)", 542 "Print LC_ID_DYLIB information (ELF: SONAME)",
543 "Find a specified library", 543 "Find a specified library",
546 " MH_OBJECT,MH_EXECUTE ... (ELF: etype)", 546 " MH_OBJECT,MH_EXECUTE ... (ELF: etype)",
547 "Print only Mach-O files matching numeric bits", 547 "Print only Mach-O files matching numeric bits",
548 "Print Endianness", 548 "Print Endianness",
549 "Print only Mach-O files matching octal permissions", 549 "Print only Mach-O files matching octal permissions",
550 "Print Mach-O file size", 550 "Print Mach-O file size",
551 "Print all scanned info (-F\"%o %O %D %b %F\")\n", 551 "Print all useful/simple info\n",
552 "Only output 'bad' things", 552 "Only output 'bad' things",
553 "Be verbose (can be specified more than once)", 553 "Be verbose (can be specified more than once)",
554 "Use specified format for output", 554 "Use specified format for output",
555 "Read input stream from a filename", 555 "Read input stream from a filename",
556 "Write output stream to a filename", 556 "Write output stream to a filename",
557 "Don't emit color in output",
557 "Don't display the header", 558 "Don't display the header",
558 "Print this help and exit", 559 "Print this help and exit",
559 "Print version and exit", 560 "Print version and exit",
560 NULL 561 NULL
561}; 562};
628 } 629 }
629 case 'Z': show_size = 1; break; 630 case 'Z': show_size = 1; break;
630 case 'g': g_match = 1; break; 631 case 'g': g_match = 1; break;
631 case 'y': scan_symlink = 0; break; 632 case 'y': scan_symlink = 0; break;
632 case 'A': scan_archives = 1; break; 633 case 'A': scan_archives = 1; break;
634 case 'C': color_init(true); break;
633 case 'B': show_banner = 0; break; 635 case 'B': show_banner = 0; break;
634 case 'p': scan_envpath = 1; break; 636 case 'p': scan_envpath = 1; break;
635 case 'R': dir_recurse = 1; break; 637 case 'R': dir_recurse = 1; break;
636 case 'm': dir_crossmount = 0; break; 638 case 'm': dir_crossmount = 0; break;
637 case 'n': show_needed = 1; break; 639 case 'n': show_needed = 1; break;
723int main(int argc, char *argv[]) 725int main(int argc, char *argv[])
724{ 726{
725 int ret; 727 int ret;
726 if (argc < 2) 728 if (argc < 2)
727 usage(EXIT_FAILURE); 729 usage(EXIT_FAILURE);
730 color_init(false);
728 ret = parseargs(argc, argv); 731 ret = parseargs(argc, argv);
729 fclose(stdout); 732 fclose(stdout);
730 return ret; 733 return ret;
731} 734}

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.20

  ViewVC Help
Powered by ViewVC 1.1.20