summaryrefslogtreecommitdiff
path: root/src/format/elf/symbols.c
blob: 15c3a6b90bb3b29886dc19c52e3fe61c12c12104 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596

/* Chrysalide - Outil d'analyse de fichiers binaires
 * symbols.c - gestion des symboles d'un ELF
 *
 * Copyright (C) 2008-2013 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  OpenIDA is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OpenIDA is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "symbols.h"


#include <malloc.h>
#include <string.h>


#include <i18n.h>


#include "elf-int.h"
#include "helper_x86.h"
#include "section.h"
#include "../mangling/demangler.h"
#include "../../arch/raw.h"
#include "../../common/extstr.h"
#include "../../core/params.h"
#include "../../gui/panels/log.h"







/* Récupère la désignation d'un symbole donné. */
const char *get_elf_symbol_name(GElfFormat *, const elf_shdr *, const elf_shdr *, off_t);






/* ------------------------ CHARGEMENT DE SYMBOLES DU FORMAT ------------------------ */


/* Charge tous les symboles de l'en-tête ELF. */
static bool annotate_elf_header(GElfFormat *);

/* Charge tous les symboles liés aux en-têtes de programme ELF. */
static bool annotate_elf_program_header_table(GElfFormat *);

/* Charge tous les symboles liés aux en-têtes de section ELF. */
static bool annotate_elf_section_header_table(GElfFormat *);



/* -------------------------- DETAIL DES SYMBOLES INTERNES -------------------------- */


/* Charge tous les symboles internes possibles. */
static bool load_elf_internal_symbols(GElfFormat *);



/* -------------------------- DETAIL DES SYMBOLES EXTERNES -------------------------- */


/* Retrouve un élément donné dans la section dynamique. */
static bool find_elf_dynamic_item(const GElfFormat *, const elf_shdr *, int32_t, elf_dyn *);

/* Charge tous les éléments dynamiques externes possibles. */
static bool load_elf_external_symbols(GElfFormat *, const elf_shdr *);










/******************************************************************************
*                                                                             *
*  Paramètres  : format = description de l'exécutable à compléter.            *
*                                                                             *
*  Description : Charge en mémoire la liste humaine des symboles.             *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool load_elf_symbols(GElfFormat *format)
{
    bool result;                            /* Bilan à retourner           */
    elf_shdr *sections;                     /* Groupe de sections trouvées */
    size_t count;                           /* Quantité de données         */

    result = true;



    annotate_elf_header(format);

    annotate_elf_program_header_table(format);

    annotate_elf_section_header_table(format);



    /* Symboles internes */
    result = load_elf_internal_symbols(format);




    /* Symboles externes */

    if (find_elf_sections_by_type(format, SHT_DYNAMIC, &sections, &count))
    {
        log_variadic_message(LMT_INFO, _("Binary is dynamically linked"));

        result &= load_elf_external_symbols(format, &sections[0]);

        free(sections);

    }
    else log_variadic_message(LMT_INFO, _("Binary is statically linked"));

    /* Symboles internes */
    //result &= load_elf_internal_symbols(format);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : format = description de l'exécutable à consulter.            *
*                sym    = section comprenant les symboles à venir lire.       *
*                str    = section de chaînes de caractères pour les noms.     *
*                index  = indice de l'entrée à venir lire.                    *
*                                                                             *
*  Description : Récupère la désignation d'un symbole donné.                  *
*                                                                             *
*  Retour      : Nom du symbole trouvé, ou NULL si erreur ou non adapté.      *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

const char *get_elf_symbol_name(GElfFormat *format, const elf_shdr *sym, const elf_shdr *str, off_t index)
{
    const char *result;                     /* Résultat à retourner        */
    off_t sym_start;                        /* Début de section            */
    off_t sym_size;                         /* Taille de section           */
    off_t str_start;                        /* Début de section            */
    off_t str_size;                         /* Taille de section           */
    off_t offset;                           /* Emplacement à venir lire    */
    elf_sym symbol;                         /* Symbole aux infos visées    */

    result = NULL;

    get_elf_section_content(format, sym, &sym_start, &sym_size, NULL);
    get_elf_section_content(format, str, &str_start, &str_size, NULL);

    offset = sym_start + index * ELF_SIZEOF_SYM(format);
    if ((offset + ELF_SIZEOF_SYM(format)) > (sym_start + sym_size)) return NULL;

    if (read_elf_symbol(format, &offset, &symbol))
        result = extract_name_from_elf_string_section(format, str, ELF_SYM(format, symbol, st_name));

    return result;

}




/* ---------------------------------------------------------------------------------- */
/*                          CHARGEMENT DE SYMBOLES DU FORMAT                          */
/* ---------------------------------------------------------------------------------- */


/******************************************************************************
*                                                                             *
*  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   : -                                                            *
*                                                                             *
******************************************************************************/

static bool annotate_elf_header(GElfFormat *format)
{
    const bin_t *content;                   /* Contenu binaire à lire      */
    off_t length;                           /* Taille totale du contenu    */
    vmpa2t *pos;                            /* Localisation des symboles   */
    const char *text;                       /* Texte constant à insérer    */
    GArchInstruction *instr;                /* Instruction décodée         */
    GArchOperand *operand;                  /* Opérande à venir modifier   */
    GDbComment *comment;                    /* Définition de commentaire   */
    GBinSymbol *symbol;                     /* Symbole à intégrer          */

    content = G_BIN_FORMAT(format)->content;
    length = G_BIN_FORMAT(format)->length;

    pos = make_vmpa(0, 0x123);

    /* ELFMAG (0) */

    instr = g_raw_instruction_new_array(content, MDS_8_BITS, 4, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 1, IOD_CHAR);
    SET_IMM_DISPLAY(instr, operand, 2, IOD_CHAR);
    SET_IMM_DISPLAY(instr, operand, 3, IOD_CHAR);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("ELF magic number"));

    /* EI_CLASS (4) */

    switch (format->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;
    }

    instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, text);

    /* EI_DATA (5) */

    switch (format->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;
    }

    instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, text);

    /* EI_VERSION (6) */

    switch (format->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;
    }

    instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, text);

    /* EI_OSABI (7) */

    switch (format->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;
    }

    instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, text);

    /* EI_ABIVERSION (8) */

    instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("ABI version"));

    /* Padding */

    instr = g_raw_instruction_new_array(content, MDS_8_BITS, 7, pos, length, format->endian);

    g_raw_instruction_mark_as_padding(G_RAW_INSTRUCTION(instr), true);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Padding"));

    /* Champ "e_type" */

    switch (format->header.hdr32.e_ident[EI_DATA])
    {
        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;
    }

    instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, text);

    /* Champ "e_machine" */

    switch (format->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;
    }

    instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, text);

    /* Champ "e_version" */

    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, _("Object file version"));

    if (format->header.hdr32.e_ident[EI_CLASS] == ELFCLASS32)
    {
        /* Champ "e_entry" */

        instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);

        ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Entry point virtual address"));

        /* Champ "e_phoff" */

        instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);

        ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Program header table file offset"));

        /* Champ "e_shoff" */

        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 header table file offset"));

    }

    else if (format->header.hdr32.e_ident[EI_CLASS] == ELFCLASS64)
    {
        /* Champ "e_entry" */

        instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);

        ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Entry point virtual address"));

        /* Champ "e_phoff" */

        instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);

        ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Program header table file offset"));

        /* Champ "e_shoff" */

        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 header table file offset"));

    }

    else return false;

    /* Champ "e_flags" */

    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, _("Processor-specific flags"));

    /* Champ "e_ehsize" */

    instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("ELF header size in bytes"));

    /* Champ "e_phentsize" */

    instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Program header table entry size"));

    /* Champ "e_phnum" */

    instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Program header table entry count"));

    /* Champ "e_shentsize" */

    instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section header table entry size"));

    /* Champ "e_shnum" */

    instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section header table entry count"));

    /* Champ "e_shstrndx" */

    instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);

    SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);

    ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section header string table index"));

    return true;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : format = description de l'exécutable à compléter.            *
*                                                                             *
*  Description : Charge tous les symboles liés aux en-têtes de programme ELF. *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool annotate_elf_program_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 */
    vmpa2t *pos;                            /* Localisation des symboles   */
    uint16_t e_phnum;                       /* Nombre d'éléments 'Program' */
    uint16_t i;                             /* Boucle de parcours          */
    elf_phdr phdr;                          /* En-tête de programme ELF    */
    ImmOperandDisplay disp;                 /* Afficahge de valeur         */
    const char *text;                       /* Texte constant à insérer    */
    GArchInstruction *instr;                /* Instruction décodée         */
    GArchOperand *operand;                  /* Opérande à venir modifier   */
    GDbComment *comment;                    /* Définition de commentaire   */
    GBinSymbol *symbol;                     /* Symbole à intégrer          */
    char *dtext;                            /* Texte dynamique à créer     */
    bool filled;                            /* Suivi de mise en place      */

    content = G_BIN_FORMAT(format)->content;
    length = G_BIN_FORMAT(format)->length;

    offset = ELF_HDR(format, format->header, e_phoff);

    pos = make_vmpa(offset, 0x5500);

    e_phnum = ELF_HDR(format, format->header, e_phnum);

    for (i = 0; i < e_phnum; i++)
    {
        if (!read_elf_program_header(format, &offset, &phdr))
            break;

        /* Champ "p_type" */

        disp = IOD_DEC;

        switch (ELF_PHDR(format, phdr, p_type))
        {
            case PT_NULL:
                text = _("Segment type: unused");
                break;
            case PT_LOAD:
                text = _("Segment type: loadable program segment");
                break;
            case PT_DYNAMIC:
                text = _("Segment type: dynamic linking information");
                break;
            case PT_INTERP:
                text = _("Segment type: program interpreter");
                break;
            case PT_NOTE:
                text = _("Segment type: auxiliary information");
                break;
            case PT_SHLIB:
                text = _("Segment type: reserved");
                break;
            case PT_PHDR:
                text = _("Segment type: entry for header table itself");
                break;
            case PT_TLS:
                text = _("Segment type: thread-local storage segment");
                break;
            case PT_LOOS ... PT_HIOS:
                disp = IOD_HEX;
                switch (ELF_PHDR(format, phdr, p_type))
                {
                    case PT_GNU_EH_FRAME:
                        text = _("Segment type: GCC .eh_frame_hdr segment");
                        break;
                    case PT_GNU_STACK:
                        text = _("Segment type: indicates stack executability");
                        break;
                    case PT_GNU_RELRO:
                        text = _("Segment type: read-only after relocation");
                        break;
                    case PT_LOSUNW ... PT_HISUNW:
                        switch (ELF_PHDR(format, phdr, p_type))
                        {
                            case PT_SUNWSTACK:
                                text = _("Segment type: Sun Stack segment");
                                break;
                            default:
                                text = _("Segment type: Sun specific segment");
                                break;
                        }
                        break;
                    default:
                        text = _("Segment type: OS-specific");
                        break;
                }
                break;
            case PT_LOPROC ... PT_HIPROC:
                disp = IOD_HEX;
                text = _("Segment type: processor-specific");
                break;
            default:
                disp = IOD_HEX;
                text = _("Segment type: unknown");
                break;
        }

        instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);

        SET_IMM_DISPLAY(instr, operand, 0, disp);

        ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, text);

        if (format->is_32b)
        {
            /* Champ "p_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, _("Segment file offset"));

            /* Champ "p_vaddr" */

            instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);

            ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment virtual address"));

            /* Champ "p_paddr" */

            instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);

            ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment physical address"));

            /* Champ "p_filesz" */

            instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);

            ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment size in file"));

            /* Champ "p_memsz" */

            instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);

            ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment size in memory"));

            /* Champ "p_flags" */

            dtext = strdup(_("Segment flags: "));
            filled = false;

            if (ELF_PHDR(format, phdr, p_flags) & PF_R)
            {
                dtext = stradd(dtext, "R");
                filled = true;
            }

            if (ELF_PHDR(format, phdr, p_flags) & PF_W)
            {
                dtext = stradd(dtext, "W");
                filled = true;
            }

            if (ELF_PHDR(format, phdr, p_flags) & PF_X)
            {
                dtext = stradd(dtext, "X");
                filled = true;
            }

            if (ELF_PHDR(format, phdr, p_flags) & PF_MASKOS)
                /* TODO */;

            if (ELF_PHDR(format, phdr, p_flags) & PF_MASKPROC)
                /* TODO */;

            if (!filled)
                dtext = stradd(dtext, _("none"));

            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 "p_align" */

            instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);

            ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment alignment"));

        }
        else
        {
            /* Champ "p_flags" */

            dtext = strdup(_("Segment flags: "));
            filled = false;

            if (ELF_PHDR(format, phdr, p_flags) & PF_R)
            {
                dtext = stradd(dtext, "R");
                filled = true;
            }

            if (ELF_PHDR(format, phdr, p_flags) & PF_W)
            {
                dtext = stradd(dtext, "W");
                filled = true;
            }

            if (ELF_PHDR(format, phdr, p_flags) & PF_X)
            {
                dtext = stradd(dtext, "X");
                filled = true;
            }

            if (ELF_PHDR(format, phdr, p_flags) & PF_MASKOS)
                /* TODO */;

            if (ELF_PHDR(format, phdr, p_flags) & PF_MASKPROC)
                /* TODO */;

            if (!filled)
                dtext = stradd(dtext, _("none"));

            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 "p_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, _("Segment file offset"));

            /* Champ "p_vaddr" */

            instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);

            ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment virtual address"));

            /* Champ "p_paddr" */

            instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);

            ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment physical address"));

            /* Champ "p_filesz" */

            instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);

            ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment size in file"));

            /* Champ "p_memsz" */

            instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);

            ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment size in memory"));

            /* Champ "p_align" */

            instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);

            ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment alignment"));

        }

    }

    return true;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : format = description de l'exécutable à compléter.            *
*                                                                             *
*  Description : Charge tous les symboles liés aux en-têtes de section ELF.   *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

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         */
    GArchOperand *operand;                  /* Opérande à venir modifier   */
    GDbComment *comment;                    /* Définition de commentaire   */
    GBinSymbol *symbol;                     /* Symbole à intégrer          */
    char *dtext;                            /* Texte dynamique à créer     */
    bool filled;                            /* Suivi de mise en place      */

    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);

    e_shnum = ELF_HDR(format, format->header, e_shnum);

    for (i = 0; i < e_shnum; i++)
    {
        if (!read_elf_section_header(format, get_phy_addr(pos), &shdr))
            break;

        /* Champ "sh_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, dtext);

        free(dtext);

        /* Champ "sh_type" */

        disp = IOD_DEC;

        switch (ELF_SHDR(format, shdr, sh_type))
        {
            case SHT_NULL:
                text = _("Section type: unused");
                break;
            case SHT_PROGBITS:
                text = _("Section type: program data");
                break;
            case SHT_SYMTAB:
                text = _("Section type: symbol table");
                break;
            case SHT_STRTAB:
                text = _("Section type: string table");
                break;
            case SHT_RELA:
                text = _("Section type: relocation entries with addends");
                break;
            case SHT_HASH:
                text = _("Section type: symbol hash table");
                break;
            case SHT_DYNAMIC:
                text = _("Section type: dynamic linking information");
                break;
            case SHT_NOTE:
                text = _("Section type: notes");
                break;
            case SHT_NOBITS:
                text = _("Section type: program space with no data (bss)");
                break;
            case SHT_REL:
                text = _("Section type: relocation entries, no addends");
                break;
            case SHT_SHLIB:
                text = _("Section type: reserved");
                break;
            case SHT_DYNSYM:
                text = _("Section type: dynamic linker symbol table");
                break;
            case SHT_INIT_ARRAY:
                text = _("Section type: array of constructors");
                break;
            case SHT_FINI_ARRAY:
                text = _("Section type: array of destructors");
                break;
            case SHT_PREINIT_ARRAY:
                text = _("Section type: array of pre-constructors");
                break;
            case SHT_GROUP:
                text = _("Section type: section group");
                break;
            case SHT_SYMTAB_SHNDX:
                text = _("Section type: extended section indeces");
                break;
            case SHT_LOOS ... SHT_HIOS:
                disp = IOD_HEX;
                switch (ELF_SHDR(format, shdr, sh_type))
                {
                    case SHT_GNU_ATTRIBUTES:
                        text = _("Section type: object attributes");
                        break;
                    case SHT_GNU_HASH:
                        text = _("Section type: GNU-style hash table");
                        break;
                    case SHT_GNU_LIBLIST:
                        text = _("Section type: prelink library list");
                        break;
                    case SHT_CHECKSUM:
                        text = _("Section type: checksum for DSO content");
                        break;
                    case SHT_LOSUNW ... SHT_HISUNW:
                        switch (ELF_SHDR(format, shdr, sh_type))
                        {
                            case SHT_SUNW_move:
                                text = _("Section type: SHT_SUNW_move");
                                break;
                            case SHT_SUNW_COMDAT:
                                text = _("Section type: SHT_SUNW_COMDAT");
                                break;
                            case SHT_SUNW_syminfo:
                                text = _("Section type: SHT_SUNW_syminfo");
                                break;
                            case SHT_GNU_verdef:
                                text = _("Section type: version definition section");
                                break;
                            case SHT_GNU_verneed:
                                text = _("Section type: version needs section");
                                break;
                            case SHT_GNU_versym:
                                text = _("Section type: version symbol table");
                                break;
                            default:
                                text = _("Section type: Sun-specific");
                                break;
                        }
                        break;
                    default:
                        text = _("Section type: OS-specific");
                        break;
                }
                break;
            case SHT_LOPROC ... SHT_HIPROC:
                disp = IOD_HEX;
                text = _("Section type: processor-specific");
                break;
            case SHT_LOUSER ... SHT_HIUSER:
                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);

        SET_IMM_DISPLAY(instr, operand, 0, disp);

        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"));

        }

    }

    return true;

}



/* ---------------------------------------------------------------------------------- */
/*                            DETAIL DES SYMBOLES INTERNES                            */
/* ---------------------------------------------------------------------------------- */


/******************************************************************************
*                                                                             *
*  Paramètres  : format = description de l'exécutable à compléter.            *
*                                                                             *
*  Description : Charge tous les symboles internes possibles.                 *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool load_elf_internal_symbols(GElfFormat *format)
{
    bool result;                            /* Bilan à retourner           */
    bool no_name;                           /* Choix de construction de nom*/
    elf_shdr *sections;                      /* Groupe de sections trouvées */
    size_t count;                           /* Quantité de données         */
    size_t i;                               /* Boucle de parcours          */

    result = true;

    /* Charge tous les symboles définis dans une section */
    bool add_all_symbols_from_section(GElfFormat *format, const elf_shdr *section, bool use_virt)
    {
        elf_shdr strtab;                    /* Section .strtab trouvée     */
        bool has_strtab;                    /* Présence de cette section   */
        off_t start;                        /* Début de la zone à traiter  */
        off_t size;                         /* Taille de cette même zone   */
        off_t iter;                         /* Boucle de parcours          */
        elf_sym sym;                        /* Symbole aux infos visées    */
        vmpa2t addr;                        /* Localisation d'une routine  */
        mrange_t range;                     /* Couverture mémoire associée */
        const char *name;                   /* Nom du symbole trouvé       */
        char alt_name[5 + VMPA_MAX_LEN];    /* Nom abstrait de substitution*/
        GBinRoutine *routine;               /* Nouvelle routine trouvée    */
        GBinSymbol *symbol;                 /* Nouveau symbole construit   */

        has_strtab = find_elf_section_by_index(format, ELF_SHDR(format, *section, sh_link), &strtab);

        get_elf_section_content(format, section, &start, &size, NULL);

        for (iter = start; iter < (start + size); )
        {
            result = read_elf_symbol(format, &iter, &sym);
            if (!result) break;

            if (ELF_SYM(format, sym, st_value) == 0) continue;

            /* Résolution précise d'adresse */


            /* TODO */

            init_vmpa(&addr, ELF_SYM(format, sym, st_value), VMPA_NO_VIRTUAL);


            init_mrange(&range, &addr, ELF_SYM(format, sym, st_size));


            /* Première ébauche de nom */

            if (!has_strtab) name = NULL;
            else name = get_elf_symbol_name(format, section, &strtab,
                                            ((iter - start) / ELF_SIZEOF_SYM(format)) - 1);

            /* Traitements particuliers */

            switch (ELF_ST_TYPE(format, sym))
            {
                case STT_OBJECT:

                    /* Création d'un nom unique ? */

                    if (name != NULL)
                    {
                        strcpy(alt_name, "obj_");

                        if (use_virt)
                            vmpa2_virt_to_string(&addr, MDS_UNDEFINED, alt_name + 4, NULL);
                        else
                            vmpa2_phys_to_string(&addr, MDS_UNDEFINED, alt_name + 4, NULL);

                    }


                    /* TODO */

                    symbol = NULL;


                    break;

                case STT_FUNC:

                    /* Création d'un nom unique ? */

                    if (name != NULL)
                    {
                        strcpy(alt_name, "func_");

                        if (use_virt)
                            vmpa2_virt_to_string(&addr, MDS_UNDEFINED, alt_name + 5, NULL);
                        else
                            vmpa2_phys_to_string(&addr, MDS_UNDEFINED, alt_name + 5, NULL);

                    }

                    /* Routine */

                    routine = try_to_demangle_routine(name);

                    g_binary_routine_set_range(routine, &range);

                    /* Symbole uniquement */

                    symbol = g_binary_symbol_new(STP_ROUTINE, name, ~0);
                    g_binary_symbol_attach_routine(symbol, routine);

                    break;

                default:
                    symbol = NULL;
                    break;

            }

            if (symbol != NULL)
                g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);

        }

        return true;

    }

    if (!g_generic_config_get_value(get_main_configuration(), MPK_FORMAT_NO_NAME, &no_name))
        return false;

    if (find_elf_sections_by_type(format, SHT_DYNSYM, &sections, &count))
        for (i = 0; i < count && result; i++)
            result = add_all_symbols_from_section(format, &sections[i], no_name);

    if (find_elf_sections_by_type(format, SHT_SYMTAB, &sections, &count))
        for (i = 0; i < count && result; i++)
            result = add_all_symbols_from_section(format, &sections[i], no_name);

    return result;

}



/* ---------------------------------------------------------------------------------- */
/*                            DETAIL DES SYMBOLES EXTERNES                            */
/* ---------------------------------------------------------------------------------- */


/******************************************************************************
*                                                                             *
*  Paramètres  : format  = informations chargées à consulter.                 *
*                dynamic = section de type SHT_DYNAMIC.                       *
*                type    = sorte d'élément recherché.                         *
*                item    = élément retrouvé dans la section. [OUT]            *
*                                                                             *
*  Description : Retrouve un élément donné dans la section dynamique.         *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool find_elf_dynamic_item(const GElfFormat *format, const elf_shdr *section, int32_t type, elf_dyn *item)
{
    bool result;                            /* Bilan à retourner           */
    const bin_t *content;                   /* Contenu binaire à lire      */
    off_t length;                           /* Taille totale du contenu    */
    off_t pos;                              /* Position de lecture         */
    off_t tmp;                              /* Position écrasable          */
    int32_t tag32;                          /* Type de l'entrée (32 bits)  */
    int64_t tag64;                          /* Type de l'entrée (64 bits)  */

    result = true;

    content = G_BIN_FORMAT(format)->content;
    length = G_BIN_FORMAT(format)->length;

    for (pos = ELF_SHDR(format, *section, sh_offset);
         pos < length/* FIXME !! + xploit */ && result;
         pos += ELF_SIZEOF_DYN(format))
    {
        tmp = pos;

        if (format->is_32b)
        {
            result = read_s32(&tag32, content, &tmp, length, format->endian);
            if (tag32 == type) break;
        }
        else
        {
            result = read_s64(&tag64, content, &tmp, length, format->endian);
            if (tag64 == type) break;
        }

    }

    result &= (pos < length);

    if (result)
    {
        if (format->is_32b)
        {
            result = read_s32(&item->dyn32.d_tag, content, &pos, length, format->endian);
            result &= read_s32(&item->dyn32.d_un.d_val, content, &pos, length, format->endian);
        }
        else
        {
            result = read_s64(&item->dyn64.d_tag, content, &pos, length, format->endian);
            result &= read_s64(&item->dyn64.d_un.d_val, content, &pos, length, format->endian);
        }

    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : format  = informations chargées à consulter.                 *
*                dynamic = section de type SHT_DYNAMIC.                       *
*                                                                             *
*  Description : Charge tous les éléments dynamiques externes possibles.      *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool load_elf_external_symbols(GElfFormat *format, const elf_shdr *section)
{
    bool result;                            /* Bilan à retourner           */

    elf_dyn item;                           /* Elément dynamique           */
    elf_shdr relxxx;                        /* Section .rel.xxx trouvée    */
    elf_shdr dynsym;                        /* Section .dynsym trouvée     */
    elf_shdr dynstr;                        /* Section .dynstr trouvée     */
    elf_shdr plt;                           /* Section .plt trouvée        */

    result = true;






    /* Section .rel.plt */
    if (find_elf_dynamic_item(format, section, DT_JMPREL, &item))
    {
        result &= find_elf_section_by_virtual_address(format, ELF_DYN(format, item, d_un.d_ptr), &relxxx);

        if (result)
            result = find_elf_section_by_index(format, ELF_SHDR(format, relxxx, sh_link), &dynsym);

        if (result)
            result = find_elf_section_by_index(format, ELF_SHDR(format, dynsym, sh_link), &dynstr);

        if (result)
            switch (g_exe_format_get_target_machine(G_EXE_FORMAT(format)))
            {
                case FTM_386:
                    result = load_elf_x86_relocated_symbols(format, &relxxx, &dynsym, &dynstr);
                    break;

                default:
                    break;

            }

    }

    /* Entrées équivalentes dans le binaire */
    if (find_elf_dynamic_item(format, section, DT_SYMTAB, &item))
    {
        result &= find_elf_section_by_virtual_address(format, ELF_DYN(format, item, d_un.d_ptr), &dynsym);

        if (result)
            result = find_elf_section_by_index(format, ELF_SHDR(format, dynsym, sh_link), &dynstr);

        if (result)
            switch (g_exe_format_get_target_machine(G_EXE_FORMAT(format)))
            {
                case FTM_MIPS:
                    //result = find_elf_mips_dynamic_symbols(format, &dynsym, &dynstr);
                    break;

                case FTM_386:

                    if (find_elf_dynamic_item(format, section, DT_JMPREL, &item))
                    {
                        result &= find_elf_section_by_virtual_address(format, ELF_DYN(format, item, d_un.d_ptr), &relxxx);


                        printf("VMA :: 0x%08llx\n", ELF_DYN(format, item, d_un.d_ptr));



                        if (result)
                            result = find_elf_section_by_index(format, ELF_SHDR(format, relxxx, sh_info), &plt);

                        if (result)
                            result = find_elf_x86_dynamic_symbols(format, &plt, &relxxx, &dynsym, &dynstr);

                    }

                    break;

                default:
                    break;

            }

    }

    return result;

}