zoukankan      html  css  js  c++  java
  • 在纯C工程的main函数之前跑代码(手工找到程序入口点, 替换为我们自己的函数)

    在main函数之前跑代码的方法

    方法: 手工找到程序入口点, 替换为我们自己的函数

    [cpp] view plain copy
     
    1. 写测试程序  
    2. // test.cpp : Defines the entry point for the console application.  
    3. //  
    4.   
    5. #include "stdafx.h"  
    6. #include <windows.h>  
    7. #include <crtdbg.h>  
    8.   
    9. /// 程序入口点 00671140 >|?  55            push    ebp  
    10. /// 用OD可知  
    11.   
    12. extern "C" void mainCRTStartup(void);  
    13.   
    14. int foo()  
    15. {  
    16.     /** 
    17.     00671020 
    18.     */  
    19.   
    20.     /// 执行不带CRT函数的代码  
    21.     MessageBox(NULL, "foo before main", "test", MB_OK);  
    22.   
    23.     mainCRTStartup();  
    24.     return 0;  
    25. }  
    26.   
    27. int main(int argc, char* argv[])  
    28. {  
    29.     /** ALT + 8 
    30.     00671080 
    31.     */  
    32.     foo();  
    33.     printf("&main = %p ", &main);  
    34.     getchar();  
    35.     return 0;  
    36. }  

    用DASM窗口记录foo函数的地址为 0x00671020

    用WinHex打开PE文件, 找到程序入口点在0x100, 内容为0x1140, 修改程序入口点为0x1020. 

    手工查找程序入口点的方法: http://blog.csdn.net/lostspeed/article/details/49506193

    修改后

    运行效果

    在程序中单步,看看效果

    可以看到程序先运行到了foo, 而不是main.

    http://blog.csdn.net/lostspeed/article/details/49748555

  • 相关阅读:
    视频遮挡问题
    calc兼容性
    javascript变量声明提升
    jquery插件
    prop和attr在 jquery的
    onclick防止冒泡和json对象放入
    git 入门
    去掉ie滚动条兼容性
    单页面应用程序(SPA)
    swiper轮播图插件
  • 原文地址:https://www.cnblogs.com/findumars/p/5187291.html
Copyright © 2011-2022 走看看