|
Lines 12-24
Link Here
|
| 12 |
# include "config.h" |
12 |
# include "config.h" |
| 13 |
#endif |
13 |
#endif |
| 14 |
|
14 |
|
|
|
15 |
#include <dlfcn.h> |
| 16 |
#include <elf.h> |
| 17 |
#include <fcntl.h> |
| 15 |
#include <stdio.h> |
18 |
#include <stdio.h> |
| 16 |
#include <stdlib.h> |
19 |
#include <stdlib.h> |
|
|
20 |
#include <string.h> |
| 17 |
#include <unistd.h> |
21 |
#include <unistd.h> |
| 18 |
#ifdef HAVE_GETOPT_H |
22 |
#ifdef HAVE_GETOPT_H |
| 19 |
#include <getopt.h> |
23 |
#include <getopt.h> |
| 20 |
#endif |
24 |
#endif |
| 21 |
#include "protos.h" |
25 |
|
|
|
26 |
typedef int (*killrpath_t)(const char *filename); |
| 27 |
typedef int (*chrpath_t)(const char *filename, const char *newpath, int convert); |
| 22 |
|
28 |
|
| 23 |
#ifdef HAVE_GETOPT_LONG |
29 |
#ifdef HAVE_GETOPT_LONG |
| 24 |
# define GETOPT_LONG getopt_long |
30 |
# define GETOPT_LONG getopt_long |
|
Lines 61-66
Link Here
|
| 61 |
printf("\n"); |
67 |
printf("\n"); |
| 62 |
} |
68 |
} |
| 63 |
|
69 |
|
|
|
70 |
static unsigned |
| 71 |
elf_class(const char *filename) |
| 72 |
{ |
| 73 |
Elf32_Ehdr ehdr; |
| 74 |
int fd; |
| 75 |
|
| 76 |
fd = open(filename, O_RDONLY); |
| 77 |
if (fd == -1) |
| 78 |
return 0; |
| 79 |
if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) |
| 80 |
{ |
| 81 |
close(fd); |
| 82 |
return 0; |
| 83 |
} |
| 84 |
close(fd); |
| 85 |
if ((memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0) |
| 86 |
|| (ehdr.e_ident[EI_VERSION] != EV_CURRENT)) |
| 87 |
{ |
| 88 |
fprintf(stderr, "`%s' probably isn't an ELF file.\n", filename); |
| 89 |
return 0; |
| 90 |
} |
| 91 |
return ehdr.e_ident[EI_CLASS]; |
| 92 |
} |
| 93 |
|
| 64 |
int |
94 |
int |
| 65 |
main(int argc, char * const argv[]) |
95 |
main(int argc, char * const argv[]) |
| 66 |
{ |
96 |
{ |
|
Lines 73-78
Link Here
|
| 73 |
#ifdef HAVE_GETOPT_LONG |
103 |
#ifdef HAVE_GETOPT_LONG |
| 74 |
int option_index = 0; |
104 |
int option_index = 0; |
| 75 |
#endif /* HAVE_GETOPT_LONG */ |
105 |
#endif /* HAVE_GETOPT_LONG */ |
|
|
106 |
void* dll[2]; |
| 107 |
killrpath_t killrpath[2]; |
| 108 |
chrpath_t chrpath[2]; |
| 76 |
|
109 |
|
| 77 |
if (argc < 2) |
110 |
if (argc < 2) |
| 78 |
{ |
111 |
{ |
|
Lines 116-129
Link Here
|
| 116 |
} |
149 |
} |
| 117 |
} while (-1 != opt); |
150 |
} while (-1 != opt); |
| 118 |
|
151 |
|
|
|
152 |
dll[0] = dlopen("libchrpath32.so", RTLD_LAZY); |
| 153 |
killrpath[0] = (killrpath_t)dlsym(dll[0], "killrpath"); |
| 154 |
chrpath[0] = (chrpath_t)dlsym(dll[0], "chrpath"); |
| 155 |
|
| 156 |
dll[1] = dlopen("libchrpath64.so", RTLD_LAZY); |
| 157 |
killrpath[1] = (killrpath_t)dlsym(dll[1], "killrpath"); |
| 158 |
chrpath[1] = (chrpath_t)dlsym(dll[1], "chrpath"); |
| 159 |
|
| 119 |
while (optind < argc && (!retval || keep_going)) |
160 |
while (optind < argc && (!retval || keep_going)) |
| 120 |
{ |
161 |
{ |
|
|
162 |
const char* program = argv[optind++]; |
| 163 |
unsigned eclass = elf_class(program); |
| 164 |
if (!eclass) |
| 165 |
{ |
| 166 |
retval = 1; |
| 167 |
continue; |
| 168 |
} |
| 121 |
if (remove) |
169 |
if (remove) |
| 122 |
retval |= killrpath(argv[optind++]); |
170 |
retval |= killrpath[eclass - ELFCLASS32](program); |
| 123 |
else |
171 |
else |
| 124 |
/* list by default, replace if path is set */ |
172 |
/* list by default, replace if path is set */ |
| 125 |
retval |= chrpath(argv[optind++], newpath, convert); |
173 |
retval |= chrpath[eclass - ELFCLASS32](program, newpath, convert); |
| 126 |
} |
174 |
} |
| 127 |
|
175 |
|
|
|
176 |
dlclose(dll[0]); |
| 177 |
dlclose(dll[1]); |
| 128 |
return retval; |
178 |
return retval; |
| 129 |
} |
179 |
} |