zoukankan      html  css  js  c++  java
  • VC++实现IE定向劫持跳转

    建立黑名单,防范钓鱼网站

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App About
    
    class CAboutDlg : public CDialog
    {
    public:
    	CAboutDlg();
    
    // Dialog Data
    	//{{AFX_DATA(CAboutDlg)
    	enum { IDD = IDD_ABOUTBOX };
    	//}}AFX_DATA
    
    	// ClassWizard generated virtual function overrides
    	//{{AFX_VIRTUAL(CAboutDlg)
    	protected:
    	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    	//}}AFX_VIRTUAL
    
    // Implementation
    protected:
    	//{{AFX_MSG(CAboutDlg)
    	//}}AFX_MSG
    	DECLARE_MESSAGE_MAP()
    };
    
    CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    	//{{AFX_DATA_INIT(CAboutDlg)
    	//}}AFX_DATA_INIT
    }
    
    void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CAboutDlg)
    	//}}AFX_DATA_MAP
    }
    
    BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    	//{{AFX_MSG_MAP(CAboutDlg)
    		// No message handlers
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CIehookDlg dialog
    
    CIehookDlg::CIehookDlg(CWnd* pParent /*=NULL*/)
    	: CDialog(CIehookDlg::IDD, pParent)
    {
    	//{{AFX_DATA_INIT(CIehookDlg)
    		// 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 CIehookDlg::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CIehookDlg)
    		// NOTE: the ClassWizard will add DDX and DDV calls here
    	//}}AFX_DATA_MAP
    }
    
    BEGIN_MESSAGE_MAP(CIehookDlg, CDialog)
    	//{{AFX_MSG_MAP(CIehookDlg)
    	ON_WM_SYSCOMMAND()
    	ON_WM_PAINT()
    	ON_WM_QUERYDRAGICON()
    	ON_BN_CLICKED(IDC_KAISHI, OnKaishi)
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CIehookDlg message handlers
    
    BOOL CIehookDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    
    	// Add "About..." menu item to system menu.
    
    	// IDM_ABOUTBOX must be in the system command range.
    	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    	ASSERT(IDM_ABOUTBOX < 0xF000);
    
    	CMenu* pSysMenu = GetSystemMenu(FALSE);
    	if (pSysMenu != NULL)
    	{
    		CString strAboutMenu;
    		strAboutMenu.LoadString(IDS_ABOUTBOX);
    		if (!strAboutMenu.IsEmpty())
    		{
    			pSysMenu->AppendMenu(MF_SEPARATOR);
    			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    		}
    	}
    
    	// 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
    	
    	// TODO: Add extra initialization here
    	
    	return TRUE;  // return TRUE  unless you set the focus to a control
    }
    
    void CIehookDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    	{
    		CAboutDlg dlgAbout;
    		dlgAbout.DoModal();
    	}
    	else
    	{
    		CDialog::OnSysCommand(nID, lParam);
    	}
    }
    
    // If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.
    
    void CIehookDlg::OnPaint() 
    {
    	if (IsIconic())
    	{
    		CPaintDC dc(this); // device context for painting
    
    		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
    
    		// Center icon in client rectangle
    		int cxIcon = GetSystemMetrics(SM_CXICON);
    		int cyIcon = GetSystemMetrics(SM_CYICON);
    		CRect rect;
    		GetClientRect(&rect);
    		int x = (rect.Width() - cxIcon + 1) / 2;
    		int y = (rect.Height() - cyIcon + 1) / 2;
    
    		// Draw the icon
    		dc.DrawIcon(x, y, m_hIcon);
    	}
    	else
    	{
    		CDialog::OnPaint();
    	}
    }
    
    // The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CIehookDlg::OnQueryDragIcon()
    {
    	return (HCURSOR) m_hIcon;
    }
    //开始得到IE窗口
    void CIehookDlg::OnKaishi() 
    {
      skaishi=AfxBeginThread(kaishi,NULL);	
    }
    
    UINT kaishi(LPVOID lParam)
    {
    HWND zwnd;
    HWND hwnd1,hwnd2;
    HWND anniuwnd;
    HWND editwnd;
    //ToolbarWindow32
    
    int i=0;
    CString sn,s1;
    CRect qr;
    for(;;)
    {
    Sleep(10);
    zwnd=::GetForegroundWindow();//得到IE主窗口
        TCHAR szClassName[_MAX_PATH];
        ZeroMemory(szClassName,_MAX_PATH*sizeof(TCHAR));
       ::GetClassName(zwnd,szClassName,_MAX_PATH);
    	sn.Format("%s",szClassName);
    	sn.Replace(" ","");
       if(sn=="IEFrame")//如果是IE
       {
    hwnd1=::FindWindowEx(zwnd,NULL,_T("WorkerW"),NULL);
    hwnd2=::FindWindowEx(hwnd1,NULL,_T("ReBarWindow32"),NULL);
    hwnd1=::FindWindowEx(hwnd2,NULL,_T("ComboBoxEx32"),NULL);
    anniuwnd=::FindWindowEx(hwnd1,NULL,_T("ToolbarWindow32"),NULL);
    hwnd2=::FindWindowEx(hwnd1,NULL,_T("ComboBox"),NULL);
    editwnd=::FindWindowEx(hwnd2,NULL,_T("Edit"),NULL);
    if(editwnd!=NULL&&i==0)
    {
    	char sz[255];
    	::SendMessage(editwnd,WM_GETTEXT,255,(LPARAM)sz);
    	sn.Format("%s",sz);
    	sn.Replace("//","`");
        AfxExtractSubString(s1,sn,0,'/');
        s1.Replace("`","//");
    	//这里插入通讯
    	if(s1!="http://www.baidu.com"&&s1!="about:blank")//如果不是指向的地址
    	{
        sn.Format("http://www.baidu.com",sz);//修改为指向的地址
    	char *ss=sn.GetBuffer(0);
    	::SendMessage(editwnd,WM_SETTEXT,255,(LPARAM)ss);
           ::GetWindowRect(anniuwnd,qr);
           SetCursorPos(qr.left+15,qr.top+8);
           ::mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP,0,0,0,0);
    	}
    }
       }
    }
    ExitThread(0);
    return 0;
    }


     

  • 相关阅读:
    upc组队赛3 T-net【贪心】
    upc组队赛5 Assembly Required【思维】
    upc组队赛5 Bulbs
    upc组队赛5 Ingenious Lottery Tickets【排序】
    upc组队赛5 Hunter’s Apprentice 【判断多边形边界曲线顺逆时针】
    upc组队赛5 Ground Defense【枚举】
    upc组队赛4 Go Latin
    upc组队赛4 TV Show Game 【2-SAT】
    POJ 3250 Bad Hair Day【单调栈入门】
    016.NET5_MVC_视图组件扩展定制
  • 原文地址:https://www.cnblogs.com/new0801/p/6177740.html
Copyright © 2011-2022 走看看