What does this char array call do as a function?

I came across this piece of code:

char code[] = "\xb0\x01\x31\xdb\xcd\x80"; int main(int argc, char **argv) { int (*func)(); func = (int (*)()) code; (int)(*func)(); } 

Copied from Writing Shellcode for Linux and the Windows Tutorial .

Can anyone explain what this function call does (int)(*func)(); ?

+3
source share
1 answer

It calls a function whose machine code is in the code array. The line contains some machine-level instructions ((three, I think, look at the x86 instruction set). func declared as a pointer to a function that takes no argument and returns int . func then given by the address of the first byte of this line (machine instructions are remembered). Then func is called, so a function call is made for the first line instruction.

I did not install the x86 command set very quickly, but it seems to be a system call (I don’t know which one); 0xcd 0x80 is a trap for the system.


As @etheranger said, this is a call to the _exit system call.

Remember that it depends on Linux, see What is "int 0x80" in the assembly code?

A brief description of this mechanism is available here: http://www.linfo.org/system_call_number.html

+3
source

Source: https://habr.com/ru/post/1239331/


All Articles