问题描述
在任何暗示的cdecl工具,我已经尝试过了。奇怪的是,大部分的查询语句都返回了语法错误警告。
Before anyone suggests the cdecl tool, I have already tried it. Strangely enough, most of the statements queried are returned with a syntax error warning.
下面是我在网上找到的不只是运行一个成型外壳code的C程序。
Below is a C program I found online that does nothing but run a piece of shellcode.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv) {
char shellcode[] = "\xb0\x01\x31\xdb\xcd\x80";
int (*func)();
func = (int (*)()) shellcode;
(int)(*func)();
return 0;
}
该项目工程按预期,但C语法是我见过最奇怪的之一。我会尽量间preT他们,尽我所能。
The program works as intended, but the C syntax is among the strangest I ever seen. I will try to interpret them as best I can.
int (*func)();
该语句声明FUNC作为指针(以表示*)传递给函数(用')(表示)返回一个int。
This statement declares func as a pointer (indicated by '*') to a function (indicated by '()') that returns an int.
func = (int (*)()) shellcode;
本声明的类型转换壳code数组的指针(以表示'(*)')传递给函数(以表示()),返回一个int和分配指针FUNC。
This statement typecasts the shellcode array as a pointer (indicated by '(*)') to a function (indicated by '()') that returns an int and assigns the pointer to func.
(int)(*func)();
这最后一条语句执行的功能(以表示())由指针FUNC(以表示'(* FUNC)')和类型转换的结果作为一个整数指出。
This final statement executes the function (indicated by '()') pointed to by the pointer func (indicated by '(*func)') and typecasts the result as an integer.
我的认为的是什么是怎么回事。如果任何人有经验的用C看到任何错误与我之间的pretations或可提供一种替代或以上教育间pretation,我非常欢迎您的参与。
I think that is what is going on here. If anyone more experienced with C sees any mistakes with my interpretations or can provide an alternative or more educational interpretation, I very much welcome your input.
我从来没有写过变量初始化或函数调用这个样子,让我有些还是相当困惑中显示的语法。如果你有写上面的code更可读的方式,也请提供输入。
I have never written variable initializations or function calls like this, so I am somewhat still quite confused about the syntax displayed. If you have a more readable way to write the code above, please also provide input.
感谢您。
推荐答案
这是正确的,虽然我不知道为什么它施放的返回值的int;我的怀疑是,即使是谁写的这还不是全部用C函数指针语法信心。
That's all correct, although I don't get why it casts the return value to an int; my suspicion is that even who wrote that wasn't all that confident with C function pointer syntax.
在现实世界中,你可能会看到使用一个typedef写的是code:
In the real world you would probably see the that code written using a typedef:
typedef (*funcT)();
funcT func = (funcT) shellcode;
(*func)();
这篇关于在指针声明和函数调用奇C语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!