File Coverage

examples/elf.pl
Criterion Covered Total %
statement 24 106 22.6
branch 2 52 3.8
condition 0 15 0.0
subroutine 6 12 50.0
pod n/a
total 32 185 17.3


line stmt bran cond sub pod time code
1             #!/usr/local/pkg/cover/20070318/sw/bin/perl -w
2             ################################################################################
3             #
4             # $Project: /Convert-Binary-C $
5             # $Author: mhx $
6             # $Date: 2006/02/10 06:56:36 +0100 $
7             # $Revision: 2 $
8             # $Source: /bin/elf.PL $
9             #
10             ################################################################################
11             #
12             # Copyright (c) 2005-2006 Marcus Holland-Moritz. All rights reserved.
13             # This program is free software; you can redistribute it and/or modify
14             # it under the same terms as Perl itself.
15             #
16             ################################################################################
17              
18 1     1   33 use Convert::Binary::C;
  1         10  
  1         14  
19 1     1   41 use Data::Dumper;
  1         10  
  1         22  
20 1     1   38 use Getopt::Long;
  1         9  
  1         20  
21 1     1   16 use strict;
  1         9  
  1         25  
22              
23             #-------------------------------------------------
24             # Constants for accessing ELF identification data
25             #-------------------------------------------------
26 1     1   14 use constant EI_CLASS => 4;
  1         9  
  1         15  
27 1     1   14 use constant EI_DATA => 5;
  1         47  
  1         13  
28              
29 1         12 my %opt;
30 1         27 Getopt::Long::Configure('bundling');
31 1 50       74 unless (GetOptions(\%opt, qw( list|l info|i debug section|s=s symbols ))) {
32 0         0   eval q{
33             require Pod::Usage;
34             Pod::Usage::pod2usage(2);
35             };
36 0         0   print "Cannot show help, please consider installing Pod::Usage.\n";
37 0         0   exit;
38             }
39              
40 1 50       842 unless (@ARGV) {
41 1         79   print "No input file (try '$0 -h' for usage).\n";
42 1         16   exit;
43             }
44              
45             #---------------------------------------------------
46             # Compiler Configuration (generated using ccconfig)
47             #---------------------------------------------------
48 0         0 my %config = (
49               Alignment => 4,
50               CharSize => 1,
51               CompoundAlignment => 1,
52               IntSize => 4,
53               LongLongSize => 8,
54               LongSize => 4,
55               ShortSize => 2,
56               UnsignedChars => 0
57             );
58              
59             #-----------
60             # ELF Types
61             #-----------
62 0         0 my @elftype = qw( ET_NONE ET_REL ET_EXEC ET_DYN ET_CORE );
63              
64             #-------------------
65             # ELF Section Types
66             #-------------------
67 0         0 my @sectype = qw(
68             SHT_NULL SHT_PROGBITS SHT_SYMTAB SHT_STRTAB SHT_RELA SHT_HASH
69             SHT_DYNAMIC SHT_NOTE SHT_NOBITS SHT_REL SHT_SHLIB SHT_DYNSYM
70             );
71              
72             #-------------------
73             # ELF Machine Types
74             #-------------------
75 0         0 my %machine = (
76                0 => 'EM_NONE (No machine)',
77                1 => 'EM_M32 (AT&T WE 32100)',
78                2 => 'EM_SPARC (SUN SPARC)',
79                3 => 'EM_386 (Intel 80386)',
80                4 => 'EM_68K (Motorola m68k family)',
81                5 => 'EM_88K (Motorola m88k family)',
82                7 => 'EM_860 (Intel 80860)',
83                8 => 'EM_MIPS (MIPS R3000 big-endian)',
84                9 => 'EM_S370 (IBM System/370)',
85               10 => 'EM_MIPS_RS3_LE (MIPS R3000 little-endian)',
86               15 => 'EM_PARISC (HPPA)',
87               17 => 'EM_VPP500 (Fujitsu VPP500)',
88               18 => 'EM_SPARC32PLUS (Sun\'s "v8plus")',
89               19 => 'EM_960 (Intel 80960)',
90               20 => 'EM_PPC (PowerPC)',
91               21 => 'EM_PPC64 (PowerPC 64-bit)',
92               22 => 'EM_S390 (IBM S390)',
93               36 => 'EM_V800 (NEC V800 series)',
94               37 => 'EM_FR20 (Fujitsu FR20)',
95               38 => 'EM_RH32 (TRW RH-32)',
96               39 => 'EM_RCE (Motorola RCE)',
97               40 => 'EM_ARM (ARM)',
98               41 => 'EM_FAKE_ALPHA (Digital Alpha)',
99               42 => 'EM_SH (Hitachi SH)',
100               43 => 'EM_SPARCV9 (SPARC v9 64-bit)',
101               44 => 'EM_TRICORE (Siemens Tricore)',
102               45 => 'EM_ARC (Argonaut RISC Core)',
103               46 => 'EM_H8_300 (Hitachi H8/300)',
104               47 => 'EM_H8_300H (Hitachi H8/300H)',
105               48 => 'EM_H8S (Hitachi H8S)',
106               49 => 'EM_H8_500 (Hitachi H8/500)',
107               50 => 'EM_IA_64 (Intel Merced)',
108               51 => 'EM_MIPS_X (Stanford MIPS-X)',
109               52 => 'EM_COLDFIRE (Motorola Coldfire)',
110               53 => 'EM_68HC12 (Motorola M68HC12)',
111               54 => 'EM_MMA (Fujitsu MMA Multimedia Accelerator)',
112               55 => 'EM_PCP (Siemens PCP)',
113               56 => 'EM_NCPU (Sony nCPU embeeded RISC)',
114               57 => 'EM_NDR1 (Denso NDR1 microprocessor)',
115               58 => 'EM_STARCORE (Motorola Start*Core processor)',
116               59 => 'EM_ME16 (Toyota ME16 processor)',
117               60 => 'EM_ST100 (STMicroelectronic ST100 processor)',
118               61 => 'EM_TINYJ (Advanced Logic Corp. Tinyj emb.fam)',
119               62 => 'EM_X86_64 (AMD x86-64 architecture)',
120               63 => 'EM_PDSP (Sony DSP Processor)',
121               66 => 'EM_FX66 (Siemens FX66 microcontroller)',
122               67 => 'EM_ST9PLUS (STMicroelectronics ST9+ 8/16 mc)',
123               68 => 'EM_ST7 (STmicroelectronics ST7 8 bit mc)',
124               69 => 'EM_68HC16 (Motorola MC68HC16 microcontroller)',
125               70 => 'EM_68HC11 (Motorola MC68HC11 microcontroller)',
126               71 => 'EM_68HC08 (Motorola MC68HC08 microcontroller)',
127               72 => 'EM_68HC05 (Motorola MC68HC05 microcontroller)',
128               73 => 'EM_SVX (Silicon Graphics SVx)',
129               74 => 'EM_ST19 (STMicroelectronics ST19 8 bit mc)',
130               75 => 'EM_VAX (Digital VAX)',
131               76 => 'EM_CRIS (Axis Communications 32-bit embedded processor)',
132               77 => 'EM_JAVELIN (Infineon Technologies 32-bit embedded processor)',
133               78 => 'EM_FIREPATH (Element 14 64-bit DSP Processor)',
134               79 => 'EM_ZSP (LSI Logic 16-bit DSP Processor)',
135               80 => 'EM_MMIX (Donald Knuth\'s educational 64-bit processor)',
136               81 => 'EM_HUANY (Harvard University machine-independent object files)',
137               82 => 'EM_PRISM (SiTera Prism)',
138               83 => 'EM_AVR (Atmel AVR 8-bit microcontroller)',
139               84 => 'EM_FR30 (Fujitsu FR30)',
140               85 => 'EM_D10V (Mitsubishi D10V)',
141               86 => 'EM_D30V (Mitsubishi D30V)',
142               87 => 'EM_V850 (NEC v850)',
143               88 => 'EM_M32R (Mitsubishi M32R)',
144               89 => 'EM_MN10300 (Matsushita MN10300)',
145               90 => 'EM_MN10200 (Matsushita MN10200)',
146               91 => 'EM_PJ (picoJava)',
147               92 => 'EM_OPENRISC (OpenRISC 32-bit embedded processor)',
148               93 => 'EM_ARC_A5 (ARC Cores Tangent-A5)',
149               94 => 'EM_XTENSA (Tensilica Xtensa Architecture)',
150             );
151              
152             #-----------------------------
153             # ELF Symbol Binding and Type
154             #-----------------------------
155 0         0 my %symbind = (
156                0 => 'STB_LOCAL',
157                1 => 'STB_GLOBAL',
158                2 => 'STB_WEAK',
159                3 => 'STB_NUM',
160               10 => 'STB_LOOS',
161               12 => 'STB_HIOS',
162               13 => 'STB_LOPROC',
163               15 => 'STB_HIPROC',
164             );
165              
166 0         0 my %symtype = (
167                0 => 'STT_NOTYPE',
168                1 => 'STT_OBJECT',
169                2 => 'STT_FUNC',
170                3 => 'STT_SECTION',
171                4 => 'STT_FILE',
172                5 => 'STT_COMMON',
173                6 => 'STT_TLS',
174                7 => 'STT_NUM',
175               10 => 'STT_LOOS',
176               12 => 'STT_HIOS',
177               13 => 'STT_LOPROC',
178               15 => 'STT_HIPROC',
179             );
180              
181             #--------------------------------------------------------
182             # Create a C::B::C object to convert ELF data structures
183             #--------------------------------------------------------
184 0         0 my $ep = Convert::Binary::C->new(%config)->parse(elf_header());
185              
186             #-------------------------------------------
187             # Attach hooks to certain interesting types
188             #-------------------------------------------
189 0         0 my %hook = (
190               'Ehdr.e_machine' => \%machine,
191               'Ehdr.e_type' => \@elftype,
192               'Shdr.sh_type' => \@sectype,
193             );
194              
195 0         0 for my $c (qw( Elf32 Elf64 )) {
196 0         0   while (my($k,$v) = each %hook) {
197                 $ep->tag("$c\_$k", Hooks => { unpack => sub {
198 0 0   0   0       my $x = shift; (ref $v eq 'HASH' ? $v->{$x} : $v->[$x]) || "Unknown ($x)"
  0 0       0  
199 0         0     }});
200               }
201              
202               $ep->tag("$c\_Sym.st_info", Hooks => { unpack => sub {
203 0     0   0     my $x = shift;
204 0         0     my $b = $x >> 4;
205 0         0     my $t = $x & 0xf;
206                 {
207 0   0     0       sti_bind => $symbind{$b} || "Unknown ($b)",
      0        
208                   sti_type => $symtype{$t} || "Unknown ($t)",
209                 }
210 0         0   }});
211             }
212              
213             #---------------------------------------
214             # Read the whole ELF file (inefficient)
215             #---------------------------------------
216 0         0 my $elf = do { local($/, *FH);
  0         0  
217 0 0       0                open FH, $ARGV[0] or die "$ARGV[0]: $!\n";
218 0         0                <FH>;
219                          };
220              
221             #---------------------------------
222             # Process ELF identification data
223             #---------------------------------
224 0         0 my @ident = unpack "C16", substr $elf, 0, 16;
225              
226             #-----------------------------
227             # Is this really an ELF file?
228             #-----------------------------
229 0 0 0     0 unless ($ident[0] == 0x7F && pack("C*", @ident[1..3]) eq 'ELF')
230 0         0   { die "not an ELF file\n" }
231              
232             #-----------------------------
233             # Check ELF class (32/64-Bit)
234             #-----------------------------
235 0 0       0 if ($ident[EI_CLASS] == 0) { die "invalid ELF class ($ident[EI_CLASS])\n" }
  0         0  
236 0 0       0 if ($ident[EI_CLASS] > 2) { die "unsupported ELF class ($ident[EI_CLASS])\n" }
  0         0  
237 0 0       0 my $class = $ident[EI_CLASS] == 1 ? 'Elf32' : 'Elf64';
238              
239             #-------------------------------------------
240             # Check Byte Order (BigEndian/LittleEndian)
241             #-------------------------------------------
242 0 0       0 if ($ident[EI_DATA] == 0) { die "invalid data encoding ($ident[EI_DATA])\n" }
  0         0  
243 0 0       0 if ($ident[EI_DATA] > 2) { die "unsupported data encoding ($ident[EI_DATA])\n" }
  0         0  
244 0 0       0 $ep->ByteOrder($ident[EI_DATA] == 1 ? 'LittleEndian' : 'BigEndian');
245              
246             sub get
247             {
248 0     0       my($type, $off, $len) = @_;
249 0 0           $ep->unpack("$class\_$type", @_ > 2 ? substr $elf, $off, $len
250                                                   : substr $elf, $off);
251             }
252              
253             #---------------------------------------------------
254             # Unpack ELF header and section header string table
255             #---------------------------------------------------
256 0         0 my $header = get('Ehdr', 0);
257 0         0 my $shstrtab = get('Shdr', $header->{e_shoff} +
258                                        $header->{e_shstrndx}*$header->{e_shentsize});
259              
260 0 0       0 print Data::Dumper->Dump([$header], ["*$class\_Ehdr"]) if $opt{debug};
261              
262             #----------------------------
263             # Get Name from String Table
264             #----------------------------
265             sub get_name
266             {
267 0     0       my($tab, $off) = @_;
268 0             return unpack "Z*", substr $elf, $tab->{sh_offset} + $off;
269             }
270              
271             #--------------------------
272             # Read all section headers
273             #--------------------------
274 0         0 my %section; # for lookup by section name
275 0         0 my @section; # for lookup by section index
276              
277 0         0 for my $ix (0 .. $header->{e_shnum}-1) {
278 0         0   my $shdr = get('Shdr', $header->{e_shoff} + $ix*$header->{e_shentsize});
279 0 0       0   print Data::Dumper->Dump([$shdr], ["*$class\_Shdr"]) if $opt{debug};
280 0         0   $section{get_name($shstrtab, $shdr->{sh_name})} = $shdr;
281 0         0   push @section, $shdr;
282             }
283              
284             #-----------------------------------
285             # Get Section Name by Section Index
286             #-----------------------------------
287             sub get_section_name
288             {
289 0     0       my $sec = shift;
290 0 0 0         if ($sec == 0 || $sec >= 0xff00) {
291 0               my %res = (0 => 'SHN_UNDEF', 0xfff1 => 'SHN_ABS', 0xfff2 => 'SHN_COMMON');
292 0   0           return $res{$sec} || sprintf "reserved section 0x%04X", $sec;
293               }
294 0 0           return $sec < @section ? get_name($shstrtab, $section[$sec]{sh_name})
295                                      : "invalid section $sec";
296             }
297              
298             #--------------------------
299             # Print Header Information
300             #--------------------------
301 0 0       0 if ($opt{info}) {
302 0         0   printf "Byte Order: %s\n", $ep->ByteOrder;
303 0         0   printf "ELF Class : %s\n", $class;
304 0         0   printf "ELF Type : %s\n", $header->{e_type};
305 0         0   printf "Machine : %s\n", $header->{e_machine};
306             }
307              
308             #------------------------
309             # Print List Of Sections
310             #------------------------
311 0 0       0 if ($opt{list}) {
312 0         0   printf "%-3s %-38s %-13s %-9s %-9s\n%s\n",
313                      'Idx', 'Section', 'Type', 'Offset', 'Size', '-'x80;
314 0         0   for my $ix (0 .. $#section) {
315 0         0     my $sh = $section[$ix];
316 0         0     printf "%3d %-38s %-13s %9d %9d\n",
317                         $ix,
318                              get_name($shstrtab, $sh->{sh_name}),
319                                     $sh->{sh_type},
320                                            $sh->{sh_offset},
321                                                 $sh->{sh_size};
322               }
323             }
324              
325             #--------------------
326             # Print Symbol Table
327             #--------------------
328 0 0       0 if ($opt{symbols}) {
329 0 0       0   my $symtab = $section{'.symtab'} or die "got no symbol table\n";
330 0 0       0   my $strtab = $section{'.strtab'} or die "got no symbol string table\n";
331              
332 0         0   my @sym = get('Sym', $symtab->{sh_offset}, $symtab->{sh_size});
333              
334 0         0   printf "%-6s %-30s %-9s %-9s %-11s %-11s %-30s\n%s\n",
335                      'Index', 'Symbol', 'Value', 'Size', 'Bind', 'Type', 'Section', '-'x120;
336              
337 0         0   for my $ix (0 .. $#sym) {
338 0         0     my $s = $sym[$ix];
339              
340 0 0       0     print Data::Dumper->Dump([$s], ['*sym']) if $opt{debug};
341              
342 0         0     printf "%6d %-30s %9d %9d %-11s %-11s %-30s\n",
343                         $ix,
344                              get_name($strtab, $s->{st_name}),
345                                     $s->{st_value},
346                                          $s->{st_size},
347                                               $s->{st_info}{sti_bind},
348                                                      $s->{st_info}{sti_type},
349                                                             get_section_name($s->{st_shndx});
350               }
351             }
352              
353             #-------------------------
354             # Write Section to stdout
355             #-------------------------
356 0 0       0 if ($opt{section}) {
357 0 0       0   my $sec = $opt{section} =~ /^\d+$/ ? $section[$opt{section}]
358                                                  : $section{$opt{section}};
359               
360 0 0       0   die "no such section ($opt{section})\n" unless defined $sec;
361               
362 0         0   print substr $elf, $sec->{sh_offset}, $sec->{sh_size};
363             }
364              
365 0         0 exit;
366              
367             ###############################################################################
368             #
369             # This routine contains the ELF data structures and was generated using:
370             #
371             # perl -MConvert::Binary::C -e'print Convert::Binary::C->new(%{require \
372             # "devel/gcc-config.pl"})->parse_file("elf.h")->sourcify'
373             #
374             ###############################################################################
375              
376             sub elf_header
377             {
378 0     0       return <<'ENDC';
379             /* typedef predeclarations */
380            
381             typedef signed char int8_t;
382             typedef short int int16_t;
383             typedef int int32_t;
384             typedef long long int int64_t;
385             typedef unsigned char uint8_t;
386             typedef unsigned short int uint16_t;
387             typedef unsigned int uint32_t;
388             typedef unsigned long long int uint64_t;
389             typedef signed char int_least8_t;
390             typedef short int int_least16_t;
391             typedef int int_least32_t;
392             typedef long long int int_least64_t;
393             typedef unsigned char uint_least8_t;
394             typedef unsigned short int uint_least16_t;
395             typedef unsigned int uint_least32_t;
396             typedef unsigned long long int uint_least64_t;
397             typedef signed char int_fast8_t;
398             typedef int int_fast16_t;
399             typedef int int_fast32_t;
400             typedef long long int int_fast64_t;
401             typedef unsigned char uint_fast8_t;
402             typedef unsigned int uint_fast16_t;
403             typedef unsigned int uint_fast32_t;
404             typedef unsigned long long int uint_fast64_t;
405             typedef int intptr_t;
406             typedef unsigned int uintptr_t;
407             typedef long long int intmax_t;
408             typedef unsigned long long int uintmax_t;
409            
410            
411             /* typedefs */
412            
413             typedef uint16_t Elf32_Half;
414            
415             typedef uint16_t Elf64_Half;
416            
417             typedef uint32_t Elf32_Word;
418            
419             typedef int32_t Elf32_Sword;
420            
421             typedef uint32_t Elf64_Word;
422            
423             typedef int32_t Elf64_Sword;
424            
425             typedef uint64_t Elf32_Xword;
426            
427             typedef int64_t Elf32_Sxword;
428            
429             typedef uint64_t Elf64_Xword;
430            
431             typedef int64_t Elf64_Sxword;
432            
433             typedef uint32_t Elf32_Addr;
434            
435             typedef uint64_t Elf64_Addr;
436            
437             typedef uint32_t Elf32_Off;
438            
439             typedef uint64_t Elf64_Off;
440            
441             typedef uint16_t Elf32_Section;
442            
443             typedef uint16_t Elf64_Section;
444            
445             typedef Elf32_Half Elf32_Versym;
446            
447             typedef Elf64_Half Elf64_Versym;
448            
449             typedef struct
450             {
451             unsigned char e_ident[16];
452             Elf32_Half e_type;
453             Elf32_Half e_machine;
454             Elf32_Word e_version;
455             Elf32_Addr e_entry;
456             Elf32_Off e_phoff;
457             Elf32_Off e_shoff;
458             Elf32_Word e_flags;
459             Elf32_Half e_ehsize;
460             Elf32_Half e_phentsize;
461             Elf32_Half e_phnum;
462             Elf32_Half e_shentsize;
463             Elf32_Half e_shnum;
464             Elf32_Half e_shstrndx;
465             } Elf32_Ehdr;
466            
467             typedef struct
468             {
469             unsigned char e_ident[16];
470             Elf64_Half e_type;
471             Elf64_Half e_machine;
472             Elf64_Word e_version;
473             Elf64_Addr e_entry;
474             Elf64_Off e_phoff;
475             Elf64_Off e_shoff;
476             Elf64_Word e_flags;
477             Elf64_Half e_ehsize;
478             Elf64_Half e_phentsize;
479             Elf64_Half e_phnum;
480             Elf64_Half e_shentsize;
481             Elf64_Half e_shnum;
482             Elf64_Half e_shstrndx;
483             } Elf64_Ehdr;
484            
485             typedef struct
486             {
487             Elf32_Word sh_name;
488             Elf32_Word sh_type;
489             Elf32_Word sh_flags;
490             Elf32_Addr sh_addr;
491             Elf32_Off sh_offset;
492             Elf32_Word sh_size;
493             Elf32_Word sh_link;
494             Elf32_Word sh_info;
495             Elf32_Word sh_addralign;
496             Elf32_Word sh_entsize;
497             } Elf32_Shdr;
498            
499             typedef struct
500             {
501             Elf64_Word sh_name;
502             Elf64_Word sh_type;
503             Elf64_Xword sh_flags;
504             Elf64_Addr sh_addr;
505             Elf64_Off sh_offset;
506             Elf64_Xword sh_size;
507             Elf64_Word sh_link;
508             Elf64_Word sh_info;
509             Elf64_Xword sh_addralign;
510             Elf64_Xword sh_entsize;
511             } Elf64_Shdr;
512            
513             typedef struct
514             {
515             Elf32_Word st_name;
516             Elf32_Addr st_value;
517             Elf32_Word st_size;
518             unsigned char st_info;
519             unsigned char st_other;
520             Elf32_Section st_shndx;
521             } Elf32_Sym;
522            
523             typedef struct
524             {
525             Elf64_Word st_name;
526             unsigned char st_info;
527             unsigned char st_other;
528             Elf64_Section st_shndx;
529             Elf64_Addr st_value;
530             Elf64_Xword st_size;
531             } Elf64_Sym;
532            
533             typedef struct
534             {
535             Elf32_Half si_boundto;
536             Elf32_Half si_flags;
537             } Elf32_Syminfo;
538            
539             typedef struct
540             {
541             Elf64_Half si_boundto;
542             Elf64_Half si_flags;
543             } Elf64_Syminfo;
544            
545             typedef struct
546             {
547             Elf32_Addr r_offset;
548             Elf32_Word r_info;
549             } Elf32_Rel;
550            
551             typedef struct
552             {
553             Elf64_Addr r_offset;
554             Elf64_Xword r_info;
555             } Elf64_Rel;
556            
557             typedef struct
558             {
559             Elf32_Addr r_offset;
560             Elf32_Word r_info;
561             Elf32_Sword r_addend;
562             } Elf32_Rela;
563            
564             typedef struct
565             {
566             Elf64_Addr r_offset;
567             Elf64_Xword r_info;
568             Elf64_Sxword r_addend;
569             } Elf64_Rela;
570            
571             typedef struct
572             {
573             Elf32_Word p_type;
574             Elf32_Off p_offset;
575             Elf32_Addr p_vaddr;
576             Elf32_Addr p_paddr;
577             Elf32_Word p_filesz;
578             Elf32_Word p_memsz;
579             Elf32_Word p_flags;
580             Elf32_Word p_align;
581             } Elf32_Phdr;
582            
583             typedef struct
584             {
585             Elf64_Word p_type;
586             Elf64_Word p_flags;
587             Elf64_Off p_offset;
588             Elf64_Addr p_vaddr;
589             Elf64_Addr p_paddr;
590             Elf64_Xword p_filesz;
591             Elf64_Xword p_memsz;
592             Elf64_Xword p_align;
593             } Elf64_Phdr;
594            
595             typedef struct
596             {
597             Elf32_Sword d_tag;
598             union
599             {
600             Elf32_Word d_val;
601             Elf32_Addr d_ptr;
602             } d_un;
603             } Elf32_Dyn;
604            
605             typedef struct
606             {
607             Elf64_Sxword d_tag;
608             union
609             {
610             Elf64_Xword d_val;
611             Elf64_Addr d_ptr;
612             } d_un;
613             } Elf64_Dyn;
614            
615             typedef struct
616             {
617             Elf32_Half vd_version;
618             Elf32_Half vd_flags;
619             Elf32_Half vd_ndx;
620             Elf32_Half vd_cnt;
621             Elf32_Word vd_hash;
622             Elf32_Word vd_aux;
623             Elf32_Word vd_next;
624             } Elf32_Verdef;
625            
626             typedef struct
627             {
628             Elf64_Half vd_version;
629             Elf64_Half vd_flags;
630             Elf64_Half vd_ndx;
631             Elf64_Half vd_cnt;
632             Elf64_Word vd_hash;
633             Elf64_Word vd_aux;
634             Elf64_Word vd_next;
635             } Elf64_Verdef;
636            
637             typedef struct
638             {
639             Elf32_Word vda_name;
640             Elf32_Word vda_next;
641             } Elf32_Verdaux;
642            
643             typedef struct
644             {
645             Elf64_Word vda_name;
646             Elf64_Word vda_next;
647             } Elf64_Verdaux;
648            
649             typedef struct
650             {
651             Elf32_Half vn_version;
652             Elf32_Half vn_cnt;
653             Elf32_Word vn_file;
654             Elf32_Word vn_aux;
655             Elf32_Word vn_next;
656             } Elf32_Verneed;
657            
658             typedef struct
659             {
660             Elf64_Half vn_version;
661             Elf64_Half vn_cnt;
662             Elf64_Word vn_file;
663             Elf64_Word vn_aux;
664             Elf64_Word vn_next;
665             } Elf64_Verneed;
666            
667             typedef struct
668             {
669             Elf32_Word vna_hash;
670             Elf32_Half vna_flags;
671             Elf32_Half vna_other;
672             Elf32_Word vna_name;
673             Elf32_Word vna_next;
674             } Elf32_Vernaux;
675            
676             typedef struct
677             {
678             Elf64_Word vna_hash;
679             Elf64_Half vna_flags;
680             Elf64_Half vna_other;
681             Elf64_Word vna_name;
682             Elf64_Word vna_next;
683             } Elf64_Vernaux;
684            
685             typedef struct
686             {
687             int a_type;
688             union
689             {
690             long int a_val;
691             void *a_ptr;
692             void *a_fcn;
693             } a_un;
694             } Elf32_auxv_t;
695            
696             typedef struct
697             {
698             long int a_type;
699             union
700             {
701             long int a_val;
702             void *a_ptr;
703             void *a_fcn;
704             } a_un;
705             } Elf64_auxv_t;
706            
707             typedef struct
708             {
709             Elf32_Word n_namesz;
710             Elf32_Word n_descsz;
711             Elf32_Word n_type;
712             } Elf32_Nhdr;
713            
714             typedef struct
715             {
716             Elf64_Word n_namesz;
717             Elf64_Word n_descsz;
718             Elf64_Word n_type;
719             } Elf64_Nhdr;
720            
721             typedef struct
722             {
723             Elf32_Xword m_value;
724             Elf32_Word m_info;
725             Elf32_Word m_poffset;
726             Elf32_Half m_repeat;
727             Elf32_Half m_stride;
728             } Elf32_Move;
729            
730             typedef struct
731             {
732             Elf64_Xword m_value;
733             Elf64_Xword m_info;
734             Elf64_Xword m_poffset;
735             Elf64_Half m_repeat;
736             Elf64_Half m_stride;
737             } Elf64_Move;
738            
739             typedef union
740             {
741             struct
742             {
743             Elf32_Word gt_current_g_value;
744             Elf32_Word gt_unused;
745             } gt_header;
746             struct
747             {
748             Elf32_Word gt_g_value;
749             Elf32_Word gt_bytes;
750             } gt_entry;
751             } Elf32_gptab;
752            
753             typedef struct
754             {
755             Elf32_Word ri_gprmask;
756             Elf32_Word ri_cprmask[4];
757             Elf32_Sword ri_gp_value;
758             } Elf32_RegInfo;
759            
760             typedef struct
761             {
762             unsigned char kind;
763             unsigned char size;
764             Elf32_Section section;
765             Elf32_Word info;
766             } Elf_Options;
767            
768             typedef struct
769             {
770             Elf32_Word hwp_flags1;
771             Elf32_Word hwp_flags2;
772             } Elf_Options_Hw;
773            
774             typedef struct
775             {
776             Elf32_Word l_name;
777             Elf32_Word l_time_stamp;
778             Elf32_Word l_checksum;
779             Elf32_Word l_version;
780             Elf32_Word l_flags;
781             } Elf32_Lib;
782            
783             typedef struct
784             {
785             Elf64_Word l_name;
786             Elf64_Word l_time_stamp;
787             Elf64_Word l_checksum;
788             Elf64_Word l_version;
789             Elf64_Word l_flags;
790             } Elf64_Lib;
791            
792             typedef Elf32_Addr Elf32_Conflict;
793             ENDC
794             }
795              
796             __END__
797            
798             =head1 NAME
799            
800             elf.pl - Read ELF Files
801            
802             =head1 SYNOPSIS
803            
804             elf.pl {I<options>} elf-file
805            
806             I<options>:
807            
808             -i --info print information
809             -l --list print section list
810             --symbols print symbol table
811             -s --section NAME write section to stdout
812             --debug enable debug output
813            
814             example:
815            
816             elf.pl -il C.o
817            
818             =cut
819