1 |
vapier 11/09/27 18:37:22 |
2 |
|
3 |
Modified: scanelf.c xfuncs.c xfuncs.h |
4 |
Log: |
5 |
allow people to search for multiple libraries (-N) or data sections (-k) |
6 |
|
7 |
Revision Changes Path |
8 |
1.226 pax-utils/scanelf.c |
9 |
|
10 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.226&view=markup |
11 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.226&content-type=text/plain |
12 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?r1=1.225&r2=1.226 |
13 |
|
14 |
Index: scanelf.c |
15 |
=================================================================== |
16 |
RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v |
17 |
retrieving revision 1.225 |
18 |
retrieving revision 1.226 |
19 |
diff -u -r1.225 -r1.226 |
20 |
--- scanelf.c 27 Sep 2011 17:28:19 -0000 1.225 |
21 |
+++ scanelf.c 27 Sep 2011 18:37:22 -0000 1.226 |
22 |
@@ -1,13 +1,13 @@ |
23 |
/* |
24 |
* Copyright 2003-2007 Gentoo Foundation |
25 |
* Distributed under the terms of the GNU General Public License v2 |
26 |
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.225 2011/09/27 17:28:19 vapier Exp $ |
27 |
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.226 2011/09/27 18:37:22 vapier Exp $ |
28 |
* |
29 |
* Copyright 2003-2007 Ned Ludd - <solar@g.o> |
30 |
* Copyright 2004-2007 Mike Frysinger - <vapier@g.o> |
31 |
*/ |
32 |
|
33 |
-static const char *rcsid = "$Id: scanelf.c,v 1.225 2011/09/27 17:28:19 vapier Exp $"; |
34 |
+static const char *rcsid = "$Id: scanelf.c,v 1.226 2011/09/27 18:37:22 vapier Exp $"; |
35 |
const char argv0[] = "scanelf"; |
36 |
|
37 |
#include "paxinc.h" |
38 |
@@ -58,7 +58,9 @@ |
39 |
static char be_semi_verbose = 0; |
40 |
static char *find_sym = NULL; |
41 |
static char *find_lib = NULL; |
42 |
+static array_t _find_lib_arr = array_init_decl, *find_lib_arr = &_find_lib_arr; |
43 |
static char *find_section = NULL; |
44 |
+static array_t _find_section_arr = array_init_decl, *find_section_arr = &_find_section_arr; |
45 |
static char *out_format = NULL; |
46 |
static char *search_path = NULL; |
47 |
static char fix_elf = 0; |
48 |
@@ -814,7 +816,12 @@ |
49 |
void *strtbl_void; |
50 |
char *p; |
51 |
|
52 |
- if ((op==0 && !show_needed) || (op==1 && !find_lib)) return NULL; |
53 |
+ /* |
54 |
+ * -n -> op==0 -> print all |
55 |
+ * -N -> op==1 -> print requested |
56 |
+ */ |
57 |
+ if ((op == 0 && !show_needed) || (op == 1 && !find_lib)) |
58 |
+ return NULL; |
59 |
|
60 |
strtbl_void = elf_findsecbyname(elf, ".dynstr"); |
61 |
|
62 |
@@ -826,10 +833,15 @@ |
63 |
Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ |
64 |
Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \ |
65 |
Elf ## B ## _Off offset; \ |
66 |
+ size_t matched = 0; \ |
67 |
+ /* Walk all the program headers to find the PT_DYNAMIC */ \ |
68 |
for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ |
69 |
- if (EGET(phdr[i].p_type) != PT_DYNAMIC || EGET(phdr[i].p_filesz) == 0) continue; \ |
70 |
+ if (EGET(phdr[i].p_type) != PT_DYNAMIC || EGET(phdr[i].p_filesz) == 0) \ |
71 |
+ continue; \ |
72 |
offset = EGET(phdr[i].p_offset); \ |
73 |
- if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \ |
74 |
+ if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) \ |
75 |
+ continue; \ |
76 |
+ /* Walk all the dynamic tags to find NEEDED entries */ \ |
77 |
dyn = DYN ## B (elf->vdata + offset); \ |
78 |
while (EGET(dyn->d_tag) != DT_NULL) { \ |
79 |
if (EGET(dyn->d_tag) == DT_NEEDED) { \ |
80 |
@@ -840,6 +852,7 @@ |
81 |
} \ |
82 |
needed = elf->data + offset; \ |
83 |
if (op == 0) { \ |
84 |
+ /* -n -> print all entries */ \ |
85 |
if (!be_wewy_wewy_quiet) { \ |
86 |
if (*found_needed) xchrcat(ret, ',', ret_len); \ |
87 |
if (use_ldcache) \ |
88 |
@@ -849,9 +862,17 @@ |
89 |
} \ |
90 |
*found_needed = 1; \ |
91 |
} else { \ |
92 |
- if (!strncmp(find_lib, needed, strlen( !g_match ? needed : find_lib))) { \ |
93 |
+ /* -N -> print matching entries */ \ |
94 |
+ size_t n; \ |
95 |
+ const char *find_lib_name; \ |
96 |
+ \ |
97 |
+ array_for_each(find_lib_arr, n, find_lib_name) \ |
98 |
+ if (!strcmp(find_lib_name, needed)) \ |
99 |
+ ++matched; \ |
100 |
+ \ |
101 |
+ if (matched == array_cnt(find_lib_arr)) { \ |
102 |
*found_lib = 1; \ |
103 |
- return (be_wewy_wewy_quiet ? NULL : needed); \ |
104 |
+ return (be_wewy_wewy_quiet ? NULL : find_lib); \ |
105 |
} \ |
106 |
} \ |
107 |
} \ |
108 |
@@ -1213,11 +1234,20 @@ |
109 |
|
110 |
#define FIND_SECTION(B) \ |
111 |
if (elf->elf_class == ELFCLASS ## B) { \ |
112 |
+ size_t matched, n; \ |
113 |
int invert; \ |
114 |
+ const char *section_name; \ |
115 |
Elf ## B ## _Shdr *section; \ |
116 |
- invert = (*find_section == '!' ? 1 : 0); \ |
117 |
- section = SHDR ## B (elf_findsecbyname(elf, find_section+invert)); \ |
118 |
- if ((section == NULL && invert) || (section != NULL && !invert)) \ |
119 |
+ \ |
120 |
+ matched = 0; \ |
121 |
+ array_for_each(find_section_arr, n, section_name) { \ |
122 |
+ invert = (*section_name == '!' ? 1 : 0); \ |
123 |
+ section = SHDR ## B (elf_findsecbyname(elf, section_name + invert)); \ |
124 |
+ if ((section == NULL && invert) || (section != NULL && !invert)) \ |
125 |
+ ++matched; \ |
126 |
+ } \ |
127 |
+ \ |
128 |
+ if (matched == array_cnt(find_section_arr)) \ |
129 |
*found_section = 1; \ |
130 |
} |
131 |
FIND_SECTION(32) |
132 |
@@ -1822,7 +1852,7 @@ |
133 |
"Find a specified symbol", |
134 |
"Find a specified section", |
135 |
"Find a specified library", |
136 |
- "Use strncmp to match libraries. (use with -N)", |
137 |
+ "Use regex matching rather than string compare (use with -s)", |
138 |
"Locate cause of TEXTREL", |
139 |
"Print only ELF files matching etype ET_DYN,ET_EXEC ...", |
140 |
"Print only ELF files matching numeric bits", |
141 |
@@ -1918,20 +1948,16 @@ |
142 |
break; |
143 |
} |
144 |
case 'k': |
145 |
- if (find_section) warn("You prob don't want to specify -k twice"); |
146 |
- find_section = optarg; |
147 |
+ xarraypush(find_section_arr, optarg, strlen(optarg)); |
148 |
break; |
149 |
case 's': { |
150 |
if (find_sym) warn("You prob don't want to specify -s twice"); |
151 |
find_sym = optarg; |
152 |
break; |
153 |
} |
154 |
- case 'N': { |
155 |
- if (find_lib) warn("You prob don't want to specify -N twice"); |
156 |
- find_lib = optarg; |
157 |
+ case 'N': |
158 |
+ xarraypush(find_lib_arr, optarg, strlen(optarg)); |
159 |
break; |
160 |
- } |
161 |
- |
162 |
case 'F': { |
163 |
if (out_format) warn("You prob don't want to specify -F twice"); |
164 |
out_format = optarg; |
165 |
@@ -2022,6 +2048,11 @@ |
166 |
if (which("objdump") != NULL) |
167 |
has_objdump = 1; |
168 |
} |
169 |
+ /* flatten arrays for display */ |
170 |
+ if (array_cnt(find_lib_arr)) |
171 |
+ find_lib = array_flatten_str(find_lib_arr); |
172 |
+ if (array_cnt(find_section_arr)) |
173 |
+ find_section = array_flatten_str(find_section_arr); |
174 |
/* let the format option override all other options */ |
175 |
if (out_format) { |
176 |
show_pax = show_phdr = show_textrel = show_rpath = \ |
177 |
@@ -2112,6 +2143,8 @@ |
178 |
/* clean up */ |
179 |
for (i = 0; ldpaths[i]; ++i) |
180 |
free(ldpaths[i]); |
181 |
+ free(find_lib); |
182 |
+ free(find_section); |
183 |
|
184 |
if (ldcache != 0) |
185 |
munmap(ldcache, ldcache_size); |
186 |
|
187 |
|
188 |
|
189 |
1.10 pax-utils/xfuncs.c |
190 |
|
191 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.c?rev=1.10&view=markup |
192 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.c?rev=1.10&content-type=text/plain |
193 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.c?r1=1.9&r2=1.10 |
194 |
|
195 |
Index: xfuncs.c |
196 |
=================================================================== |
197 |
RCS file: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v |
198 |
retrieving revision 1.9 |
199 |
retrieving revision 1.10 |
200 |
diff -u -r1.9 -r1.10 |
201 |
--- xfuncs.c 13 Feb 2010 23:27:12 -0000 1.9 |
202 |
+++ xfuncs.c 27 Sep 2011 18:37:22 -0000 1.10 |
203 |
@@ -1,7 +1,7 @@ |
204 |
/* |
205 |
* Copyright 2003-2007 Gentoo Foundation |
206 |
* Distributed under the terms of the GNU General Public License v2 |
207 |
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v 1.9 2010/02/13 23:27:12 vapier Exp $ |
208 |
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v 1.10 2011/09/27 18:37:22 vapier Exp $ |
209 |
* |
210 |
* Copyright 2003-2007 Ned Ludd - <solar@g.o> |
211 |
* Copyright 2004-2007 Mike Frysinger - <vapier@g.o> |
212 |
@@ -64,3 +64,43 @@ |
213 |
my_app[1] = '\0'; |
214 |
xstrcat(dst, my_app, curr_len); |
215 |
} |
216 |
+ |
217 |
+void *xmemdup(const void *src, size_t n) |
218 |
+{ |
219 |
+ void *ret = xmalloc(n); |
220 |
+ memcpy(ret, src, n); |
221 |
+ return ret; |
222 |
+} |
223 |
+ |
224 |
+void xarraypush(array_t *arr, const void *ele, size_t ele_len) |
225 |
+{ |
226 |
+ size_t n = arr->num++; |
227 |
+ arr->eles = xrealloc_array(arr->eles, arr->num, sizeof(ele)); |
228 |
+ arr->eles[n] = xmemdup(ele, ele_len); |
229 |
+} |
230 |
+ |
231 |
+void xarrayfree(array_t *arr) |
232 |
+{ |
233 |
+ array_t blank = array_init_decl; |
234 |
+ size_t n; |
235 |
+ |
236 |
+ for (n = 0; n < arr->num; ++n) |
237 |
+ free(arr->eles[n]); |
238 |
+ free(arr->eles); |
239 |
+ |
240 |
+ *arr = blank; |
241 |
+} |
242 |
+ |
243 |
+char *array_flatten_str(array_t *array) |
244 |
+{ |
245 |
+ size_t n, len = 0; |
246 |
+ char *str, *ret = NULL; |
247 |
+ |
248 |
+ array_for_each(array, n, str) { |
249 |
+ if (ret) |
250 |
+ xchrcat(&ret, ',', &len); |
251 |
+ xstrcat(&ret, str, &len); |
252 |
+ } |
253 |
+ |
254 |
+ return ret; |
255 |
+} |
256 |
|
257 |
|
258 |
|
259 |
1.5 pax-utils/xfuncs.h |
260 |
|
261 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.h?rev=1.5&view=markup |
262 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.h?rev=1.5&content-type=text/plain |
263 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.h?r1=1.4&r2=1.5 |
264 |
|
265 |
Index: xfuncs.h |
266 |
=================================================================== |
267 |
RCS file: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v |
268 |
retrieving revision 1.4 |
269 |
retrieving revision 1.5 |
270 |
diff -u -r1.4 -r1.5 |
271 |
--- xfuncs.h 3 Dec 2009 04:15:54 -0000 1.4 |
272 |
+++ xfuncs.h 27 Sep 2011 18:37:22 -0000 1.5 |
273 |
@@ -1,7 +1,7 @@ |
274 |
/* |
275 |
* Copyright 2003-2007 Gentoo Foundation |
276 |
* Distributed under the terms of the GNU General Public License v2 |
277 |
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v 1.4 2009/12/03 04:15:54 vapier Exp $ |
278 |
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v 1.5 2011/09/27 18:37:22 vapier Exp $ |
279 |
* |
280 |
* Copyright 2003-2007 Ned Ludd - <solar@g.o> |
281 |
* Copyright 2004-2007 Mike Frysinger - <vapier@g.o> |
282 |
@@ -18,4 +18,19 @@ |
283 |
#define xstrcat(dst,src,curr_len) xstrncat(dst,src,curr_len,0) |
284 |
void xchrcat(char **dst, const char append, size_t *curr_len); |
285 |
|
286 |
+void *xmemdup(const void *src, size_t n); |
287 |
+ |
288 |
+typedef struct { |
289 |
+ void **eles; |
290 |
+ size_t num; |
291 |
+} array_t; |
292 |
+void xarraypush(array_t *array, const void *ele, size_t ele_len); |
293 |
+void xarrayfree(array_t *array); |
294 |
+#define xrealloc_array(ptr, size, ele_size) xrealloc(ptr, (size) * (ele_size)) |
295 |
+#define array_for_each(arr, n, ele) \ |
296 |
+ for (n = 0, ele = arr->eles[n]; n < arr->num; ++n, ele = arr->eles[n]) |
297 |
+#define array_init_decl { .eles = NULL, .num = 0, } |
298 |
+#define array_cnt(arr) (arr)->num |
299 |
+char *array_flatten_str(array_t *array); |
300 |
+ |
301 |
#endif |