Puisqu'il est ma première entrée sur le SO: bonjour à tout le monde :)Comment trouver un type de variable globale dans un fichier ELF?
maintenant à la bonne partie ... Je me bats pour trouver un type d'une variable globale à partir d'un fichier ELF. Mon code source avant la compilation ressemble à ceci:
#include "stdint.h"
uint8_t variable_global1;
uint8_t variable_global2 = 1;
uint8_t variable_global4;
uint16_t variable_global16b = 1;
int16_t variable_global16b8;
uint16_t variable_global16b9;
int main(void)
{
variable_global1 = 2;
static uint8_t variable_global3;
static uint8_t variable_global5 = 8;
static uint8_t variable_global6;
variable_global6 = 7;
variable_global16b9 = 500;
}
Lorsque je tente ma chance avec readelf ou objectdump c'est le plus que je reçois. Résultat de readelf -s LEKCJA2.elf
est:
Symbol table '.symtab' contains 72 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 SECTION LOCAL DEFAULT 1
2: 00800060 0 SECTION LOCAL DEFAULT 2
3: 00800064 0 SECTION LOCAL DEFAULT 3
4: 00000000 0 SECTION LOCAL DEFAULT 4
5: 00000000 0 SECTION LOCAL DEFAULT 5
6: 00000042 0 NOTYPE LOCAL DEFAULT 1 .do_copy_data_start
7: 0000003e 0 NOTYPE LOCAL DEFAULT 1 .do_copy_data_loop
8: 00000052 0 NOTYPE LOCAL DEFAULT 1 .do_clear_bss_start
9: 00000050 0 NOTYPE LOCAL DEFAULT 1 .do_clear_bss_loop
10: 00000000 0 FILE LOCAL DEFAULT ABS main.c
11: 0000003f 0 NOTYPE LOCAL DEFAULT ABS __SREG__
12: 0000003e 0 NOTYPE LOCAL DEFAULT ABS __SP_H__
13: 0000003d 0 NOTYPE LOCAL DEFAULT ABS __SP_L__
14: 00000034 0 NOTYPE LOCAL DEFAULT ABS __CCP__
15: 00000000 0 NOTYPE LOCAL DEFAULT ABS __tmp_reg__
16: 00000001 0 NOTYPE LOCAL DEFAULT ABS __zero_reg__
17: 00800064 1 OBJECT LOCAL DEFAULT 3 variable_global6.1217
18: 00800063 1 OBJECT LOCAL DEFAULT 2 variable_global5.1216
19: 00800065 1 OBJECT LOCAL DEFAULT 3 variable_global3.1215
20: 0000008a 0 NOTYPE LOCAL DEFAULT 1 __stop_program
21: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_1
22: 00000026 0 NOTYPE GLOBAL DEFAULT 1 __trampolines_start
23: 0000008c 0 NOTYPE GLOBAL DEFAULT 1 _etext
24: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_12
25: 0000005c 0 NOTYPE GLOBAL DEFAULT 1 __bad_interrupt
26: 00000090 0 NOTYPE GLOBAL DEFAULT ABS __data_load_end
27: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_6
28: 00000026 0 NOTYPE GLOBAL DEFAULT 1 __trampolines_end
29: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_3
30: 00800066 1 OBJECT GLOBAL DEFAULT 3 variable_global1
31: 0000008c 0 NOTYPE GLOBAL DEFAULT ABS __data_load_start
32: 00000026 0 NOTYPE GLOBAL DEFAULT 1 __dtors_end
33: 0080006c 0 NOTYPE GLOBAL DEFAULT 3 __bss_end
34: 00800067 2 OBJECT GLOBAL DEFAULT 3 variable_global16b9
35: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_11
36: 00000026 0 NOTYPE WEAK DEFAULT 1 __init
37: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_13
38: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_17
39: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_7
40: 00000048 0 NOTYPE GLOBAL DEFAULT 1 __do_clear_bss
41: 00810000 0 NOTYPE GLOBAL DEFAULT 4 __eeprom_end
42: 00000000 0 NOTYPE GLOBAL DEFAULT 1 __vectors
43: 00800064 0 NOTYPE GLOBAL DEFAULT 2 __data_end
44: 00000000 0 NOTYPE WEAK DEFAULT 1 __vector_default
45: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_5
46: 00000026 0 NOTYPE GLOBAL DEFAULT 1 __ctors_start
47: 00000032 0 NOTYPE GLOBAL DEFAULT 1 __do_copy_data
48: 00800064 0 NOTYPE GLOBAL DEFAULT 3 __bss_start
49: 0000005e 42 FUNC GLOBAL DEFAULT 1 main
50: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_4
51: 00000000 0 NOTYPE WEAK DEFAULT ABS __heap_end
52: 00800060 1 OBJECT GLOBAL DEFAULT 2 variable_global2
53: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_9
54: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_2
55: 00800061 2 OBJECT GLOBAL DEFAULT 2 variable_global16b
56: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_15
57: 00800069 1 OBJECT GLOBAL DEFAULT 3 variable_global4
58: 00000026 0 NOTYPE GLOBAL DEFAULT 1 __dtors_start
59: 00000026 0 NOTYPE GLOBAL DEFAULT 1 __ctors_end
60: 0000045f 0 NOTYPE WEAK DEFAULT ABS __stack
61: 00800064 0 NOTYPE GLOBAL DEFAULT 2 _edata
62: 0080006c 0 NOTYPE GLOBAL DEFAULT 4 _end
63: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_8
64: 0080006a 2 OBJECT GLOBAL DEFAULT 3 variable_global16b8
65: 00000088 0 NOTYPE WEAK DEFAULT 1 exit
66: 00000088 0 NOTYPE GLOBAL DEFAULT 1 _exit
67: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_14
68: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_10
69: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_16
70: 00800060 0 NOTYPE GLOBAL DEFAULT 2 __data_start
71: 0000005c 0 NOTYPE WEAK DEFAULT 1 __vector_18
Comme vous pouvez le voir, je peux énumérer mes variables globales (par exemple variable_global1
), je sais aussi sa taille dans la mémoire, mais malheureusement pas le type - que ce soit unsigned int, signé int, UBYTE et ainsi de suite.
Enfin ma question: Est-il même possible de trouver un type de variable globale (non initialisée ou initialisée) à partir d'un fichier ELF et si oui, comment pourrais-je faire cela? Pour l'instant je joue avec différents outils CMD et bibliothèques Python pour analyser les fichiers ELF, mais je ne peux pas me rapprocher de ce que j'essaie de faire.
Je vous remercie de tout ce que vous aider :)
Merci. J'ai compris cela et j'ai fini par analyser la décharge de DWARF. C'est toujours difficile et fastidieux en raison des exigences du projet, mais cela fonctionne. – tomly