吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1819|回复: 15
收起左侧

[C&C++ 原创] 弹窗拦截cpp源码

  [复制链接]
Panel 发表于 2023-12-14 11:26
本帖最后由 Panel 于 2023-12-14 11:27 编辑

用户自定义拦截指定弹窗

#include <afxwin.h>
#include <iostream>
#include <fstream>
#include <string>
#include <thread>
#define RULE_FILE "rules.data"
using namespace std;

HWND hWnd;
string wndtitle;
BOOL showflag = false;

bool Init();
void GetWnd(HWND& wnd, string& title);
void WriteRules(string rule);
bool IsHit(string title);
void FindAd();
void ShowHide();
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);

int main()
{
    SetWindowTextA(GetForegroundWindow(),"Panel AD Killer made by Panel www.52pojie.cn");

    if (!Init())
    {
        return 0;
    }

    HANDLE hThread;
    hThread = CreateThread(
        NULL,                  
        0,                     
        (LPTHREAD_START_ROUTINE)FindAd,        
        NULL,            
        0,               
        NULL);           

    // 消息循环
    MSG msg = { 0 };
    while (GetMessage(&msg, NULL, 0, 0) != 0) {
        if (msg.wParam == 1) {
            GetWnd(hWnd, wndtitle);
            WriteRules(wndtitle);
        }if (msg.wParam == 2)
        {
            ShowHide();
        }
        if (msg.message == WM_CLOSE) {

            ShowWindow(hWnd, SW_HIDE);
        }
    }
}

bool Init()
{
    BOOL flag;
    if (RegisterHotKey(NULL, 1, MOD_CONTROL | MOD_ALT, 'E')) {
        cout << "初始化成功1\n";
        flag = true;
    }
    else {
        cout << "初始化失败,热键可能被占用1\n";
        flag = false;
    }
    if (RegisterHotKey(NULL, 2, MOD_CONTROL | MOD_ALT, 'T')) {
        cout << "初始化成功2\n";
        flag = true;
    }
    else {
        cout << "初始化失败,热键可能被占用2\n";
        flag = false;
    }
    return flag;
}
void GetWnd(HWND& wnd, string& title)
{

    POINT pNow = { 0,0 };
    if (GetCursorPos(&pNow)) 
    {
        HWND hwndPointNow = NULL;
        hwndPointNow = WindowFromPoint(pNow);  
        wnd = hwndPointNow;
        if (hwndPointNow)
        {
            char szWindowTitle[50];
            ::GetWindowTextA(hwndPointNow, szWindowTitle, sizeof(szWindowTitle)); 
            title = string(szWindowTitle);
            //cout << hex << (int)hwndPointNow << endl;  
            cout << szWindowTitle << endl; 
        }
        else
            cout << "Error!!" << endl;
    }
}
void WriteRules(string rule)
{
    ofstream file(RULE_FILE,ios::binary|ios::app);
    if (!file.is_open()) {
        std::cerr << "配置文件无法打开" << std::endl;
        return;
    }
    file << rule << std::endl;
    file.close();
}
bool IsHit(string title)
{
    ifstream inputFile(RULE_FILE,ios::app);

    if (!inputFile.is_open()) {
        std::cerr << "无法打开文件" << std::endl;
        return false; // 返回错误代码
    }

    std::string line;
    while (std::getline(inputFile, line)) {
        if (line == title)
        {
            inputFile.close();
            return true;
        }
    }

    return false;
}
void FindAd()
{
    do
    {
        EnumWindows(EnumWindowsProc, 0); Sleep(1000);
    } while (true);
}
void ShowHide()
{
    showflag = !showflag;
    if (showflag)
    {
        ShowWindow(GetForegroundWindow(), SW_HIDE);
    }
    else {
        ShowWindow(GetForegroundWindow(), SW_SHOW);
    }
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
    char windowTitle[256];

    GetWindowTextA(hwnd, windowTitle, sizeof(windowTitle));

    if (string(windowTitle) == "")
    {
        return true;
    }

    if (string(windowTitle).find("shadow") != string::npos)
    {
        PostMessage(hwnd, WM_CLOSE, 0, 0);
    }

    if (IsHit(string(windowTitle)))
    {
        PostMessage(hwnd, WM_CLOSE, 0, 0);
    }

    return TRUE; // 继续列举下一个窗口
}

免费评分

参与人数 6吾爱币 +8 热心值 +6 收起 理由
qsqbqx + 1 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
NaiveScrooge + 1 用心讨论,共获提升!
hrh123 + 1 + 1 用心讨论,共获提升!
helian147 + 1 + 1 热心回复!
sam喵喵 + 1 是能拦截所有制定的弹窗吗,譬如063这些

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

FruitBaby 发表于 2023-12-14 14:05
楼主你好,这段代码有通用性的吗,
 楼主| Panel 发表于 2023-12-14 14:08
FruitBaby 发表于 2023-12-14 14:05
楼主你好,这段代码有通用性的吗,

有啊,很多广告拦截思路都这样
FruitBaby 发表于 2023-12-14 14:09
Panel 发表于 2023-12-14 14:08
有啊,很多广告拦截思路都这样

我好好研究研究哈,向大佬学习
luoyin168 发表于 2023-12-14 14:16
学习了!!
gqdsc 发表于 2023-12-15 08:40
感谢分享源码,参考下
dong19872008 发表于 2023-12-15 08:59
感谢分享!!
NaiveScrooge 发表于 2023-12-15 10:44
学习了zsbd
Fixbluesky 发表于 2023-12-24 16:11

感谢分享源码,参考下
叁贰设计 发表于 2023-12-25 20:13
感谢分享源码,参考下
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-3 04:35

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表