writting a stack tracer?
Posted: Sat Mar 03, 2012 6:16 pm
I know most c/c++ functions gets put on the stack or at least when you call them.
Usually call func equals to a push return address , jmp to func.
Usually code does it by Enter which is equivalent to push ebp/bp , mov ebp/bp , esp/sp , sub esp/sp number of bytes to top or add esp/sp n if it grows the other way. ( determine by a bit in the GDT or selector)
I can get the begining of the whole stack by ss selector address but my problem is a few things
1) I can look for the machine code for ENTER and LEAVE ( ENTER imm,imm ; C8 iw ib , LEAVE ; C9) on the stack
But how can I get the names of the functions corrosponding to these stack entries if their is no symbol table ?
2) Typically does OS like linux or windows have a different stack for each program. For example if I can get the begining of the stack will it corrospond to the begining of my program I am analysising, or do the typical OS's (like ms,linux) use the same stack for multiple programs?
The main problem is if it is not the beging of my programming stack then I don't know a way to get the begining of my programming stack or to tell the difference between the other programs using the stacks functions.
If the begining of the ss corrosponds to my programs begining of the stack that would imply the first ENTER machine code I see would be the first function call that my program used.(i.e the first function that the program called after the loader loads and jumps to the starting address)
Anybody know more about how to analysis the stack or write a stack tracer.
I know this thread could cause confusion because I am looking at it from 2 aspects. One I want to know from a program runing under an OS like linux/windows.... and the other way of looking at it is if I was to do a stack tracer with no OS my own in ring 0 with no ntloader type of program as a middle man.
Usually call func equals to a push return address , jmp to func.
Usually code does it by Enter which is equivalent to push ebp/bp , mov ebp/bp , esp/sp , sub esp/sp number of bytes to top or add esp/sp n if it grows the other way. ( determine by a bit in the GDT or selector)
I can get the begining of the whole stack by ss selector address but my problem is a few things
1) I can look for the machine code for ENTER and LEAVE ( ENTER imm,imm ; C8 iw ib , LEAVE ; C9) on the stack
But how can I get the names of the functions corrosponding to these stack entries if their is no symbol table ?
2) Typically does OS like linux or windows have a different stack for each program. For example if I can get the begining of the stack will it corrospond to the begining of my program I am analysising, or do the typical OS's (like ms,linux) use the same stack for multiple programs?
The main problem is if it is not the beging of my programming stack then I don't know a way to get the begining of my programming stack or to tell the difference between the other programs using the stacks functions.
If the begining of the ss corrosponds to my programs begining of the stack that would imply the first ENTER machine code I see would be the first function call that my program used.(i.e the first function that the program called after the loader loads and jumps to the starting address)
Anybody know more about how to analysis the stack or write a stack tracer.
I know this thread could cause confusion because I am looking at it from 2 aspects. One I want to know from a program runing under an OS like linux/windows.... and the other way of looking at it is if I was to do a stack tracer with no OS my own in ring 0 with no ntloader type of program as a middle man.