📄 ybjj.cpp
字号:
void GetDefault(TCHAR *PAGE, int Analysis)
{
thread_param *tp=new thread_param;
lstrcpy(tp->SendBuffer,_T("GET "));
// lstrcat(tp->SendBuffer,now_http_head->Host );
lstrcat(tp->SendBuffer,now_http_head->Path );
lstrcat(tp->SendBuffer,PAGE);
lstrcat(tp->SendBuffer,_T(" HTTP/1.1\r\n"));
lstrcat(tp->SendBuffer,_T("Accept: */*\r\n"));
lstrcat(tp->SendBuffer,_T("Referer: http://"));
lstrcat(tp->SendBuffer,now_http_head->Host );
lstrcat(tp->SendBuffer,now_http_head->Path );
lstrcat(tp->SendBuffer,_T("XK1.ShowMainMenu\r\n"));
lstrcat(tp->SendBuffer,ACCEPT_LANGUAGE);
lstrcat(tp->SendBuffer,ACCEPT_ENCODING);
lstrcat(tp->SendBuffer,USER_AGENT);
//lstrcat(tp->SendBuffer,"User-Agent: YBJJ-1.2 Beta\r\n");
lstrcat(tp->SendBuffer,_T("Host: "));
lstrcat(tp->SendBuffer,now_http_head->Host );
lstrcat(tp->SendBuffer,_T("\r\n"));
lstrcat(tp->SendBuffer,UserCookie);
lstrcat(tp->SendBuffer,_T("Connection: close\r\n\r\n"));
switch(Analysis)
{
case 2:
tp->hProgress =GetDlgItem(hDlgCancel,IDC_PROGRESS);break;
case 6:
tp->hProgress =GetDlgItem(hDlgArrangement,IDC_PROGRESS);break;
}
tp->NeedBuffer2 =false;
tp->Analysis =Analysis;
CloseHandle((HANDLE)_beginthreadex(0,0,SendThread,(void*)tp,0,0));
}
void LogOFF(TCHAR *tips)
{
mystatus.LOGINED =false;
SetWindowText(hMain,szTitle);
RtlZeroMemory(UserCookie,sizeof(UserCookie));
lout(tips);
lout(_T("\r\n"));
if (!mystatus.Autoing ) MessageBox(0,tips,szTitle,MB_ICONINFORMATION);
}
void LogIN()
{
//if (mystatus.Busy ) return;
thread_param *tp=new thread_param;
lstrcpy(tp->SendBuffer2,_T("cUserId="));
lstrcat(tp->SendBuffer2,UserName);
lstrcat(tp->SendBuffer2,_T("&cUserPass="));
lstrcat(tp->SendBuffer2,PassWord);
int l=lstrlen(tp->SendBuffer2);
TCHAR len[10];
_itot(l,len,10);
lstrcpy(tp->SendBuffer,_T("POST "));
lstrcat(tp->SendBuffer,now_http_head->Path );
lstrcat(tp->SendBuffer,_T("XK1.ShowMainPage HTTP/1.1\r\n"));
lstrcat(tp->SendBuffer,_T("Accept:*/*\r\n"));
lstrcat(tp->SendBuffer,_T("Referer: http://xkapp84.njtu.thcic.cn/pls/bfjd_wwwpub/XK1.LoginWindow\r\n"));
lstrcat(tp->SendBuffer,ACCEPT_LANGUAGE);
lstrcat(tp->SendBuffer,CONTENT_TYPE);
lstrcat(tp->SendBuffer,ACCEPT_ENCODING);
lstrcat(tp->SendBuffer,USER_AGENT);
lstrcat(tp->SendBuffer,_T("Host: "));
lstrcat(tp->SendBuffer,now_http_head->Host );
lstrcat(tp->SendBuffer,_T("\r\nConnection: close\r\n"));
lstrcat(tp->SendBuffer,_T("Cache-Control: no-cache\r\n"));
lstrcat(tp->SendBuffer,_T("Content-Length: "));
lstrcat(tp->SendBuffer,len);
lstrcat(tp->SendBuffer,_T("\r\n\r\n"));
lstrcat(tp->SendBuffer,tp->SendBuffer2);
tp->NeedBuffer2 =false;
tp->Analysis =4;
tp->hProgress =0;
CloseHandle((HANDLE)_beginthreadex(0,0,SendThread,(void*)tp,0,0));
}
unsigned int __stdcall SendThread(LPVOID lParam)
{
SOCKADDR_IN ServerAddr;
thread_param * tp=(thread_param*)lParam;
SOCKET mSocket;
fd_set myfdset;
TIMEVAL mytimeval;
char *BufferA=new char[MAIN_BUFFER_SIZE],*pA=BufferA;
int a,left=MAIN_BUFFER_SIZE;
__try
{
if (tp->hProgress ) SendMessage(tp->hProgress ,PBM_SETPOS,0,0);
mystatus.Busy |=tp->Analysis ;
mSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if (mSocket== INVALID_SOCKET)
{
lout(_T("创建SOCKET失败\r\n"));
return 0;
}
if (tp->hProgress ) SendMessage(tp->hProgress ,PBM_SETPOS,5,0);
a=TIMER_RECV_TIMEOUT;
if ( setsockopt(mSocket,SOL_SOCKET,SO_RCVTIMEO,(char*)&a,sizeof(a))==SOCKET_ERROR)
{
lout(_T("初始化SOCKET失败\r\n"));
return 0;
}
if (tp->hProgress ) SendMessage(tp->hProgress ,PBM_SETPOS,10,0);
RtlZeroMemory(&ServerAddr,sizeof(ServerAddr));
ServerAddr.sin_family = AF_INET;
ServerAddr.sin_port = htons(now_http_head->PORT );
ServerAddr.sin_addr.s_addr = inet_addr(now_http_head->IPA);
if ( connect(mSocket, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr)) == SOCKET_ERROR )
{
lout(_T("连接到服务器失败\r\n"));
return 0;
}
if (tp->hProgress ) SendMessage(tp->hProgress ,PBM_SETPOS,20,0);
lout(_T("数据发送中..."));
#ifdef loutBuffer
lout(tp->SendBuffer);
#endif
if (send(mSocket,tp->SendBuffer,lstrlen(tp->SendBuffer),0) == SOCKET_ERROR)
{
lout(_T("失败\r\n"));
return 0;
}
if (tp->hProgress ) SendMessage(tp->hProgress ,PBM_SETPOS,30,0);
if (tp->NeedBuffer2 )
{
#ifdef loutBuffer
lout(tp->SendBuffer2);
#endif
if (send(mSocket,tp->SendBuffer2,lstrlen(tp->SendBuffer2),0)== SOCKET_ERROR)
{
lout(_T("失败\r\n"));
return 0;
}
}
if (tp->hProgress ) SendMessage(tp->hProgress ,PBM_SETPOS,40,0);
ZeroMemory(BufferA,MAIN_BUFFER_SIZE);
ZeroMemory(&myfdset,sizeof(myfdset));
ZeroMemory(&mytimeval,sizeof(mytimeval));
myfdset.fd_count =1;
myfdset.fd_array[0] =mSocket;
mytimeval.tv_sec = g_iTimeOut;
#ifdef loutBuffer
lout("\r\n\r\n");
#endif
lout(_T("发送完毕...\r\n数据接收中..."));
while (true)
{
a=select(0,&myfdset,0,0,&mytimeval);
if ( a == SOCKET_ERROR || a == 0 )
{
lout(_T("接收数据超时\r\n"));
return 0;
}
a=recv(mSocket,pA,left,0);
#ifdef loutBuffer
lout(pA);
#endif
if (a==0) break; //closed
if (a==SOCKET_ERROR)
{
lout(_T("接收数据失败\r\n"));
return 0;
}
left-=a; //剩余BufferSize
pA+=a;
if (tp->hProgress ) SendMessage(tp->hProgress ,PBM_SETPOS,(SendMessage(tp->hProgress ,PBM_GETPOS,0,0)+8)%100,0);
}
closesocket(mSocket);
mSocket=0;
lout(_T("接收完毕\r\n"));
if (tp->hProgress ) SendMessage(tp->hProgress ,PBM_SETPOS,80,0);
pA=AnalysisHttpHeader(BufferA);
if (pA==0) return 0;
switch(tp->Analysis )
{
case 1:
Analysis1(pA);break;
case 2:
Analysis2(pA);break;
case 3:
Analysis3(pA);break;
case 4:
Analysis4(pA);break;
case 5:
Analysis5(pA);break;
case 6:
Analysis6(pA);break;
case 10:
Analysis10(pA);break;
}
}
__finally
{
if (tp->hProgress ) SendMessage(tp->hProgress ,PBM_SETPOS,100,0);
mystatus.Busy &=~tp->Analysis ;
if (mSocket) closesocket(mSocket);
if (tp) delete tp;
if (BufferA) delete[] BufferA;
#ifdef _DEBUG
lout(_T("连接已断开\r\n"));
#endif
if (hDlgQuery)
{
SetDlgItemText(hDlgQuery,IDC_QUERY_ALL,_T("任选课"));
SetDlgItemText(hDlgQuery,IDC_ALL_PE,_T("体育课"));
SetDlgItemText(hDlgQuery,IDC_ALL_COMPUTER,_T("计算机课"));
}
}
return 1;
}
unsigned int __stdcall ThreadForPostCourse(PVOID lParam)
{
const short seq=HIWORD(lParam);
const short post=LOWORD(lParam);
InterlockedIncrement(&g_iCountThread);
SOCKADDR_IN ServerAddr;
SOCKET mSocket=INVALID_SOCKET;
fd_set myfdset;
TIMEVAL mytimeval;
char ThreadSendBuffer[1024];
char ThreadSendBuffer2[512];
char Buffer[POSTCOURSE_BUFFER_SIZE];
char szKCH[10],szKXH[10];
char *R=Buffer;
TCHAR times[10];
int a,left=POSTCOURSE_BUFFER_SIZE;
RtlZeroMemory(times,sizeof(times));
_itot(post,times,10);
__try
{
//==============================================
// 是否达到最大线程数
//==============================================
if ( g_iCountThread > g_iMaxThread )
{
lout(_T("第"));
lout(times);
lout(_T("次提交已放弃(达到最大线程数)\r\n"));
return 1;
}
//==============================================
// 初始化套接字
//==============================================
mSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if (mSocket== INVALID_SOCKET)
{
lout(_T("PostCourse SOCKET失败\r\n"));
return 0;
}
a=TIMER_RECV_TIMEOUT;
setsockopt(mSocket,SOL_SOCKET,SO_RCVTIMEO,(char*)&a,sizeof(a));
RtlZeroMemory(&ServerAddr,sizeof(ServerAddr));
ServerAddr.sin_family = AF_INET;
ServerAddr.sin_port = htons(now_http_head->PORT );
ServerAddr.sin_addr.s_addr = inet_addr(now_http_head->IPA);
//ServerAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
//==============================================
// HTTP包 头
//==============================================
ZeroMemory(ThreadSendBuffer,sizeof(ThreadSendBuffer));
ZeroMemory(ThreadSendBuffer2,sizeof(ThreadSendBuffer2));
ZeroMemory(szKCH,sizeof(szKCH));
ZeroMemory(szKXH,sizeof(szKXH));
GetDlgItemText(hDlgAuto,IDC_EDIT1+seq,szKCH,8);
GetDlgItemText(hDlgAuto,IDC_EDIT4+seq,szKXH,3);
wsprintf(ThreadSendBuffer2,"aInsertKch=%s&aInsertKxh=%s",szKCH,szKXH);
wsprintf(ThreadSendBuffer,"\
POST %sXK1.CourseInput HTTP/1.1\r\n\
Referer: http://%s%sXK1.CourseInput\r\n\
%s%s%s\
Host: %s\r\nConnection: close\r\n\
Cache-Control: no-cache\r\n\
%s\
Content-Length: %d\
\r\n\r\n",
now_http_head->Path,
now_http_head->Host,now_http_head->Path,
ACCEPT_LANGUAGE,CONTENT_TYPE,USER_AGENT,
now_http_head->Host,
UserCookie,
strlen(ThreadSendBuffer2));
#ifdef _DEBUG
//lout(ThreadSendBuffer);
//lout(ThreadSendBuffer2);
#endif
//==============================================
// 连接服务器
//==============================================
if ( connect(mSocket, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr)) == SOCKET_ERROR )
{
lout(_T("第"));
lout(times);
lout(_T("次提交结果:连接服务器失败\r\n"));
return 0;
}
//==============================================
// 发送
//==============================================
if (send(mSocket,ThreadSendBuffer,lstrlen(ThreadSendBuffer),0) == SOCKET_ERROR)
{
lout(_T("第"));
lout(times);
lout(_T("次提交结果:发送失败\r\n"));
return 0;
}
if (send(mSocket,ThreadSendBuffer2,lstrlen(ThreadSendBuffer2),0) == SOCKET_ERROR)
{
lout(_T("第"));
lout(times);
lout(_T("次提交结果:发送二失败\r\n"));
return 0;
}
//==============================================
// 接收
//==============================================
mytimeval.tv_sec = g_iTimeOut;
ZeroMemory(Buffer,POSTCOURSE_BUFFER_SIZE);
while (true) //</html>
{
#ifdef _DEBUG
if ( g_iServer == IDM_SERVER_DEBUG)
{
Sleep(100);
}
#endif
FD_ZERO(&myfdset);
FD_SET(mSocket,&myfdset);
a=select(0,&myfdset,0,0,&mytimeval);
if ( a == SOCKET_ERROR || a == 0 )
{
lout(_T("第"));
lout(times);
lout(_T("次提交结果:等待超时,线程结束\r\n"));
return 0;
}
a=recv(mSocket,R,left,0);
if ( a == 0 ) break;
if ( a == SOCKET_ERROR || a == WSAETIMEDOUT)
{
lout(_T("第"));
lout(times);
lout(_T("次提交结果:读取超时,线程结束\r\n"));
return 0;
}
if (Locate(R-9,_T("</script>"),0,0,0)) break;
R+=a;
left-=a;
}
lout(_T("第"));
lout(times);
lout(_T("次提交结果:"));
#ifdef _DEBUG
// lout(Buffer);
#endif
Analysis8(Buffer,seq);
}
__finally
{
if ( mSocket != INVALID_SOCKET) closesocket(mSocket);
InterlockedDecrement(&g_iCountThread);
}
return 1;
}
unsigned int __stdcall ThreadForSchedule(PVOID lParam)
{
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -