这是什么调用转换为功能的字符数组的呢? [英] What does this invocation of a char array cast as a function do?

查看:107
本文介绍了这是什么调用转换为功能的字符数组的呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我穿过这片code来到

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)();
}

它是由编写外壳code Linux和Windows教程

有人能解释一下这个函数调用(INT)(* FUNC)();

Could someone explain that what this function invocation (int)(*func)(); is doing?

推荐答案

它调用的机器code是数组中的一个函数 code 。该的字符串的包含了一些机器级别的指令((三级我想,看看x86指令集)。 FUNC 被声明为指针一个函数,没有参数和返回 INT FUNC 然后设置为第一字节的地址的字符串的(机器指令记得了),然后 FUNC 被调用,所以一个函数调用的字符串的第一个指令的而成。

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

我不知道现在的x86指令集非常好,但它似乎使一个系统调用(不知道是哪一个); 0x80的0XCD 是一个陷阱系统。

I don't now x86 instruction set very well, but it seems to make a system call (don't know which one); 0xcd 0x80 is a trap to the system.

由于@etheranger说,它是对 _exit 系统调用,

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

当心,这是Linux的依赖性,请参见什么的确" INT 0x80的"在装配code是什么意思?

Beware that this is Linux-dependent, see What does "int 0x80" mean in assembly code?

本机构的简短说明,请访问: http://www.linfo.org/system_call_number。 HTML

A short explanation for this mechanism is available here: http://www.linfo.org/system_call_number.html

这篇关于这是什么调用转换为功能的字符数组的呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆