forked from zmrbak/PcWeChatHooK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
2,016 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
62. ���������ĸ�����Э�飺etcp(����etcp c++Դ�����) | ||
1) �½���Ŀ�����ƴ��� | ||
framework.h ?? stdafx.h | ||
pch.h ?? stdafx.h | ||
tcp.h ?? tcp.h | ||
dllmain.cpp ?? dllmain.cpp | ||
pch.cpp ?? stdafx.cpp | ||
tcp.cpp ?? tcp.cpp | ||
2) ����������� | ||
������ʾ�����Ӷ��� | ||
#define _WINSOCK_DEPRECATED_NO_WARNINGS | ||
#define _CRT_SECURE_NO_WARNINGS | ||
3) ����������� | ||
����\��������\������\����\�����ض�Ĭ�Ͽ�: LIBCMT | ||
4) ���п� | ||
����\��������\C/C++\��������\���п�:/MT | ||
5) ����Ա� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29123.89 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "etcp60", "etcp60\etcp60.vcxproj", "{5B81DD67-A97F-4FB2-9D6C-A61F476E0F25}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5B81DD67-A97F-4FB2-9D6C-A61F476E0F25}.Debug|x64.ActiveCfg = Debug|x64 | ||
{5B81DD67-A97F-4FB2-9D6C-A61F476E0F25}.Debug|x64.Build.0 = Debug|x64 | ||
{5B81DD67-A97F-4FB2-9D6C-A61F476E0F25}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{5B81DD67-A97F-4FB2-9D6C-A61F476E0F25}.Debug|x86.Build.0 = Debug|Win32 | ||
{5B81DD67-A97F-4FB2-9D6C-A61F476E0F25}.Release|x64.ActiveCfg = Release|x64 | ||
{5B81DD67-A97F-4FB2-9D6C-A61F476E0F25}.Release|x64.Build.0 = Release|x64 | ||
{5B81DD67-A97F-4FB2-9D6C-A61F476E0F25}.Release|x86.ActiveCfg = Release|Win32 | ||
{5B81DD67-A97F-4FB2-9D6C-A61F476E0F25}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {5661EA06-206B-4694-AAF9-7C7411ECB41B} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
LIBRARY | ||
EXPORTS | ||
etcp_vip | ||
etcp_tcp_server | ||
etcp_tcp_send | ||
etcp_tcp_sends | ||
etcp_tcp_close_Client | ||
etcp_tcp_close | ||
etcp_tcp_client | ||
etcp_tcp_client_send | ||
etcp_tcp_client_close | ||
etcp_tcp_get_port | ||
etcp_tcp_get_ip | ||
etcp_get_ip | ||
etcp_tcp_get_socket | ||
etcp_tcp_client_so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
// dllmain.cpp : 定义 DLL 应用程序的入口点。 | ||
#include "pch.h" | ||
#include "tcp.h" | ||
#pragma comment(lib,"msvcrt.lib") | ||
|
||
unsigned __stdcall tcp_iocp_fun(void* pParam) | ||
{ | ||
while (true) | ||
{ | ||
ULONG cb = NULL; | ||
ULONG_PTR key = NULL; | ||
tcpstruct* op = NULL; | ||
bool error = false; | ||
|
||
if (!GetQueuedCompletionStatus(g_iocp, &cb, (PULONG_PTR)& key, (LPOVERLAPPED*)& op, INFINITE)) | ||
{ | ||
error = true; | ||
} | ||
tcp* so = op->so; | ||
if (op->state == tcp_recv && 0 >= cb) | ||
{ | ||
error = true; | ||
} | ||
op->cb = cb; | ||
|
||
if (so->m_Close) | ||
{ | ||
so->OnSend(true, op); | ||
continue; | ||
} | ||
switch (op->state) | ||
{ | ||
case tcp_connt: | ||
so->ClientAccept(error, op); | ||
break; | ||
case tcp_recv: | ||
so->RecvData(error, op); | ||
break; | ||
case tcp_send: | ||
so->OnSend(error, op); | ||
break; | ||
} | ||
|
||
} | ||
_endthreadex(0); | ||
return 0; | ||
} | ||
unsigned __stdcall tcp_iocp_fun_client(void* pParam) | ||
{ | ||
while (true) | ||
{ | ||
ULONG cb = NULL; | ||
ULONG_PTR key = NULL; | ||
tcpstruct_client* op = NULL; | ||
bool error = false; | ||
|
||
if (!GetQueuedCompletionStatus(g_iocp_client, &cb, (PULONG_PTR)& key, (LPOVERLAPPED*)& op, INFINITE)) | ||
{ | ||
error = true; | ||
} | ||
tcp_client* so = op->so; | ||
if (op->state == tcp_recv_client && 0 >= cb) | ||
{ | ||
error = true; | ||
} | ||
op->cb = cb; | ||
|
||
switch (op->state) | ||
{ | ||
case tcp_connt_client: | ||
so->OnConnect(error, op); | ||
break; | ||
case tcp_recv_client: | ||
so->OnRecv(error, op); | ||
break; | ||
case tcp_send_client: | ||
so->OnSend(error, op); | ||
break; | ||
} | ||
} | ||
_endthreadex(0); | ||
return 0; | ||
} | ||
|
||
int __stdcall etcp_vip(tcp_fun nFun, tcp_fun_client cFun, int buflen) | ||
{ | ||
if (buflen <= 0) | ||
{ | ||
buflen = 512; | ||
} | ||
|
||
buf_len = buflen; | ||
|
||
WSAData wsa; | ||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) | ||
{ | ||
return WSAGetLastError(); | ||
} | ||
g_fun = nFun; | ||
g_fun_client = cFun; | ||
g_iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 0); | ||
if (NULL == g_iocp) | ||
{ | ||
CloseHandle(g_iocp); | ||
return GetLastError(); | ||
} | ||
|
||
g_iocp_client = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 0); | ||
if (NULL == g_iocp_client) | ||
{ | ||
CloseHandle(g_iocp_client); | ||
return GetLastError(); | ||
} | ||
|
||
SYSTEM_INFO info; | ||
GetSystemInfo(&info); | ||
g_cpu = info.dwNumberOfProcessors + 2; | ||
if (g_cpu < 5) | ||
{ | ||
g_cpu = 5; | ||
} | ||
|
||
for (int i = 0; i < g_cpu; i++) | ||
{ | ||
CloseHandle((HANDLE)_beginthreadex(NULL, 0, &tcp_iocp_fun, NULL, 0, NULL)); | ||
CloseHandle((HANDLE)_beginthreadex(NULL, 0, &tcp_iocp_fun_client, NULL, 0, NULL)); | ||
} | ||
|
||
return 0; | ||
} | ||
int __stdcall etcp_tcp_server(char* host, unsigned short nPort, int nIs) | ||
{ | ||
tcp* t_tcp = new tcp; | ||
if (0 != t_tcp->Init(host, nPort, nIs)) | ||
{ | ||
delete t_tcp; | ||
t_tcp = NULL; | ||
return 0; | ||
} | ||
return (int)t_tcp; | ||
} | ||
int __stdcall etcp_tcp_send(HANDLE sso, SOCKET so, char* buf, int len) | ||
{ | ||
return ((tcp*)sso)->SoSend(so, buf, len); | ||
} | ||
int __stdcall etcp_tcp_sends(HANDLE sso, SOCKET so, char* buf, int len) | ||
{ | ||
return ((tcp*)sso)->SoSends(so, buf, len); | ||
} | ||
int __stdcall etcp_tcp_close_Client(SOCKET so) | ||
{ | ||
return closesockets(so); | ||
} | ||
int __stdcall etcp_tcp_close(HANDLE so) | ||
{ | ||
if (IsBadReadPtr(so, 4) != 0) | ||
{ | ||
return 0; | ||
} | ||
tcp* t_tcp = ((tcp*)so); | ||
t_tcp->Close(); | ||
delete t_tcp; | ||
t_tcp = NULL; | ||
return 0; | ||
} | ||
int __stdcall etcp_tcp_get_port(HANDLE so) | ||
{ | ||
return ((tcp*)so)->get_port(); | ||
} | ||
char* __stdcall etcp_tcp_get_ip(HANDLE so, SOCKET client_so) | ||
{ | ||
return ((tcp*)so)->get_ip(client_so); | ||
} | ||
|
||
|
||
|
||
int __stdcall etcp_tcp_client(char* host, unsigned short nPort, BOOL nIs, EProxyType proxyType, PCHAR proxyhost, WORD proxyport, PCHAR username, PCHAR userpass, int time) | ||
{ | ||
tcp_client* t_tcp = new tcp_client; | ||
if (0 != t_tcp->Init(host, nPort, nIs, proxyType, proxyhost, proxyport, username, userpass, time)) | ||
{ | ||
delete t_tcp; | ||
t_tcp = NULL; | ||
return 0; | ||
} | ||
return (int)t_tcp; | ||
} | ||
int __stdcall etcp_tcp_client_send(HANDLE so, char* buf, int len, int isok, char* outbuf, int outtime) | ||
{ | ||
return ((tcp_client*)so)->SoSend(buf, len, isok, outbuf, outtime); | ||
} | ||
|
||
int __stdcall etcp_tcp_client_close(HANDLE so) | ||
{ | ||
return ((tcp_client*)so)->Close(); | ||
} | ||
|
||
int __stdcall etcp_tcp_client_so(HANDLE so) | ||
{ | ||
return ((tcp_client*)so)->get_socket(); | ||
} | ||
bool __stdcall etcp_get_ip(char* ip) | ||
{ | ||
|
||
//2.获取主机名 | ||
char hostname[256]; | ||
int ret = gethostname(hostname, sizeof(hostname)); | ||
if (ret == SOCKET_ERROR) | ||
{ | ||
return false; | ||
} | ||
//3.获取主机ip | ||
HOSTENT* host = gethostbyname(hostname); | ||
if (host == NULL) | ||
{ | ||
return false; | ||
} | ||
//4.转化为char*并拷贝返回 | ||
strcpy(ip, inet_ntoa(*(in_addr*)* host->h_addr_list)); | ||
return true; | ||
} | ||
|
||
SOCKET __stdcall etcp_tcp_get_socket(HANDLE so) | ||
{ | ||
return ((tcp*)so)->get_socket(); | ||
} | ||
|
||
|
||
|
||
BOOL APIENTRY DllMain( HMODULE hModule, | ||
DWORD ul_reason_for_call, | ||
LPVOID lpReserved | ||
) | ||
{ | ||
switch (ul_reason_for_call) | ||
{ | ||
case DLL_PROCESS_ATTACH: | ||
case DLL_THREAD_ATTACH: | ||
case DLL_THREAD_DETACH: | ||
case DLL_PROCESS_DETACH: | ||
break; | ||
} | ||
return TRUE; | ||
} | ||
|
Oops, something went wrong.