summaryrefslogtreecommitdiff
path: root/src/format/elf
diff options
context:
space:
mode:
Diffstat (limited to 'src/format/elf')
-rw-r--r--src/format/elf/elf_def.h23
-rw-r--r--src/format/elf/symbols.c171
2 files changed, 187 insertions, 7 deletions
diff --git a/src/format/elf/elf_def.h b/src/format/elf/elf_def.h
index 91e1c18..f863257 100644
--- a/src/format/elf/elf_def.h
+++ b/src/format/elf/elf_def.h
@@ -408,10 +408,25 @@ typedef union _elf_shdr
/* Valeurs possibles pour sh_flags */
-#define SHF_WRITE (1 << 0) /* Accessible en écriture */
-#define SHF_ALLOC (1 << 1) /* Copie en mémoire pdt l'exec.*/
-#define SHF_EXECINSTR (1 << 2) /* Section exécutable */
-#define SHF_STRINGS (1 << 5) /* Contient des chaînes ('\0') */
+#define SHF_WRITE (1 << 0) /* Accessible en écriture */
+#define SHF_ALLOC (1 << 1) /* Copie en mémoire pdt l'exec.*/
+#define SHF_EXECINSTR (1 << 2) /* Section exécutable */
+#define SHF_MERGE (1 << 4) /* Peut être fusionné */
+#define SHF_STRINGS (1 << 5) /* Contient des chaînes ('\0') */
+#define SHF_INFO_LINK (1 << 6) /* 'sh_info' contient un index */
+#define SHF_LINK_ORDER (1 << 7) /* Préservation de l'ordre */
+#define SHF_OS_NONCONFORMING (1 << 8) /* Gestion non standard requise*/
+#define SHF_GROUP (1 << 9) /* Section membre d'un groupe */
+#define SHF_TLS (1 << 10) /* Données pour un thread local*/
+
+#define SHF_MASKOS 0x0ff00000 /* OS-specific. */
+#define SHF_MASKPROC 0xf0000000 /* Processor-specific */
+#define SHF_ORDERED (1 << 30) /* Special ordering requirement
+ (Solaris). */
+#define SHF_EXCLUDE (1 << 31) /* Section is excluded unless
+ referenced or allocated (Solaris).*/
+
+
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c
index 33a8c3f..dc3fbe0 100644
--- a/src/format/elf/symbols.c
+++ b/src/format/elf/symbols.c
@@ -912,10 +912,12 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
const bin_t *content; /* Contenu binaire à lire */
off_t length; /* Taille totale du contenu */
off_t offset; /* Tête de lecture du bbinaire */
+ elf_shdr strings; /* Section des descriptions */
vmpa2t *pos; /* Localisation des symboles */
uint16_t e_shnum; /* Nombre d'éléments 'Program' */
uint16_t i; /* Boucle de parcours */
elf_shdr shdr; /* En-tête de programme ELF */
+ const char *secname; /* Nom d'une section analysée */
ImmOperandDisplay disp; /* Afficahge de valeur */
const char *text; /* Texte constant à insérer */
GArchInstruction *instr; /* Instruction décodée */
@@ -928,6 +930,9 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
content = G_BIN_FORMAT(format)->content;
length = G_BIN_FORMAT(format)->length;
+ if (!find_elf_section_by_index(format, ELF_HDR(format, format->header, e_shstrndx), &strings))
+ return false;
+
offset = ELF_HDR(format, format->header, e_shoff);
pos = make_vmpa(offset, 0x9900);
@@ -936,18 +941,30 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
for (i = 0; i < e_shnum; i++)
{
- if (!read_elf_section_header(format, offset, &shdr))
+ if (!read_elf_section_header(format, get_phy_addr(pos), &shdr))
break;
/* Champ "sh_name" */
- text = _("Section name");
+ secname = extract_name_from_elf_string_section(format, &strings,
+ ELF_SHDR(format, shdr, sh_name));
+
+ if (secname == NULL)
+ dtext = strdup(_("Section name: <invalid>"));
+ else
+ {
+ dtext = strdup(_("Section name: '"));
+ dtext = stradd(dtext, secname);
+ dtext = stradd(dtext, "'");
+ }
instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
- ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, text);
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, dtext);
+
+ free(dtext);
/* Champ "sh_type" */
@@ -1061,6 +1078,10 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
disp = IOD_HEX;
text = _("Section type: application-specific");
break;
+ default:
+ disp = IOD_HEX;
+ text = _("Section type: unknown");
+ break;
}
instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
@@ -1069,15 +1090,159 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, text);
+ /* Champ "sh_flags"... */
+ dtext = strdup(_("Section flags: "));
+ filled = false;
+
+ if (ELF_SHDR(format, shdr, sh_type) & SHF_WRITE)
+ {
+ dtext = stradd(dtext, "W");
+ filled = true;
+ }
+ if (ELF_SHDR(format, shdr, sh_type) & SHF_ALLOC)
+ {
+ dtext = stradd(dtext, "A");
+ filled = true;
+ }
+ if (ELF_SHDR(format, shdr, sh_type) & SHF_EXECINSTR)
+ {
+ dtext = stradd(dtext, "X");
+ filled = true;
+ }
+ if (ELF_SHDR(format, shdr, sh_type) & SHF_MERGE)
+ {
+ dtext = stradd(dtext, "M");
+ filled = true;
+ }
+ if (ELF_SHDR(format, shdr, sh_type) & SHF_LINK_ORDER)
+ {
+ dtext = stradd(dtext, "L");
+ filled = true;
+ }
+ if (ELF_SHDR(format, shdr, sh_type) & SHF_TLS)
+ {
+ dtext = stradd(dtext, "T");
+ filled = true;
+ }
+ if (!filled)
+ dtext = stradd(dtext, _("none"));
+ if (format->is_32b)
+ {
+ /* Champ "sh_flags" (suite) */
+ instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, dtext);
+
+ free(dtext);
+
+ /* Champ "sh_addr" */
+
+ instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section virtual addr at execution"));
+
+ /* Champ "sh_offset" */
+
+ instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section file offset"));
+
+ /* Champ "sh_size" */
+
+ instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+
+ SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section size in bytes"));
+
+ }
+ else
+ {
+ /* Champ "sh_flags" (suite) */
+
+ instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, dtext);
+
+ free(dtext);
+
+ /* Champ "sh_addr" */
+
+ instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section virtual addr at execution"));
+
+ /* Champ "sh_offset" */
+
+ instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section file offset"));
+
+ /* Champ "sh_size" */
+
+ instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+
+ SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section size in bytes"));
+
+ }
+
+ /* Champ "sh_link" */
+
+ instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Link to another section"));
+
+ /* Champ "sh_info" */
+
+ instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Additional section information"));
+
+ if (format->is_32b)
+ {
+ /* Champ "sh_addralign" */
+
+ instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section alignment"));
+
+ /* Champ "sh_entsize" */
+
+ instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+
+ SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Entry size if section holds table"));
+
+ }
+ else
+ {
+ /* Champ "sh_addralign" */
+
+ instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section alignment"));
+
+ /* Champ "sh_entsize" */
+
+ instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+
+ SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
+
+ ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Entry size if section holds table"));
+
+ }
}