Maschinensprache ed

x86 g++ ed

Funktionsaufruf ed

langweilig

void a()
    ...
void b()
    a()

a():
push ebp            55
mov ebp, esp        89.e5
sub.b esp, 0x10     83.ec.10
...
leave               c9
ret                 c3

b():
push ebp            55
mov ebp, esp        89.e5
call ...            e8....
pop ebp             5d
ret                 c3

mit lokalen Variablen, Parametern

void f1(int a, int b)
	int sdf = a +b

void f2(int a)
	int bb = 3
	f1(a, 4)

f1():
push ebp                                         // 55
mov ebp, esp                                     // 89.e5
sub.b esp, 0x10                                  // 83.ec.10
mov eax, [ebp + 0x0c]                            // 8b.45.0c
mov edx, [ebp + 0x08]                            // 8b.55.08
lea eax, [edx + eax]                             // 8d.04.02     interessant...
mov [ebp + 0xfc], eax                            // 89.45.fc
leave                                            // c9
ret                                              // c3

f2():
push ebp                                         // 55
mov ebp, esp                                     // 89.e5
sub.b esp, 0x18                                  // 83.ec.18
mov [ebp + 0xfc], 0x00.00.00.03                  // c7.45.fc.03.00.00.00
mov [esp + 0x04], 0x00.00.00.04                  // c7.44.24.04.04.00.00.00
mov eax, [ebp + 0x08]                            // 8b.45.08
mov [esp], eax                                   // 89.04.24
call ...                                         // e8....
leave                                            // c9
ret                                              // c3

Rückgabewert > 4b

vector f1(int u)
	return e_x

void f2()
	vector a = f1()

f1():
push ebp                                         // 55
mov ebp, esp                                     // 89.e5
mov eax, [ebp + 0x08]                            // 8b.45.08
mov edx, [0x08.94.0f.c4]                         // 8b.15.c4.0f.94.08
mov [eax], edx                                   // 89.10
mov edx, [0x08.94.0f.c8]                         // 8b.15.c8.0f.94.08
mov [eax + 0x04], edx                            // 89.50.04
mov edx, [0x08.94.0f.cc]                         // 8b.15.cc.0f.94.08
mov [eax + 0x08], edx                            // 89.50.08
pop ebp                                          // 5d
ret 0x00.04                                      // c2.04.00

f2():
push ebp                                         // 55
mov ebp, esp                                     // 89.e5
sub.b esp, 0x18                                  // 83.ec.18
lea eax, [ebp + 0xf4]                            // 8d.45.f4
mov [esp + 0x04], 0x00.00.00.05                  // c7.44.24.04.05.00.00.00
mov [esp], eax                                   // 89.04.24
call 0xff.ff.ff.c3                               // e8.c3.ff.ff.ff
sub.b esp, 0x04                                  // 83.ec.04
leave                                            // c9
ret                                              // c3

Klassen-Funktion

class C
        int i
        vector f(int a)
                i += a
                return e_x
void ff()
        C c
        c.f(3)

C.f():
push ebp                                         // 55
mov ebp, esp                                     // 89.e5
mov eax, [ebp + 0x08]                            // 8b.45.08
mov edx, [ebp + 0x0c]                            // 8b.55.0c
mov edx, [edx]                                   // 8b.12
mov ecx, edx                                     // 89.d1
add ecx, [ebp + 0x10]                            // 03.4d.10
mov edx, [ebp + 0x0c]                            // 8b.55.0c
mov [edx], ecx                                   // 89.0a
mov edx, [0x08.94.0f.c4]                         // 8b.15.c4.0f.94.08
mov [eax], edx                                   // 89.10
mov edx, [0x08.94.0f.c8]                         // 8b.15.c8.0f.94.08
mov [eax + 0x04], edx                            // 89.50.04
mov edx, [0x08.94.0f.cc]                         // 8b.15.cc.0f.94.08
mov [eax + 0x08], edx                            // 89.50.08
pop ebp                                          // 5d
ret 0x00.04                                      // c2.04.00

ff():
push ebp                                         // 55
mov ebp, esp                                     // 89.e5
sub.b esp, 0x28                                  // 83.ec.28
lea eax, [ebp + 0xe8]                            // 8d.45.e8
mov [esp + 0x08], 0x00.00.00.03                  // c7.44.24.08.03.00.00.00
lea edx, [ebp + 0xf4]                            // 8d.55.f4
mov [esp + 0x04], edx                            // 89.54.24.04
mov [esp], eax                                   // 89.04.24
call 0x00.00.03.a2                               // e8.a2.03.00.00
sub.b esp, 0x04                                  // 83.ec.04
leave                                            // c9
ret                                              // c3

Stack ed

     normal           ret > 4           Klasse
ebp +
  16_  Param        16_  Param       16_  Param
  12_  Param        12_  Param       12_  Instanz
   8_  Param         8_  Return       8_  Return
   4_  eip'          4_  eip'         4_  eip'
   0_  ebp'          0_  ebp'         0_  ebp'
  -4_  Lokal        -4_  Lokal       -4_  Lokal
  -8_  Lokal        -8_  Lokal       -8_  Lokal

Caller

Callee

Caller

x86 Visual C++ ed

... beim Aufruf Return-Adresse und Klasseninstanz in unterschiedlicher Reihenfolge pushen

amd64 g++ ed

Funktionsaufruf ed

langweilig

void a()
    ...
void b()
    a()

a():
push ebp                                         // 55
mov rbp, rsp                                     // 48.89.e5
...
leave                                            // c9
ret                                              // c3

b():
push ebp                                         // 55
mov rbp, rsp                                     // 48.89.e5
call 0xff.ff.ff.ea                               // e8.ea.ff.ff.ff
leave                                            // c9
ret                                              // c3

mit lokalen Variablen, Parametern

void f1(int a, int b)
	int sdf = a +b

void f2(int a)
	int bb = 3
	f1(a, 4)

f1():
push ebp                                         // 55
mov rbp, rsp                                     // 48.89.e5
mov [ebp + 0xec], edi                            // 89.7d.ec
mov [ebp + 0xe8], esi                            // 89.75.e8
mov eax, [ebp + 0xe8]                            // 8b.45.e8
mov edx, [ebp + 0xec]                            // 8b.55.ec
lea eax, [edx + eax]                             // 8d.04.02
mov [ebp + 0xfc], eax                            // 89.45.fc
leave                                            // c9
ret                                              // c3

f2():
push ebp                                         // 55
mov rbp, rsp                                     // 48.89.e5
sub.b rsp, 0x18                                  // 48.83.ec.18
mov [ebp + 0xec], edi                            // 89.7d.ec
mov [ebp + 0xfc], 0x00.00.00.03                  // c7.45.fc.03.00.00.00
mov eax, [ebp + 0xec]                            // 8b.45.ec
mov esi, 0x00.00.00.04                           // be.04.00.00.00
mov edi, eax                                     // 89.c7
call 0xff.ff.ff.c7                               // e8.c7.ff.ff.ff
leave                                            // c9
ret                                              // c3

Rückgabewert > 4b

vector f1()
	return e_x

void f2()
	vector a = f1()

f1():
push ebp                                         // 55
dec eax                                          // 48
mov ebp, esp                                     // 89.e5
dec eax                                          // 48
mov eax, [0x00.a2.1e.1d]                         // 8b.05.1d.1e.a2.00
dec eax                                          // 48
mov [ebp + 0xf0], eax                            // 89.45.f0
mov eax, [0x00.a2.1e.1b]                         // 8b.05.1b.1e.a2.00
mov [ebp + 0xf8], eax                            // 89.45.f8
dec eax                                          // 48
mov edx, [ebp + 0xf0]                            // 8b.55.f0
mov eax, [ebp + 0xf8]                            // 8b.45.f8
dec eax                                          // 48
mov [ebp + 0xd8], edx                            // 89.55.d8
rep                                              // f3
????? -                          unknown         // 0f
jle.b 0x45                                       // 7e.45
fmul [ecx + 0x0f.f3.d4.45]                       // d8.89.45.d4.f3.0f
adc.b [ebp + 0xd4], cl                           // 10.4d.d4
leave                                            // c9
ret                                              // c3

f2():
push ebp                                         // 55
dec eax                                          // 48
mov ebp, esp                                     // 89.e5
dec eax                                          // 48
sub.b esp, 0x20                                  // 83.ec.20
call 0xff.ff.ff.c1                               // e8.c1.ff.ff.ff
????? -                          unknown         // 66.0f
????? -                          unknown         // 6f
????? -                          unknown         // d0
????? -                          unknown         // 0f
sub.b cl, al                                     // 28.c1
????? -                          unknown         // 66.0f
????? -                          unknown         // d6
push ebp                                         // 55
loopne 0xf3                                      // e0.f3
????? -                          unknown         // 0f
adc [ebp + 0xe8], eax                            // 11.45.e8
dec eax                                          // 48
mov eax, [ebp + 0xe0]                            // 8b.45.e0
dec eax                                          // 48
mov [ebp + 0xf0], eax                            // 89.45.f0
mov eax, [ebp + 0xe8]                            // 8b.45.e8
mov [ebp + 0xf8], eax                            // 89.45.f8
leave                                            // c9
ret                                              // c3

Categories: Computer, Programmieren