summaryrefslogtreecommitdiff
path: root/plugins/readelf/header.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/readelf/header.c')
-rw-r--r--plugins/readelf/header.c670
1 files changed, 354 insertions, 316 deletions
diff --git a/plugins/readelf/header.c b/plugins/readelf/header.c
index d0aee92..21884a3 100644
--- a/plugins/readelf/header.c
+++ b/plugins/readelf/header.c
@@ -24,435 +24,473 @@
#include "header.h"
-#include <i18n.h>
-#include <arch/raw.h>
-#include <format/symbol.h>
+#include <common/cpp.h>
+#include <plugins/fmtp/parser.h>
+
+
+
+/* Définition des champs */
+
+static field_desc_switch _elf_classes[] = {
+
+ { .fixed = EV_NONE, .desc = __("File class: invalid") },
+ { .fixed = ELFCLASS32, .desc = __("File class: 32-bit objects") },
+ { .fixed = ELFCLASS64, .desc = __("File class: 64-bit objects") }
+
+};
+
+static field_desc_switch _elf_data[] = {
+
+ { .fixed = ELFDATANONE, .desc = __("Data encoding: invalid") },
+ { .fixed = ELFDATA2LSB, .desc = __("Data encoding: 2's complement, little endian") },
+ { .fixed = ELFDATA2MSB, .desc = __("Data encoding: 2's complement, big endian") }
+
+};
+
+static field_desc_switch _elf_versions[] = {
+
+ { .fixed = EV_NONE, .desc = __("File version: invalid") },
+ { .fixed = EV_CURRENT, .desc = __("File version: current") }
+
+};
+
+static field_desc_switch _elf_os_abis[] = {
+
+ { .fixed = ELFOSABI_SYSV, .desc = __("OS ABI: UNIX System V ABI") },
+ { .fixed = ELFOSABI_HPUX, .desc = __("OS ABI: HP-UX") },
+ { .fixed = ELFOSABI_NETBSD, .desc = __("OS ABI: NetBSD") },
+ { .fixed = ELFOSABI_GNU, .desc = __("OS ABI: Object uses GNU ELF extensions") },
+ { .fixed = ELFOSABI_SOLARIS, .desc = __("OS ABI: Sun Solaris") },
+ { .fixed = ELFOSABI_AIX, .desc = __("OS ABI: IBM AIX") },
+ { .fixed = ELFOSABI_IRIX, .desc = __("OS ABI: SGI Irix") },
+ { .fixed = ELFOSABI_FREEBSD, .desc = __("OS ABI: FreeBSD") },
+ { .fixed = ELFOSABI_TRU64, .desc = __("OS ABI: Compaq TRU64 UNIX") },
+ { .fixed = ELFOSABI_MODESTO, .desc = __("OS ABI: Novell Modesto") },
+ { .fixed = ELFOSABI_OPENBSD, .desc = __("OS ABI: OpenBSD") },
+ { .fixed = ELFOSABI_ARM_AEABI, .desc = __("OS ABI: ARM EABI") },
+ { .fixed = ELFOSABI_ARM, .desc = __("OS ABI: ARM") },
+ { .fixed = ELFOSABI_STANDALONE, .desc = __("OS ABI: Standalone (embedded) application") }
+
+};
+
+static field_desc_switch _elf_types[] = {
+
+ { .fixed = ET_NONE, .desc = __("Object file type: no file type") },
+ { .fixed = ET_REL, .desc = __("Object file type: relocatable file") },
+ { .fixed = ET_EXEC, .desc = __("Object file type: executable file") },
+ { .fixed = ET_DYN, .desc = __("Object file type: shared object file") },
+ { .fixed = ET_CORE, .desc = __("Object file type: core file") },
+ { .lower = ET_LOOS, .upper = ET_HIOS, .desc = __("Object file type: OS-specific") },
+ { .lower = ET_LOPROC, .upper = ET_HIPROC, .desc = __("Object file type: processor-specific") }
+
+};
+
+static field_desc_switch _elf_machines[] = {
+
+ { .fixed = EM_NONE, .desc = __("Architecture: No machine") },
+ { .fixed = EM_M32, .desc = __("Architecture: AT&T WE 32100") },
+ { .fixed = EM_SPARC, .desc = __("Architecture: SUN SPARC") },
+ { .fixed = EM_386, .desc = __("Architecture: Intel 80386") },
+ { .fixed = EM_68K, .desc = __("Architecture: Motorola m68k family") },
+ { .fixed = EM_88K, .desc = __("Architecture: Motorola m88k family") },
+ { .fixed = EM_860, .desc = __("Architecture: Intel 80860") },
+ { .fixed = EM_MIPS, .desc = __("Architecture: MIPS R3000 big-endian") },
+ { .fixed = EM_S370, .desc = __("Architecture: IBM System/370") },
+ { .fixed = EM_MIPS_RS3_LE, .desc = __("Architecture: MIPS R3000 little-endian") },
+ { .fixed = EM_PARISC, .desc = __("Architecture: HPPA") },
+ { .fixed = EM_VPP500, .desc = __("Architecture: Fujitsu VPP500") },
+ { .fixed = EM_SPARC32PLUS, .desc = __("Architecture: Sun's \"v8plus\"") },
+ { .fixed = EM_960, .desc = __("Architecture: Intel 80960") },
+ { .fixed = EM_PPC, .desc = __("Architecture: PowerPC") },
+ { .fixed = EM_PPC64, .desc = __("Architecture: PowerPC 64-bit") },
+ { .fixed = EM_S390, .desc = __("Architecture: IBM S390") },
+ { .fixed = EM_V800, .desc = __("Architecture: NEC V800 series") },
+ { .fixed = EM_FR20, .desc = __("Architecture: Fujitsu FR20") },
+ { .fixed = EM_RH32, .desc = __("Architecture: TRW RH-32") },
+ { .fixed = EM_RCE, .desc = __("Architecture: Motorola RCE") },
+ { .fixed = EM_ARM, .desc = __("Architecture: ARM") },
+ { .fixed = EM_FAKE_ALPHA, .desc = __("Architecture: Digital Alpha") },
+ { .fixed = EM_SH, .desc = __("Architecture: Hitachi SH") },
+ { .fixed = EM_SPARCV9, .desc = __("Architecture: SPARC v9 64-bit") },
+ { .fixed = EM_TRICORE, .desc = __("Architecture: Siemens Tricore") },
+ { .fixed = EM_ARC, .desc = __("Architecture: Argonaut RISC Core") },
+ { .fixed = EM_H8_300, .desc = __("Architecture: Hitachi H8/300") },
+ { .fixed = EM_H8_300H, .desc = __("Architecture: Hitachi H8/300H") },
+ { .fixed = EM_H8S, .desc = __("Architecture: Hitachi H8S") },
+ { .fixed = EM_H8_500, .desc = __("Architecture: Hitachi H8/500") },
+ { .fixed = EM_IA_64, .desc = __("Architecture: Intel Merced") },
+ { .fixed = EM_MIPS_X, .desc = __("Architecture: Stanford MIPS-X") },
+ { .fixed = EM_COLDFIRE, .desc = __("Architecture: Motorola Coldfire") },
+ { .fixed = EM_68HC12, .desc = __("Architecture: Motorola M68HC12") },
+ { .fixed = EM_MMA, .desc = __("Architecture: Fujitsu MMA Multimedia Accelerator") },
+ { .fixed = EM_PCP, .desc = __("Architecture: Siemens PCP") },
+ { .fixed = EM_NCPU, .desc = __("Architecture: Sony nCPU embeeded RISC") },
+ { .fixed = EM_NDR1, .desc = __("Architecture: Denso NDR1 microprocessor") },
+ { .fixed = EM_STARCORE, .desc = __("Architecture: Motorola Start*Core processor") },
+ { .fixed = EM_ME16, .desc = __("Architecture: Toyota ME16 processor") },
+ { .fixed = EM_ST100, .desc = __("Architecture: STMicroelectronic ST100 processor") },
+ { .fixed = EM_TINYJ, .desc = __("Architecture: Advanced Logic Corp. Tinyj emb.fam") },
+ { .fixed = EM_X86_64, .desc = __("Architecture: AMD x86-64 architecture") },
+ { .fixed = EM_PDSP, .desc = __("Architecture: Sony DSP Processor") },
+ { .fixed = EM_FX66, .desc = __("Architecture: Siemens FX66 microcontroller") },
+ { .fixed = EM_ST9PLUS, .desc = __("Architecture: STMicroelectronics ST9+ 8/16 mc") },
+ { .fixed = EM_ST7, .desc = __("Architecture: STmicroelectronics ST7 8 bit mc") },
+ { .fixed = EM_68HC16, .desc = __("Architecture: Motorola MC68HC16 microcontroller") },
+ { .fixed = EM_68HC11, .desc = __("Architecture: Motorola MC68HC11 microcontroller") },
+ { .fixed = EM_68HC08, .desc = __("Architecture: Motorola MC68HC08 microcontroller") },
+ { .fixed = EM_68HC05, .desc = __("Architecture: Motorola MC68HC05 microcontroller") },
+ { .fixed = EM_SVX, .desc = __("Architecture: Silicon Graphics SVx") },
+ { .fixed = EM_ST19, .desc = __("Architecture: STMicroelectronics ST19 8 bit mc") },
+ { .fixed = EM_VAX, .desc = __("Architecture: Digital VAX") },
+ { .fixed = EM_CRIS, .desc = __("Architecture: Axis Communications 32-bit embedded processor") },
+ { .fixed = EM_JAVELIN, .desc = __("Architecture: Infineon Technologies 32-bit embedded processor") },
+ { .fixed = EM_FIREPATH, .desc = __("Architecture: Element 14 64-bit DSP Processor") },
+ { .fixed = EM_ZSP, .desc = __("Architecture: LSI Logic 16-bit DSP Processor") },
+ { .fixed = EM_MMIX, .desc = __("Architecture: Donald Knuth's educational 64-bit processor") },
+ { .fixed = EM_HUANY, .desc = __("Architecture: Harvard University machine-independent object files") },
+ { .fixed = EM_PRISM, .desc = __("Architecture: SiTera Prism") },
+ { .fixed = EM_AVR, .desc = __("Architecture: Atmel AVR 8-bit microcontroller") },
+ { .fixed = EM_FR30, .desc = __("Architecture: Fujitsu FR30") },
+ { .fixed = EM_D10V, .desc = __("Architecture: Mitsubishi D10V") },
+ { .fixed = EM_D30V, .desc = __("Architecture: Mitsubishi D30V") },
+ { .fixed = EM_V850, .desc = __("Architecture: NEC v850") },
+ { .fixed = EM_M32R, .desc = __("Architecture: Mitsubishi M32R") },
+ { .fixed = EM_MN10300, .desc = __("Architecture: Matsushita MN10300") },
+ { .fixed = EM_MN10200, .desc = __("Architecture: Matsushita MN10200") },
+ { .fixed = EM_PJ, .desc = __("Architecture: picoJava") },
+ { .fixed = EM_OPENRISC, .desc = __("Architecture: OpenRISC 32-bit embedded processor") },
+ { .fixed = EM_ARC_A5, .desc = __("Architecture: ARC Cores Tangent-A5") },
+ { .fixed = EM_XTENSA, .desc = __("Architecture: Tensilica Xtensa Architecture") },
+ { .fixed = EM_AARCH64, .desc = __("Architecture: ARM AARCH64") },
+ { .fixed = EM_TILEPRO, .desc = __("Architecture: Tilera TILEPro") },
+ { .fixed = EM_MICROBLAZE, .desc = __("Architecture: Xilinx MicroBlaze") },
+ { .fixed = EM_TILEGX, .desc = __("Architecture: Tilera TILE-Gx") }
+
+};
+
+static fmt_field_def _elf_header_base[] = {
+ {
+ .name = "e_ident[EI_MAG]",
+ .size = MDS_8_BITS,
+ .repeat = 4,
-/******************************************************************************
-* *
-* Paramètres : format = description de l'exécutable à compléter. *
-* *
-* Description : Charge tous les symboles de l'en-tête ELF. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
+ DISPLAY_RULES(IOD_HEX, IOD_CHAR, IOD_CHAR, IOD_CHAR),
-bool annotate_elf_header(GElfFormat *format)
-{
- GBinContent *content; /* Contenu binaire à lire */
- const elf_header *header; /* En-tête principale */
- SourceEndian endian; /* Boutisme utilisé */
- vmpa2t pos; /* Tête de lecture des symboles*/
- GArchInstruction *instr; /* Instruction décodée */
- GArchOperand *operand; /* Opérande à venir modifier */
- GDbComment *comment; /* Définition de commentaire */
- GBinSymbol *symbol; /* Symbole à intégrer */
- const char *text; /* Texte constant à insérer */
+ PLAIN_COMMENT(__("ELF magic number"))
- content = g_binary_format_get_content(G_BIN_FORMAT(format));
+ },
- header = g_elf_format_get_header(format);
- endian = g_binary_format_get_endianness(G_BIN_FORMAT(format));
+ {
+ .name = "e_ident[EI_CLASS]",
+
+ .size = MDS_8_BITS,
+ .repeat = 1,
+
+ DISPLAY_RULES(IOD_DEC),
- if (!g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), 0, &pos))
- return false;
+ SWITCH_COMMENT(_elf_classes, __("File class: unknown"))
- /* ELFMAG (0) */
+ },
+
+ {
+ .name = "e_ident[EI_DATA]",
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 4, &pos, endian);
+ .size = MDS_8_BITS,
+ .repeat = 1,
- SET_IMM_DISPLAY(instr, operand, 1, IOD_CHAR);
- SET_IMM_DISPLAY(instr, operand, 2, IOD_CHAR);
- SET_IMM_DISPLAY(instr, operand, 3, IOD_CHAR);
+ DISPLAY_RULES(IOD_DEC),
- ADD_RAW_AS_SYM_CST(format, symbol, instr, comment, _("ELF magic number"));
+ SWITCH_COMMENT(_elf_data, __("Data encoding: unknown"))
- /* EI_CLASS (4) */
+ },
- switch (header->hdr32.e_ident[EI_CLASS])
{
- case EV_NONE:
- text = _("File class: invalid");
- break;
- case ELFCLASS32:
- text = _("File class: 32-bit objects");
- break;
- case ELFCLASS64:
- text = _("File class: 64-bit objects");
- break;
- default:
- text = _("File class: unknown");
- break;
- }
+ .name = "e_ident[EI_VERSION]",
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, &pos, endian);
+ .size = MDS_8_BITS,
+ .repeat = 1,
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ DISPLAY_RULES(IOD_DEC),
- ADD_RAW_AS_SYM(format, symbol, instr, comment, text);
+ SWITCH_COMMENT(_elf_versions, __("File version: unknown"))
- /* EI_DATA (5) */
+ },
- switch (header->hdr32.e_ident[EI_DATA])
{
- case ELFDATANONE:
- text = _("Data encoding: invalid");
- break;
- case ELFDATA2LSB:
- text = _("Data encoding: 2's complement, little endian");
- break;
- case ELFDATA2MSB:
- text = _("Data encoding: 2's complement, big endian");
- break;
- default:
- text = _("Data encoding: unknown");
- break;
- }
+ .name = "e_ident[EI_OSABI]",
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, &pos, endian);
+ .size = MDS_8_BITS,
+ .repeat = 1,
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ DISPLAY_RULES(IOD_DEC),
- ADD_RAW_AS_SYM(format, symbol, instr, comment, text);
+ SWITCH_COMMENT(_elf_os_abis, __("OS ABI: unknown"))
- /* EI_VERSION (6) */
+ },
- switch (header->hdr32.e_ident[EI_VERSION])
{
- case EV_NONE:
- text = _("File version: invalid");
- break;
- case EV_CURRENT:
- text = _("File version: current");
- break;
- default:
- text = _("File version: unknown");
- break;
- }
+ .name = "e_ident[EI_ABIVERSION]",
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, &pos, endian);
+ .size = MDS_8_BITS,
+ .repeat = 1,
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ DISPLAY_RULES(IOD_DEC),
- ADD_RAW_AS_SYM(format, symbol, instr, comment, text);
+ PLAIN_COMMENT(__("ABI version"))
- /* EI_OSABI (7) */
+ },
- switch (header->hdr32.e_ident[EI_OSABI])
{
- case ELFOSABI_SYSV:
- text = _("OS ABI: UNIX System V");
- break;
- case ELFOSABI_HPUX:
- text = _("OS ABI: HP-UX");
- break;
- case ELFOSABI_NETBSD:
- text = _("OS ABI: NetBSD");
- break;
- case ELFOSABI_GNU:
- text = _("OS ABI: object uses GNU ELF extensions");
- break;
- case ELFOSABI_SOLARIS:
- text = _("OS ABI: Sun Solaris");
- break;
- case ELFOSABI_AIX:
- text = _("OS ABI: IBM AIX");
- break;
- case ELFOSABI_IRIX:
- text = _("OS ABI: SGI Irix");
- break;
- case ELFOSABI_FREEBSD:
- text = _("OS ABI: FreeBSD");
- break;
- case ELFOSABI_TRU64:
- text = _("OS ABI: Compaq TRU64 UNIX");
- break;
- case ELFOSABI_MODESTO:
- text = _("OS ABI: Novell Modesto");
- break;
- case ELFOSABI_OPENBSD:
- text = _("OS ABI: OpenBSD");
- break;
- case ELFOSABI_ARM_AEABI:
- text = _("OS ABI: ARM EABI");
- break;
- case ELFOSABI_ARM:
- text = _("OS ABI: ARM");
- break;
- case ELFOSABI_STANDALONE:
- text = _("OS ABI: standalone (embedded) application");
- break;
- default:
- text = _("OS ABI: unknown");
- break;
- }
+ .name = "...",
+
+ .size = MDS_8_BITS,
+ .repeat = 7,
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, &pos, endian);
+ .is_padding = true,
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ PLAIN_COMMENT(__("Padding"))
- ADD_RAW_AS_SYM(format, symbol, instr, comment, text);
+ },
- /* EI_ABIVERSION (8) */
+ {
+ .name = "e_type",
+
+ .size = MDS_16_BITS,
+ .repeat = 1,
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, &pos, endian);
+ DISPLAY_RULES(IOD_DEC),
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ SWITCH_COMMENT(_elf_types, __("Object file type: unkown"))
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("ABI version"));
+ },
- /* Padding */
+ {
+ .name = "e_machine",
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 7, &pos, endian);
+ .size = MDS_16_BITS,
+ .repeat = 1,
- g_raw_instruction_mark_as_padding(G_RAW_INSTRUCTION(instr), true);
+ DISPLAY_RULES(IOD_DEC),
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Padding"));
+ SWITCH_COMMENT(_elf_machines, __("Architecture: unknown"))
- /* Champ "e_type" */
+ },
- switch (header->hdr32.e_type)
{
- case ET_NONE:
- text = _("Object file type: no file type");
- break;
- case ET_REL:
- text = _("Object file type: relocatable file");
- break;
- case ET_EXEC:
- text = _("Object file type: executable file");
- break;
- case ET_DYN:
- text = _("Object file type: shared object file");
- break;
- case ET_CORE:
- text = _("Object file type: core file");
- break;
- case ET_LOOS ... ET_HIOS:
- text = _("Object file type: OS-specific");
- break;
- case ET_LOPROC ... ET_HIPROC:
- text = _("Object file type: processor-specific");
- break;
- default:
- text = _("Object file type: unkown");
- break;
+ .name = "e_version",
+
+ .size = MDS_32_BITS,
+ .repeat = 1,
+
+ DISPLAY_RULES(IOD_DEC),
+
+ PLAIN_COMMENT(__("Object file version"))
+
}
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, &pos, endian);
+};
+
+static fmt_field_def _elf_header_offset_32[] = {
+
+ {
+ .name = "e_entry",
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ .size = MDS_32_BITS,
+ .repeat = 1,
- ADD_RAW_AS_SYM(format, symbol, instr, comment, text);
+ PLAIN_COMMENT(__("Entry point virtual address"))
- /* Champ "e_machine" */
+ },
- switch (header->hdr32.e_machine)
{
- case EM_NONE: text = _("Architecture: No machine"); break;
- case EM_M32: text = _("Architecture: AT&T WE 32100"); break;
- case EM_SPARC: text = _("Architecture: SUN SPARC"); break;
- case EM_386: text = _("Architecture: Intel 80386"); break;
- case EM_68K: text = _("Architecture: Motorola m68k family"); break;
- case EM_88K: text = _("Architecture: Motorola m88k family"); break;
- case EM_860: text = _("Architecture: Intel 80860"); break;
- case EM_MIPS: text = _("Architecture: MIPS R3000 big-endian"); break;
- case EM_S370: text = _("Architecture: IBM System/370"); break;
- case EM_MIPS_RS3_LE:text = _("Architecture: MIPS R3000 little-endian"); break;
- case EM_PARISC: text = _("Architecture: HPPA"); break;
- case EM_VPP500: text = _("Architecture: Fujitsu VPP500"); break;
- case EM_SPARC32PLUS:text = _("Architecture: Sun's \"v8plus\""); break;
- case EM_960: text = _("Architecture: Intel 80960"); break;
- case EM_PPC: text = _("Architecture: PowerPC"); break;
- case EM_PPC64: text = _("Architecture: PowerPC 64-bit"); break;
- case EM_S390: text = _("Architecture: IBM S390"); break;
- case EM_V800: text = _("Architecture: NEC V800 series"); break;
- case EM_FR20: text = _("Architecture: Fujitsu FR20"); break;
- case EM_RH32: text = _("Architecture: TRW RH-32"); break;
- case EM_RCE: text = _("Architecture: Motorola RCE"); break;
- case EM_ARM: text = _("Architecture: ARM"); break;
- case EM_FAKE_ALPHA: text = _("Architecture: Digital Alpha"); break;
- case EM_SH: text = _("Architecture: Hitachi SH"); break;
- case EM_SPARCV9: text = _("Architecture: SPARC v9 64-bit"); break;
- case EM_TRICORE: text = _("Architecture: Siemens Tricore"); break;
- case EM_ARC: text = _("Architecture: Argonaut RISC Core"); break;
- case EM_H8_300: text = _("Architecture: Hitachi H8/300"); break;
- case EM_H8_300H: text = _("Architecture: Hitachi H8/300H"); break;
- case EM_H8S: text = _("Architecture: Hitachi H8S"); break;
- case EM_H8_500: text = _("Architecture: Hitachi H8/500"); break;
- case EM_IA_64: text = _("Architecture: Intel Merced"); break;
- case EM_MIPS_X: text = _("Architecture: Stanford MIPS-X"); break;
- case EM_COLDFIRE: text = _("Architecture: Motorola Coldfire"); break;
- case EM_68HC12: text = _("Architecture: Motorola M68HC12"); break;
- case EM_MMA: text = _("Architecture: Fujitsu MMA Multimedia Accelerator"); break;
- case EM_PCP: text = _("Architecture: Siemens PCP"); break;
- case EM_NCPU: text = _("Architecture: Sony nCPU embeeded RISC"); break;
- case EM_NDR1: text = _("Architecture: Denso NDR1 microprocessor"); break;
- case EM_STARCORE: text = _("Architecture: Motorola Start*Core processor"); break;
- case EM_ME16: text = _("Architecture: Toyota ME16 processor"); break;
- case EM_ST100: text = _("Architecture: STMicroelectronic ST100 processor"); break;
- case EM_TINYJ: text = _("Architecture: Advanced Logic Corp. Tinyj emb.fam"); break;
- case EM_X86_64: text = _("Architecture: AMD x86-64 architecture"); break;
- case EM_PDSP: text = _("Architecture: Sony DSP Processor"); break;
- case EM_FX66: text = _("Architecture: Siemens FX66 microcontroller"); break;
- case EM_ST9PLUS: text = _("Architecture: STMicroelectronics ST9+ 8/16 mc"); break;
- case EM_ST7: text = _("Architecture: STmicroelectronics ST7 8 bit mc"); break;
- case EM_68HC16: text = _("Architecture: Motorola MC68HC16 microcontroller"); break;
- case EM_68HC11: text = _("Architecture: Motorola MC68HC11 microcontroller"); break;
- case EM_68HC08: text = _("Architecture: Motorola MC68HC08 microcontroller"); break;
- case EM_68HC05: text = _("Architecture: Motorola MC68HC05 microcontroller"); break;
- case EM_SVX: text = _("Architecture: Silicon Graphics SVx"); break;
- case EM_ST19: text = _("Architecture: STMicroelectronics ST19 8 bit mc"); break;
- case EM_VAX: text = _("Architecture: Digital VAX"); break;
- case EM_CRIS: text = _("Architecture: Axis Communications 32-bit embedded processor"); break;
- case EM_JAVELIN: text = _("Architecture: Infineon Technologies 32-bit embedded processor"); break;
- case EM_FIREPATH: text = _("Architecture: Element 14 64-bit DSP Processor"); break;
- case EM_ZSP: text = _("Architecture: LSI Logic 16-bit DSP Processor"); break;
- case EM_MMIX: text = _("Architecture: Donald Knuth's educational 64-bit processor"); break;
- case EM_HUANY: text = _("Architecture: Harvard University machine-independent object files"); break;
- case EM_PRISM: text = _("Architecture: SiTera Prism"); break;
- case EM_AVR: text = _("Architecture: Atmel AVR 8-bit microcontroller"); break;
- case EM_FR30: text = _("Architecture: Fujitsu FR30"); break;
- case EM_D10V: text = _("Architecture: Mitsubishi D10V"); break;
- case EM_D30V: text = _("Architecture: Mitsubishi D30V"); break;
- case EM_V850: text = _("Architecture: NEC v850"); break;
- case EM_M32R: text = _("Architecture: Mitsubishi M32R"); break;
- case EM_MN10300: text = _("Architecture: Matsushita MN10300"); break;
- case EM_MN10200: text = _("Architecture: Matsushita MN10200"); break;
- case EM_PJ: text = _("Architecture: picoJava"); break;
- case EM_OPENRISC: text = _("Architecture: OpenRISC 32-bit embedded processor"); break;
- case EM_ARC_A5: text = _("Architecture: ARC Cores Tangent-A5"); break;
- case EM_XTENSA: text = _("Architecture: Tensilica Xtensa Architecture"); break;
- case EM_AARCH64: text = _("Architecture: ARM AARCH64"); break;
- case EM_TILEPRO: text = _("Architecture: Tilera TILEPro"); break;
- case EM_MICROBLAZE: text = _("Architecture: Xilinx MicroBlaze"); break;
- case EM_TILEGX: text = _("Architecture: Tilera TILE-Gx"); break;
- default: text = _("Architecture: unknown"); break;
- }
+ .name = "e_phoff",
+
+ .size = MDS_32_BITS,
+ .repeat = 1,
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Program header table file offset"))
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ },
- ADD_RAW_AS_SYM(format, symbol, instr, comment, text);
+ {
+ .name = "e_shoff",
- /* Champ "e_version" */
+ .size = MDS_32_BITS,
+ .repeat = 1,
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Section header table file offset"))
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ }
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Object file version"));
+};
+
+static fmt_field_def _elf_header_offset_64[] = {
- if (header->hdr32.e_ident[EI_CLASS] == ELFCLASS32)
{
- /* Champ "e_entry" */
+ .name = "e_entry",
+
+ .size = MDS_64_BITS,
+ .repeat = 1,
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Entry point virtual address"))
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Entry point virtual address"));
+ },
- /* Champ "e_phoff" */
+ {
+ .name = "e_phoff",
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ .size = MDS_64_BITS,
+ .repeat = 1,
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Program header table file offset"));
+ PLAIN_COMMENT(__("Program header table file offset"))
- /* Champ "e_shoff" */
+ },
+
+ {
+ .name = "e_shoff",
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ .size = MDS_64_BITS,
+ .repeat = 1,
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Section header table file offset"));
+ PLAIN_COMMENT(__("Section header table file offset"))
}
- else if (header->hdr32.e_ident[EI_CLASS] == ELFCLASS64)
+};
+
+static fmt_field_def _elf_header_ending[] = {
+
{
- /* Champ "e_entry" */
+ .name = "e_flags",
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, &pos, endian);
+ .size = MDS_32_BITS,
+ .repeat = 1,
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Entry point virtual address"));
+ PLAIN_COMMENT(__("Processor-specific flags"))
- /* Champ "e_phoff" */
+ },
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, &pos, endian);
+ {
+ .name = "e_ehsize",
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Program header table file offset"));
+ .size = MDS_16_BITS,
+ .repeat = 1,
- /* Champ "e_shoff" */
+ DISPLAY_RULES(IOD_DEC),
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("ELF header size in bytes"))
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Section header table file offset"));
+ },
- }
+ {
+ .name = "e_phentsize",
- else return false;
+ .size = MDS_16_BITS,
+ .repeat = 1,
- /* Champ "e_flags" */
+ DISPLAY_RULES(IOD_DEC),
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Program header table entry size"))
+
+ },
+
+ {
+ .name = "e_phnum",
+
+ .size = MDS_16_BITS,
+ .repeat = 1,
+
+ DISPLAY_RULES(IOD_DEC),
+
+ PLAIN_COMMENT(__("Program header table entry count"))
+
+ },
+
+ {
+ .name = "e_shentsize",
- //SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ .size = MDS_16_BITS,
+ .repeat = 1,
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Processor-specific flags"));
+ DISPLAY_RULES(IOD_DEC),
- /* Champ "e_ehsize" */
+ PLAIN_COMMENT(__("Section header table entry size"))
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, &pos, endian);
+ },
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ {
+ .name = "e_shnum",
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("ELF header size in bytes"));
+ .size = MDS_16_BITS,
+ .repeat = 1,
- /* Champ "e_phentsize" */
+ DISPLAY_RULES(IOD_DEC),
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, &pos, endian);
+ PLAIN_COMMENT(__("Section header table entry count"))
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ },
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Program header table entry size"));
+ {
+ .name = "e_shstrndx",
- /* Champ "e_phnum" */
+ .size = MDS_16_BITS,
+ .repeat = 1,
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, &pos, endian);
+ DISPLAY_RULES(IOD_DEC),
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ PLAIN_COMMENT(__("Section header string table index"))
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Program header table entry count"));
+ }
- /* Champ "e_shentsize" */
+};
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, &pos, endian);
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Section header table entry size"));
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à compléter. *
+* *
+* Description : Charge tous les symboles de l'en-tête ELF. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- /* Champ "e_shnum" */
+bool annotate_elf_header(GBinFormat *format)
+{
+ bool result; /* Bilan à retourner */
+ const elf_header *header; /* En-tête principale */
+ vmpa2t pos; /* Tête de lecture des symboles*/
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, &pos, endian);
+ header = g_elf_format_get_header(G_ELF_FORMAT(format));
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ result = g_exe_format_translate_offset_into_vmpa(G_EXE_FORMAT(format), 0, &pos);
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Section header table entry count"));
+ if (result)
+ result = parse_field_definitions(_elf_header_base, ARRAY_SIZE(_elf_header_base), format, &pos);
- /* Champ "e_shstrndx" */
+ if (result)
+ {
+ if (header->hdr32.e_ident[EI_CLASS] == ELFCLASS32)
+ result = parse_field_definitions(_elf_header_offset_32, ARRAY_SIZE(_elf_header_offset_32),
+ format, &pos);
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, &pos, endian);
+ else if (header->hdr32.e_ident[EI_CLASS] == ELFCLASS64)
+ result = parse_field_definitions(_elf_header_offset_64, ARRAY_SIZE(_elf_header_offset_64),
+ format, &pos);
- SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+ else
+ result = false;
- ADD_RAW_AS_SYM(format, symbol, instr, comment, _("Section header string table index"));
+ }
- g_object_unref(G_OBJECT(content));
+ if (result)
+ result = parse_field_definitions(_elf_header_ending, ARRAY_SIZE(_elf_header_ending), format, &pos);
- return true;
+ return result;
}