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

Diff of /pax-utils/scanelf.c

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

Revision 1.119 Revision 1.120
1/* 1/*
2 * Copyright 2003-2006 Gentoo Foundation 2 * Copyright 2003-2006 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/scanelf.c,v 1.119 2006/02/05 02:25:58 solar Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.120 2006/02/05 03:01:30 solar Exp $
5 * 5 *
6 * Copyright 2003-2006 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2006 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2006 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2006 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
10#include "paxinc.h" 10#include "paxinc.h"
11 11
12static const char *rcsid = "$Id: scanelf.c,v 1.119 2006/02/05 02:25:58 solar Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.120 2006/02/05 03:01:30 solar Exp $";
13#define argv0 "scanelf" 13#define argv0 "scanelf"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#') 15#define IS_MODIFIER(c) (c == '%' || c == '#')
16 16
17 17
60static char *search_path = NULL; 60static char *search_path = NULL;
61static char fix_elf = 0; 61static char fix_elf = 0;
62static char gmatch = 0; 62static char gmatch = 0;
63static char use_ldcache = 0; 63static char use_ldcache = 0;
64 64
65 65int match_bits = 0;
66caddr_t ldcache = 0; 66caddr_t ldcache = 0;
67size_t ldcache_size = 0; 67size_t ldcache_size = 0;
68 68
69/* sub-funcs for scanelf_file() */ 69/* sub-funcs for scanelf_file() */
70static void scanelf_file_get_symtabs(elfobj *elf, void **sym, void **tab) 70static void scanelf_file_get_symtabs(elfobj *elf, void **sym, void **tab)
1020} 1020}
1021 1021
1022/* scan a single elf */ 1022/* scan a single elf */
1023static int scanelf_elf(const char *filename, int fd, size_t len) 1023static int scanelf_elf(const char *filename, int fd, size_t len)
1024{ 1024{
1025 int ret; 1025 int ret = 1;
1026 elfobj *elf; 1026 elfobj *elf;
1027 1027
1028 /* verify this is real ELF */ 1028 /* verify this is real ELF */
1029 if ((elf = _readelf_fd(filename, fd, len, !fix_elf)) == NULL) { 1029 if ((elf = _readelf_fd(filename, fd, len, !fix_elf)) == NULL) {
1030 if (be_verbose > 2) printf("%s: not an ELF\n", filename); 1030 if (be_verbose > 2) printf("%s: not an ELF\n", filename);
1031 return 1; 1031 return ret;
1032 } 1032 }
1033 1033 switch (match_bits) {
1034 case 32:
1035 if (elf->elf_class != ELFCLASS32)
1036 goto label_done;
1037 break;
1038 case 64:
1039 if (elf->elf_class != ELFCLASS64)
1040 goto label_done;
1041 break;
1042 default: break;
1043 }
1034 if (strlen(match_etypes)) { 1044 if (strlen(match_etypes)) {
1035 char sbuf[126]; 1045 char sbuf[126];
1036 strncpy(sbuf, match_etypes, sizeof(sbuf)); 1046 strncpy(sbuf, match_etypes, sizeof(sbuf));
1037 if (strchr(match_etypes, ',') != NULL) { 1047 if (strchr(match_etypes, ',') != NULL) {
1038 char *p; 1048 char *p;
1040 *p = 0; 1050 *p = 0;
1041 if (atoi(p+1) == get_etype(elf)) 1051 if (atoi(p+1) == get_etype(elf))
1042 goto label_ret; 1052 goto label_ret;
1043 } 1053 }
1044 } 1054 }
1045 if (atoi(sbuf) != get_etype(elf)) { 1055 if (atoi(sbuf) != get_etype(elf))
1046 ret = 1;
1047 goto label_done; 1056 goto label_done;
1048 }
1049 } 1057 }
1050 1058
1051label_ret: 1059label_ret:
1052 ret = scanelf_elfobj(elf); 1060 ret = scanelf_elfobj(elf);
1053 1061
1256 free(path); 1264 free(path);
1257} 1265}
1258 1266
1259 1267
1260/* usage / invocation handling functions */ 1268/* usage / invocation handling functions */
1261#define PARSE_FLAGS "plRmyAXxetrnLibSs:gN:TaqvF:f:o:E:BhV" 1269#define PARSE_FLAGS "plRmyAXxetrnLibSs:gN:TaqvF:f:o:M:E:BhV"
1262#define a_argument required_argument 1270#define a_argument required_argument
1263static struct option const long_opts[] = { 1271static struct option const long_opts[] = {
1264 {"path", no_argument, NULL, 'p'}, 1272 {"path", no_argument, NULL, 'p'},
1265 {"ldpath", no_argument, NULL, 'l'}, 1273 {"ldpath", no_argument, NULL, 'l'},
1266 {"recursive", no_argument, NULL, 'R'}, 1274 {"recursive", no_argument, NULL, 'R'},
1280 {"symbol", a_argument, NULL, 's'}, 1288 {"symbol", a_argument, NULL, 's'},
1281 {"lib", a_argument, NULL, 'N'}, 1289 {"lib", a_argument, NULL, 'N'},
1282 {"gmatch", no_argument, NULL, 'g'}, 1290 {"gmatch", no_argument, NULL, 'g'},
1283 {"textrels", no_argument, NULL, 'T'}, 1291 {"textrels", no_argument, NULL, 'T'},
1284 {"etype", a_argument, NULL, 'E'}, 1292 {"etype", a_argument, NULL, 'E'},
1293 {"bits", a_argument, NULL, 'M'},
1285 {"all", no_argument, NULL, 'a'}, 1294 {"all", no_argument, NULL, 'a'},
1286 {"quiet", no_argument, NULL, 'q'}, 1295 {"quiet", no_argument, NULL, 'q'},
1287 {"verbose", no_argument, NULL, 'v'}, 1296 {"verbose", no_argument, NULL, 'v'},
1288 {"format", a_argument, NULL, 'F'}, 1297 {"format", a_argument, NULL, 'F'},
1289 {"from", a_argument, NULL, 'f'}, 1298 {"from", a_argument, NULL, 'f'},
1313 "Print SONAME information", 1322 "Print SONAME information",
1314 "Find a specified symbol", 1323 "Find a specified symbol",
1315 "Find a specified library", 1324 "Find a specified library",
1316 "Use strncmp to match libraries. (use with -N)", 1325 "Use strncmp to match libraries. (use with -N)",
1317 "Locate cause of TEXTREL", 1326 "Locate cause of TEXTREL",
1318 "Print only ELF files matching numeric constant", 1327 "Print only ELF files matching numeric constant type",
1328 "Print only ELF files matching numeric bits",
1319 "Print all scanned info (-x -e -t -r -b)\n", 1329 "Print all scanned info (-x -e -t -r -b)\n",
1320 "Only output 'bad' things", 1330 "Only output 'bad' things",
1321 "Be verbose (can be specified more than once)", 1331 "Be verbose (can be specified more than once)",
1322 "Use specified format for output", 1332 "Use specified format for output",
1323 "Read input stream from a filename", 1333 "Read input stream from a filename",
1380 if (from_file) warn("You prob don't want to specify -f twice"); 1390 if (from_file) warn("You prob don't want to specify -f twice");
1381 from_file = optarg; 1391 from_file = optarg;
1382 break; 1392 break;
1383 case 'E': 1393 case 'E':
1384 strncpy(match_etypes, optarg, sizeof(match_etypes)); 1394 strncpy(match_etypes, optarg, sizeof(match_etypes));
1395 break;
1396 case 'M':
1397 match_bits = atoi(optarg);
1385 break; 1398 break;
1386 case 'o': { 1399 case 'o': {
1387 FILE *fp = NULL; 1400 FILE *fp = NULL;
1388 if ((fp = freopen(optarg, "w", stdout)) == NULL) 1401 if ((fp = freopen(optarg, "w", stdout)) == NULL)
1389 err("Could not open output stream '%s': %s", optarg, strerror(errno)); 1402 err("Could not open output stream '%s': %s", optarg, strerror(errno));

Legend:
Removed from v.1.119  
changed lines
  Added in v.1.120

  ViewVC Help
Powered by ViewVC 1.1.20