gcc on linux :)<br><br>it seems that it prefers just "asm" over __asm__<br><br>so, compiling:<br><br><br>#include<stdio.h><br>unsigned long sp(void)<br>{<br> asm("movl %esp, %eax");<br>}<br><br>
void main(void)<br>{<br> printf("0x%x\n", sp());<br>}<br><br><br><br>returns:<br><br><br><br>tel0s@bufferoverflow:~$ cd Desktop/<br>tel0s@bufferoverflow:~/Desktop$ gcc -o sp sp.c<br>sp.c: In function ‘main’:<br>
sp.c:9: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘long unsigned int’<br>sp.c:8: warning: return type of ‘main’ is not ‘int’<br>tel0s@bufferoverflow:~/Desktop$ <br><br><br>changing main to int main() kills the last error it seems:<br>
<br>tel0s@bufferoverflow:~/Desktop$ gcc -o sp sp.c<br>sp.c: In function ‘main’:<br>sp.c:9: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘long unsigned int’<br>tel0s@bufferoverflow:~/Desktop$ <br>
<br><br><br>any ideas?<br><br><br><br><br><br><br><div class="gmail_quote">On Mon, Mar 23, 2009 at 7:50 AM, Robert Ladyman <span dir="ltr"><<a href="mailto:it@file-away.co.uk">it@file-away.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Which O/S, which compiler...and what's the compilation error?<br>
<br>
The call might be asm or __asm or __asm__ with curly brackets or<br>
whatever...the error will help.<br>
<div><div></div><div class="h5"><br>
<br>
<br>
On Sunday 22 March 2009 20:44:36 Nicholas Walker wrote:<br>
> Hi guys im doing some work with buffer overflows, and I've been scratching<br>
> my head for a while with this one. I have little experience in C, I can<br>
> read some source adn get a general idea of what each bit does, however i'm<br>
> required to grab the current address that the stack pointer is looking at.<br>
><br>
> I've been given this bit of source:<br>
><br>
><br>
><br>
><br>
><br>
> 3. The Stack Pointer<br>
> =================<br>
><br>
><br>
> Every program has a stack pointer which is the address of the<br>
> beginning of the stack. We can<br>
> find the stack pointer for a system using the following code:<br>
><br>
><br>
> unsigned long sp(void)<br>
> {<br>
> __asm__("movl %esp, %eax");<br>
> }<br>
><br>
> void main(void)<br>
> {<br>
> printf("0x%x\n", sp());<br>
> }<br>
><br>
><br>
> The function sp() contains the assembly instruction movl which copies<br>
> the value of the stack<br>
> pointer to the return buffer for the function, so it is returned to<br>
> the main function and<br>
> displayed.<br>
><br>
> $ ./sp<br>
><br>
> 0xbfbffbc8<br>
><br>
><br>
> however after adding the correct headers, it still wont compile....<br>
><br>
><br>
> I understand the Assembly language instruction, ESP holds the address of<br>
> where the stack pointer is currently pointing, movl esp eax moves it to the<br>
> eax register, for returning. If anyone could help it would be great. its<br>
> the last bit of work i need to do to finish my project.<br>
<br>
--<br>
<br>
</div></div>Robert Ladyman<br>
File-Away Limited, 32 Church Street, Newtyle<br>
Perthshire, PH12 8TZ SCOTLAND<br>
Registered in Scotland, Company Number SC222086<br>
Tel: +44 (0) 1828 898 158<br>
Mobile: +44 (0) 7732 771 649<br>
<a href="http://www.file-away.co.uk" target="_blank">http://www.file-away.co.uk</a><br>
<br>
<br>
_______________________________________________<br>
dundee GNU/Linux Users Group mailing list<br>
<a href="mailto:dundee@lists.lug.org.uk">dundee@lists.lug.org.uk</a> <a href="http://dundee.lug.org.uk" target="_blank">http://dundee.lug.org.uk</a><br>
<a href="https://mailman.lug.org.uk/mailman/listinfo/dundee" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/dundee</a><br>
Chat on IRC, #tlug on <a href="http://dundee.lug.org.uk" target="_blank">dundee.lug.org.uk</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><br><br>Nick Walker<br>Vice President : The Linux Society<br>UAD Ethical Hacker<br>