有人在SO发布了一个问题,询问他如何“隐藏”一个函数。这是我的回答:内联汇编和函数覆盖导致段错误
#include <stdio.h>
#include <stdlib.h>
int encrypt(void)
{
char *text="Hello World";
asm("push text");
asm("call printf");
return 0;
}
int main(int argc, char *argv[])
{
volatile unsigned char *i=encrypt;
while(*i!=0x00)
*i++^=0xBE;
return EXIT_SUCCESS;
}
,但也有问题:
encode.c: In function `main': encode.c:13: warning: initialization from incompatible pointer type C:\DOCUME~1\Aviral\LOCALS~1\Temp/ccYaOZhn.o:encode.c:(.text+0xf): undefined reference to `text' C:\DOCUME~1\Aviral\LOCALS~1\Temp/ccYaOZhn.o:encode.c:(.text+0x14): undefined reference to `printf' collect2: ld returned 1 exit status
我的第一个问题是,为什么是内联汇编失败......这将是正确的做到这一点呢?其他的东西 - “ret”或“retn”的代码是0x00,正确的...我的代码xor的东西,直到达到一个返回......那么为什么它是SEGFAULTing?