Just wondering what does it do ?

Dec 5, 2011 at 2:39pm
I came across a script that was like injecting live codes into itself O_o !
Can anyone tell what if I write some sort of codes like this:

1
2
3
4
5
6
7
8
#include<stdio.h>

int main()
{
     char a[] = {"cmd.exe"};
     (void(*)a)();  // <------ WHAT WILL HAPPEN HERE ??
     return 0;
}


What would the third line do ? Can someone help please ?
Dec 5, 2011 at 3:17pm
I think that crashes the program. Yes, you could write into memory (a char array for instance) executable code and then execute it, but Data Execution Prevention will stop this in Windows (and I don't know about Unix/Linux). To appropriately do this, the memory needs to be maked as executable using VirtualProtect() in Windows.

And just giving an executable name doesn't do the trick. Like I said, most likely this crashes the application.
Dec 5, 2011 at 7:10pm
It does this:

$ g++ -o test test.cpp 
test.cpp: In function ‘int main(int, char**)’:
test.cpp:4:14: error: ‘(void*)((char*)(& a))’ cannot be used as a function

Which is the compiler saying: "What the hell is that supposed to mean?"
Topic archived. No new replies allowed.