Difference between revisions of "LU-LSP-b11:L08"
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
=== Praktiskais darbs #8 - steka satura analīze un piekļuve stekam. === |
=== Praktiskais darbs #8 - steka satura analīze un piekļuve stekam. === |
||
* [http://www.codeproject.com/KB/windows/CallStackTest/ |
* [http://www.codeproject.com/KB/windows/CallStackTest/StackLayout2.jpg Steka kadra uzbūve x86 arhitektūrā]. |
||
* Funkciju izsaukumu analīze. printf() lietošana steka satura izdrukai. |
* Funkciju izsaukumu analīze. printf() lietošana steka satura izdrukai. |
||
| Line 19: | Line 19: | ||
Šoreiz nekas nav jānodod. PD notiek interaktīvi. Drīkst arī strādāt pie MD4. |
Šoreiz nekas nav jānodod. PD notiek interaktīvi. Drīkst arī strādāt pie MD4. |
||
Atceraties, ka mājasdarbos asamblera kodu lietot nav paredzēts! |
|||
==== Parauga kods ==== |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
void **stackBottom; |
|||
void print(int *ip, char *c) |
|||
{ |
|||
void **head = &head; |
|||
int i; |
|||
while (head <= stackBottom) { |
|||
// for (i = 0; i < 10; i++) { |
|||
printf("%p: %p\n", head, *head); |
|||
head++; |
|||
} |
|||
} |
|||
void g(int *ip, char *c) |
|||
{ |
|||
int local = 0xcafe; |
|||
print(ip, c); |
|||
} |
|||
void f(int *ip, char *c) |
|||
{ |
|||
int local = 0xdeadbeef; |
|||
g(ip, c); |
|||
} |
|||
int main(void) |
|||
{ |
|||
int dummy; |
|||
stackBottom = &dummy; |
|||
int *i = 0x11111111; |
|||
char *c = 0x22222222; |
|||
f(i, c); |
|||
return 0; |
|||
} |
|||
Latest revision as of 18:24, 1 November 2011
Praktiskais darbs #8 - steka satura analīze un piekļuve stekam.
- Funkciju izsaukumu analīze. printf() lietošana steka satura izdrukai.
- objdump programma un tās lietošana koda analīzei.
- Funkciju "calling conventions". Atšķirības starp cdecl, stdcall, un citām.
- Piekļuve steka saturam caur inline asamblera kodu.
#define GET_EBP_VALUE(result) \
asm volatile("movl %%ebp, %0\n" : "=m" (result))
- Optimizācija un tās ietekme uz steka izskatu.
Iesūtīšana
Šoreiz nekas nav jānodod. PD notiek interaktīvi. Drīkst arī strādāt pie MD4.
Atceraties, ka mājasdarbos asamblera kodu lietot nav paredzēts!
Parauga kods
#include <stdio.h>
#include <stdlib.h>
void **stackBottom;
void print(int *ip, char *c)
{
void **head = &head;
int i;
while (head <= stackBottom) {
// for (i = 0; i < 10; i++) {
printf("%p: %p\n", head, *head);
head++;
}
}
void g(int *ip, char *c)
{
int local = 0xcafe;
print(ip, c);
}
void f(int *ip, char *c)
{
int local = 0xdeadbeef;
g(ip, c);
}
int main(void)
{
int dummy;
stackBottom = &dummy;
int *i = 0x11111111;
char *c = 0x22222222;
f(i, c);
return 0;
}