[dundee] Grabbing the stack pointer...
Robert Ladyman
it at file-away.co.uk
Mon Mar 23 07:51:00 UTC 2009
Which O/S, which compiler...and what's the compilation error?
The call might be asm or __asm or __asm__ with curly brackets or
whatever...the error will help.
On Sunday 22 March 2009 20:44:36 Nicholas Walker wrote:
> Hi guys im doing some work with buffer overflows, and I've been scratching
> my head for a while with this one. I have little experience in C, I can
> read some source adn get a general idea of what each bit does, however i'm
> required to grab the current address that the stack pointer is looking at.
>
> I've been given this bit of source:
>
>
>
>
>
> 3. The Stack Pointer
> =================
>
>
> Every program has a stack pointer which is the address of the
> beginning of the stack. We can
> find the stack pointer for a system using the following code:
>
>
> unsigned long sp(void)
> {
> __asm__("movl %esp, %eax");
> }
>
> void main(void)
> {
> printf("0x%x\n", sp());
> }
>
>
> The function sp() contains the assembly instruction movl which copies
> the value of the stack
> pointer to the return buffer for the function, so it is returned to
> the main function and
> displayed.
>
> $ ./sp
>
> 0xbfbffbc8
>
>
> however after adding the correct headers, it still wont compile....
>
>
> I understand the Assembly language instruction, ESP holds the address of
> where the stack pointer is currently pointing, movl esp eax moves it to the
> eax register, for returning. If anyone could help it would be great. its
> the last bit of work i need to do to finish my project.
--
Robert Ladyman
File-Away Limited, 32 Church Street, Newtyle
Perthshire, PH12 8TZ SCOTLAND
Registered in Scotland, Company Number SC222086
Tel: +44 (0) 1828 898 158
Mobile: +44 (0) 7732 771 649
http://www.file-away.co.uk
More information about the dundee
mailing list