有人在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?