448,538 Members | 875 Online
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

How this function call works???

 P: n/a could some body help me what's happening here... thanks.. char sc[] = "\x31\xc0" /* xor %eax, %eax */ "\x50" /* push %eax */ "\x68\x2f\x2f\x73\x68" /* push \$0x68732f2f */ "\x68\x2f\x62\x69\x6e" /* push \$0x6e69622f */ "\x89\xe3" /* mov %esp,%ebx */ "\x50" /* push %eax */ "\x53" /* push %ebx */ "\x89\xe1" /* mov %esp,%ecx */ "\x31\xd2" /* xor %edx,%edx */ "\xb0\x0b" /* mov \$0xb,%al */ "\xcd\x80"; /* int \$0x80 */ main() { void (*fp) (void); // what is happening at this line fp = (void *)sc; fp(); } -- A day spent without Linux is a day spent without learning! -- Java Böy --- Posted via news://freenews.netfront.net Complaints to ne**@netfront.net Nov 13 '05 #1
25 Replies

 P: n/a "Java Böy" wrote: could some body help me what's happening here... char sc[] = "\x31\xc0" /* xor %eax, %eax */ [...] "\xcd\x80"; /* int \$0x80 */ main() { void (*fp) (void); // what is happening at this line This line declares the variable fp as an pointer to an function of void which returns void. fp = (void *)sc; fp(); } Let me give you an example (hopefully) easier to understand: #include void foo(void) { printf("Hallo Welt\n"); } int main(void) { void (*f)(void); // declare a pointer to a function f = foo; // assign the address of foo to the pointer f f(); // call the function f points to -> foo return 0; } The additional problem with the program given by you is that the function is not declared as one, but as a array of chars char sc[] =... This array is initialized with some 80x86 assembler hexcodes which end int some linux kernel call I don't know... Hopefully it will terminate the program for there is no return instruction in the function. BTW: main doesn't need to be a function either :) long long main = 0xC300000000B8; // int main(void) { return 0; } Nov 13 '05 #2

 P: n/a On Fri, 1 Aug 2003 01:27:26 +0500, "Java Böy" wrote in comp.lang.c: could some body help me what's happening here... thanks.. char sc[] = "\x31\xc0" /* xor %eax, %eax */ "\x50" /* push %eax */ "\x68\x2f\x2f\x73\x68" /* push \$0x68732f2f */ "\x68\x2f\x62\x69\x6e" /* push \$0x6e69622f */ "\x89\xe3" /* mov %esp,%ebx */ "\x50" /* push %eax */ "\x53" /* push %ebx */ "\x89\xe1" /* mov %esp,%ecx */ "\x31\xd2" /* xor %edx,%edx */ "\xb0\x0b" /* mov \$0xb,%al */ "\xcd\x80"; /* int \$0x80 */ main() The current C standard requires that main() be defined with a return type of int. { void (*fp) (void); // what is happening at this line Defines fp to be a pointer to a function that takes no arguments and returns nothing. fp = (void *)sc; This is undefined behavior. There is no cast from pointer to char to pointer to function of any kind defined in C. At this point you do not have a C program anymore. fp(); } Whatever happens when you attempt to call an array of characters via a pointer to a function has nothing to do with C. On many platforms it will just plain crash. If you want to find out what someone expected it to do on one particular compiler, you might try asking in a group that discusses that particular compiler. As far as the C language is concerned, anything that happens during or after the assignment of the array to the function pointer is just as correct or incorrect as anything else. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq Nov 13 '05 #3

 P: n/a On Thu, 31 Jul 2003 22:42:57 +0200, Jens Schicke wrote in comp.lang.c: "Java Böy" wrote: could some body help me what's happening here... char sc[] = "\x31\xc0" /* xor %eax, %eax */ [...] "\xcd\x80"; /* int \$0x80 */ main() { void (*fp) (void); // what is happening at this line This line declares the variable fp as an pointer to an function of void which returns void. fp = (void *)sc; fp(); } Let me give you an example (hopefully) easier to understand: #include void foo(void) { printf("Hallo Welt\n"); } int main(void) { void (*f)(void); // declare a pointer to a function f = foo; // assign the address of foo to the pointer f f(); // call the function f points to -> foo return 0; } The additional problem with the program given by you is that the function is not declared as one, but as a array of chars char sc[] =... This array is initialized with some 80x86 assembler hexcodes which end int some linux kernel call I don't know... Hopefully it will terminate the program for there is no return instruction in the function. BTW: main doesn't need to be a function either :) We discuss the C language here. If you want to spout bullsh*t, go somewhere else. long long main = 0xC300000000B8; // int main(void) { return 0; } If you think the above is C, you are brain-damaged. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq Nov 13 '05 #4

 P: n/a In "Jeff" writes: "Java Böy" wrote in message news:bg**********@adenine.netfront.net... could some body help me what's happening here... thanks.. char sc[] = "\x31\xc0" /* xor %eax, %eax */ "\x50" /* push %eax */ "\x68\x2f\x2f\x73\x68" /* push \$0x68732f2f */ "\x68\x2f\x62\x69\x6e" /* push \$0x6e69622f */ "\x89\xe3" /* mov %esp,%ebx */ "\x50" /* push %eax */ "\x53" /* push %ebx */ "\x89\xe1" /* mov %esp,%ecx */ "\x31\xd2" /* xor %edx,%edx */ "\xb0\x0b" /* mov \$0xb,%al */ "\xcd\x80"; /* int \$0x80 */ main() { void (*fp) (void); // what is happening at this line fp = (void *)sc; fp(); }Just for your information, I think your code (including the assembly part) *is not illegal* in C,in factFrom ISO/IEC 9899:1999------------------------------------- J.5.7 Function pointer casts Do you have the slightest clue about the connection between J.5 and the normative part of the C99 standard? 1 A pointer to an object or to void may be cast to a pointer to a function, allowing data tobe invoked as a function (6.5.4). Where can you see such a cast in the OP's code? Are you visually impaired or merely a patent idiot? From line 1 "allowing data to be invoked as a function" What about it? And what about the following quote from the *normative* part of the same standard: 6.5.16.1 Simple assignment Constraints 1 One of the following shall hold:93) - the left operand has qualified or unqualified arithmetic type and the right has arithmetic type; - the left operand has a qualified or unqualified version of a structure or union type compatible with the type of the right; - both operands are pointers to qualified or unqualified versions of compatible types, and the type pointed to by the left has all the qualifiers of the type pointed to by the right; - one operand is a pointer to an object or incomplete type and the other is a pointer to a qualified or unqualified version of void, and the type pointed to by the left has all the qualifiers of the type pointed to by the right; - the left operand is a pointer and the right is a null pointer constant; or - the left operand has type _Bool and the right is a pointer. Which of these alternatives is matched by fp = (void *)sc; ? Any idea about what happens when a constraint is violated? If the line in question was: fp = (void(*)(void))sc; /* no 6.5.16.1 constraint violation */ the code would have invoked undefined behaviour and the quote from J.5.7 would have explained why such code *may* work on *certain* implementations (still without giving it *any* legitimation). It doesn't hurt to get a clue before posting irrelevant quotes from the standard! Dan -- Dan Pop DESY Zeuthen, RZ group Email: Da*****@ifh.de Nov 13 '05 #5

 P: n/a "Dan Pop" wrote in message news:bg**********@sunnews.cern.ch... In "Jeff" writes:"Java Böy" wrote in message news:bg**********@adenine.netfront.net... could some body help me what's happening here... thanks.. char sc[] = "\x31\xc0" /* xor %eax, %eax */ "\x50" /* push %eax */ "\x68\x2f\x2f\x73\x68" /* push \$0x68732f2f */ "\x68\x2f\x62\x69\x6e" /* push \$0x6e69622f */ "\x89\xe3" /* mov %esp,%ebx */ "\x50" /* push %eax */ "\x53" /* push %ebx */ "\x89\xe1" /* mov %esp,%ecx */ "\x31\xd2" /* xor %edx,%edx */ "\xb0\x0b" /* mov \$0xb,%al */ "\xcd\x80"; /* int \$0x80 */ main() { void (*fp) (void); // what is happening at this line fp = (void *)sc; fp(); }Just for your information, I think your code (including the assembly part) *is not illegal* in C,in factFrom ISO/IEC 9899:1999------------------------------------- J.5.7 Function pointer casts Do you have the slightest clue about the connection between J.5 and the normative part of the C99 standard?1 A pointer to an object or to void may be cast to a pointer to a function, allowing data tobe invoked as a function (6.5.4). Where can you see such a cast in the OP's code? Are you visually impaired or merely a patent idiot?From line 1 "allowing data to be invoked as a function" What about it? And what about the following quote from the *normative* part of the same standard: 6.5.16.1 Simple assignment Constraints 1 One of the following shall hold:93) - the left operand has qualified or unqualified arithmetic type and the right has arithmetic type; - the left operand has a qualified or unqualified version of a structure or union type compatible with the type of the right; - both operands are pointers to qualified or unqualified versions of compatible types, and the type pointed to by the left has all the qualifiers of the type pointed to by the right; - one operand is a pointer to an object or incomplete type and the other is a pointer to a qualified or unqualified version of void, and the type pointed to by the left has all the qualifiers of the type pointed to by the right; - the left operand is a pointer and the right is a null pointer constant; or - the left operand has type _Bool and the right is a pointer. Which of these alternatives is matched by fp = (void *)sc; ? Any idea about what happens when a constraint is violated? If the line in question was: fp = (void(*)(void))sc; /* no 6.5.16.1 constraint violation */ the code would have invoked undefined behaviour and the quote from J.5.7 would have explained why such code *may* work on *certain* implementations (still without giving it *any* legitimation). It doesn't hurt to get a clue before posting irrelevant quotes from the standard! Dan -- Dan Pop DESY Zeuthen, RZ group Email: Da*****@ifh.de I understand what is the problem. Thank you for your explanation. -- Jeff Nov 13 '05 #6

 P: n/a # In "Java BÃ¶y" writes: # # # could some body help me what's happening here... # # char sc[] = # "\x31\xc0" /* xor %eax, %eax */ # "\x50" /* push %eax */ # "\x68\x2f\x2f\x73\x68" /* push \$0x68732f2f */ # "\x68\x2f\x62\x69\x6e" /* push \$0x6e69622f */ # "\x89\xe3" /* mov %esp,%ebx */ # "\x50" /* push %eax */ # "\x53" /* push %ebx */ # "\x89\xe1" /* mov %esp,%ecx */ # "\x31\xd2" /* xor %edx,%edx */ # "\xb0\x0b" /* mov \$0xb,%al */ # "\xcd\x80"; /* int \$0x80 */ # # main() # { # void (*fp) (void); // what is happening at this line # # fp = (void *)sc; # fp(); # } It's a hand-coded system or bios interrupt call. You can probably get more information about the call from an intel newsgroup. Rather than use some kind 'asm' insert or separate assembly file, someone figured out all the opcodes and inserted them into the char array. The data pointer to this is forced into a code pointer and then the code is executed with a function call mechanism. The code is, of course, machine specific. And to some degree so is converting a data pointer to a code pointer: on some machines they are very different creatures. -- Derk Gwen http://derkgwen.250free.com/html/index.html What kind of convenience store do you run here? Nov 13 '05 #7

 P: n/a In article , Derk Gwen wrote:It's a hand-coded system or bios interrupt call. You can probablyget more information about the call from an intel newsgroup. ...The code is, of course, machine specific. And to some degree sois converting a data pointer to a code pointer: on some machinesthey are very different creatures. Oddly enough, one of those machines is the very machine for which it is written: the Intel IA32. If the CPU's registers were set up so as to deter certain forms of viruses, the code would not work at all. Fortunately for the original author, however, most people prefer to get the wrong answer as fast as possible. :-) -- In-Real-Life: Chris Torek, Wind River Systems (BSD engineering) Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: forget about it http://67.40.109.61/torek/index.html (for the moment) Reading email is like searching for food in the garbage, thanks to spammers. Nov 13 '05 #8

 P: n/a Why is everyone in these newsgroups so friggin nasty and mean? This is why usenet has gone to crap and it is now virtually useless as a mechanism for a newby to get any kind of help. "Dan Pop" wrote in message news:bg**********@sunnews.cern.ch... In "Jeff" writes:"Java Böy" wrote in message news:bg**********@adenine.netfront.net... could some body help me what's happening here... thanks.. char sc[] = "\x31\xc0" /* xor %eax, %eax */ "\x50" /* push %eax */ "\x68\x2f\x2f\x73\x68" /* push \$0x68732f2f */ "\x68\x2f\x62\x69\x6e" /* push \$0x6e69622f */ "\x89\xe3" /* mov %esp,%ebx */ "\x50" /* push %eax */ "\x53" /* push %ebx */ "\x89\xe1" /* mov %esp,%ecx */ "\x31\xd2" /* xor %edx,%edx */ "\xb0\x0b" /* mov \$0xb,%al */ "\xcd\x80"; /* int \$0x80 */ main() { void (*fp) (void); // what is happening at this line fp = (void *)sc; fp(); }Just for your information, I think your code (including the assembly part) *is not illegal* in C,in factFrom ISO/IEC 9899:1999------------------------------------- J.5.7 Function pointer casts Do you have the slightest clue about the connection between J.5 and the normative part of the C99 standard?1 A pointer to an object or to void may be cast to a pointer to a function, allowing data tobe invoked as a function (6.5.4). Where can you see such a cast in the OP's code? Are you visually impaired or merely a patent idiot?From line 1 "allowing data to be invoked as a function" What about it? And what about the following quote from the *normative* part of the same standard: 6.5.16.1 Simple assignment Constraints 1 One of the following shall hold:93) - the left operand has qualified or unqualified arithmetic type and the right has arithmetic type; - the left operand has a qualified or unqualified version of a structure or union type compatible with the type of the right; - both operands are pointers to qualified or unqualified versions of compatible types, and the type pointed to by the left has all the qualifiers of the type pointed to by the right; - one operand is a pointer to an object or incomplete type and the other is a pointer to a qualified or unqualified version of void, and the type pointed to by the left has all the qualifiers of the type pointed to by the right; - the left operand is a pointer and the right is a null pointer constant; or - the left operand has type _Bool and the right is a pointer. Which of these alternatives is matched by fp = (void *)sc; ? Any idea about what happens when a constraint is violated? If the line in question was: fp = (void(*)(void))sc; /* no 6.5.16.1 constraint violation */ the code would have invoked undefined behaviour and the quote from J.5.7 would have explained why such code *may* work on *certain* implementations (still without giving it *any* legitimation). It doesn't hurt to get a clue before posting irrelevant quotes from the standard! Dan -- Dan Pop DESY Zeuthen, RZ group Email: Da*****@ifh.de Nov 13 '05 #9

 P: n/a Xenos scribbled the following: Why is everyone in these newsgroups so friggin nasty and mean? This is why usenet has gone to crap and it is now virtually useless as a mechanism for a newby to get any kind of help. 1) That's Dan Pop. He's the nastiest guy around here. We others are a little friendlier. A *little*. 2) Don't top-post, please. And try to trim quotes. 3) We have to be nasty sometimes to preserve proper topicality. "Dan Pop" wrote in message news:bg**********@sunnews.cern.ch... (snip a very long bit of text that Xenos didn't bother to comment on, but felt it was worth it to include nonetheless) It doesn't hurt to get a clue before posting irrelevant quotes from the standard! (snip Dan Pop's signature, which is merely superfluous baggage in quoted replies) -- /-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\ | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++| | http://www.helsinki.fi/~palaste W++ B OP+ | \----------------------------------------- Finland rules! ------------/ "That's no raisin - it's an ALIEN!" - Tourist in MTV's Oddities Nov 13 '05 #10

 P: n/a Joona I Palaste wrote: 3) We have to be nasty sometimes to preserve proper topicality. You don't feel it's possible to preserve topicality pleasantly? -- |_ CJSonnack _____________| How's my programming? | |_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL | |_____________________________________________|___ ____________________| Nov 13 '05 #11

 P: n/a Programmer Dude scribbled the following: Joona I Palaste wrote: 3) We have to be nasty sometimes to preserve proper topicality. You don't feel it's possible to preserve topicality pleasantly? I did say "sometimes". -- /-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\ | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++| | http://www.helsinki.fi/~palaste W++ B OP+ | \----------------------------------------- Finland rules! ------------/ "As we all know, the hardware for the PC is great, but the software sucks." - Petro Tyschtschenko Nov 13 '05 #12

 P: n/a Xenos wrote: [WRT one of Dab Pop's replies] Why is everyone in these newsgroups so friggin nasty and mean? Why is the sun made of green cheese? Not everyone here is "friggin nasty and mean", despite the temptations. This is why usenet has gone to crap and it is now virtually useless as a mechanism for a newby to get any kind of help. Well, I disagree. Places in usenet also turn to crap because conversations are allowed to stray arbitrarily off-topic, core competance gets lost, and the noise dominates the signal. For a technical newsgroup, this is even *less* helpful to newbies. Dan's reply was his normal model of politeness and decorum, but Dan is not "everyone", and his technical content, if he's not furiously trying to wriggle out of a corner or taking a joke too seriously [1], is bang-on. Given that newsgroups are exchange-of-text, not face-to-face, I'd rather have accurate information than not. [1] That's my reading; it's *only* my opinion. -- Chris "electric hedgehog" Dollin C FAQs at: http://www.faqs.org/faqs/by-newsgrou...mp.lang.c.html C welcome: http://www.angelfire.com/ms3/bchambl...me_to_clc.html Nov 13 '05 #13

 P: n/a # Why is everyone in these newsgroups so friggin nasty and mean? "Assholes do vex me" Robin Williams -- Derk Gwen http://derkgwen.250free.com/html/index.html You hate people. But I love gatherings. Isn't it ironic. Nov 13 '05 #14

 P: n/a In Jens Schicke writes: Jack Klein wrote: BTW: main doesn't need to be a function either :) We discuss the C language here. If you want to spout bullsh*t, go somewhere else. long long main = 0xC300000000B8; // int main(void) { return 0; } If you think the above is C, you are brain-damaged.# cat foo.cint main = 0xC3C031;# gcc -W -Wall -pedantic -ansi foo.cfoo.c:1: warning: `main' is usually a function#To me it looks like valid ansi-C, If it's valid ANSI C, please explain to the rest of us its meaning, according to the ANSI C standard. What can I expect from this program when running it on a SPARC/Solaris or POWER/AIX system? Let's see: mentor:~/tmp 8> uname -a SunOS mentor 5.8 Generic_108528-11 sun4u sparc mentor:~/tmp 9> cat test.c int main = 0xC3C031; mentor:~/tmp 10> gcc -Wall test.c test.c:1: warning: `main' is usually a function mentor:~/tmp 11> ./a.out Illegal instruction (core dumped) at least the gcc thinks of it as such... On the contrary, gcc has clearly expressed its doubts. Dan -- Dan Pop DESY Zeuthen, RZ group Email: Da*****@ifh.de Nov 13 '05 #15

 P: n/a Programmer Dude wrote: Joona I Palaste wrote: We have to be nasty sometimes to preserve proper topicality. You don't feel it's possible to preserve topicality pleasantly? I did say "sometimes". Yes you did. My question: why any times? Why participate AT ALL in making the world an even colder, nastier place than it is? Non sequitur. If being nasty to an insistent off-topic poster or even troll makes him go away or even teaches him to keep on topic, that makes comp.lang.c a more useful and pleasant place, not a colder, nastier one. Richard Nov 13 '05 #16

 P: n/a Programmer Dude wrote in message news:<3F***************@mmm.com>... Joona I Palaste wrote: We have to be nasty sometimes to preserve proper topicality. You don't feel it's possible to preserve topicality pleasantly? I did say "sometimes". Yes you did. My question: why any times? Why participate AT ALL in making the world an even colder, nastier place than it is? cos thats how you build an evil empire, silly :-) goose, evil overload number 9833418898134321993 Nov 13 '05 #17

 P: n/a Richard Bos wrote: > We have to be nasty sometimes to preserve proper topicality. You don't feel it's possible to preserve topicality pleasantly? I did say "sometimes". Yes you did. My question: why any times? Why participate AT ALL in making the world an even colder, nastier place than it is? Non sequitur. If being nasty to an insistent off-topic poster or even troll makes him go away or even teaches him to keep on topic, that makes comp.lang.c a more useful and pleasant place, not a colder, nastier one. First, clc != the world. Second, you'll need to demonstrate that such tactics are the ONLY successful ones. Third, being nasty is rarely an effective teaching technique. -- |_ CJSonnack _____________| How's my programming? | |_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL | |_____________________________________________|___ ____________________| Nov 13 '05 #18

 P: n/a In <3F***************@mmm.com> Programmer Dude writes: Third, being nasty is rarely an effective teaching technique. It is a very effective technique for teaching people to check their answers before posting them. It certainly worked for me, back when I was a c.l.c newbie. Dan -- Dan Pop DESY Zeuthen, RZ group Email: Da*****@ifh.de Nov 13 '05 #19

 P: n/a "Programmer Dude" wrote Dan Pop wrote: Third, being nasty is rarely an effective teaching technique. It is a very effective technique for teaching people to check their answers before posting them. So would breaking their arm. The problem is the side effects. It certainly worked for me, back when I was a c.l.c newbie. And no other, less severe, technique would? For some people, possibly not. Using myself as an example, I once posted a mostly but not completely accurate reply to a debugging request. The information I got wrong was certainly available in a fair number of C references that I could have used to check. But I didn't. I got two polite corrections and one flaming correction (from Dan Pop no less). At the time I was quite irritated, but a few things resulted from that. 1) I got over it. 2) I made more of an effort to check myself for correctness. 3) I still remember the details of what I inaccurately posted, and I am not likely to make the mistake again. So, while I was anything but happy about the not-so-polite response when I received it, I learned to be more careful about what I post, and I learned something that stuck with me. Chances are fairly good that I would not have learned either of those things had everyone been nice about it. Of course, not all people are the same, and flaming may be counterproductive in some cases, but there are times when it is both necessary and useful. Nov 13 '05 #20

 P: n/a Programmer Dude wrote: Richard Bos wrote:>> We have to be nasty sometimes to preserve proper topicality.>> You don't feel it's possible to preserve topicality pleasantly? I did say "sometimes". Yes you did. My question: why any times? Why participate AT ALL in making the world an even colder, nastier place than it is? Non sequitur. If being nasty to an insistent off-topic poster or even troll makes him go away or even teaches him to keep on topic, that makes comp.lang.c a more useful and pleasant place, not a colder, nastier one. First, clc != the world. Exactly. So just because we apply a bit of well-warranted heat to a repeating airhead here on c.l.c, that doesn't mean we're out to kick your puppy or something. Second, you'll need to demonstrate that such tactics are the ONLY successful ones. Third, being nasty is rarely an effective teaching technique. We're not talking about first-time posters, here. First-time offenders do always deserve a civilised reply, provided they don't start off abusive - and if they do, they're probably just trolls anyway. Nasty replies are only warranted if someone has repeatedly been asked to post nicely, and doesn't seem to want to get the point, or if they have been asked politely to be topical and then turn nasty themselves. In those cases, the civilised reply has been proven not to work; and at a guess, in 90% of those cases a little heat does prove to either scare them off or reform them. Richard Nov 13 '05 #21

 P: n/a In <3F***************@mmm.com> Programmer Dude writes: Dan Pop wrote: Third, being nasty is rarely an effective teaching technique. It is a very effective technique for teaching people to check their answers before posting them.So would breaking their arm. The problem is the side effects. Precisely. A bruised ego is the worst side effect of a nasty correction when a nasty correction is due. There are a few posters who really deserve a broken arm for their perseverance in posting wrong answers. It certainly worked for me, back when I was a c.l.c newbie.And no other, less severe, technique would? There are cases (the above mentioned posters) where neither polite nor nasty corrections help (and breaking their arm is, unfortunately, not an option :-) But, for most people, the nasty correction is more effective than the polite one. It motivates them to avoid posting unchecked answers in the future (no such motivation from a polite correction). The newsgroup greatly benefits from that. It's a dirty job, but someone has to do it. I'm greatly indebted to the people who flamed me when I deserved to be flamed. Dan -- Dan Pop DESY Zeuthen, RZ group Email: Da*****@ifh.de Nov 13 '05 #22

 P: n/a "Java Böy" wrote in message news:... could some body help me what's happening here... In general, it's shoehorning a hand-coded x86 assembly subroutine into a C program. As Dan and others have pointed out, this code is not legal in ISO C. However, depending on the compiler, you can get an executable that does what you intend, but that's a happy accident more than anything else. thanks.. char sc[] = "\x31\xc0" /* xor %eax, %eax */ "\x50" /* push %eax */ "\x68\x2f\x2f\x73\x68" /* push \$0x68732f2f */ "\x68\x2f\x62\x69\x6e" /* push \$0x6e69622f */ "\x89\xe3" /* mov %esp,%ebx */ "\x50" /* push %eax */ "\x53" /* push %ebx */ "\x89\xe1" /* mov %esp,%ecx */ "\x31\xd2" /* xor %edx,%edx */ "\xb0\x0b" /* mov \$0xb,%al */ "\xcd\x80"; /* int \$0x80 */ sc is being used to store the actual machine code for the operations described in the comments (opcodes and data). Each "\x.." entry represents a single byte. Each line of bytes consists correpsonds to operation listed in the comment. If you look at this array in a debugger you will see something like sc+0: 31 c0 50 68 2f 2f 73 68 sc+7: 68 2f 62 69 6e 89 e3 50 .... main() { void (*fp) (void); // what is happening at this line This declares fp as a pointer to a function returning void with no parameters. fp = (void *)sc; This assigns the address of sc to fp, allowing the bytes of the array to be executed as a function by main(). Unfortunately, it's a bad assignment for several reasons. First of all, the cast expression isn't even correct; the type of fp isn't void *, it's void (*)(void). Secondly, this type of conversion (from pointer to object to pointer to function) isn't allowed under ISO C. It may have been allowed in earlier implementations, and some compilers may still allow it if you don't have strict conformance turned on. fp(); And this calls the function. } [snip] Nov 13 '05 #23

 P: n/a Richard Bos wrote: Nasty replies are only warranted if someone has repeatedly been asked to post nicely, and doesn't seem to want to get the point, or if they have been asked politely to be topical and then turn nasty themselves. In those cases, the civilised reply has been proven not to work; and at a guess, in 90% of those cases a little heat does prove to either scare them off or reform them. One can't help but wonder if quietly ignoring them might not be more effective and with less potential for flamewars. But whatever. Your group, your rules. (-: -- |_ CJSonnack _____________| How's my programming? | |_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL | |_____________________________________________|___ ____________________| Nov 13 '05 #24

 P: n/a Dan Pop wrote: Precisely. A bruised ego is the worst side effect of a nasty correction when a nasty correction is due. I disagree with this very strongly. I think are much better off correcting the person firmly and succinctly. If the person doesn't wish to listen or argues in a foolish manner, then perhaps. But to always have the opening shot be abusive is ludricrous. It's more likely to bring out a defensive response and make the subject less likely to listen to what you have to say. I respect your knowledge, but increasingly of late I do not respect you. I compare your style with the thorough and gentlemanly manner of Chris Torek, and you come up very short. Brian Rodenborn Nov 13 '05 #25

 P: n/a Programmer Dude wrote: Richard Bos wrote: Nasty replies are only warranted if someone has repeatedly been asked to post nicely, and doesn't seem to want to get the point, or if they have been asked politely to be topical and then turn nasty themselves. In those cases, the civilised reply has been proven not to work; and at a guess, in 90% of those cases a little heat does prove to either scare them off or reform them. One can't help but wonder if quietly ignoring them might not be more effective and with less potential for flamewars. I've seen groups where this happened. The answer is a resounding "no". But whatever. Your group, your rules. (-: No, _our_ group. All non-moderated groups are the group of the regulars, _all_ the regulars. Richard Nov 13 '05 #26