论坛风格切换
 
  • 帖子
  • 日志
  • 用户
  • 版块
  • 群组
帖子
购买邀请后未收到邀请联系sdbeta@qq.com
  • 2059阅读
  • 0回复

[绿色软件]QQ优化小工具源码 [复制链接]

上一主题 下一主题
离线vs007
 
发帖
*
今日发帖
最后登录
1970-01-01
只看楼主 倒序阅读 使用道具 楼主  发表于: 2012-04-16 21:20:01
  1. //.h
  2. //---------------------------------------------------------------------------
  3. #ifndef Unit1H
  4. #define Unit1H
  5. //---------------------------------------------------------------------------
  6. #include <Classes.hpp>
  7. #include <Controls.hpp>
  8. #include <StdCtrls.hpp>
  9. #include <Forms.hpp>
  10. //---------------------------------------------------------------------------
  11. class TForm1 : public TForm
  12. {
  13. __published: // IDE-managed Components
  14. void __fastcall Button1Click(TObject *Sender);
  15. void __fastcall Button2Click(TObject *Sender);
  16. void __fastcall FormCreate(TObject *Sender);
  17. private: // User declarations
  18. public: // User declarations
  19. __fastcall TForm1(TComponent* Owner);
  20. };
  21. //---------------------------------------------------------------------------
  22. extern PACKAGE TForm1 *Form1;
  23. //---------------------------------------------------------------------------
  24. #endif
  25. //---------------------------------------------------------------------------
  26. //.cpp
  27. //---------------------------------------------------------------------------
  28. #include <vcl.h>
  29. #pragma hdrstop
  30. #include "Unit1.h"
  31. #include <SysUtils.hpp>
  32. #include <Dbghelp.h>
  33. #include <windows.h>
  34. #include <Registry.hpp>
  35. #include <stdio.h>
  36. //---------------------------------------------------------------------------
  37. #pragma package(smart_init)
  38. #pragma resource "*.dfm"
  39. TForm1 *Form1;
  40. TGroupBox *GroupBox;
  41. TCheckBox *CheckBox[8];
  42. AnsiString appdata = getenv("APPDATA");
  43. AnsiString temp = getenv("temp");
  44. AnsiString CurPath = GetCurrentDir();
  45. AnsiString Bin = CurPath + "\\Bin";
  46. AnsiString QQ = appdata + "\\Tencent\\QQ";
  47. AnsiString QQPhotoDrawEx = Bin + "\\QQPhotoDrawEx.dll";
  48. AnsiString npQQPhotoDrawEx = Bin + "\\npQQPhotoDrawEx.dll";
  49. AnsiString TXFTNActiveX = Bin + "\\TXFTNActiveX.dll";
  50. 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"};
  51. 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"};
  52. //---------------------------------------------------------------------------
  53. __fastcall TForm1::TForm1(TComponent* Owner)
  54. : TForm(Owner)
  55. {
  56. }
  57. //---------------------------------------------------------------------------
  58. bool DeleteDirectoryEx(const AnsiString &P)
  59. {
  60. if(P.IsEmpty()||P.Length()<4)
  61. return false;//参数长度必须大于3,即不能为磁盘根目录或空白
  62. int len=P.Length();
  63. char *Path=P.c_str();
  64. AnsiString Dir=Path;
  65. if(Path[len-1]!='\\')
  66. Dir=Dir+'\\';
  67. AnsiString Files=Dir + "*.*";
  68. WIN32_FIND_DATA wfd;
  69. HANDLE hFind=FindFirstFile(Files.c_str(),&wfd);
  70. bool Ret=true;
  71. AnsiString Tmp;
  72. if(hFind!=INVALID_HANDLE_VALUE)
  73. {
  74. bool bFind=true;
  75. while(bFind)
  76. {
  77. if(wfd.cFileName[0]!='.') //排除.与..
  78. {
  79. Tmp = Dir + wfd.cFileName;
  80. if(wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) //递归删除所有子目录
  81. Ret = Ret && DeleteDirectoryEx(Tmp.c_str());
  82. else
  83. {//删除所有文件,属性设置为Normal
  84. SetFileAttributes(Tmp.c_str(),FILE_ATTRIBUTE_NORMAL);
  85. Ret = Ret && DeleteFile(Tmp.c_str());
  86. }
  87. }
  88. bFind = FindNextFile(hFind,&wfd);
  89. }
  90. FindClose(hFind);
  91. }
  92. if(Ret)
  93. return RemoveDirectory(Path);
  94. return false;
  95. }
  96. //---------------------------------------------------------------------------
  97. bool CreateDirectoryEx(const AnsiString &path)
  98. {
  99. PCSTR str = path.SubString(1,path.LastDelimiter("\\\\")).c_str();
  100. return MakeSureDirectoryPathExists(str);
  101. }
  102. //---------------------------------------------------------------------------
  103. void CreateFileSD(const AnsiString &Filepath,bool ChooseDenied = true)
  104. {
  105. HANDLE file;
  106. SECURITY_ATTRIBUTES sa; //和文件有关的安全结构
  107. SECURITY_DESCRIPTOR sd; //声明一个SD
  108. BYTE aclBuffer[1024];
  109. PACL pacl=(PACL)&aclBuffer; //声明一个ACL,长度是1024
  110. BYTE sidBuffer[100];
  111. PSID psid=(PSID) &sidBuffer; //声明一个SID,长度是100
  112. DWORD sidBufferSize = 100;
  113. char domainBuffer[80];
  114. DWORD domainBufferSize = 80;
  115. SID_NAME_USE snu;
  116. //初始化SD
  117. InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
  118. //初始化ACL
  119. InitializeAcl(pacl,1024,ACL_REVISION);
  120. //查找用户,并取得用户SID
  121. LookupAccountName(0,"Everyone",psid,&sidBufferSize,domainBuffer,&domainBufferSize,&snu);
  122. //设置该用户的Access-Allowed或Access-Denied的ACE,其权限为只读或可读写
  123. if(ChooseDenied)
  124. AddAccessDeniedAce(pacl,ACL_REVISION,GENERIC_ALL,psid);
  125. else
  126. AddAccessAllowedAce(pacl,ACL_REVISION,GENERIC_ALL,psid);
  127. //把ACL设置到SD中
  128. SetSecurityDescriptorDacl(&sd,TRUE,pacl,FALSE);
  129. //把SD放到文件安全结构SA中
  130. sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  131. sa.bInheritHandle = FALSE;
  132. sa.lpSecurityDescriptor = &sd;
  133. file = CreateFile(Filepath.c_str(),GENERIC_ALL,FILE_SHARE_READ,&sa,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,0);
  134. CloseHandle(file);
  135. }
  136. //---------------------------------------------------------------------------
  137. void DeleteAD(const AnsiString &path)
  138. {
  139. if(DirectoryExists(path))
  140. {
  141. if(DeleteDirectoryEx(path))
  142. CreateFileSD(path.c_str(),false);
  143. }
  144. else
  145. {
  146. CreateDirectoryEx(path);
  147. CreateFileSD(path.c_str(),false);
  148. }
  149. }
  150. //---------------------------------------------------------------------------
  151. bool RegisterDLLOrNot(AnsiString DLL,bool isReg = true)
  152. {
  153. HINSTANCE hLib = LoadLibrary(DLL.c_str());
  154. if(hLib == NULL)
  155. {
  156. MessageBox(0, "不能载入Dll文件!", "结果", MB_OK);
  157. return false;
  158. }
  159. //获取注册函数DllRegisterServer or DllUnregisterServer地址
  160. FARPROC lpDllEntryPoint = NULL;
  161. if(isReg)
  162. lpDllEntryPoint = GetProcAddress(hLib, "DllRegisterServer");
  163. else
  164. lpDllEntryPoint = GetProcAddress(hLib, "DllUnregisterServer");
  165. //调用注册函数DllRegisterServer or DllUnRegisterServer
  166. if(lpDllEntryPoint != NULL)
  167. {
  168. if(FAILED((*lpDllEntryPoint)()))
  169. {
  170. FreeLibrary(hLib);
  171. return false;
  172. }
  173. MessageBox(0, "注册或者反注册成功", "结果", MB_OK);
  174. }
  175. else
  176. MessageBox(0, "调用DllRegisterServer或DllUnregisterServer失败!", "结果", MB_OK);
  177. FreeLibrary(hLib);
  178. return true;
  179. }
  180. //---------------------------------------------------------------------------
  181. void __fastcall TForm1::FormCreate(TObject *Sender)
  182. {
  183. if(Application->MessageBox("该工具是否放置到QQ安装目录下与Bin文件夹相同目录?如没有请点取消!","QQ优化小工具",MB_OKCANCEL)==1)
  184. {
  185. GroupBox = new TGroupBox(Form1);
  186. GroupBox->Parent = Form1;
  187. GroupBox->Top = 10;
  188. GroupBox->Left = 10;
  189. GroupBox->Height = 200;
  190. GroupBox->Width = 260;
  191. GroupBox->Caption = "功能优化列表";
  192. GroupBox->Visible = true;
  193. for(int i=0;i<10;++i)
  194. {
  195. CheckBox = new TCheckBox(GroupBox);
  196. CheckBox->Parent = GroupBox;
  197. CheckBox->Height = 17;
  198. CheckBox->Top = 17+17*i;
  199. CheckBox->Left = 17;
  200. CheckBox->Width = 200;
  201. CheckBox->Visible = true;
  202. }
  203. CheckBox[0]->Caption="屏蔽QQ自动升级文件";
  204. CheckBox[0]->Checked = true;
  205. CheckBox[1]->Caption="屏蔽QQ群相册快照临时文件";
  206. CheckBox[2]->Caption="屏蔽QQ祈福之类小图标";
  207. CheckBox[3]->Caption="屏蔽登陆界面节日";
  208. CheckBox[4]->Caption="屏蔽登录中图片链接";
  209. CheckBox[5]->Caption="屏蔽QQ群页面";
  210. CheckBox[6]->Caption="注册网盘、相册上传dll";
  211. CheckBox[7]->Checked = true;
  212. CheckBox[7]->Caption="彻底屏蔽QQ安全扫描";
  213. CheckBox[8]->Caption="桌面便签补丁";
  214. CheckBox[9]->Caption="魔法表情补丁";
  215. TButton *Button1 = new TButton(Form1);
  216. TButton *Button2 = new TButton(Form1);
  217. Button1->Parent = Form1;
  218. Button2->Parent = Form1;
  219. Button1->Caption = "执行";
  220. Button2->Caption = "恢复";
  221. Button1->OnClick = Button1Click;
  222. Button2->OnClick = Button2Click;
  223. Button1->Left = 10;
  224. Button1->Top = 215;
  225. Button2->Left = 190;
  226. Button2->Top = 215;
  227. }
  228. else
  229. {
  230. ShowMessage("请放置到QQ安装目录下重新运行次工具");
  231. Application->Terminate();
  232. }
  233. }
  234. //---------------------------------------------------------------------------
  235. void __fastcall TForm1::Button1Click(TObject *Sender)
  236. {
  237. for(int i=0;i<5;++i)
  238. if(CheckBox->Checked)
  239. DeleteAD(path);
  240. if(CheckBox[5]->Checked)
  241. {
  242. DeleteDirectoryEx(path[5]);
  243. DeleteAD(path[6]);
  244. }
  245. if(CheckBox[6]->Checked)
  246. {
  247. RegisterDLLOrNot(QQPhotoDrawEx);
  248. RegisterDLLOrNot(npQQPhotoDrawEx);
  249. RegisterDLLOrNot(TXFTNActiveX);
  250. }
  251. if(CheckBox[7]->Checked)
  252. {
  253. DeleteAD(path[8]);
  254. DeleteAD(path[9]);
  255. for(int j=0;j<13;++j)
  256. CreateFileSD(filename[j]);
  257. }
  258. if(CheckBox[8]->Checked)
  259. {
  260. AnsiString FromPath = CurPath+"\\Misc\\TxApp";
  261. AnsiString ToPath = QQ+"\\TxApp";
  262. int nLengthFrm = strlen(FromPath.c_str());
  263. char *NewPathFrm = new char[nLengthFrm+2];
  264. strcpy(NewPathFrm,FromPath.c_str());
  265. NewPathFrm[nLengthFrm] = '\0';
  266. NewPathFrm[nLengthFrm+1] = '\0';
  267. SHFILEOPSTRUCT FileOp;
  268. ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));
  269. FileOp.fFlags = FOF_NOCONFIRMATION ;
  270. FileOp.hNameMappings = NULL;
  271. FileOp.hwnd = NULL;
  272. FileOp.lpszProgressTitle = NULL;
  273. FileOp.pFrom = NewPathFrm;
  274. FileOp.pTo = ToPath.c_str();
  275. FileOp.wFunc = FO_COPY;
  276. SHFileOperation(&FileOp) == 0;
  277. }
  278. if(CheckBox[9]->Checked)
  279. {
  280. AnsiString xtml = CurPath +"\\Resource.1.65.2222\\Xtml.rdb";
  281. ExtractShortPathName(xtml);
  282. FILE *fp = fopen(xtml.c_str(),"rb+");
  283. if(fp!=NULL)
  284. {
  285. //跳到文件开始第x字节处
  286. fseek(fp, 0xA280D,SEEK_SET);
  287. //写入16进制值,
  288. char a = 0x0F;
  289. fwrite(&a,sizeof(a),1,fp);
  290. fclose(fp);
  291. }
  292. }
  293. ShowMessage("操作完成,请关闭!");
  294. }
  295. //---------------------------------------------------------------------------
  296. void __fastcall TForm1::Button2Click(TObject *Sender)
  297. {
  298. for(int i=0;i<5;++i)
  299. {
  300. if(CheckBox->Checked)
  301. {
  302. if(FileExists(path))
  303. DeleteFile(path);
  304. ShowMessage(CheckBox->Caption+"恢复完成");
  305. }
  306. }
  307. if(CheckBox[5]->Checked)
  308. {
  309. if(FileExists(path[6]))
  310. DeleteFile(path[6]);
  311. ShowMessage(CheckBox[5]->Caption+"恢复完成");
  312. }
  313. if(CheckBox[6]->Checked)
  314. {
  315. RegisterDLLOrNot(QQPhotoDrawEx,false);
  316. RegisterDLLOrNot(npQQPhotoDrawEx,false);
  317. RegisterDLLOrNot(TXFTNActiveX,false);
  318. ShowMessage(CheckBox[6]->Caption+"恢复完成");
  319. }
  320. if(CheckBox[7]->Checked)
  321. ShowMessage("该项建义不恢复!");
  322. if(CheckBox[8]->Checked)
  323. {
  324. AnsiString TxApp = QQ + "\\TxApp";
  325. DeleteDirectoryEx(TxApp);
  326. ShowMessage(CheckBox[8]->Caption+"恢复完成");
  327. }
  328. if(CheckBox[9]->Checked)
  329. {
  330. AnsiString xtml = CurPath +"\\Resource.1.65.2222\\Xtml.rdb";
  331. ExtractShortPathName(xtml);
  332. FILE *fp = fopen(xtml.c_str(),"rb+");
  333. if(fp!=NULL)
  334. {
  335. //跳到文件开始第x字节处
  336. fseek(fp, 0xA280D,SEEK_SET);
  337. //写入16进制值,
  338. char a = 0x08;
  339. fwrite(&a,sizeof(a),1,fp);
  340. fclose(fp);
  341. }
  342. }
  343. ShowMessage("操作完成,请关闭!");
  344. }
  345. //---------------------------------------------------------------------------


软件下载咨询邮箱: sdbeta@qq.com (回复及时)