www.gusucode.com > VC++写的QQ农场辅助源代码及分析资料源码程序 > VC++写的QQ农场辅助源代码及分析资料源码程序\code\qq农场源代码\qq农场源代码\QQHOOK.cpp

    // QQHOOK.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "SKSGODweb.h"
#include "QQHOOK.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////////////////////////////////////////////////////
//hook 页面,数据分析
/////////////////////////////////////////////////////////////////////////////
// CQQHOOK dialog
#include <afxsock.h>
#include "JEINFUN.h"

CULHook g_hook_recv;
CULHook g_hook_send;
CULHook g_hook_closesocket;
CQQHOOK *qqhookDlg = 0;	//对话框
//////////////////////////////////////////////////////////////////////////
SOCKET s_savesocket=0;

char szfarmKey[128];
char farmTime[128];

//////////////////////////////////////////////////////////////////////////
int WINAPI jein_closesocket (
							 SOCKET s  
							 )
{
	int nret =0;
	g_hook_closesocket.Unhook();
	
	if (s_savesocket)	nret=closesocket(s_savesocket);
	s_savesocket=s;
	jein_outinfo("保存socket:%d		==%d",s,nret);
	g_hook_closesocket.Rehook();
	
	return nret;
	
}
//////////////////////////////////////////////////////////////////////////


//farmKey=bd784b2971e5e06a3dad1de9f7d3c7ed&ownerId=0&farmTime=1245694128//点击我的完
//////////////////////////////////////////////////////////////////////////
void SaveKey(CString buf)
{
	
	buf.TrimLeft();
	buf.TrimRight();
	jein_outinfo("%d: 保存:%s",time(0), buf);
	//farmKey=c6fd6b4fae5fef37104d8a2c5462b534&cId=7&number=1&farmTime=1245685678
	int nstat = buf.Find("farmKey=");
	int nend = buf.Find("&");	//他的结束
	
	CString csfarmkey= buf.Mid(nstat+ strlen("farmKey=") ,32 );	//取32位
	
	nstat = buf.ReverseFind('=');
	nstat++;
	CString cstime = buf.Mid(nstat, buf.GetLength() - nstat );
	
	strcpy(szfarmKey,csfarmkey);
	strcpy(farmTime,cstime);
	
	jein_outinfo("保存值:%s	时间:%s",csfarmkey,cstime);
	
	
}


//////////////////////////////////////////////////////////////////////////

int WINAPI jein_send (
					  SOCKET s,              
					  char FAR * buf,  
					  int len,               
					  int flags              
					  )
{
	
	int nret=0;
	
	g_hook_send.Unhook();
	
	//////////////////////////////////////////////////////////////////////////
	nret = send(s,buf,len,flags);
	
	//////////////////////////////////////////////////////////////////////////
	
	//
	g_hook_send.Rehook();
	
	
	if (nret && len !=1)	//数据正常
	{
		//////////////////////////////////////////////////////////////////////////
		//保存一 farmkey 与 farmtime
		if (strstr(buf,"farmKey=") && strstr(buf,"farmTime="))	//有时间的包
		{
			
			//////////////////////////////////////////////////////////////////////////
			SaveKey(buf);
		}
		
		//////////////////////////////////////////////////////////////////////////
		
		char *bufbuf=new char[len+128] ;
		memset(bufbuf,0,len+128);
		sprintf(bufbuf,"发送:%d  send: (sock=%d,  ,len=%d,flags=%d) ",nret,s,len,flags);
		int nlenText = qqhookDlg->m_str_recv.GetWindowTextLength();
		
		qqhookDlg->m_str_recv.SetSel(nlenText,nlenText);
		
		strcat(bufbuf,"\r\n");
		strcat(bufbuf,buf);
		strcat(bufbuf,"\r\n");
		qqhookDlg->m_str_recv.ReplaceSel(bufbuf);
		
		qqhookDlg->m_str_recv.SendMessage(WM_VSCROLL,SB_BOTTOM,0);
		
		nlenText = qqhookDlg->m_str_recv.GetWindowTextLength();
		if (nlenText > 1024*1024)
		{
			qqhookDlg->m_str_recv.SetWindowText("");
		}
		delete bufbuf;	//释放 空间
		
	}
	
	return nret;
}



//////////////////////////////////////////////////////////////////////////

int WINAPI jein_recv (
					  SOCKET s,       
					  char * buf,  
					  int len,        
					  int flags       
					  )
{
	
	
	int nRet=0;
	
	g_hook_recv.Unhook();
	nRet = recv(s,buf,len,flags);
	g_hook_recv.Rehook(); 
	
	
	
	
	if (nRet>1 )
	{
		
		char *recvbuf=new char[len+64];
		memset(recvbuf,0,len+64);
		sprintf(recvbuf,"recv(SOCKET:%d,len:%d, flags:%d) == 返回长度:%d  ,GetLastError=%d\r\n",s,len,flags, nRet ,GetLastError());
		strcat(recvbuf,"\r\n");
		strcat(recvbuf,buf);
		strcat(recvbuf,"\r\n");
		
		
		int nlenText = qqhookDlg->m_str_recv.GetWindowTextLength();
		
		qqhookDlg->m_str_recv.SetSel(nlenText,nlenText);
		qqhookDlg->m_str_recv.ReplaceSel(recvbuf);
		qqhookDlg->m_str_recv.SendMessage(WM_VSCROLL,SB_BOTTOM,0);
		
		nlenText = qqhookDlg->m_str_recv.GetWindowTextLength();
		if (nlenText > 1024*1024)
		{
			qqhookDlg->m_str_recv.SetWindowText("");
		}
	}
	
	
	if (nRet== -1   )
	{
		
		return 1;
		
	}
	else
	{
		
		return nRet;
	}
}

//////////////////////////////////////////////////////////////////////////

//开始 hook
void HookOnRecv()
{
	static int is=1;
	if (is)
	{
		is=!is;
		
		g_hook_recv.SetAPIHook("ws2_32.dll","recv",(PROC)jein_recv);
	}
	else
	{
		g_hook_recv.Rehook();
	}
}

//停止hook
void HookOffRecv()
{
	g_hook_recv.Unhook();
}
//////////////////////////////////////////////////////////////////////////

CQQHOOK::CQQHOOK(CWnd* pParent /*=NULL*/)
: CDialog(CQQHOOK::IDD, pParent)
{
	//{{AFX_DATA_INIT(CQQHOOK)
	m_pack = _T("");
	//}}AFX_DATA_INIT
}


void CQQHOOK::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CQQHOOK)
	DDX_Control(pDX, IDC_EDIT1, m_str_recv);
	DDX_Text(pDX, IDC_EDIT2_PACK, m_pack);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CQQHOOK, CDialog)
//{{AFX_MSG_MAP(CQQHOOK)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnCC)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
ON_EN_MAXTEXT(IDC_EDIT1, OnMaxtextEdit1)
ON_BN_CLICKED(IDC_BUTTON13, OnHookAPI)
ON_BN_CLICKED(IDC_BUTTON3, OnSend)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CQQHOOK message handlers

void CQQHOOK::OnButton1() 
{
	
	//hookon
	static int is=1;
	if (is)
	{
		is=!is;
		SetDlgItemText(IDC_BUTTON1,"停止recv");
		HookOnRecv();
	}
	else
	{
		is=!is;
		
		SetDlgItemText(IDC_BUTTON1,"截取recv");
		HookOffRecv();
	}
}

BOOL CQQHOOK::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	
	qqhookDlg = this;
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CQQHOOK::OnCC() 
{
	
	m_str_recv.SetWindowText("");
}


//开始截取 send


//////////////////////////////////////////////////////////////////////////


void HookOnSend()
{
	
	
	
	
	static int is=1;
	if (is)
	{
		is=!is;
		
		g_hook_send.SetAPIHook("ws2_32.dll","send",(PROC)jein_send);
	}
	else
	{
		g_hook_send.Rehook();
	}
	
}

void HookOffSend() 
{
	g_hook_send.Unhook();
	
}
void CQQHOOK::OnButton10() 
{
	// TODO: Add your control notification handler code here
	//	
	//hookon
	static int is=1;
	if (is)
	{
		is=!is;
		SetDlgItemText(IDC_BUTTON10,"停止send");
		HookOnSend();
	}
	else
	{
		is=!is;
		
		SetDlgItemText(IDC_BUTTON10,"截取send");
		HookOffSend();		//停止send 
	}
	
}


void CQQHOOK::OnClose() 
{
	
	
	
	//HookOffRecv();
	CDialog::OnClose();
}

//最大值?
void CQQHOOK::OnMaxtextEdit1() 
{
	// TODO: Add your control notification handler code here
	m_str_recv.SetWindowText("");
	
}

void CQQHOOK::OnHookAPI() 
{
	static int ishook=1;
	if (ishook)
	{
		ishook=!ishook;
		g_hook_closesocket.SetAPIHook("ws2_32.dll","closesocket",(PROC)jein_closesocket);
		SetDlgItemText(IDC_BUTTON13,"停止APIHOOK");
		return ;
	}
	
	static int is=1;
	if (is)
	{
		is=!is;
		SetDlgItemText(IDC_BUTTON13,"HOOKAPI");
		g_hook_closesocket.Unhook();
	}
	else
	{
		is=!is;
		SetDlgItemText(IDC_BUTTON13,"停止APIHOOK");
		g_hook_closesocket.Rehook();
	}
}

//发送一个包
void CQQHOOK::OnSend() 
{
	// TODO: Add your control notification handler code here
	//
	
	//send()
	
	UpdateData();
	
	CString str = m_pack;
	
	str.Replace("密码",szfarmKey);
	str.Replace("时间",farmTime);
	
	jein_outinfo("我发送的包:%s",str);
	
	/*
	send(s_savesocket,str.GetBuffer(0),str.GetLength(),0);
	str.ReleaseBuffer();
	*/
	Sock_SendPost("happyfarm.xiaoyou.qq.com","/api.php?mod=repertory&act=sale",str);
	
	
	
	
	
}