模仿Rundll32.exe

 
  1. /*  
  2.  * FileName: my_Rundll32.cpp 
  3.  * Creator: 冷却 
  4.  * Date: 2009年10月7日 
  5.  * Comment: 模仿Windows里的一个名为Rundll32.exe的小工具 
  6.  */  
  7.   
  8. #include <windows.h>   
  9. #pragma comment(linker, "/subsystem:windows")   
  10.   
  11. typedef void (*EntryPoint)(  
  12.                            HWND hwnd,        // handle to owner window   
  13.                            HINSTANCE hinst,  // instance handle for the DLL   
  14.                            LPTSTR lpCmdLine, // string the DLL will parse   
  15.                            int nCmdShow      // show state   
  16.                            );  
  17.   
  18. int WINAPI WinMain(  
  19.                    HINSTANCE hInstance,      // handle to current instance   
  20.                    HINSTANCE hPrevInstance,  // handle to previous instance   
  21.                    LPSTR lpCmdLine,          // command line   
  22.                    int nCmdShow              // show state   
  23.                    )  
  24. {  
  25.     if ( strlen(lpCmdLine)==0 )  
  26.     {  
  27.         return -1;  
  28.     }  
  29.       
  30.     char* buf=lpCmdLine;  
  31.     char* tmp=NULL;  
  32.     bool haveArg=true;  
  33.       
  34.     int n,n1;  
  35.     int len = strlen(buf);  
  36.       
  37.     tmp = strchr(buf, ',');  
  38.     if ( tmp == NULL )  
  39.     {  
  40.         return -1;  
  41.     }  
  42.     int commaPos = (tmp-buf);  
  43.       
  44.     int spacePos;  
  45.     tmp = strchr(buf, ' ');  
  46.     if ( tmp == NULL )  
  47.     {  
  48.         spacePos = len;  
  49.         haveArg = false;  
  50.     }  
  51.     else  
  52.     {  
  53.         spacePos = (tmp-buf);  
  54.     }  
  55.       
  56.     char* dllName=NULL;  
  57.     char* funName=NULL;  
  58.     char* arguments=NULL;  
  59.       
  60.     dllName = new char[commaPos+1];  
  61.     funName = new char[spacePos-commaPos];  
  62.       
  63.     if ( haveArg )  
  64.     {  
  65.         arguments = new char[len-spacePos];  
  66.     }  
  67.     else  
  68.     {  
  69.         arguments = new char[1];  
  70.         strcpy(arguments, "");  
  71.     }  
  72.       
  73.     for ( n=0; n<commaPos; n++ )  
  74.     {  
  75.         dllName[n] = buf[n];  
  76.     }  
  77.     dllName[commaPos]=0;  
  78.       
  79.     for ( n1=0,n=(commaPos+1); n<spacePos; n1++,n++ )  
  80.     {  
  81.         funName[n1] = buf[n];  
  82.     }  
  83.     funName[spacePos-commaPos-1]=0;  
  84.       
  85.     if ( haveArg )  
  86.     {  
  87.         for ( n1=0,n=spacePos+1; n<len; n1++,n++)  
  88.         {  
  89.             arguments[n1] = buf[n];  
  90.         }  
  91.         arguments[len-spacePos-1]=0;  
  92.     }  
  93.       
  94.     //这部分为核心部分,其余的均是为了解析参数   
  95.     HINSTANCE dll_handle = LoadLibrary(dllName);  
  96.     if ( dll_handle != NULL )  
  97.     {  
  98.         EntryPoint my_fun = (EntryPoint)GetProcAddress(dll_handle, funName);  
  99.         if ( my_fun != NULL )  
  100.         {  
  101.             my_fun((HWND)hInstance, dll_handle, arguments, nCmdShow);  
  102.         }  
  103.         else  
  104.         {  
  105.             MessageBox(0,"丢失条目!",0,0);  
  106.         }  
  107.     }  
  108.     else  
  109.     {  
  110.         MessageBox(0,"找不到指定的模块!",0,0);  
  111.     }  
  112.     FreeLibrary(dll_handle);  
  113.     //   
  114.       
  115.     delete[] dllName;  
  116.     delete[] funName;  
  117.       
  118.     if ( haveArg )  
  119.     {  
  120.         delete[] arguments;  
  121.     }  
  122.       
  123.     return 0;  
  124. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值