// wgdll.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "wgdll.h"
#include "DLLDLG.h"
#include <WinInet.h>
#include "string"
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
HHOOK g_hhook=NULL;
CDLLDLG *pCWndWGMain;
BOOL ishook=FALSE; //表示是否自已HOOK过了;
HMODULE hmod=NULL;
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CWgdllApp
BEGIN_MESSAGE_MAP(CWgdllApp, CWinApp)
//{{AFX_MSG_MAP(CWgdllApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWgdllApp construction
CWgdllApp::CWgdllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CWgdllApp object
CWgdllApp theApp;
//下面是自己编写的代码
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
BOOL installhook()
{
HMODULE hmod2=::GetModuleHandle(L"wgdll.dll");
if (g_hhook == NULL)
{
HWND gameh=FindWindow(NULL,L"PEiD v0.95");//查找游戏窗口
if (gameh==0) { AfxMessageBox(L"未找到游戏",MB_OK,NULL);}//出错处理
DWORD tid=::GetWindowThreadProcessId(gameh,NULL);//获取线程ID
g_hhook=::SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hmod2,tid); //安装线程勾子
if (g_hhook != NULL)
return TRUE;
}
return FALSE;
}
BOOL selfhook()
{
if (g_hhook == NULL) {
g_hhook = ::SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc,NULL,GetCurrentThreadId());
if (g_hhook != NULL)
return TRUE;
}
return FALSE;
}
BOOL uninstallhook()
{
BOOL result=::UnhookWindowsHookEx(g_hhook);
g_hhook=NULL;
return result;
}
BOOL showdlg()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd *pCWnd = CWnd::GetForegroundWindow();
if (pCWndWGMain==NULL)
{
pCWndWGMain=new CDLLDLG;
pCWndWGMain->Create(IDD_DLG,pCWnd);
}
pCWndWGMain->ShowWindow(SW_SHOW);
return true;
}
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//按F12弹起时呼出外挂
AFX_MANAGE_STATE(AfxGetStaticModuleState());
BOOL bKeyUp = lParam & (1 << 31);
if (bKeyUp && wParam == VK_F12 && nCode == HC_ACTION)
{
if(ishook)
{
showdlg();
}else
{
LoadLibrary(L"F:\\study\\c++\\wgdll\\Debug\\wgdll.dll"); //这个地址要注意,自己改一下;
selfhook();
ishook=true;
showdlg();
}
}
return ::CallNextHookEx(g_hhook, nCode, wParam ,lParam);
}
BOOL CWgdllApp::InitInstance()
{
// TODO: 在此添加专用代码和/或调用基类
hmod=this->m_hInstance;
return CWinApp::InitInstance();
}