Counting the number of frames on the stack

To get started, I need to write a build function (Intel IA-32) that returns the contents of the caller's frame pointer. I don't think I'm doing it right, but what I came up with was

pushl %ebp movl %esp, %ebp movl %eax, 4(ebp) leave ret 

However, I have to use this in function c to count the number of frames on the stack, and I'm really not sure how this should work. Should I go to the value in the old ebp and then call the function again? Any guidance would be greatly appreciated.

+4
source share
1 answer

No, you don’t have to jump anywhere, but once you have copied a pointer to a local variable, you can think of it as a linked list.

  int mymagicfunction(int a, int b){ int *c = asm_copy_ebp(); int *d = c; while ( it_makes_sense ) { c=*c; dump_memory_between(c,d); d=c; } 

Perhaps this makes sense only when the distance between c and d is small.

+1
source

Source: https://habr.com/ru/post/1444419/


All Articles