复制内容到剪贴板
代码:
//.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <SysUtils.hpp>
#include <Dbghelp.h>
#include <windows.h>
#include <Registry.hpp>
#include <stdio.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TGroupBox *GroupBox;
TCheckBox *CheckBox[8];
AnsiString appdata = getenv("APPDATA");
AnsiString temp = getenv("temp");
AnsiString CurPath = GetCurrentDir();
AnsiString Bin = CurPath + "\\Bin";
AnsiString QQ = appdata + "\\Tencent\\QQ";
AnsiString QQPhotoDrawEx = Bin + "\\QQPhotoDrawEx.dll";
AnsiString npQQPhotoDrawEx = Bin + "\\npQQPhotoDrawEx.dll";
AnsiString TXFTNActiveX = Bin + "\\TXFTNActiveX.dll";
AnsiString path[10]={QQ + "\\AuTemp",QQ + "\\Misc\\GroupAlbumSnapshot",QQ +"\\Misc\\LNN",QQ + "\\Misc\\LogoFile",QQ + "\\Misc\\OAPanelLogo",QQ + "\\Temp\\gm",QQ + "\\Misc\\GMF",CurPath + "\\Bin",QQ+"\\SafeBase",appdata+"\\Tencent\\QQDoctor"};
AnsiString filename[13]= {temp + "\\qqsafeud.exe",temp + "\\selfupdate.exe",temp + "\\tf000001.tsd",temp + "\\tm000001.tsd",temp + "\\tseh.dat",temp + "\\tsehres.dat",temp + "\\tseloder.dat",temp + "\\tsengine.dat",temp + "\\tssafeedit.dat",temp + "\\tsvulengine.dat",temp + "\\tsvulinc.dat",temp + "\\tvl00000.tvl",temp + "tvl00001.tvl"};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
bool DeleteDirectoryEx(const AnsiString &P)
{
if(P.IsEmpty()||P.Length()<4)
return false;//参数长度必须大于3,即不能为磁盘根目录或空白
int len=P.Length();
char *Path=P.c_str();
AnsiString Dir=Path;
if(Path[len-1]!='\\')
Dir=Dir+'\\';
AnsiString Files=Dir + "*.*";
WIN32_FIND_DATA wfd;
HANDLE hFind=FindFirstFile(Files.c_str(),&wfd);
bool Ret=true;
AnsiString Tmp;
if(hFind!=INVALID_HANDLE_VALUE)
{
bool bFind=true;
while(bFind)
{
if(wfd.cFileName[0]!='.') //排除.与..
{
Tmp = Dir + wfd.cFileName;
if(wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) //递归删除所有子目录
Ret = Ret && DeleteDirectoryEx(Tmp.c_str());
else
{//删除所有文件,属性设置为Normal
SetFileAttributes(Tmp.c_str(),FILE_ATTRIBUTE_NORMAL);
Ret = Ret && DeleteFile(Tmp.c_str());
}
}
bFind = FindNextFile(hFind,&wfd);
}
FindClose(hFind);
}
if(Ret)
return RemoveDirectory(Path);
return false;
}
//---------------------------------------------------------------------------
bool CreateDirectoryEx(const AnsiString &path)
{
PCSTR str = path.SubString(1,path.LastDelimiter("\\\")).c_str();
return MakeSureDirectoryPathExists(str);
}
//---------------------------------------------------------------------------
void CreateFileSD(const AnsiString &Filepath,DWORD AccessMask = GENERIC_WRITE ,bool ChooseDenied = true)
{
HANDLE file;
SECURITY_ATTRIBUTES sa; //和文件有关的安全结构
SECURITY_DESCRIPTOR sd; //声明一个SD
BYTE aclBuffer[1024];
PACL pacl=(PACL)&aclBuffer; //声明一个ACL,长度是1024
BYTE sidBuffer[100];
PSID psid=(PSID) &sidBuffer; //声明一个SID,长度是100
DWORD sidBufferSize = 100;
char domainBuffer[80];
DWORD domainBufferSize = 80;
SID_NAME_USE snu;
//初始化SD
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
//初始化ACL
InitializeAcl(pacl,1024,ACL_REVISION);
//查找用户,并取得用户SID
LookupAccountName(0,"Everyone",psid,&sidBufferSize,domainBuffer,&domainBufferSize,&snu);
//设置该用户的Access-Allowed或Access-Denied的ACE,其权限为只读或可读写
if(ChooseDenied)
AddAccessDeniedAce(pacl,ACL_REVISION,AccessMask,psid);
else
AddAccessAllowedAce(pacl,ACL_REVISION,AccessMask,psid);
//把ACL设置到SD中
SetSecurityDescriptorDacl(&sd,TRUE,pacl,FALSE);
//把SD放到文件安全结构SA中
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = FALSE;
sa.lpSecurityDescriptor = &sd;
file = CreateFile(Filepath.c_str(),NULL,FILE_SHARE_READ,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,0);
CloseHandle(file);
}
//---------------------------------------------------------------------------
void DeleteAD(const AnsiString &path)
{
if(DirectoryExists(path))
{
if(DeleteDirectoryEx(path))
CreateFileSD(path.c_str(),GENERIC_ALL,false);
}
else
{
CreateDirectoryEx(path);
CreateFileSD(path.c_str(),GENERIC_ALL,false);
}
}
//---------------------------------------------------------------------------
bool RegisterDLLOrNot(AnsiString DLL,bool isReg = true)
{
HINSTANCE hLib = LoadLibrary(DLL.c_str());
if(hLib == NULL)
{
MessageBox(0, "不能载入Dll文件!", "结果", MB_OK);
return false;
}
//获取注册函数DllRegisterServer or DllUnregisterServer地址
FARPROC lpDllEntryPoint = NULL;
if(isReg)
lpDllEntryPoint = GetProcAddress(hLib, "DllRegisterServer");
else
lpDllEntryPoint = GetProcAddress(hLib, "DllUnregisterServer");
//调用注册函数DllRegisterServer or DllUnRegisterServer
if(lpDllEntryPoint != NULL)
{
if(FAILED((*lpDllEntryPoint)()))
{
FreeLibrary(hLib);
return false;
}
MessageBox(0, "注册或者反注册成功", "结果", MB_OK);
}
else
MessageBox(0, "调用DllRegisterServer或DllUnregisterServer失败!", "结果", MB_OK);
FreeLibrary(hLib);
return true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
if(Application->MessageBox("该工具是否放置到QQ安装目录下与Bin文件夹相同目录?如没有请点取消!","QQ优化小工具",MB_OKCANCEL)==1)
{
GroupBox = new TGroupBox(Form1);
GroupBox->Parent = Form1;
GroupBox->Top = 10;
GroupBox->Left = 10;
GroupBox->Height = 200;
GroupBox->Width = 260;
GroupBox->Caption = "功能优化列表";
GroupBox->Visible = true;
for(int i=0;i<10;++i)
{
CheckBox = new TCheckBox(GroupBox);
CheckBox->Parent = GroupBox;
CheckBox->Height = 17;
CheckBox->Top = 17+17*i;
CheckBox->Left = 17;
CheckBox->Width = 200;
CheckBox->Visible = true;
}
CheckBox[0]->Caption="屏蔽QQ自动升级文件";
CheckBox[0]->Checked = true;
CheckBox[1]->Caption="屏蔽QQ群相册快照临时文件";
CheckBox[2]->Caption="屏蔽QQ祈福之类小图标";
CheckBox[3]->Caption="屏蔽登陆界面节日";
CheckBox[4]->Caption="屏蔽登录中图片链接";
CheckBox[5]->Caption="屏蔽QQ群页面";
CheckBox[6]->Caption="注册网盘、相册上传dll";
CheckBox[7]->Checked = true;
CheckBox[7]->Caption="彻底屏蔽QQ安全扫描";
CheckBox[8]->Caption="网络备忘录补丁";
CheckBox[9]->Caption="魔法表情补丁";
TButton *Button1 = new TButton(Form1);
TButton *Button2 = new TButton(Form1);
Button1->Parent = Form1;
Button2->Parent = Form1;
Button1->Caption = "执行";
Button2->Caption = "恢复";
Button1->OnClick = Button1Click;
Button2->OnClick = Button2Click;
Button1->Left = 10;
Button1->Top = 215;
Button2->Left = 190;
Button2->Top = 215;
}
else
{
ShowMessage("请放置到QQ安装目录下重新运行次工具");
Application->Terminate();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
for(int i=0;i<5;++i)
if(CheckBox->Checked)
DeleteAD(path);
if(CheckBox[5]->Checked)
{
DeleteDirectoryEx(path[5]);
DeleteAD(path[6]);
}
if(CheckBox[6]->Checked)
{
RegisterDLLOrNot(QQPhotoDrawEx);
RegisterDLLOrNot(npQQPhotoDrawEx);
RegisterDLLOrNot(TXFTNActiveX);
}
if(CheckBox[7]->Checked)
{
DeleteAD(path[8]);
DeleteAD(path[9]);
for(int j=0;j<13;++j)
CreateFileSD(filename[j]);
}
if(CheckBox[8]->Checked)
{
AnsiString FromPath = CurPath+"\\Misc\\TxApp";
AnsiString ToPath = QQ+"\\TxApp";
int nLengthFrm = strlen(FromPath.c_str());
char *NewPathFrm = new char[nLengthFrm+2];
strcpy(NewPathFrm,FromPath.c_str());
NewPathFrm[nLengthFrm] = '\0';
NewPathFrm[nLengthFrm+1] = '\0';
SHFILEOPSTRUCT FileOp;
ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));
FileOp.fFlags = FOF_NOCONFIRMATION ;
FileOp.hNameMappings = NULL;
FileOp.hwnd = NULL;
FileOp.lpszProgressTitle = NULL;
FileOp.pFrom = NewPathFrm;
FileOp.pTo = ToPath.c_str();
FileOp.wFunc = FO_COPY;
SHFileOperation(&FileOp) == 0;
}
if(CheckBox[9]->Checked)
{
AnsiString xtml = CurPath +"\\Resource.1.65.2221\\Xtml.rdb";
ExtractShortPathName(xtml);
FILE *fp = fopen(xtml.c_str(),"rb+");
if(fp!=NULL)
{
//跳到文件开始第x字节处
fseek(fp, 0xA280D,SEEK_SET);
//写入16进制值,
char a = 0x08;
fwrite(&a,sizeof(a),1,fp);
fclose(fp);
}
}
ShowMessage("操作完成,请关闭!"); ShowMessage("操作完成,请关闭!");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
for(int i=0;i<5;++i)
{
if(CheckBox->Checked)
{
if(FileExists(path))
DeleteFile(path);
ShowMessage(CheckBox->Caption+"恢复完成");
}
}
if(CheckBox[5]->Checked)
{
if(FileExists(path[6]))
DeleteFile(path[6]);
ShowMessage(CheckBox[5]->Caption+"恢复完成");
}
if(CheckBox[6]->Checked)
{
RegisterDLLOrNot(QQPhotoDrawEx,false);
RegisterDLLOrNot(npQQPhotoDrawEx,false);
RegisterDLLOrNot(TXFTNActiveX,false);
ShowMessage(CheckBox[6]->Caption+"恢复完成");
}
if(CheckBox[7]->Checked)
{
for(int j=0;j<13;++j)
{
CreateFileSD(filename[j],GENERIC_ALL,false);
DeleteFile(filename[j]);
}
ShowMessage(CheckBox[7]->Caption+"恢复完成");
}
if(CheckBox[8]->Checked)
{
AnsiString TxApp = QQ + "\\TxApp";
DeleteDirectoryEx(TxApp);
ShowMessage(CheckBox[8]->Caption+"恢复完成");
}
if(CheckBox[9]->Checked)
{
AnsiString xtml = CurPath +"\\Resource.1.65.2221\\Xtml.rdb";
ExtractShortPathName(xtml);
FILE *fp = fopen(xtml.c_str(),"rb+");
if(fp!=NULL)
{
//跳到文件开始第x字节处
fseek(fp, 0xA280D,SEEK_SET);
//写入16进制值,
char a = 0x08;
fwrite(&a,sizeof(a),1,fp);
fclose(fp);
}
}
ShowMessage("操作完成,请关闭!");