C++实现优酷土豆去视频广告的方法
本文实例讲述了C++实现优酷土豆去视频广告的方法。分享给大家供大家参考。具体分析如下:
之前写的一个工具,好不好用我不知道,我自己用着挺好,编译环境VC6.0,原理是改HOST文件,不过还改了其他地方,可以看看源码,暂时支持XP,WIN7没写,代码可能有些乱,有兴趣的朋友可以自己改改。
//guanggaoDlg.cpp:implementationfile
WIN32_FIND_DATAFindFileData;
voidCGuanggaoDlg::OnButton1()
{
//屏蔽功能
CopyFile("C:\\WINDOWS\\system32\\drivers\\etc\\hosts","C:\\WINDOWS\\system32\\drivers\\etc\\bak.hosts",TRUE);
TCHARlujing[MAX_PATH]="C:\\DocumentsandSettings\\Administrator\\ApplicationData\\Macromedia\\FlashPlayer\\#SharedObjects\\";
TCHARlujing2[MAX_PATH]="C:\\DocumentsandSettings\\Administrator\\ApplicationData\\Macromedia\\FlashPlayer\\#SharedObjects\\";
TCHARyouku[MAX_PATH]="\\static.youku.com";
TCHARtudou[MAX_PATH]="\\js.tudouui.com";
HANDLEhFist=FindFirstFile("C:\\DocumentsandSettings\\Administrator\\ApplicationData\\Macromedia\\FlashPlayer\\#SharedObjects\\*",&FindFileData);
FindNextFile(hFist,&FindFileData);
FindNextFile(hFist,&FindFileData);
strcat(lujing,FindFileData.cFileName);
strcat(lujing2,FindFileData.cFileName);
LPSTRdedaoquanlujing=strcat(lujing,youku);
LPSTRdedaoquanlujing2=strcat(lujing2,tudou);
SHFILEOPSTRUCTfilecaoz;
ZeroMemory(&filecaoz,sizeof(filecaoz));
filecaoz.wFunc=FO_DELETE;
filecaoz.fFlags=FOF_NOCONFIRMATION|FOF_SIMPLEPROGRESS;
filecaoz.hNameMappings=NULL;
filecaoz.hwnd=NULL;
filecaoz.lpszProgressTitle=NULL;
filecaoz.pFrom=dedaoquanlujing;
SHFileOperation(&filecaoz);
SHFILEOPSTRUCTfilecaoz2;
ZeroMemory(&filecaoz2,sizeof(filecaoz2));
filecaoz.wFunc=FO_DELETE;
filecaoz.fFlags=FOF_NOCONFIRMATION|FOF_SIMPLEPROGRESS;
filecaoz.hNameMappings=NULL;
filecaoz.hwnd=NULL;
filecaoz.lpszProgressTitle=NULL;
filecaoz.pFrom=dedaoquanlujing2;
SHFileOperation(&filecaoz2);
SetFileAttributes(dedaoquanlujing,0);
DeleteFile(dedaoquanlujing);
DeleteFile(dedaoquanlujing2);
HANDLEwenjian=CreateFile(dedaoquanlujing,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
HANDLEwenjian2=CreateFile(dedaoquanlujing2,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
SetFileAttributes(dedaoquanlujing,0);
SetFileAttributes(dedaoquanlujing2,0);
CloseHandle(hFist);
CloseHandle(wenjian);
CloseHandle(wenjian2);
//HOST
SetFileAttributes("C:\\WINDOWS\\system32\\drivers\\etc\\hosts",0);
HANDLEwenjianjubing=CreateFile("C:\\WINDOWS\\system32\\drivers\\etc\\hosts",GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
//去优酷
DWORDsizebuff=0;
chara1[]={"#youku\r\n"};
chara2[]={"127.0.0.1atm.youku.com\r\n"};
chara3[]={"127.0.0.1Fvid.atm.youku.com\r\n"};
chara4[]={"127.0.0.1html.atm.youku.com\r\n"};
chara5[]={"127.0.0.1valb.atm.youku.com\r\n"};
chara6[]={"127.0.0.1valf.atm.youku.com\r\n"};
chara7[]={"127.0.0.1valo.atm.youku.com\r\n"};
chara8[]={"127.0.0.1valp.atm.youku.com\r\n"};
chara9[]={"127.0.0.1lstat.youku.com\r\n"};
chara10[]={"127.0.0.1speed.lstat.youku.com\r\n"};
chara11[]={"127.0.0.1urchin.lstat.youku.com\r\n"};
chara12[]={"127.0.0.1stat.youku.com\r\n"};
chara13[]={"127.0.0.1valc.atm.youku.com\r\n"};
chara14[]={"127.0.0.1vid.atm.youku.com\r\n"};
chara15[]={"127.0.0.1walp.atm.youku.com\r\n"};
chara16[]={"127.0.0.1static.lstat.youku.com\r\n"};
WriteFile(wenjianjubing,a1,sizeof(a1)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a2,sizeof(a2)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a3,sizeof(a3)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a4,sizeof(a4)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a5,sizeof(a5)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a6,sizeof(a6)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a7,sizeof(a7)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a8,sizeof(a8)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a9,sizeof(a9)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a10,sizeof(a10)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a11,sizeof(a11)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a12,sizeof(a12)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a13,sizeof(a13)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a14,sizeof(a14)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a15,sizeof(a15)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a16,sizeof(a16)-1,&sizebuff,NULL);
//去土豆
charb0[]={"#tudou\r\n"};
charb1[]={"127.0.0.1adextensioncontrol.tudou.com\r\n"};
charb2[]={"127.0.0.1iwstat.tudou.com\r\n"};
charb3[]={"127.0.0.1nstat.tudou.com\r\n"};
charb4[]={"127.0.0.1stats.tudou.com\r\n"};
charb5[]={"127.0.0.1*.p2v.tudou.com*\r\n"};
charb6[]={"127.0.0.1at-img1.tdimg.com\r\n"};
charb7[]={"127.0.0.1at-img2.tdimg.com\r\n"};
charb8[]={"127.0.0.1at-img3.tdimg.com\r\n"};
charb9[]={"127.0.0.1adplay.tudou.com\r\n"};
charb10[]={"127.0.0.1adcontrol.tudou.com\r\n"};
charb11[]={"127.0.0.1stat.tudou.com\r\n"};
WriteFile(wenjianjubing,b0,sizeof(b0)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,b1,sizeof(b1)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,b2,sizeof(b2)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,b3,sizeof(b3)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,b4,sizeof(b4)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,b5,sizeof(b5)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,b6,sizeof(b6)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,b7,sizeof(b7)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,b8,sizeof(b8)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,b9,sizeof(b9)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,b10,sizeof(b10)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,b11,sizeof(b11)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,a15,sizeof(a15)-1,&sizebuff,NULL);
//去酷6
charc0[]={"#ku6\r\n"};
charc1[]={"127.0.0.11.allyes.com.cn\r\n"};
charc2[]={"127.0.0.1analytics.ku6.com\r\n"};
charc3[]={"127.0.0.1gug.ku6cdn.com\r\n"};
charc4[]={"127.0.0.1ku6.allyes.com\r\n"};
charc5[]={"127.0.0.1ku6afp.allyes.com\r\n"};
charc6[]={"127.0.0.1pq.stat.ku6.com\r\n"};
charc7[]={"127.0.0.1st.vq.ku6.cn\r\n"};
charc8[]={"127.0.0.1stat0.888.ku6.com\r\n"};
charc9[]={"127.0.0.1stat1.888.ku6.com\r\n"};
charc10[]={"127.0.0.1stat2.888.ku6.com\r\n"};
charc11[]={"127.0.0.1stat3.888.ku6.com\r\n"};
charc12[]={"127.0.0.1static.ku6.com\r\n"};
charc13[]={"127.0.0.1v0.stat.ku6.com\r\n"};
charc14[]={"127.0.0.1v1.stat.ku6.com\r\n"};
charc15[]={"127.0.0.1v2.stat.ku6.com\r\n"};
charc16[]={"127.0.0.1v3.stat.ku6.com\r\n"};
WriteFile(wenjianjubing,c0,sizeof(c0)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c1,sizeof(c1)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c2,sizeof(c2)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c3,sizeof(c3)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c4,sizeof(c4)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c5,sizeof(c5)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c6,sizeof(c6)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c7,sizeof(c7)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c8,sizeof(c8)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c9,sizeof(c9)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c10,sizeof(c10)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c11,sizeof(c11)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c12,sizeof(c12)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c13,sizeof(c13)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c14,sizeof(c14)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c15,sizeof(c15)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,c16,sizeof(c16)-1,&sizebuff,NULL);
////去奇艺广告
chard0[]={"#qiyi\r\n"};
chard1[]={"127.0.0.1afp.qiyi.com\r\n"};
chard2[]={"127.0.0.1focusbaiduafp.allyes.com\r\n"};
WriteFile(wenjianjubing,d0,sizeof(d0)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,d1,sizeof(d1)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,d2,sizeof(d2)-1,&sizebuff,NULL);
//新浪视频
chare0[]={"#sina\r\n"};
chare3[]={"127.0.0.1dcads.sina.com.cn\r\n"};
WriteFile(wenjianjubing,e0,sizeof(e0)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,e3,sizeof(e3)-1,&sizebuff,NULL);
//去PPTV
charf0[]={"#pptv\r\n"};
charf4[]={"127.0.0.1pp2.pptv.com\r\n"};
WriteFile(wenjianjubing,f0,sizeof(f0)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,f4,sizeof(f4)-1,&sizebuff,NULL);
//搜狐
charg0[]={"#sohu\r\n"};
charg5[]={"127.0.0.1images.sohu.com\r\n"};
WriteFile(wenjianjubing,g0,sizeof(g0)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,g5,sizeof(g5)-1,&sizebuff,NULL);
//乐视
charh0[]={"#leshi\r\n"};
charh6[]={"127.0.0.1pro.letv.com\r\n"};
WriteFile(wenjianjubing,h0,sizeof(h0)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,h6,sizeof(h6)-1,&sizebuff,NULL);
//迅雷看看
charj0[]={"#xunlei\r\n"};
charj1[]={"127.0.0.1mcfg.sandai.net\r\n"};
charj2[]={"127.0.0.1biz5.sandai.net\r\n"};
charj3[]={"127.0.0.1server1.adpolestar.net\r\n"};
charj4[]={"127.0.0.1advstat.xunlei.com\r\n"};
charj5[]={"127.0.0.1mpv.sandai.net\r\n"};
WriteFile(wenjianjubing,j0,sizeof(j0)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,j1,sizeof(j1)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,j2,sizeof(j2)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,j3,sizeof(j3)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,j3,sizeof(j3)-1,&sizebuff,NULL);
//QQ
charqq1[]={"#qq\r\n"};
charqq2[]={"127.0.0.1adslvfile.qq.com\r\n"};
charqq3[]={"127.0.0.1adsfile.qq.com\r\n"};
WriteFile(wenjianjubing,qq1,sizeof(qq1)-1,&sizebuff,NULL);
WriteFile(wenjianjubing,qq2,sizeof(qq2)-1,&sizebuff,NULL);
BOOLbWite=WriteFile(wenjianjubing,qq3,sizeof(qq3)-1,&sizebuff,NULL);
if(bWite!=0)
{
AfxMessageBox("屏蔽成功!");
SetFileAttributes("C:\\WINDOWS\\system32\\drivers\\etc\\hosts",1);
system("echoy|caclsC:\\WINDOWS\\system32\\drivers\\etc\\hosts/geveryone:r");
return;
}
else
{
AfxMessageBox("已经屏蔽!");
return;
}
}
voidCGuanggaoDlg::OnButton2()
{
//恢复
TCHARlujing[MAX_PATH]="C:\\DocumentsandSettings\\Administrator\\ApplicationData\\Macromedia\\FlashPlayer\\#SharedObjects\\";
TCHARlujing2[MAX_PATH]="C:\\DocumentsandSettings\\Administrator\\ApplicationData\\Macromedia\\FlashPlayer\\#SharedObjects\\";
TCHARmingche2[MAX_PATH]="\\static.youku.com";
TCHARtudou[MAX_PATH]="\\js.tudouui.com";
HANDLEhFist2=FindFirstFile("C:\\DocumentsandSettings\\Administrator\\ApplicationData\\Macromedia\\FlashPlayer\\#SharedObjects\\*",&FindFileData);
FindNextFile(hFist2,&FindFileData);
FindNextFile(hFist2,&FindFileData);
strcat(lujing,FindFileData.cFileName);
strcat(lujing2,FindFileData.cFileName);
LPSTRdedaoquanlujing=strcat(lujing,mingche2);
LPSTRdedaoquanlujing2=strcat(lujing2,tudou);
DeleteFile(dedaoquanlujing);
DeleteFile(dedaoquanlujing2);
CloseHandle(hFist2);
system("echoy|caclsC:\\WINDOWS\\system32\\drivers\\etc\\hosts/geveryone:f");
SetFileAttributes("C:\\WINDOWS\\system32\\drivers\\etc\\hosts",0);
BOOLbCpy=CopyFile("C:\\WINDOWS\\system32\\drivers\\etc\\bak.hosts","C:\\WINDOWS\\system32\\drivers\\etc\\hosts",FALSE);
if(bCpy!=0)
{
AfxMessageBox("恢复成功!");
return;
}
else
{
AfxMessageBox("恢复失败!");
return;
}
}
voidCGuanggaoDlg::OnButton3()
{
//优酷测试
ShellExecute(NULL,"open","http://www.youku.com",NULL,NULL,SW_SHOWNORMAL);
}
希望本文所述对大家的C++程序设计有所帮助。