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

📄 hookremotedlg.cpp

📁 《Windows应用程序捆绑核心编程》配套源码
💻 CPP
字号:
// HookRemoteDlg.cpp : implementation file
//

#include "stdafx.h"
#include "HookRemote.h"
#include "HookRemoteDlg.h"
#include "Injector.h"

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


/////////////////////////////////////////////////////////////////////////////
// CHookRemoteDlg dialog

CHookRemoteDlg::CHookRemoteDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CHookRemoteDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CHookRemoteDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CHookRemoteDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CHookRemoteDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CHookRemoteDlg, CDialog)
	//{{AFX_MSG_MAP(CHookRemoteDlg)
	ON_BN_CLICKED(IDC_RADIO_IAT, OnRadioIat)
	ON_BN_CLICKED(IDC_RADIO_JMP, OnRadioJmp)
	ON_BN_CLICKED(IDC_RADIO_UNHOOK, OnRadioUnhook)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHookRemoteDlg message handlers

BOOL CHookRemoteDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

    m_nLabel=0; // 0 for unhook, 1 for IAT, 2 for JMP 
	m_bIATLoaded = FALSE;
	m_bJMPLoaded = FALSE;
    ButtonCheck();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CHookRemoteDlg::ButtonCheck() 
{
    CButton *pBtnUnHook=(CButton*)GetDlgItem(IDC_RADIO_UNHOOK);
    CButton *pBtnIAT=(CButton*)GetDlgItem(IDC_RADIO_IAT);
    CButton *pBtnJMP=(CButton*)GetDlgItem(IDC_RADIO_JMP);
    pBtnUnHook->SetCheck(m_nLabel==0);
	pBtnIAT->SetCheck(m_nLabel==1);
	pBtnJMP->SetCheck(m_nLabel==2);
}

void CHookRemoteDlg::LoadDll(CString strDll) 
{
	// DLL文件全路径名.
	CString strDllFullPathName;

	char cCurDir[MAX_PATH];
    GetCurrentDirectory(MAX_PATH,cCurDir);

	strDllFullPathName=CString(cCurDir)+strDll;

	DWORD dwProcessId = 0;
	// 查找目标窗口句柄. 也可以采取其他方法来查找.
	HWND hWnd=::FindWindow(NULL,"HookMsgbx");
	if (hWnd == NULL) return;

	// 获得目标进程的进程号pid.
	GetWindowThreadProcessId(hWnd, &dwProcessId);
	int nLen=strDllFullPathName.GetLength();

    LoadLib(dwProcessId,strDllFullPathName.GetBuffer(nLen));
}

void CHookRemoteDlg::FreeDll(CString strDll) 
{
	// DLL文件全路径名.
	CString strDllFullPathName;

	char cCurDir[MAX_PATH];
    GetCurrentDirectory(MAX_PATH,cCurDir);

	strDllFullPathName=CString(cCurDir)+strDll;

	DWORD dwProcessId = 0;
	// 查找目标窗口句柄. 也可以采取其他方法来查找.
	HWND hWnd=::FindWindow(NULL,"HookMsgbx");
	if (hWnd == NULL) return;

	// 获得目标进程的进程号pid.
	GetWindowThreadProcessId(hWnd, &dwProcessId);
	int nLen=strDllFullPathName.GetLength();

    FreeLib(dwProcessId,strDllFullPathName.GetBuffer(nLen));
}

void CHookRemoteDlg::OnRadioIat() 
{
    OnRadioUnhook();
	LoadDll(TEXT("\\HookIAT.Dll"));
	m_bIATLoaded = TRUE;
	m_nLabel=1;
    ButtonCheck();
}

void CHookRemoteDlg::OnRadioJmp() 
{
    OnRadioUnhook();
	LoadDll(TEXT("\\HookJMP.Dll"));
	m_bJMPLoaded = TRUE;
	m_nLabel=2;
    ButtonCheck();
}

void CHookRemoteDlg::OnRadioUnhook() 
{
	if(m_bIATLoaded) 
		 FreeDll(TEXT("\\HookIAT.Dll"));
	
	if(m_bJMPLoaded) 
		FreeDll(TEXT("\\HookJMP.Dll"));
	
	m_bIATLoaded = FALSE;
	m_bJMPLoaded = FALSE;

	m_nLabel=0;
    ButtonCheck();
}

⌨️ 快捷键说明

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