diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-05-01 22:59:59 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-05-01 22:59:59 +0200 |
commit | 1cb89d0393bac19f3b9e409ba46d1fd4136ff332 (patch) | |
tree | 2cebe25379cb82268a7b1426747fbcb4faa0ee59 | |
parent | ad9dc67eb7331616c4bbe6229576495a25741928 (diff) | |
download | libextractor-1cb89d0393bac19f3b9e409ba46d1fd4136ff332.tar.gz libextractor-1cb89d0393bac19f3b9e409ba46d1fd4136ff332.zip |
revive ELF plugin
-rw-r--r-- | .gitignore | 258 | ||||
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | src/plugins/Makefile.am | 15 | ||||
-rw-r--r-- | src/plugins/elf_extractor.c (renamed from src/plugins/old/elf_extractor.c) | 460 | ||||
-rw-r--r-- | src/plugins/pack.c (renamed from src/plugins/old/pack.c) | 0 | ||||
-rw-r--r-- | src/plugins/pack.h (renamed from src/plugins/old/pack.h) | 0 | ||||
-rw-r--r-- | src/plugins/test_elf.c | 83 | ||||
-rwxr-xr-x | src/plugins/testdata/chello-elf | bin | 0 -> 2984 bytes |
8 files changed, 411 insertions, 408 deletions
@@ -1,8 +1,4 @@ | |||
1 | On branch master | 1 | **/*~ |
2 | Your branch is up-to-date with 'origin/master'. | ||
3 | Untracked files: | ||
4 | (use "git add <file>..." to include in what will be committed) | ||
5 | |||
6 | INSTALL | 2 | INSTALL |
7 | Makefile | 3 | Makefile |
8 | Makefile.in | 4 | Makefile.in |
@@ -72,290 +68,60 @@ src/main/extract.o | |||
72 | src/main/getopt.o | 68 | src/main/getopt.o |
73 | src/main/getopt1.o | 69 | src/main/getopt1.o |
74 | src/main/libextractor.la | 70 | src/main/libextractor.la |
75 | src/main/libextractor_la-extractor.lo | 71 | src/main/*.o |
76 | src/main/libextractor_la-extractor.o | 72 | src/main/*.lo |
77 | src/main/libextractor_la-extractor_common.lo | 73 | src/main/*.la |
78 | src/main/libextractor_la-extractor_common.o | 74 | src/main/*.trs |
79 | src/main/libextractor_la-extractor_datasource.lo | 75 | src/main/*.log |
80 | src/main/libextractor_la-extractor_datasource.o | ||
81 | src/main/libextractor_la-extractor_ipc.lo | ||
82 | src/main/libextractor_la-extractor_ipc.o | ||
83 | src/main/libextractor_la-extractor_ipc_gnu.lo | ||
84 | src/main/libextractor_la-extractor_ipc_gnu.o | ||
85 | src/main/libextractor_la-extractor_logging.lo | ||
86 | src/main/libextractor_la-extractor_logging.o | ||
87 | src/main/libextractor_la-extractor_metatypes.lo | ||
88 | src/main/libextractor_la-extractor_metatypes.o | ||
89 | src/main/libextractor_la-extractor_plugin_main.lo | ||
90 | src/main/libextractor_la-extractor_plugin_main.o | ||
91 | src/main/libextractor_la-extractor_plugins.lo | ||
92 | src/main/libextractor_la-extractor_plugins.o | ||
93 | src/main/libextractor_la-extractor_plugpath.lo | ||
94 | src/main/libextractor_la-extractor_plugpath.o | ||
95 | src/main/libextractor_la-extractor_print.lo | ||
96 | src/main/libextractor_la-extractor_print.o | ||
97 | src/main/libextractor_test.la | ||
98 | src/main/libextractor_test2.la | ||
99 | src/main/test-suite.log | ||
100 | src/main/test2_extractor.lo | ||
101 | src/main/test2_extractor.o | ||
102 | src/main/test_bzip2 | 76 | src/main/test_bzip2 |
103 | src/main/test_bzip2.log | ||
104 | src/main/test_bzip2.o | ||
105 | src/main/test_bzip2.trs | ||
106 | src/main/test_extractor.lo | ||
107 | src/main/test_extractor.o | ||
108 | src/main/test_file | 77 | src/main/test_file |
109 | src/main/test_file.log | ||
110 | src/main/test_file.o | ||
111 | src/main/test_file.trs | ||
112 | src/main/test_gzip | 78 | src/main/test_gzip |
113 | src/main/test_gzip.log | ||
114 | src/main/test_gzip.o | ||
115 | src/main/test_gzip.trs | ||
116 | src/main/test_ipc | 79 | src/main/test_ipc |
117 | src/main/test_ipc.log | ||
118 | src/main/test_ipc.o | ||
119 | src/main/test_ipc.trs | ||
120 | src/main/test_plugin_load_multi | 80 | src/main/test_plugin_load_multi |
121 | src/main/test_plugin_load_multi.log | ||
122 | src/main/test_plugin_load_multi.o | ||
123 | src/main/test_plugin_load_multi.trs | ||
124 | src/main/test_plugin_loading | 81 | src/main/test_plugin_loading |
125 | src/main/test_plugin_loading.log | ||
126 | src/main/test_plugin_loading.o | ||
127 | src/main/test_plugin_loading.trs | ||
128 | src/main/test_trivial | 82 | src/main/test_trivial |
129 | src/main/test_trivial.log | ||
130 | src/main/test_trivial.o | ||
131 | src/main/test_trivial.trs | ||
132 | src/plugins/.deps/ | 83 | src/plugins/.deps/ |
133 | src/plugins/.libs/ | 84 | src/plugins/.libs/ |
134 | src/plugins/Makefile | 85 | src/plugins/Makefile |
135 | src/plugins/Makefile.in | 86 | src/plugins/Makefile.in |
136 | src/plugins/archive_extractor.lo | 87 | src/plugins/*.o |
137 | src/plugins/archive_extractor.o | 88 | src/plugins/*.lo |
138 | src/plugins/deb_extractor.lo | 89 | src/plugins/*.la |
139 | src/plugins/deb_extractor.o | 90 | src/plugins/*.log |
140 | src/plugins/dvi_extractor.lo | 91 | src/plugins/*.trs |
141 | src/plugins/dvi_extractor.o | ||
142 | src/plugins/exiv2_extractor.lo | ||
143 | src/plugins/exiv2_extractor.o | ||
144 | src/plugins/flac_extractor.lo | ||
145 | src/plugins/flac_extractor.o | ||
146 | src/plugins/gif_extractor.lo | ||
147 | src/plugins/gif_extractor.o | ||
148 | src/plugins/html_extractor.lo | ||
149 | src/plugins/html_extractor.o | ||
150 | src/plugins/it_extractor.lo | ||
151 | src/plugins/it_extractor.o | ||
152 | src/plugins/jpeg_extractor.lo | ||
153 | src/plugins/jpeg_extractor.o | ||
154 | src/plugins/thumbnailffmpeg_extractor.lo | ||
155 | src/plugins/thumbnailffmpeg_extractor.o | ||
156 | src/plugins/libextractor_archive.la | ||
157 | src/plugins/libextractor_deb.la | ||
158 | src/plugins/libextractor_dvi.la | ||
159 | src/plugins/libextractor_exiv2.la | ||
160 | src/plugins/libextractor_flac.la | ||
161 | src/plugins/libextractor_gif.la | ||
162 | src/plugins/libextractor_gstreamer.la | ||
163 | src/plugins/libextractor_thumbnailffmpeg.la | ||
164 | src/plugins/libextractor_gstreamer_la-gstreamer_extractor.lo | ||
165 | src/plugins/libextractor_gstreamer_la-gstreamer_extractor.o | ||
166 | src/plugins/libextractor_html.la | ||
167 | src/plugins/libextractor_it.la | ||
168 | src/plugins/libextractor_jpeg.la | ||
169 | src/plugins/libextractor_man.la | ||
170 | src/plugins/libextractor_midi.la | ||
171 | src/plugins/libextractor_midi_la-midi_extractor.lo | ||
172 | src/plugins/libextractor_midi_la-midi_extractor.o | ||
173 | src/plugins/libextractor_mime.la | ||
174 | src/plugins/libextractor_mpeg.la | ||
175 | src/plugins/libextractor_nsf.la | ||
176 | src/plugins/libextractor_nsfe.la | ||
177 | src/plugins/libextractor_odf.la | ||
178 | src/plugins/libextractor_ogg.la | ||
179 | src/plugins/libextractor_ole2.la | ||
180 | src/plugins/libextractor_ole2_la-ole2_extractor.lo | ||
181 | src/plugins/libextractor_ole2_la-ole2_extractor.o | ||
182 | src/plugins/libextractor_pdf.la | ||
183 | src/plugins/libextractor_png.la | ||
184 | src/plugins/libextractor_ps.la | ||
185 | src/plugins/libextractor_riff.la | ||
186 | src/plugins/libextractor_rpm.la | ||
187 | src/plugins/libextractor_s3m.la | ||
188 | src/plugins/libextractor_sid.la | ||
189 | src/plugins/libextractor_thumbnailgtk.la | ||
190 | src/plugins/libextractor_thumbnailgtk_la-thumbnailgtk_extractor.lo | ||
191 | src/plugins/libextractor_thumbnailgtk_la-thumbnailgtk_extractor.o | ||
192 | src/plugins/libextractor_tiff.la | ||
193 | src/plugins/libextractor_wav.la | ||
194 | src/plugins/libextractor_xm.la | ||
195 | src/plugins/libextractor_zip.la | ||
196 | src/plugins/libtest.la | ||
197 | src/plugins/man_extractor.lo | ||
198 | src/plugins/man_extractor.o | ||
199 | src/plugins/mime_extractor.lo | ||
200 | src/plugins/mime_extractor.o | ||
201 | src/plugins/mpeg_extractor.lo | ||
202 | src/plugins/mpeg_extractor.o | ||
203 | src/plugins/nsf_extractor.lo | ||
204 | src/plugins/nsf_extractor.o | ||
205 | src/plugins/nsfe_extractor.lo | ||
206 | src/plugins/nsfe_extractor.o | ||
207 | src/plugins/odf_extractor.lo | ||
208 | src/plugins/odf_extractor.o | ||
209 | src/plugins/ogg_extractor.lo | ||
210 | src/plugins/ogg_extractor.o | ||
211 | src/plugins/pdf_extractor.lo | ||
212 | src/plugins/pdf_extractor.o | ||
213 | src/plugins/png_extractor.lo | ||
214 | src/plugins/png_extractor.o | ||
215 | src/plugins/ps_extractor.lo | ||
216 | src/plugins/ps_extractor.o | ||
217 | src/plugins/riff_extractor.lo | ||
218 | src/plugins/riff_extractor.o | ||
219 | src/plugins/rpm_extractor.lo | ||
220 | src/plugins/rpm_extractor.o | ||
221 | src/plugins/s3m_extractor.lo | ||
222 | src/plugins/s3m_extractor.o | ||
223 | src/plugins/sid_extractor.lo | ||
224 | src/plugins/sid_extractor.o | ||
225 | src/plugins/test-suite.log | 92 | src/plugins/test-suite.log |
226 | src/plugins/test_archive | 93 | src/plugins/test_archive |
227 | src/plugins/test_archive.log | ||
228 | src/plugins/test_archive.o | ||
229 | src/plugins/test_archive.trs | ||
230 | src/plugins/test_deb | 94 | src/plugins/test_deb |
231 | src/plugins/test_deb.log | ||
232 | src/plugins/test_deb.o | ||
233 | src/plugins/test_deb.trs | ||
234 | src/plugins/test_dvi | 95 | src/plugins/test_dvi |
235 | src/plugins/test_dvi.log | 96 | src/plugins/test_elf |
236 | src/plugins/test_dvi.o | ||
237 | src/plugins/test_dvi.trs | ||
238 | src/plugins/test_exiv2 | 97 | src/plugins/test_exiv2 |
239 | src/plugins/test_exiv2.log | ||
240 | src/plugins/test_exiv2.o | ||
241 | src/plugins/test_exiv2.trs | ||
242 | src/plugins/test_flac | 98 | src/plugins/test_flac |
243 | src/plugins/test_flac.log | ||
244 | src/plugins/test_flac.o | ||
245 | src/plugins/test_flac.trs | ||
246 | src/plugins/test_gif | 99 | src/plugins/test_gif |
247 | src/plugins/test_gif.log | ||
248 | src/plugins/test_gif.o | ||
249 | src/plugins/test_gif.trs | ||
250 | src/plugins/test_gstreamer | 100 | src/plugins/test_gstreamer |
251 | src/plugins/test_gstreamer-test_gstreamer.o | ||
252 | src/plugins/test_gstreamer.log | ||
253 | src/plugins/test_gstreamer.trs | ||
254 | src/plugins/test_html | 101 | src/plugins/test_html |
255 | src/plugins/test_html.log | ||
256 | src/plugins/test_html.o | ||
257 | src/plugins/test_html.trs | ||
258 | src/plugins/test_it | 102 | src/plugins/test_it |
259 | src/plugins/test_it.log | ||
260 | src/plugins/test_it.o | ||
261 | src/plugins/test_it.trs | ||
262 | src/plugins/test_jpeg | 103 | src/plugins/test_jpeg |
263 | src/plugins/test_jpeg.log | ||
264 | src/plugins/test_jpeg.o | ||
265 | src/plugins/test_jpeg.trs | ||
266 | src/plugins/test_lib.lo | ||
267 | src/plugins/test_lib.o | ||
268 | src/plugins/test_man | 104 | src/plugins/test_man |
269 | src/plugins/test_man.log | ||
270 | src/plugins/test_man.o | ||
271 | src/plugins/test_man.trs | ||
272 | src/plugins/test_midi | 105 | src/plugins/test_midi |
273 | src/plugins/test_midi.log | ||
274 | src/plugins/test_midi.o | ||
275 | src/plugins/test_midi.trs | ||
276 | src/plugins/test_mime | 106 | src/plugins/test_mime |
277 | src/plugins/test_mime.log | ||
278 | src/plugins/test_mime.o | ||
279 | src/plugins/test_mime.trs | ||
280 | src/plugins/test_mpeg | 107 | src/plugins/test_mpeg |
281 | src/plugins/test_mpeg.log | ||
282 | src/plugins/test_mpeg.o | ||
283 | src/plugins/test_mpeg.trs | ||
284 | src/plugins/test_nsf | 108 | src/plugins/test_nsf |
285 | src/plugins/test_nsf.log | ||
286 | src/plugins/test_nsf.o | ||
287 | src/plugins/test_nsf.trs | ||
288 | src/plugins/test_nsfe | 109 | src/plugins/test_nsfe |
289 | src/plugins/test_nsfe.log | ||
290 | src/plugins/test_nsfe.o | ||
291 | src/plugins/test_nsfe.trs | ||
292 | src/plugins/test_odf | 110 | src/plugins/test_odf |
293 | src/plugins/test_odf.log | ||
294 | src/plugins/test_odf.o | ||
295 | src/plugins/test_odf.trs | ||
296 | src/plugins/test_ogg | 111 | src/plugins/test_ogg |
297 | src/plugins/test_ogg.log | ||
298 | src/plugins/test_ogg.o | ||
299 | src/plugins/test_ogg.trs | ||
300 | src/plugins/test_ole2 | 112 | src/plugins/test_ole2 |
301 | src/plugins/test_ole2.log | ||
302 | src/plugins/test_ole2.o | ||
303 | src/plugins/test_ole2.trs | ||
304 | src/plugins/test_png | 113 | src/plugins/test_png |
305 | src/plugins/test_png.log | ||
306 | src/plugins/test_png.o | ||
307 | src/plugins/test_png.trs | ||
308 | src/plugins/test_ps | 114 | src/plugins/test_ps |
309 | src/plugins/test_ps.log | ||
310 | src/plugins/test_ps.o | ||
311 | src/plugins/test_ps.trs | ||
312 | src/plugins/test_riff | 115 | src/plugins/test_riff |
313 | src/plugins/test_riff.log | ||
314 | src/plugins/test_riff.o | ||
315 | src/plugins/test_riff.trs | ||
316 | src/plugins/test_rpm | 116 | src/plugins/test_rpm |
317 | src/plugins/test_rpm.log | ||
318 | src/plugins/test_rpm.o | ||
319 | src/plugins/test_rpm.trs | ||
320 | src/plugins/test_s3m | 117 | src/plugins/test_s3m |
321 | src/plugins/test_s3m.log | ||
322 | src/plugins/test_s3m.o | ||
323 | src/plugins/test_s3m.trs | ||
324 | src/plugins/test_sid | 118 | src/plugins/test_sid |
325 | src/plugins/test_sid.log | ||
326 | src/plugins/test_sid.o | ||
327 | src/plugins/test_sid.trs | ||
328 | src/plugins/test_thumbnailgtk | 119 | src/plugins/test_thumbnailgtk |
329 | src/plugins/test_thumbnailgtk.log | ||
330 | src/plugins/test_thumbnailgtk.o | ||
331 | src/plugins/test_thumbnailgtk.trs | ||
332 | src/plugins/test_tiff | 120 | src/plugins/test_tiff |
333 | src/plugins/test_tiff.log | ||
334 | src/plugins/test_tiff.o | ||
335 | src/plugins/test_tiff.trs | ||
336 | src/plugins/test_wav | 121 | src/plugins/test_wav |
337 | src/plugins/test_wav.log | ||
338 | src/plugins/test_wav.o | ||
339 | src/plugins/test_wav.trs | ||
340 | src/plugins/test_xm | 122 | src/plugins/test_xm |
341 | src/plugins/test_xm.log | ||
342 | src/plugins/test_xm.o | ||
343 | src/plugins/test_xm.trs | ||
344 | src/plugins/test_zip | 123 | src/plugins/test_zip |
345 | src/plugins/test_zip.log | ||
346 | src/plugins/test_zip.o | ||
347 | src/plugins/test_zip.trs | ||
348 | src/plugins/tiff_extractor.lo | ||
349 | src/plugins/tiff_extractor.o | ||
350 | src/plugins/wav_extractor.lo | ||
351 | src/plugins/wav_extractor.o | ||
352 | src/plugins/xm_extractor.lo | ||
353 | src/plugins/xm_extractor.o | ||
354 | src/plugins/zip_extractor.lo | ||
355 | src/plugins/zip_extractor.o | ||
356 | stamp-h1 | 124 | stamp-h1 |
357 | test-driver | 125 | test-driver |
358 | |||
359 | nothing added to commit but untracked files present (use "git add" to track) | ||
360 | src/plugins/test_thumbnailffmpeg | 126 | src/plugins/test_thumbnailffmpeg |
361 | build-aux/ | 127 | build-aux/ |
@@ -1,3 +1,6 @@ | |||
1 | Sat 01 May 2021 10:57:55 PM CEST | ||
2 | Revive ELF plugin (fixes #2516). -CG | ||
3 | |||
1 | Tue 20 Apr 2021 06:33:46 PM CEST | 4 | Tue 20 Apr 2021 06:33:46 PM CEST |
2 | Removing plugins depending on buggy, unstable libffmpeg library. -CG | 5 | Removing plugins depending on buggy, unstable libffmpeg library. -CG |
3 | 6 | ||
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index a0e0ae3..8cbe21a 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am | |||
@@ -165,6 +165,7 @@ endif | |||
165 | 165 | ||
166 | plugin_LTLIBRARIES = \ | 166 | plugin_LTLIBRARIES = \ |
167 | libextractor_dvi.la \ | 167 | libextractor_dvi.la \ |
168 | libextractor_elf.la \ | ||
168 | libextractor_it.la \ | 169 | libextractor_it.la \ |
169 | libextractor_man.la \ | 170 | libextractor_man.la \ |
170 | libextractor_nsf.la \ | 171 | libextractor_nsf.la \ |
@@ -200,6 +201,7 @@ endif | |||
200 | 201 | ||
201 | check_PROGRAMS = \ | 202 | check_PROGRAMS = \ |
202 | test_dvi \ | 203 | test_dvi \ |
204 | test_elf \ | ||
203 | test_it \ | 205 | test_it \ |
204 | test_man \ | 206 | test_man \ |
205 | test_nsf \ | 207 | test_nsf \ |
@@ -283,6 +285,19 @@ test_dvi_SOURCES = \ | |||
283 | test_dvi_LDADD = \ | 285 | test_dvi_LDADD = \ |
284 | $(top_builddir)/src/plugins/libtest.la | 286 | $(top_builddir)/src/plugins/libtest.la |
285 | 287 | ||
288 | libextractor_elf_la_SOURCES = \ | ||
289 | elf_extractor.c \ | ||
290 | pack.c pack.h | ||
291 | libextractor_elf_la_LDFLAGS = \ | ||
292 | $(PLUGINFLAGS) | ||
293 | libextractor_elf_la_LIBADD = \ | ||
294 | $(XLIB) $(SOCKET_LIBS) | ||
295 | |||
296 | test_elf_SOURCES = \ | ||
297 | test_elf.c | ||
298 | test_elf_LDADD = \ | ||
299 | $(top_builddir)/src/plugins/libtest.la | ||
300 | |||
286 | 301 | ||
287 | libextractor_exiv2_la_SOURCES = \ | 302 | libextractor_exiv2_la_SOURCES = \ |
288 | exiv2_extractor.cc | 303 | exiv2_extractor.cc |
diff --git a/src/plugins/old/elf_extractor.c b/src/plugins/elf_extractor.c index 9c35e7c..379f615 100644 --- a/src/plugins/old/elf_extractor.c +++ b/src/plugins/elf_extractor.c | |||
@@ -1,10 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libextractor. | 2 | This file is part of libextractor. |
3 | Copyright (C) 2004, 2009 Vidyut Samanta and Christian Grothoff | 3 | Copyright (C) 2012 Vidyut Samanta and Christian Grothoff |
4 | 4 | ||
5 | libextractor is free software; you can redistribute it and/or modify | 5 | libextractor is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 2, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | libextractor is distributed in the hope that it will be useful, but | 10 | libextractor is distributed in the hope that it will be useful, but |
@@ -17,12 +17,17 @@ | |||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. |
19 | */ | 19 | */ |
20 | 20 | /** | |
21 | * @file plugins/gif_extractor.c | ||
22 | * @brief plugin to support GIF files | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
21 | #include "platform.h" | 25 | #include "platform.h" |
22 | #include "extractor.h" | 26 | #include "extractor.h" |
23 | #include "pack.h" | 27 | #include "pack.h" |
24 | #include <stdint.h> | 28 | #include <stdint.h> |
25 | 29 | ||
30 | |||
26 | typedef uint32_t Elf32_Addr; | 31 | typedef uint32_t Elf32_Addr; |
27 | typedef uint16_t Elf32_Half; | 32 | typedef uint16_t Elf32_Half; |
28 | typedef uint32_t Elf32_Off; | 33 | typedef uint32_t Elf32_Off; |
@@ -334,15 +339,34 @@ getByteorder (char ei_data) | |||
334 | * @return 0 on success, -1 on error | 339 | * @return 0 on success, -1 on error |
335 | */ | 340 | */ |
336 | static int | 341 | static int |
337 | getSectionHdr (const char *data, | 342 | getSectionHdr (struct EXTRACTOR_ExtractContext *ec, |
338 | size_t size, | 343 | unsigned int bo, |
339 | Elf32_Ehdr *ehdr, Elf32_Half idx, Elf32_Shdr *ret) | 344 | const Elf32_Ehdr *ehdr, |
345 | Elf32_Half idx, | ||
346 | Elf32_Shdr *ret) | ||
340 | { | 347 | { |
348 | ssize_t size; | ||
349 | uint64_t max; | ||
350 | int64_t off; | ||
351 | void *data; | ||
352 | |||
341 | if (ehdr->e_shnum <= idx) | 353 | if (ehdr->e_shnum <= idx) |
342 | return -1; | 354 | return -1; |
343 | 355 | max = ec->get_size (ec->cls); | |
344 | EXTRACTOR_common_cat_unpack (&data[ehdr->e_shoff + ehdr->e_shentsize * idx], | 356 | if (ehdr->e_shoff + ehdr->e_shentsize * idx + sizeof (*ret) > max) |
345 | ELF_SECTION_SPECS[getByteorder (data[EI_CLASS])], | 357 | return -1; |
358 | off = ec->seek (ec->cls, | ||
359 | ehdr->e_shoff + ehdr->e_shentsize * idx, | ||
360 | SEEK_SET); | ||
361 | if (-1 == off) | ||
362 | return -1; | ||
363 | size = ec->read (ec->cls, | ||
364 | &data, | ||
365 | sizeof (*ret)); | ||
366 | if (size < sizeof (*ret)) | ||
367 | return -1; | ||
368 | EXTRACTOR_common_cat_unpack (data, | ||
369 | ELF_SECTION_SPECS[bo], | ||
346 | ELF_SECTION_FIELDS (ret)); | 370 | ELF_SECTION_FIELDS (ret)); |
347 | return 0; | 371 | return 0; |
348 | } | 372 | } |
@@ -353,15 +377,37 @@ getSectionHdr (const char *data, | |||
353 | * @return 0 on success, -1 on error | 377 | * @return 0 on success, -1 on error |
354 | */ | 378 | */ |
355 | static int | 379 | static int |
356 | getDynTag (const char *data, | 380 | getDynTag (struct EXTRACTOR_ExtractContext *ec, |
357 | size_t size, | 381 | unsigned int bo, |
358 | Elf32_Ehdr *ehdr, | 382 | const Elf32_Ehdr *ehdr, |
359 | Elf32_Off off, Elf32_Word osize, unsigned int idx, Elf32_Dyn *ret) | 383 | Elf32_Off off, |
384 | Elf32_Word osize, | ||
385 | unsigned int idx, | ||
386 | Elf32_Dyn *ret) | ||
360 | { | 387 | { |
361 | if ((off + osize > size) || ((idx + 1) * ELF_DYN_SIZE > osize)) | 388 | ssize_t size; |
389 | uint64_t max; | ||
390 | int64_t soff; | ||
391 | void *data; | ||
392 | |||
393 | max = ec->get_size (ec->cls); | ||
394 | if ( (off + osize > max) || | ||
395 | ((idx + 1) * ELF_DYN_SIZE > osize) ) | ||
362 | return -1; | 396 | return -1; |
363 | EXTRACTOR_common_cat_unpack (&data[off + idx * ELF_DYN_SIZE], | 397 | if (off + idx * ELF_DYN_SIZE + sizeof (*ret) > max) |
364 | ELF_DYN_SPECS[getByteorder (data[EI_CLASS])], | 398 | return -1; |
399 | soff = ec->seek (ec->cls, | ||
400 | off + idx * ELF_DYN_SIZE, | ||
401 | SEEK_SET); | ||
402 | if (-1 == soff) | ||
403 | return -1; | ||
404 | size = ec->read (ec->cls, | ||
405 | &data, | ||
406 | sizeof (*ret)); | ||
407 | if (size < sizeof (*ret)) | ||
408 | return -1; | ||
409 | EXTRACTOR_common_cat_unpack (data, | ||
410 | ELF_DYN_SPECS[bo], | ||
365 | ELF_DYN_FIELDS (ret)); | 411 | ELF_DYN_FIELDS (ret)); |
366 | return 0; | 412 | return 0; |
367 | } | 413 | } |
@@ -372,295 +418,385 @@ getDynTag (const char *data, | |||
372 | * @return 0 on success, -1 on error | 418 | * @return 0 on success, -1 on error |
373 | */ | 419 | */ |
374 | static int | 420 | static int |
375 | getProgramHdr (const char *data, | 421 | getProgramHdr (struct EXTRACTOR_ExtractContext *ec, |
376 | size_t size, | 422 | unsigned int bo, |
377 | Elf32_Ehdr *ehdr, Elf32_Half idx, Elf32_Phdr *ret) | 423 | const Elf32_Ehdr *ehdr, |
424 | Elf32_Half idx, | ||
425 | Elf32_Phdr *ret) | ||
378 | { | 426 | { |
427 | void *data; | ||
428 | ssize_t size; | ||
429 | int64_t off; | ||
430 | |||
379 | if (ehdr->e_phnum <= idx) | 431 | if (ehdr->e_phnum <= idx) |
380 | return -1; | 432 | return -1; |
381 | 433 | off = ec->seek (ec->cls, | |
382 | EXTRACTOR_common_cat_unpack (&data[ehdr->e_phoff + ehdr->e_phensize * idx], | 434 | ehdr->e_phoff + ehdr->e_phensize * idx, |
383 | ELF_PHDR_SPECS[getByteorder (data[EI_CLASS])], | 435 | SEEK_SET); |
384 | ELF_PHDR_FIELDS (ret)); | 436 | if (-1 == off) |
385 | return 0; | ||
386 | } | ||
387 | |||
388 | |||
389 | /** | ||
390 | * Parse ELF header. | ||
391 | * @return 0 on success for 32 bit, 1 on success for 64 bit, -1 on error | ||
392 | */ | ||
393 | static int | ||
394 | getELFHdr (const char *data, | ||
395 | size_t size, | ||
396 | Elf32_Ehdr *ehdr, | ||
397 | Elf64_Ehdr *ehdr64) | ||
398 | { | ||
399 | /* catlib */ | ||
400 | if (size < EI_NIDENT) | ||
401 | return -1; | 437 | return -1; |
402 | if (0 != strncmp (data, elfMagic, sizeof (elfMagic))) | 438 | size = ec->read (ec->cls, |
403 | return -1; /* not an elf */ | 439 | &data, |
404 | 440 | sizeof (*ret)); | |
405 | switch (data[EI_CLASS]) | 441 | if (size < sizeof (*ret)) |
406 | { | ||
407 | case ELFCLASS32: | ||
408 | if (size < sizeof (Elf32_Ehdr) + EI_NIDENT) | ||
409 | return -1; | ||
410 | EXTRACTOR_common_cat_unpack (&data[EI_NIDENT], | ||
411 | ELF_HEADER_SPECS[getByteorder (data[EI_DATA])], | ||
412 | ELF_HEADER_FIELDS (ehdr)); | ||
413 | if (ehdr->e_shoff + ehdr->e_shentsize * ehdr->e_shnum > size) | ||
414 | return -1; /* invalid offsets... */ | ||
415 | if (ehdr->e_shentsize < ELF_SECTION_SIZE) | ||
416 | return -1; /* huh? */ | ||
417 | if (ehdr->e_phoff + ehdr->e_phensize * ehdr->e_phnum > size) | ||
418 | return -1; | ||
419 | return 0; | ||
420 | case ELFCLASS64: | ||
421 | if (size < sizeof (Elf64_Ehdr) + EI_NIDENT) | ||
422 | return -1; | ||
423 | EXTRACTOR_common_cat_unpack (&data[EI_NIDENT], | ||
424 | ELF64_HEADER_SPECS[getByteorder ( | ||
425 | data[EI_DATA])], | ||
426 | ELF64_HEADER_FIELDS (ehdr64)); | ||
427 | if (ehdr64->e_shoff + ((uint32_t) ehdr64->e_shentsize * ehdr64->e_shnum) > | ||
428 | size) | ||
429 | return -1; /* invalid offsets... */ | ||
430 | if (ehdr64->e_phoff + ((uint32_t) ehdr64->e_phensize * ehdr64->e_phnum) > | ||
431 | size) | ||
432 | return -1; | ||
433 | return 1; | ||
434 | default: | ||
435 | return -1; | 442 | return -1; |
436 | } | 443 | EXTRACTOR_common_cat_unpack (data, |
444 | ELF_PHDR_SPECS[bo], | ||
445 | ELF_PHDR_FIELDS (ret)); | ||
446 | return 0; | ||
437 | } | 447 | } |
438 | 448 | ||
439 | 449 | ||
440 | /** | 450 | /** |
441 | * @return the string (offset into data, do NOT free), NULL on error | 451 | * @return the string (offset into data, do NOT free), NULL on error |
442 | */ | 452 | */ |
443 | static const char * | 453 | static char * |
444 | readStringTable (const char *data, | 454 | readStringTable (struct EXTRACTOR_ExtractContext *ec, |
445 | size_t size, | 455 | unsigned int bo, |
446 | Elf32_Ehdr *ehdr, | 456 | const Elf32_Ehdr *ehdr, |
447 | Elf32_Half strTableOffset, Elf32_Word sh_name) | 457 | Elf32_Half strTableOffset, |
458 | Elf32_Word sh_name) | ||
448 | { | 459 | { |
449 | Elf32_Shdr shrd; | 460 | Elf32_Shdr shrd; |
450 | if (-1 == getSectionHdr (data, size, ehdr, strTableOffset, &shrd)) | 461 | char *data; |
462 | ssize_t size; | ||
463 | int64_t off; | ||
464 | |||
465 | if (-1 == getSectionHdr (ec, | ||
466 | bo, | ||
467 | ehdr, | ||
468 | strTableOffset, | ||
469 | &shrd)) | ||
451 | return NULL; | 470 | return NULL; |
452 | if ((shrd.sh_type != SHT_STRTAB) || | 471 | if ((shrd.sh_type != SHT_STRTAB) || |
453 | (shrd.sh_offset + shrd.sh_size > size) || | 472 | (shrd.sh_size <= sh_name) ) |
454 | (shrd.sh_size <= sh_name) || | 473 | return NULL; |
455 | (data[shrd.sh_offset + shrd.sh_size - 1] != '\0')) | 474 | off = ec->seek (ec->cls, |
475 | shrd.sh_offset, | ||
476 | SEEK_SET); | ||
477 | if (-1 == off) | ||
456 | return NULL; | 478 | return NULL; |
457 | return &data[shrd.sh_offset + sh_name]; | 479 | size = ec->read (ec->cls, |
480 | (void **) &data, | ||
481 | shrd.sh_size); | ||
482 | if (size < shrd.sh_size) | ||
483 | return NULL; | ||
484 | if (data[shrd.sh_size - 1] != '\0') | ||
485 | return NULL; | ||
486 | return strdup (&data[sh_name]); | ||
458 | } | 487 | } |
459 | 488 | ||
460 | 489 | ||
461 | #define ADD(s, type) do { if (0!=proc (proc_cls, "elf", type, \ | 490 | #define ADD(s, type) do { \ |
462 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", \ | 491 | if (0!=ec->proc (ec->cls, "elf", type, \ |
463 | s, strlen (s) + 1)) return 1; \ | 492 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", \ |
493 | s, strlen (s) + 1)) \ | ||
494 | { \ | ||
495 | return; \ | ||
496 | } \ | ||
464 | } while (0) | 497 | } while (0) |
465 | 498 | ||
466 | /* application/x-executable, ELF */ | 499 | |
467 | int | 500 | /** |
468 | EXTRACTOR_elf_extract (const char *data, | 501 | * Main entry method for the 'application/x-executable' extraction plugin. |
469 | size_t size, | 502 | * |
470 | EXTRACTOR_MetaDataProcessor proc, | 503 | * @param ec extraction context provided to the plugin |
471 | void *proc_cls, | 504 | */ |
472 | const char *options) | 505 | void |
506 | EXTRACTOR_elf_extract_method (struct EXTRACTOR_ExtractContext *ec) | ||
473 | { | 507 | { |
474 | Elf32_Ehdr ehdr; | 508 | Elf32_Ehdr ehdr; |
475 | Elf32_Half idx; | ||
476 | Elf64_Ehdr ehdr64; | 509 | Elf64_Ehdr ehdr64; |
477 | int ret; | 510 | int ret; |
511 | unsigned int bo; | ||
512 | char *data; | ||
513 | ssize_t size; | ||
514 | uint64_t max; | ||
515 | size_t want; | ||
516 | |||
517 | max = ec->get_size (ec->cls); | ||
518 | want = sizeof (ehdr); | ||
519 | if (sizeof (ehdr64) > want) | ||
520 | want = sizeof (ehdr64); | ||
521 | want += EI_NIDENT; | ||
522 | if (max < want) | ||
523 | return; | ||
524 | size = ec->read (ec->cls, | ||
525 | (void**) &data, | ||
526 | max); | ||
527 | if (size < EI_NIDENT) | ||
528 | return; | ||
529 | if (0 != memcmp (data, | ||
530 | elfMagic, | ||
531 | sizeof (elfMagic))) | ||
532 | return; /* not an elf */ | ||
533 | switch (data[EI_CLASS]) | ||
534 | { | ||
535 | case ELFCLASS32: | ||
536 | if (size < sizeof (Elf32_Ehdr) + EI_NIDENT) | ||
537 | return; | ||
538 | bo = getByteorder (data[EI_DATA]); | ||
539 | EXTRACTOR_common_cat_unpack (&data[EI_NIDENT], | ||
540 | ELF_HEADER_SPECS[bo], | ||
541 | ELF_HEADER_FIELDS (&ehdr)); | ||
542 | if (ehdr.e_shoff + ehdr.e_shentsize * ehdr.e_shnum > max) | ||
543 | return; /* invalid offsets... */ | ||
544 | if (ehdr.e_shentsize < ELF_SECTION_SIZE) | ||
545 | return; /* huh? */ | ||
546 | if (ehdr.e_phoff + ehdr.e_phensize * ehdr.e_phnum > max) | ||
547 | return; | ||
548 | ret = 0; | ||
549 | bo = getByteorder (data[EI_CLASS]); | ||
550 | break; | ||
551 | case ELFCLASS64: | ||
552 | if (size < sizeof (Elf64_Ehdr) + EI_NIDENT) | ||
553 | return; | ||
554 | bo = getByteorder (data[EI_DATA]); | ||
555 | EXTRACTOR_common_cat_unpack (&data[EI_NIDENT], | ||
556 | ELF64_HEADER_SPECS[bo], | ||
557 | ELF64_HEADER_FIELDS (&ehdr64)); | ||
558 | if (ehdr64.e_shoff + ((uint32_t) ehdr64.e_shentsize * ehdr64.e_shnum) > | ||
559 | max) | ||
560 | return; /* invalid offsets... */ | ||
561 | if (ehdr64.e_phoff + ((uint32_t) ehdr64.e_phensize * ehdr64.e_phnum) > | ||
562 | max) | ||
563 | return; | ||
564 | bo = getByteorder (data[EI_CLASS]); | ||
565 | ret = 1; | ||
566 | break; | ||
567 | default: | ||
568 | return; | ||
569 | } | ||
478 | 570 | ||
479 | ret = getELFHdr (data, size, &ehdr, &ehdr64); | 571 | ADD ("application/x-executable", |
480 | if (ret == -1) | 572 | EXTRACTOR_METATYPE_MIMETYPE); |
481 | return 0; | ||
482 | ADD ("application/x-executable", EXTRACTOR_METATYPE_MIMETYPE); | ||
483 | switch ( ((unsigned char*) data)[EI_OSABI]) | 573 | switch ( ((unsigned char*) data)[EI_OSABI]) |
484 | { | 574 | { |
485 | case ELFOSABI_LINUX: | 575 | case ELFOSABI_LINUX: |
486 | ADD ("Linux", EXTRACTOR_METATYPE_TARGET_OS); | 576 | ADD ("Linux", |
577 | EXTRACTOR_METATYPE_TARGET_OS); | ||
487 | break; | 578 | break; |
488 | case ELFOSABI_FREEBSD: | 579 | case ELFOSABI_FREEBSD: |
489 | ADD ("FreeBSD", EXTRACTOR_METATYPE_TARGET_OS); | 580 | ADD ("FreeBSD", |
581 | EXTRACTOR_METATYPE_TARGET_OS); | ||
490 | break; | 582 | break; |
491 | case ELFOSABI_NETBSD: | 583 | case ELFOSABI_NETBSD: |
492 | ADD ("NetBSD", EXTRACTOR_METATYPE_TARGET_OS); | 584 | ADD ("NetBSD", |
585 | EXTRACTOR_METATYPE_TARGET_OS); | ||
493 | break; | 586 | break; |
494 | case ELFOSABI_OPENBSD: | 587 | case ELFOSABI_OPENBSD: |
495 | ADD ("OpenBSD", EXTRACTOR_METATYPE_TARGET_OS); | 588 | ADD ("OpenBSD", |
589 | EXTRACTOR_METATYPE_TARGET_OS); | ||
496 | break; | 590 | break; |
497 | case ELFOSABI_IRIX: | 591 | case ELFOSABI_IRIX: |
498 | ADD ("IRIX", EXTRACTOR_METATYPE_TARGET_OS); | 592 | ADD ("IRIX", |
593 | EXTRACTOR_METATYPE_TARGET_OS); | ||
499 | break; | 594 | break; |
500 | default: | 595 | default: |
501 | break; | 596 | break; |
502 | } | 597 | } |
503 | switch ( (ret == 0) ? ehdr.e_type : ehdr64.e_type) | 598 | switch ( (0 == ret) ? ehdr.e_type : ehdr64.e_type) |
504 | { | 599 | { |
505 | case ET_REL: | 600 | case ET_REL: |
506 | ADD ("Relocatable file", EXTRACTOR_METATYPE_RESOURCE_TYPE); | 601 | ADD ("Relocatable file", |
602 | EXTRACTOR_METATYPE_RESOURCE_TYPE); | ||
507 | break; | 603 | break; |
508 | case ET_EXEC: | 604 | case ET_EXEC: |
509 | ADD ("Executable file", EXTRACTOR_METATYPE_RESOURCE_TYPE); | 605 | ADD ("Executable file", |
606 | EXTRACTOR_METATYPE_RESOURCE_TYPE); | ||
510 | break; | 607 | break; |
511 | case ET_DYN: | 608 | case ET_DYN: |
512 | ADD ("Shared object file", EXTRACTOR_METATYPE_RESOURCE_TYPE); | 609 | ADD ("Shared object file", |
610 | EXTRACTOR_METATYPE_RESOURCE_TYPE); | ||
513 | break; | 611 | break; |
514 | case ET_CORE: | 612 | case ET_CORE: |
515 | ADD ("Core file", EXTRACTOR_METATYPE_RESOURCE_TYPE); | 613 | ADD ("Core file", |
614 | EXTRACTOR_METATYPE_RESOURCE_TYPE); | ||
516 | break; | 615 | break; |
517 | default: | 616 | default: |
518 | break; /* unknown */ | 617 | break; /* unknown */ |
519 | } | 618 | } |
520 | switch ( (ret == 0) ? ehdr.e_machine : ehdr64.e_machine) | 619 | switch ( (0 == ret) ? ehdr.e_machine : ehdr64.e_machine) |
521 | { | 620 | { |
522 | case EM_M32: | 621 | case EM_M32: |
523 | ADD ("M32", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 622 | ADD ("M32", |
623 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
524 | break; | 624 | break; |
525 | case EM_386: | 625 | case EM_386: |
526 | ADD ("i386", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 626 | ADD ("i386", |
627 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
527 | break; | 628 | break; |
528 | case EM_68K: | 629 | case EM_68K: |
529 | ADD ("68K", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 630 | ADD ("68K", |
631 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
530 | break; | 632 | break; |
531 | case EM_88K: | 633 | case EM_88K: |
532 | ADD ("88K", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 634 | ADD ("88K", |
635 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
533 | break; | 636 | break; |
534 | case EM_SPARC: | 637 | case EM_SPARC: |
535 | ADD ("Sparc", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 638 | ADD ("Sparc", |
639 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
536 | break; | 640 | break; |
537 | case EM_860: | 641 | case EM_860: |
538 | ADD ("960", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 642 | ADD ("960", |
643 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
539 | break; | 644 | break; |
540 | case EM_MIPS: | 645 | case EM_MIPS: |
541 | ADD ("MIPS", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 646 | ADD ("MIPS", |
647 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
542 | break; | 648 | break; |
543 | case EM_PPC: | 649 | case EM_PPC: |
544 | ADD ("PPC", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 650 | ADD ("PPC", |
651 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
545 | break; | 652 | break; |
546 | case EM_PPC64: | 653 | case EM_PPC64: |
547 | ADD ("PPC64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 654 | ADD ("PPC64", |
655 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
548 | break; | 656 | break; |
549 | case EM_S390: | 657 | case EM_S390: |
550 | ADD ("S390", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 658 | ADD ("S390", |
659 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
551 | break; | 660 | break; |
552 | case EM_ARM: | 661 | case EM_ARM: |
553 | ADD ("ARM", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 662 | ADD ("ARM", |
663 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
554 | break; | 664 | break; |
555 | case EM_ALPHA: | 665 | case EM_ALPHA: |
556 | ADD ("ALPHA", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 666 | ADD ("ALPHA", |
667 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
557 | break; | 668 | break; |
558 | case EM_IA_64: | 669 | case EM_IA_64: |
559 | ADD ("IA-64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 670 | ADD ("IA-64", |
671 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
560 | break; | 672 | break; |
561 | case EM_X86_64: | 673 | case EM_X86_64: |
562 | ADD ("x86_64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 674 | ADD ("x86_64", |
675 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
563 | break; | 676 | break; |
564 | case EM_CUDA: | 677 | case EM_CUDA: |
565 | ADD ("NVIDIA CUDA", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | 678 | ADD ("NVIDIA CUDA", |
679 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); | ||
566 | break; | 680 | break; |
567 | default: | 681 | default: |
568 | break; /* oops */ | 682 | break; /* oops */ |
569 | } | 683 | } |
570 | 684 | ||
571 | if (ret != 0) | 685 | if (0 != ret) |
572 | return 0; /* FIXME: full support for 64-bit ELF... */ | 686 | return; /* FIXME: full support for 64-bit ELF... */ |
573 | for (idx = 0; idx < ehdr.e_phnum; idx++) | 687 | for (Elf32_Half idx = 0; idx < ehdr.e_phnum; idx++) |
574 | { | 688 | { |
575 | Elf32_Phdr phdr; | 689 | Elf32_Phdr phdr; |
576 | 690 | ||
577 | if (0 != getProgramHdr (data, size, &ehdr, idx, &phdr)) | 691 | if (0 != getProgramHdr (ec, |
578 | return 0; | 692 | bo, |
693 | &ehdr, | ||
694 | idx, | ||
695 | &phdr)) | ||
696 | return; | ||
579 | if (phdr.p_type == PT_DYNAMIC) | 697 | if (phdr.p_type == PT_DYNAMIC) |
580 | { | 698 | { |
581 | unsigned int dc = phdr.p_filesz / ELF_DYN_SIZE; | 699 | unsigned int dc = phdr.p_filesz / ELF_DYN_SIZE; |
582 | unsigned int id; | ||
583 | Elf32_Addr stringPtr; | 700 | Elf32_Addr stringPtr; |
584 | Elf32_Half stringIdx; | 701 | Elf32_Half stringIdx; |
585 | Elf32_Half six; | 702 | Elf32_Half six; |
586 | 703 | ||
587 | stringPtr = 0; | 704 | stringPtr = 0; |
588 | 705 | for (unsigned int id = 0; id < dc; id++) | |
589 | for (id = 0; id < dc; id++) | ||
590 | { | 706 | { |
591 | Elf32_Dyn dyn; | 707 | Elf32_Dyn dyn; |
592 | if (0 != getDynTag (data, | 708 | |
593 | size, | 709 | if (0 != getDynTag (ec, |
710 | bo, | ||
594 | &ehdr, | 711 | &ehdr, |
595 | phdr.p_offset, phdr.p_filesz, id, &dyn)) | 712 | phdr.p_offset, |
596 | return 0; | 713 | phdr.p_filesz, |
714 | id, | ||
715 | &dyn)) | ||
716 | return; | ||
597 | if (DT_STRTAB == dyn.d_tag) | 717 | if (DT_STRTAB == dyn.d_tag) |
598 | { | 718 | { |
599 | stringPtr = dyn.d_un.d_ptr; | 719 | stringPtr = dyn.d_un.d_ptr; |
600 | break; | 720 | break; |
601 | } | 721 | } |
602 | } | 722 | } |
603 | if (stringPtr == 0) | 723 | if (0 == stringPtr) |
604 | return 0; | 724 | return; |
605 | for (six = 0; six < ehdr.e_shnum; six++) | 725 | for (six = 0; six < ehdr.e_shnum; six++) |
606 | { | 726 | { |
607 | Elf32_Shdr sec; | 727 | Elf32_Shdr sec; |
608 | if (-1 == getSectionHdr (data, size, &ehdr, six, &sec)) | 728 | |
609 | return 0; | 729 | if (-1 == getSectionHdr (ec, |
610 | if ((sec.sh_addr == stringPtr) && (sec.sh_type == SHT_STRTAB)) | 730 | bo, |
731 | &ehdr, | ||
732 | six, | ||
733 | &sec)) | ||
734 | return; | ||
735 | if ( (sec.sh_addr == stringPtr) && | ||
736 | (sec.sh_type == SHT_STRTAB) ) | ||
611 | { | 737 | { |
612 | stringIdx = six; | 738 | stringIdx = six; |
613 | break; | 739 | break; |
614 | } | 740 | } |
615 | } | 741 | } |
616 | if (six == ehdr.e_shnum) | 742 | if (six == ehdr.e_shnum) |
617 | return 0; /* stringIdx not found */ | 743 | return; /* stringIdx not found */ |
618 | 744 | ||
619 | for (id = 0; id < dc; id++) | 745 | for (unsigned int id = 0; id < dc; id++) |
620 | { | 746 | { |
621 | Elf32_Dyn dyn; | 747 | Elf32_Dyn dyn; |
622 | if (0 != getDynTag (data, | 748 | |
623 | size, | 749 | if (0 != getDynTag (ec, |
750 | bo, | ||
624 | &ehdr, | 751 | &ehdr, |
625 | phdr.p_offset, phdr.p_filesz, id, &dyn)) | 752 | phdr.p_offset, |
626 | return 0; | 753 | phdr.p_filesz, |
754 | id, | ||
755 | &dyn)) | ||
756 | return; | ||
627 | switch (dyn.d_tag) | 757 | switch (dyn.d_tag) |
628 | { | 758 | { |
629 | case DT_RPATH: | 759 | case DT_RPATH: |
630 | { | 760 | { |
631 | const char *rpath; | 761 | char *rpath; |
632 | 762 | ||
633 | rpath = readStringTable (data, | 763 | rpath = readStringTable (ec, |
634 | size, | 764 | bo, |
635 | &ehdr, | 765 | &ehdr, |
636 | stringIdx, dyn.d_un.d_val); | 766 | stringIdx, |
767 | dyn.d_un.d_val); | ||
637 | /* "source" of the dependencies: path | 768 | /* "source" of the dependencies: path |
638 | to dynamic libraries */ | 769 | to dynamic libraries */ |
639 | if (rpath != NULL) | 770 | if (NULL != rpath) |
640 | { | 771 | { |
641 | ADD (rpath, EXTRACTOR_METATYPE_LIBRARY_SEARCH_PATH); | 772 | ADD (rpath, |
773 | EXTRACTOR_METATYPE_LIBRARY_SEARCH_PATH); | ||
774 | free (rpath); | ||
642 | } | 775 | } |
643 | break; | 776 | break; |
644 | } | 777 | } |
645 | case DT_NEEDED: | 778 | case DT_NEEDED: |
646 | { | 779 | { |
647 | const char *needed; | 780 | char *needed; |
648 | 781 | ||
649 | needed = readStringTable (data, | 782 | needed = readStringTable (ec, |
650 | size, | 783 | bo, |
651 | &ehdr, | 784 | &ehdr, |
652 | stringIdx, dyn.d_un.d_val); | 785 | stringIdx, |
653 | if (needed != NULL) | 786 | dyn.d_un.d_val); |
787 | if (NULL != needed) | ||
654 | { | 788 | { |
655 | ADD (needed, EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY); | 789 | ADD (needed, |
790 | EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY); | ||
791 | free (needed); | ||
656 | } | 792 | } |
657 | break; | 793 | break; |
658 | } | 794 | } |
659 | } | 795 | } |
660 | } | 796 | } |
661 | |||
662 | } | 797 | } |
663 | } | 798 | } |
664 | |||
665 | return 0; | ||
666 | } | 799 | } |
800 | |||
801 | |||
802 | /* end of gif_extractor.c */ | ||
diff --git a/src/plugins/old/pack.c b/src/plugins/pack.c index 4f9e19d..4f9e19d 100644 --- a/src/plugins/old/pack.c +++ b/src/plugins/pack.c | |||
diff --git a/src/plugins/old/pack.h b/src/plugins/pack.h index 74bc172..74bc172 100644 --- a/src/plugins/old/pack.h +++ b/src/plugins/pack.h | |||
diff --git a/src/plugins/test_elf.c b/src/plugins/test_elf.c new file mode 100644 index 0000000..0400304 --- /dev/null +++ b/src/plugins/test_elf.c | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | This file is part of libextractor. | ||
3 | Copyright (C) 2021 Christian Grothoff | ||
4 | |||
5 | libextractor is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libextractor is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libextractor; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file plugins/test_elf.c | ||
22 | * @brief testcase for elf plugin | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "test_lib.h" | ||
27 | |||
28 | |||
29 | /** | ||
30 | * Main function for the ELF testcase. | ||
31 | * | ||
32 | * @param argc number of arguments (ignored) | ||
33 | * @param argv arguments (ignored) | ||
34 | * @return 0 on success | ||
35 | */ | ||
36 | int | ||
37 | main (int argc, char *argv[]) | ||
38 | { | ||
39 | struct SolutionData elf_sol[] = { | ||
40 | { | ||
41 | EXTRACTOR_METATYPE_MIMETYPE, | ||
42 | EXTRACTOR_METAFORMAT_UTF8, | ||
43 | "text/plain", | ||
44 | "application/x-executable", | ||
45 | strlen ("application/x-executable") + 1, | ||
46 | 0 | ||
47 | }, | ||
48 | { | ||
49 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE, | ||
50 | EXTRACTOR_METAFORMAT_UTF8, | ||
51 | "text/plain", | ||
52 | "i386", | ||
53 | strlen ("i386") + 1, | ||
54 | 0 | ||
55 | }, | ||
56 | { | ||
57 | EXTRACTOR_METATYPE_RESOURCE_TYPE, | ||
58 | EXTRACTOR_METAFORMAT_UTF8, | ||
59 | "text/plain", | ||
60 | "Executable file", | ||
61 | strlen ("Executable file") + 1, | ||
62 | 0 | ||
63 | }, | ||
64 | { | ||
65 | EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY, | ||
66 | EXTRACTOR_METAFORMAT_UTF8, | ||
67 | "text/plain", | ||
68 | "libc.so.6", | ||
69 | strlen ("libc.so.6") + 1, | ||
70 | 0 | ||
71 | }, | ||
72 | { 0, 0, NULL, NULL, 0, -1 } | ||
73 | }; | ||
74 | struct ProblemSet ps[] = { | ||
75 | { "testdata/chello-elf", | ||
76 | elf_sol }, | ||
77 | { NULL, NULL } | ||
78 | }; | ||
79 | return ET_main ("elf", ps); | ||
80 | } | ||
81 | |||
82 | |||
83 | /* end of test_elf.c */ | ||
diff --git a/src/plugins/testdata/chello-elf b/src/plugins/testdata/chello-elf new file mode 100755 index 0000000..3422476 --- /dev/null +++ b/src/plugins/testdata/chello-elf | |||
Binary files differ | |||