D
devesh.agrawal
Hi , this program does a segfault in g++3.2 onwards , works with
g++2.95 ,
Any ideas are welcome , basically there is this instruction when
compiled with -S option , call *%eax , where the one with 2.95 goes on
to execude the given machine code , whereas the one compiled in g++3.2
segfaults.
Also if you feel , this is not an appropriate group to post this , I
would be obliged if you could pardon me for the mistake and guide me to
a better group.
#include <iostream>
#include <string>
using namespace std;
typedef long (*fptr) (long, long);
void
write (string & str)
{
str += (char) 0x55;//push %ebp
str += (char) 0x8B;//mov %esp,%ebp
str += (char) 0xEC;
str += (char) 0x8B;//mov 8(%ebp),%eax
str += (char) 0x45;
str += (char) 0x08;
str += (char) 0x03;//add 12(%ebp),%eax
str += (char) 0x45;
str += (char) 0x0C;
str += (char) 0x5D;//pop %ebp
str += (char) 0xC3;//ret
}
main ()
{
fptr Func;
unsigned int val1, val2, retVal;
string str;
write (str);
Func = (fptr) str.c_str ();
val1 = 123456;
val2 = 654321;
retVal = Func (val1, val2);
cout << "Ans: " << retVal << endl;
return 0;
}
PS : CC the replies to me would be appreciated.
g++2.95 ,
Any ideas are welcome , basically there is this instruction when
compiled with -S option , call *%eax , where the one with 2.95 goes on
to execude the given machine code , whereas the one compiled in g++3.2
segfaults.
Also if you feel , this is not an appropriate group to post this , I
would be obliged if you could pardon me for the mistake and guide me to
a better group.
#include <iostream>
#include <string>
using namespace std;
typedef long (*fptr) (long, long);
void
write (string & str)
{
str += (char) 0x55;//push %ebp
str += (char) 0x8B;//mov %esp,%ebp
str += (char) 0xEC;
str += (char) 0x8B;//mov 8(%ebp),%eax
str += (char) 0x45;
str += (char) 0x08;
str += (char) 0x03;//add 12(%ebp),%eax
str += (char) 0x45;
str += (char) 0x0C;
str += (char) 0x5D;//pop %ebp
str += (char) 0xC3;//ret
}
main ()
{
fptr Func;
unsigned int val1, val2, retVal;
string str;
write (str);
Func = (fptr) str.c_str ();
val1 = 123456;
val2 = 654321;
retVal = Func (val1, val2);
cout << "Ans: " << retVal << endl;
return 0;
}
PS : CC the replies to me would be appreciated.