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