亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1044 | 回復(fù): 0
打印 上一主題 下一主題

Calling function via jmp [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-12-09 15:28 |只看該作者 |倒序瀏覽

                The following code snippet implements calling the function via jmp.
This is here to verify that the difference between 'call' and 'jmp' instructions is that the former one pushes the return address to the stack before jump to the new label to execute while the later one won't. As a result we can emulate 'call' by pushing the address of the function we want to exec to the stack before 'jmp'.
If we can extract the content of eip before jmping we can push it into the stack before jmp. This would behave exactly as we use 'call' instruction I think.
// BEGIN OF THE PROGRAM
#include
void a();
void b(int first, int last);
void c();
int
main()
{
    a();
    printf("In main().\n");
    return 0;
}
/* stack
* |--------------|
* |  Param 2 (5) |
* |--------------|
* |  Param 1 (10)|
* |--------------|
* |Ret addr(stop)|
* |--------------|
*/
void a()
{
    printf("In a().\n");
    __asm__("pushl $5; pushl $10; pushl $stop; pushl $b; jmp c");
    // This line should be skipped
    printf("This should not be printed.\n");
    // Set a label here so we have somewhere to return after finishing
    // function b()
    __asm__("stop:");
    printf("Ending a().\n");
}
void b(int first, int last)
{
    printf("In b().\n");
    printf("param: %d and %d\n", first, last);
}
// We jump here. Because c is a function, it will invoke ret after the
// execution. ret pops the return address from stack which is the
// address of function b we pushed to stack manually in advance. Thus
// function b will be executed in turn without being called explicitly.
void c()
{
    printf("In c().\n");
}
// END OF THE PROGRAM
Compile and execute, the output will be:
In a().
In c().
In b().
param: 10 and 5
Ending a().
In main().
               
               
               
               
               

本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/6646/showart_2115442.html
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP