objdump - Adressen von Variablen

  • Themenstarter Themenstarter caffeine
  • Beginndatum Beginndatum
C

caffeine

Guest
Hey Zusammen !

Ich hab hier ein Problem mit objdump. Ich hab ein Programm geschrieben in C, relativ sinnloses Programm, der Grund war der, dass ich mir darin die Adressen der Variablen hab ausgeben lassen um dann mit objdump zu prüfen, ob sie richtig sind.Leider bekomme ich auf beiden Seiten jeweils eine andere Ausgabe und die manage von objdump hilft mir irgendwie nicht weiter.

PHP:
#include <stdio.h>
#include <stdlib.h>

/*####################
	Globale Variablen
####################*/
int glblVar;
int glblVar2=0;
int glblVar3=1;

/*####################
	Globale Konstante
####################*/
const double glblConst=3.141592;

int main(int argc, char *argv[])
{
	/*Eigentliches Programm*/

	printf("\n#####TESTPROGRAMM GESTARTET!#####\n\nEs stehen folgende Werte zur Verfuegung:\n1.Globale Variable:%i\n2.Globale Variable:%i\n3.Globale Variable:%i\n4.Globale Konstante:%f\n",glblVar,glblVar2,glblVar3,glblConst);
	printf("\n#####FAKULTAETEN BERECHNEN...#####\n1.Globale Variable:%i\n2.Globale Variable:%i\n3.Globale Variable:%i\n",fak(glblVar),fak(glblVar2),fak(glblVar3));

	if(glblConst != (int) glblConst)
	{
		printf("4.Globale Konstante ist leider keine Ganzzahl!\n\n");
	}
	else
	{
		printf("4.Globale Variable:%i\n",fak(glblConst));
	}

	/*Addressen ausgeben*/
	printf("\n#####ADRESSEN AUSGEBEN...#####\n1.Globale Variable:%p\n2.Globale Variable:%p\n3.Globale Variable:%p\n4.Globale Konstante:%p\n\n\t[Das Programm wurde beendet]\n\n",&glblVar,&glblVar2,&glblVar3,&glblConst);

	return EXIT_SUCCESS;

}

/*####################
	Fakultaet Rechner
####################*/
int fak(int n)
{
    if(n == 0 || n == 1)
    {
	return 1;
    }
    else
    {
	return fak(n - 1) * n;
    }
}

Die Ausgabe des Programms ist diese:


#####TESTPROGRAMM GESTARTET!#####

Es stehen folgende Werte zur Verfuegung:
1.Globale Variable:0
2.Globale Variable:0
3.Globale Variable:1
4.Globale Konstante:3.141592

#####FAKULTAETEN BERECHNEN...#####
1.Globale Variable:1
2.Globale Variable:1
3.Globale Variable:1
4.Globale Konstante ist leider keine Ganzzahl!


#####ADRESSEN AUSGEBEN...#####
1.Globale Variable:0x804992c
2.Globale Variable:0x8049928
3.Globale Variable:0x804991c
4.Globale Konstante:0x8048610

[Das Programm wurde beendet]

Objdump sagt aber folgendes :

obj: file format elf32-i386

Sections:
Idx Name Size VMA LMA File off Algn
0 .interp 00000013 08048114 08048114 00000114 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .note.ABI-tag 00000020 08048128 08048128 00000128 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .note.gnu.build-id 00000024 08048148 08048148 00000148 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .hash 0000002c 0804816c 0804816c 0000016c 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .gnu.hash 00000020 08048198 08048198 00000198 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .dynsym 00000060 080481b8 080481b8 000001b8 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
6 .dynstr 00000051 08048218 08048218 00000218 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .gnu.version 0000000c 0804826a 0804826a 0000026a 2**1
CONTENTS, ALLOC, LOAD, READONLY, DATA
8 .gnu.version_r 00000020 08048278 08048278 00000278 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
9 .rel.dyn 00000008 08048298 08048298 00000298 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
10 .rel.plt 00000020 080482a0 080482a0 000002a0 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
11 .init 00000030 080482c0 080482c0 000002c0 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
12 .plt 00000050 080482f0 080482f0 000002f0 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
13 .text 000002ac 08048340 08048340 00000340 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
14 .fini 0000001c 080485ec 080485ec 000005ec 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
15 .rodata 00000202 08048608 08048608 00000608 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
16 .eh_frame 00000004 0804880c 0804880c 0000080c 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
17 .ctors 00000008 08049810 08049810 00000810 2**2
CONTENTS, ALLOC, LOAD, DATA
18 .dtors 00000008 08049818 08049818 00000818 2**2
CONTENTS, ALLOC, LOAD, DATA
19 .jcr 00000004 08049820 08049820 00000820 2**2
CONTENTS, ALLOC, LOAD, DATA
20 .dynamic 000000d0 08049824 08049824 00000824 2**2
CONTENTS, ALLOC, LOAD, DATA
21 .got 00000004 080498f4 080498f4 000008f4 2**2
CONTENTS, ALLOC, LOAD, DATA
22 .got.plt 0000001c 080498f8 080498f8 000008f8 2**2
CONTENTS, ALLOC, LOAD, DATA
23 .data 0000000c 08049914 08049914 00000914 2**2
CONTENTS, ALLOC, LOAD, DATA
24 .bss 00000010 08049920 08049920 00000920 2**2
ALLOC
25 .comment 0000001c 00000000 00000000 00000920 2**0
CONTENTS, READONLY

Hat jemand eine Idee wo das Problem liegt ?

Danke euch und frohes Neues, tanye
 
Ist es nicht unmöglich die Adresse einer Variable vor der Laufzeit zu bestimmen, da:

1. Der Speicher schon belegt sein könnte und
2. ASLR benutzt wird?

Grüße,
fee1dead
 
Ist es nicht unmöglich die Adresse einer Variable vor der Laufzeit zu bestimmen, da:

1. Der Speicher schon belegt sein könnte und
2. ASLR benutzt wird?

Grüße,
fee1dead

Also soweit ich weiß kann man mit objdump das vom Linker erstellte Speicherlayout des Programms analysieren und damit auch feststellen an welchen Adressen die Variablen im Programm platziert wurden.
 
Bei printf gibt der Parameter %p die absolute Adresse aus. Deshalb kann dieser sich auch ändern, wenn das Programm mehrmals ausgeführt wird.
Code:
#####ADRESSEN AUSGEBEN...#####
1.Globale Variable:0x99044
2.Globale Variable:0x99040
3.Globale Variable:0x9902c
4.Globale Konstante:0x98db8

#####ADRESSEN AUSGEBEN...#####
1.Globale Variable:0x2c044
2.Globale Variable:0x2c040
3.Globale Variable:0x2c02c
4.Globale Konstante:0x2bdb8

In den .o und ausführbaren Dateien stehen die relativen Adressen. nm kann man für die Ausgabe benutzen:
Code:
$nm test.o
[...]
00001d30 T _fak
00001db8 S _glblConst
00002044 S _glblVar
00002040 S _glblVar2
0000202c D _glblVar3
00001bc0 T _main

Zur Überprüfung:
Code:
$otool -tV test.o
[...]
_fak:
00001d30	pushl	%ebp
00001d31	movl	%esp,%ebp
00001d33	subl	$0x18,%esp
fak() fängt bei 0x1d30 an...

Grüße,
fee1dead
 
hi

mit objdump --syms scheint's bei mir zu funktionieren

Code:
#####TESTPROGRAMM GESTARTET!#####

Es stehen folgende Werte zur Verfuegung:
1.Globale Variable:0
2.Globale Variable:0
3.Globale Variable:1
4.Globale Konstante:3.141592

#####FAKULTAETEN BERECHNEN...#####
1.Globale Variable:1
2.Globale Variable:1
3.Globale Variable:1
4.Globale Konstante ist leider keine Ganzzahl!


#####ADRESSEN AUSGEBEN...#####
1.Globale Variable:0x801480
2.Globale Variable:0x601018
3.Globale Variable:0x60101c
4.Globale Konstante:0x500c78

    [Das Programm wurde beendet]


tes1:     file format elf64-x86-64

SYMBOL TABLE:
00000000004002e0 l    d  .interp    0000000000000000 
00000000004002f4 l    d  .note.openbsd.ident    0000000000000000 
0000000000400310 l    d  .hash    0000000000000000 
00000000004003a8 l    d  .dynsym    0000000000000000 
0000000000400558 l    d  .dynstr    0000000000000000 
0000000000400610 l    d  .rela.dyn    0000000000000000 
0000000000400670 l    d  .rela.plt    0000000000000000 
00000000004006f0 l    d  .init    0000000000000000 
0000000000400700 l    d  .plt    0000000000000000 
0000000000400760 l    d  .text    0000000000000000 
0000000000400a80 l    d  .fini    0000000000000000 
0000000000500a90 l    d  .rodata    0000000000000000 
0000000000500c88 l    d  .eh_frame_hdr    0000000000000000 
0000000000601000 l    d  .data    0000000000000000 
0000000000601020 l    d  .eh_frame    0000000000000000 
0000000000601158 l    d  .dynamic    0000000000000000 
0000000000601298 l    d  .jcr    0000000000000000 
00000000007012a0 l    d  .gotpad0    0000000000000000 
00000000007012a0 l    d  .got    0000000000000000 
0000000000701300 l    d  .ctors    0000000000000000 
0000000000701310 l    d  .dtors    0000000000000000 
0000000000701320 l    d  .gotpad1    0000000000000000 
0000000000801320 l    d  .bss    0000000000000000 
0000000000000000 l    d  *ABS*    0000000000000000 
0000000000000000 l    d  *ABS*    0000000000000000 
0000000000000000 l    d  *ABS*    0000000000000000 
0000000000000000 l    df *ABS*    0000000000000000 tes1.c
0000000000400710       F *UND*    00000000000000a6 printf
0000000000601018 g     O .data    0000000000000004 glblVar2
0000000000601158 g     O *ABS*    0000000000000000 _DYNAMIC
0000000000701320 g       .gotpad1    0000000000000000 __got_end
00000000004009b0 g     F .text    000000000000001f fak
0000000000400720       F *UND*    00000000000000f6 puts
0000000000601008 g     O .data    0000000000000008 .hidden __dso_handle
00000000004006f0 g     F .init    0000000000000000 __init
00000000007012a0 g       .gotpad0    0000000000000000 __got_start
0000000000801360 g     O .bss    0000000000000008 environ
0000000000400760 g       .text    0000000000000000 __start
000000000060101c g     O .data    0000000000000004 glblVar3
0000000000601000 g     O .data    0000000000000008 __progname
0000000000400760 g       .text    0000000000000000 _start
0000000000801320 g       *ABS*    0000000000000000 __bss_start
00000000004009d0 g     F .text    00000000000000a4 main
0000000000801380 g     O .bss    0000000000000100 __progname_storage
0000000000400730       F *UND*    0000000000000009 atexit
0000000000400a80 g     F .fini    0000000000000000 __fini
0000000000400790 g     F .text    00000000000000e2 ___start
0000000000801480 g     O .bss    0000000000000004 glblVar
0000000000801320 g       *ABS*    0000000000000000 _edata
00000000007012a0 g     O *ABS*    0000000000000000 _GLOBAL_OFFSET_TABLE_
0000000000801488 g       *ABS*    0000000000000000 _end
0000000000400740       F *UND*    0000000000000011 exit
0000000000500c78 g     O .rodata    0000000000000008 glblConst
0000000000601000 g       .data    0000000000000000 __data_start
0000000000000000  w      *UND*    0000000000000000 _Jv_RegisterClasses
0000000000400880  w    F .text    0000000000000006 __register_frame_info
 
hi

mit objdump --syms scheint's bei mir zu funktionieren

Code:
#####TESTPROGRAMM GESTARTET!#####

Es stehen folgende Werte zur Verfuegung:
1.Globale Variable:0
2.Globale Variable:0
3.Globale Variable:1
4.Globale Konstante:3.141592

#####FAKULTAETEN BERECHNEN...#####
1.Globale Variable:1
2.Globale Variable:1
3.Globale Variable:1
4.Globale Konstante ist leider keine Ganzzahl!


#####ADRESSEN AUSGEBEN...#####
1.Globale Variable:0x801480
2.Globale Variable:0x601018
3.Globale Variable:0x60101c
4.Globale Konstante:0x500c78

    [Das Programm wurde beendet]


tes1:     file format elf64-x86-64

SYMBOL TABLE:
00000000004002e0 l    d  .interp    0000000000000000 
00000000004002f4 l    d  .note.openbsd.ident    0000000000000000 
0000000000400310 l    d  .hash    0000000000000000 
00000000004003a8 l    d  .dynsym    0000000000000000 
0000000000400558 l    d  .dynstr    0000000000000000 
0000000000400610 l    d  .rela.dyn    0000000000000000 
0000000000400670 l    d  .rela.plt    0000000000000000 
00000000004006f0 l    d  .init    0000000000000000 
0000000000400700 l    d  .plt    0000000000000000 
0000000000400760 l    d  .text    0000000000000000 
0000000000400a80 l    d  .fini    0000000000000000 
0000000000500a90 l    d  .rodata    0000000000000000 
0000000000500c88 l    d  .eh_frame_hdr    0000000000000000 
0000000000601000 l    d  .data    0000000000000000 
0000000000601020 l    d  .eh_frame    0000000000000000 
0000000000601158 l    d  .dynamic    0000000000000000 
0000000000601298 l    d  .jcr    0000000000000000 
00000000007012a0 l    d  .gotpad0    0000000000000000 
00000000007012a0 l    d  .got    0000000000000000 
0000000000701300 l    d  .ctors    0000000000000000 
0000000000701310 l    d  .dtors    0000000000000000 
0000000000701320 l    d  .gotpad1    0000000000000000 
0000000000801320 l    d  .bss    0000000000000000 
0000000000000000 l    d  *ABS*    0000000000000000 
0000000000000000 l    d  *ABS*    0000000000000000 
0000000000000000 l    d  *ABS*    0000000000000000 
0000000000000000 l    df *ABS*    0000000000000000 tes1.c
0000000000400710       F *UND*    00000000000000a6 printf
0000000000601018 g     O .data    0000000000000004 glblVar2
0000000000601158 g     O *ABS*    0000000000000000 _DYNAMIC
0000000000701320 g       .gotpad1    0000000000000000 __got_end
00000000004009b0 g     F .text    000000000000001f fak
0000000000400720       F *UND*    00000000000000f6 puts
0000000000601008 g     O .data    0000000000000008 .hidden __dso_handle
00000000004006f0 g     F .init    0000000000000000 __init
00000000007012a0 g       .gotpad0    0000000000000000 __got_start
0000000000801360 g     O .bss    0000000000000008 environ
0000000000400760 g       .text    0000000000000000 __start
000000000060101c g     O .data    0000000000000004 glblVar3
0000000000601000 g     O .data    0000000000000008 __progname
0000000000400760 g       .text    0000000000000000 _start
0000000000801320 g       *ABS*    0000000000000000 __bss_start
00000000004009d0 g     F .text    00000000000000a4 main
0000000000801380 g     O .bss    0000000000000100 __progname_storage
0000000000400730       F *UND*    0000000000000009 atexit
0000000000400a80 g     F .fini    0000000000000000 __fini
0000000000400790 g     F .text    00000000000000e2 ___start
0000000000801480 g     O .bss    0000000000000004 glblVar
0000000000801320 g       *ABS*    0000000000000000 _edata
00000000007012a0 g     O *ABS*    0000000000000000 _GLOBAL_OFFSET_TABLE_
0000000000801488 g       *ABS*    0000000000000000 _end
0000000000400740       F *UND*    0000000000000011 exit
0000000000500c78 g     O .rodata    0000000000000008 glblConst
0000000000601000 g       .data    0000000000000000 __data_start
0000000000000000  w      *UND*    0000000000000000 _Jv_RegisterClasses
0000000000400880  w    F .text    0000000000000006 __register_frame_info

Danke dir ! Dabei hab ich die man page "gelesen" :D :thumb_up:
 
Zurück
Oben