⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zthookapi.cpp

📁 arcAE中自己编写面积,长度测量工具,返回测量结果
💻 CPP
字号:
// ztHookApi.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "ztHookApi.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#pragma data_seg(".MyShare")
//共享数据段
HHOOK hHook=NULL;//勾子句柄
bool  bGetKeyState=NULL;//是否改变GetKeyState的返回值
bool  bGetCursorPos=NULL;//是否改变GetCursorPos的返回值
POINT CursorPos={NULL};//需要改变的鼠标点值
int   hookKey=NULL;//需要hook的健
bool  bFirst=true;//是否第一次运行
HANDLE hProcessZT=NULL;

#pragma data_seg()

#pragma comment(linker,"/SECTION:.MyShare,rws")

extern "C" LRESULT __stdcall CALLBACK GetMsgProc(int code,WPARAM wParam,LPARAM lParam);

//
//	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.
//

/////////////////////////////////////////////////////////////////////////////
// CZtHookApiApp

BEGIN_MESSAGE_MAP(CZtHookApiApp, CWinApp)
	//{{AFX_MSG_MAP(CZtHookApiApp)
		// 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()

/////////////////////////////////////////////////////////////////////////////
// CZtHookApiApp construction

CZtHookApiApp::CZtHookApiApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CZtHookApiApp object

CZtHookApiApp theApp;
//安装勾子
extern "C" bool __stdcall InitHook(bool bInit,DWORD hookThreadID,HANDLE hHookProcess)
{
	if(NULL!=bInit)
	{
		hProcessZT=hHookProcess;
		hHook=::SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,::GetModuleHandle("ztHookApi.dll"),hookThreadID);
		if(NULL==hHook)
		{
			return false;
		}
	}
	else
	{
		HANDLE hGetKS=::GetProcAddress(::GetModuleHandle("user32.dll"),"GetKeyState");
		HANDLE hGetCP=::GetProcAddress(::GetModuleHandle("user32.dll"),"GetCursorPos");
		if(hGetKS==NULL || NULL==hGetCP)
		{
			return false;
		}
		::WriteProcessMemory(hHookProcess,(void*)0x0060d248,&hGetKS,4,NULL);
		::WriteProcessMemory(hHookProcess,(void*)0x0060d2b4,&hGetCP,4,NULL);

		::UnhookWindowsHookEx(hHook);
	}
	return true;
}

extern "C" LRESULT __stdcall CALLBACK GetMsgProc(int code,WPARAM wParam,LPARAM lParam)
{
	char szTemp[125];
	DWORD szTemp1,szTemp2;
    
	if(NULL != bFirst)
	{
		bFirst=NULL;
	
		DWORD hGetKS=(DWORD)::GetProcAddress(::GetModuleHandle("ztHookApi.dll"),"MyGetKeyState");
		DWORD hGetCP=(DWORD)::GetProcAddress(::GetModuleHandle("ztHookApi.dll"),"MyGetCursorPos");

		::WriteProcessMemory(::GetCurrentProcess(),(void*)0x0060d248,&hGetKS,4,NULL);
		::WriteProcessMemory(::GetCurrentProcess(),(void*)0x0060d2b4,&hGetCP,4,NULL);

		::ReadProcessMemory(::GetCurrentProcess(),(void*)0x0060d248,&szTemp1,4,NULL);
		::ReadProcessMemory(::GetCurrentProcess(),(void*)0x0060d2b4,&szTemp2,4,NULL);
		::wsprintf(szTemp,"hGetKS=0x%08x,hGetCP=0x%08x\r\n GetKeyBoard=0x%08x,GetCursorPos=0x%08x\r\nGetCurrentProcess=0x%08x",
			hGetKS,hGetCP,szTemp1,szTemp2,::GetCurrentProcess());
		//::MessageBox(NULL,szTemp,NULL,MB_OK);

		

	}
	return ::CallNextHookEx(hHook,code,wParam,lParam);
}
//自已的获得健盘状态涵数
extern "C" DWORD __stdcall MyGetKeyState(int nVirtKey)
{
	if(bGetKeyState)
	{
		
		if(nVirtKey==hookKey)
		{
			return 0xFFFFFF80;
		}

	}

	return ::GetKeyState(nVirtKey);
}
//自已的获得当前鼠标涵数
extern "C" BOOL __stdcall MyGetCursorPos(LPPOINT lpPoint)
{
	if(bGetCursorPos)
	{
		lpPoint->x=CursorPos.x;
		lpPoint->y=CursorPos.y;
		return true;
	}
	
	return ::GetCursorPos(lpPoint);
}

//和调用程序之间交互
extern "C" void __stdcall SetKeyData(bool bHook,int nVkey)
{
	bGetKeyState=bHook;
	hookKey=nVkey;
}
//和调用程序之间交互
extern "C" void __stdcall SetCursorData(bool bHook,LPPOINT lpPoint)
{
	bGetCursorPos=bHook;

	if(NULL !=lpPoint)
	{
		CursorPos.x=lpPoint->x;
		CursorPos.y=lpPoint->y;
	}
}








		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -