The typical structure of executing shell code is the following-: (The code snippet is taken from here)
char shellcode[] = ""; /* global array */
int
main (int argc, char **argv)
{
int (*ret)(); /* ret is a function pointer */
ret = (int(*)())shellcode; /* ret points to our shellcode */
/* shellcode is type caste as a function */
(int)(*ret)(); /* execute, as a function, shellcode[] */
exit(0); /* exit() */
}
Why not use asm(inline assembler) to execute shellcode ? It is then much more simpler than doing pointer acrobatics such as converting an array to a function pointer and then executing that array as a function ?
Is there any drawbacks of using the assembler ? And are there any particular advantage of using an array to execute shell code ?