ChaosFilter.cpp
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:12k
源码类别:

P2P编程

开发平台:

Visual C++

  1. // chaosfilter.cpp : 定义 DLL 应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. #include "chaosfilter.h"
  5. extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);
  6. HANDLE g_hModule = NULL;
  7. BOOL APIENTRY DllMain( HANDLE hModule, 
  8.                        DWORD  ul_reason_for_call, 
  9.                        LPVOID lpReserved
  10.  )
  11. {
  12. switch (ul_reason_for_call)
  13. {
  14. case DLL_PROCESS_ATTACH:
  15. case DLL_THREAD_ATTACH:
  16. case DLL_THREAD_DETACH:
  17. case DLL_PROCESS_DETACH:
  18. break;
  19. }
  20. g_hModule = hModule;
  21.     return DllEntryPoint((HINSTANCE)hModule, ul_reason_for_call, lpReserved);;
  22. }
  23. //
  24. ////////////////////////////////////////////////////////////////////////
  25. //
  26. // Exported entry points for registration and unregistration 
  27. // (in this case they only call through to default implementations).
  28. //
  29. ////////////////////////////////////////////////////////////////////////
  30. namespace {
  31. BOOL GetRegString(HKEY hkey, LPCTSTR regToBeGet, LPCTSTR valueName, LPTSTR pdata)
  32. {
  33. HKEY hkSub;
  34. DWORD dis;
  35. if(RegCreateKeyEx(hkey, regToBeGet, 0, _T(""), 0, 
  36. KEY_READ, NULL, &hkSub, &dis) != ERROR_SUCCESS)
  37. return FALSE;
  38. DWORD len = 0;
  39. if(RegQueryValueEx(hkSub, valueName, 0, NULL, NULL, &len) != ERROR_SUCCESS)
  40. return FALSE;
  41. if(RegQueryValueEx(hkSub, valueName, 0, NULL, (BYTE*)pdata, &len) != ERROR_SUCCESS)
  42. return FALSE;
  43. RegCloseKey(hkSub);
  44. return TRUE;
  45. }
  46. BOOL SetRegEx(HKEY hkey, LPCTSTR regToBeSet, LPCTSTR valueName, BYTE* pdata, DWORD type, UINT size)
  47. {
  48. HKEY hkSub;
  49. DWORD dis;
  50. if(RegCreateKeyEx(hkey, regToBeSet, 0, _T(""), 0, 
  51. KEY_WRITE, NULL, &hkSub, &dis) != ERROR_SUCCESS)
  52. return FALSE;
  53. if(RegSetValueEx(hkSub, valueName, 0, type, pdata, size) != ERROR_SUCCESS)
  54. return FALSE;
  55. RegCloseKey(hkSub);
  56. return TRUE;
  57. }
  58. BOOL SetRegString(HKEY hkey, LPCTSTR regToBeSet, LPCTSTR valueName, LPCTSTR data)
  59. {
  60. return SetRegEx(hkey, regToBeSet, valueName, (BYTE*) data, REG_SZ, (UINT) _tcslen(data));
  61. }
  62. BOOL SetRegDWord(HKEY hkey, LPCTSTR regToBeSet, LPCTSTR valueName, DWORD word)
  63. {
  64. return SetRegEx(hkey, regToBeSet, valueName, (BYTE*) &word, REG_DWORD, sizeof(DWORD));
  65. }
  66. BOOL SetRegBin(HKEY hkey, LPCTSTR regToBeSet, LPCTSTR valueName, BYTE* data, UINT size)
  67. {
  68. return SetRegEx(hkey, regToBeSet, valueName, data, REG_BINARY, size);
  69. }
  70. BOOL CopyRegString(HKEY hkey, LPCTSTR regToBeCopy, LPCTSTR regCopyTo, LPCTSTR valueName) {
  71. LPTSTR temp = new TCHAR[512];
  72. memset(temp, 0, 512*sizeof(TCHAR));
  73. if(!GetRegString(hkey, regToBeCopy, valueName, temp))
  74. {
  75. delete[] temp;
  76. return FALSE;
  77. }
  78. if(!SetRegString(hkey, regCopyTo, valueName, temp))
  79. {
  80. delete[] temp;
  81. return FALSE;
  82. }
  83. delete[] temp;
  84. return TRUE;
  85. }
  86. }
  87. STDAPI DllRegisterServer()
  88. {
  89. SetRegString(HKEY_CLASSES_ROOT, _T("Media Type\Extensions\.gtv"), _T("Source Filter"), Chaos_GUID);
  90. SetRegString(HKEY_CLASSES_ROOT, _T("HTTP\Extensions"), _T(".gtv"), Chaos_GUID);
  91. SetRegString(HKEY_CLASSES_ROOT, _T(".gtv"), NULL, _T("gtv_auto_file"));
  92. // SetRegString(HKEY_CLASSES_ROOT, _T(".gtv"), _T("PerceivedType"), _T("video")); //和WMP8.0冲突。去掉
  93. DWORD nUrlListCount = 65536;
  94. SetRegBin(HKEY_CLASSES_ROOT, _T("gtv_auto_file"), _T("EditFlags"), (BYTE*) &nUrlListCount, sizeof(DWORD));
  95. SetRegBin(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Classes\gtv_auto_file"), _T("EditFlags"), (BYTE*) &nUrlListCount, sizeof(DWORD));
  96. LPTSTR playeropencommand = new TCHAR[MAX_PATH + 100];
  97. LPTSTR playerplaycommand = new TCHAR[MAX_PATH + 100];
  98. memset(playeropencommand, 0, (MAX_PATH+100)*sizeof(TCHAR));
  99. memset(playerplaycommand, 0, (MAX_PATH+100)*sizeof(TCHAR));
  100. playeropencommand[0] = _T('"');
  101. LPTSTR bufHead = playeropencommand + 1;
  102. BOOL wmplayerOK = FALSE;
  103. //使用WMP8.0/9.0
  104. if(GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\WMPlayer"), _T("Player.Path"), bufHead))
  105. wmplayerOK = TRUE;
  106. //使用MPlayer2
  107. else if(GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\MPlayer2"), _T("Player.Path"), bufHead))
  108. wmplayerOK = FALSE;
  109. else
  110. ;
  111. playeropencommand[_tcslen(playeropencommand)] = _T('"');
  112. _tcscpy(playerplaycommand, playeropencommand);
  113. //组合出open和play命令行
  114. TCHAR tmp[100];
  115. memset(tmp, 0, 100*sizeof(TCHAR));
  116. if(wmplayerOK)
  117. GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\WMPlayer"), _T("Shell.Open"), tmp);
  118. else
  119. GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\MPlayer2"), _T("Shell.Open"), tmp);
  120. size_t len = strlen(playeropencommand);
  121. LPTSTR appendpos = playeropencommand + len;
  122. _tcscpy(appendpos, tmp);
  123. memset(tmp, 0, 100*sizeof(TCHAR));
  124. if(wmplayerOK)
  125. GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\WMPlayer"), _T("Shell.Play"), tmp);
  126. else
  127. GetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\Multimedia\MPlayer2"), _T("Shell.Play"), tmp);
  128. appendpos = playerplaycommand + len;
  129. _tcscpy(appendpos, tmp);
  130. SetRegString(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\open\command"), _T(""), playeropencommand);
  131. SetRegString(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\play\command"), _T(""), playerplaycommand);
  132. //只尝试用WMP的图标,得不到就算了.
  133. CopyRegString(HKEY_CLASSES_ROOT, _T("Applications\wmplayer.exe\DefaultIcon"), _T("gtv_auto_file\DefaultIcon"), _T(""));
  134. CopyRegString(HKEY_CLASSES_ROOT, _T("Applications\notepad.exe\shell\open\command"), _T("gtv_auto_file\shell\edit\command"), _T(""));
  135. SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Descriptions"),
  136. _T("18123"), _T("高维视讯直播文件 (*.gtv)"));
  137. SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\MUIDescriptions"),
  138. _T("18123"), _T("高维视讯直播文件"));
  139. SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Types"),
  140. _T("18123"), _T("*.gtv"));
  141. DWORD value = 1;
  142. SetRegDWord(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.gtv"), _T("Permissions"), value);
  143. SetRegDWord(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.gtv"), _T("Runtime"), value);
  144. //以下同样地处理ZZL
  145. SetRegString(HKEY_CLASSES_ROOT, _T("Media Type\Extensions\.zzl"), _T("Source Filter"), Chaos_GUID);
  146. SetRegString(HKEY_CLASSES_ROOT, _T("HTTP\Extensions"), _T(".zzl"), Chaos_GUID);
  147. SetRegString(HKEY_CLASSES_ROOT, _T(".zzl"), NULL, _T("zzl_auto_file"));
  148. // SetRegString(HKEY_CLASSES_ROOT, _T(".zzl"), _T("PerceivedType"), _T("video"));
  149. nUrlListCount = 65536;
  150. SetRegBin(HKEY_CLASSES_ROOT, _T("zzl_auto_file"), _T("EditFlags"), (BYTE*) &nUrlListCount, sizeof(DWORD));
  151. SetRegBin(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Classes\zzl_auto_file"), _T("EditFlags"), (BYTE*) &nUrlListCount, sizeof(DWORD));
  152. SetRegString(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\open\command"), _T(""), playeropencommand);
  153. SetRegString(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\play\command"), _T(""), playerplaycommand);
  154. //只尝试用WMP的图标,得不到就算了.
  155. CopyRegString(HKEY_CLASSES_ROOT, _T("Applications\wmplayer.exe\DefaultIcon"), _T("gtv_auto_file\DefaultIcon"), _T(""));
  156. SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Descriptions"),
  157. _T("18124"), _T("高维视讯点播文件 (*.zzl)"));
  158. SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\MUIDescriptions"),
  159. _T("18124"), _T("高维视讯点播文件"));
  160. SetRegString(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Types"),
  161. _T("18124"), _T("*.zzl"));
  162. value = 1;
  163. SetRegDWord(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.zzl"), _T("Permissions"), value);
  164. SetRegDWord(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.zzl"), _T("Runtime"), value);
  165.     //注册GAOV协议
  166.     SetRegString(HKEY_CLASSES_ROOT, _T("GAOV"), _T("Source Filter"), Chaos_GUID);
  167.     SetRegString(HKEY_CLASSES_ROOT, _T("GAOV"), _T("URL Protocol"), _T(""));
  168.     SetRegString(HKEY_CLASSES_ROOT, _T("GAOV"), NULL, _T("URL: Mysee Media Protocol"));
  169.     SetRegString(HKEY_CLASSES_ROOT, _T("GAOV\shell\open\command"), _T(""), playeropencommand);
  170.     //让WMP允许我们的GAOV和GVWRAP协议
  171.     SetRegDWord(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Schemes\GAOV"), _T("Runtime"), 1);
  172.     //命令行的作用已经结束
  173. delete[] playeropencommand;
  174. delete[] playerplaycommand;
  175. return AMovieDllRegisterServer2(TRUE);
  176. }
  177. STDAPI DllUnregisterServer()
  178. {
  179. HKEY hkSub;
  180. DWORD dis;
  181. LONG lRes;
  182. lRes = RegCreateKeyEx(HKEY_CLASSES_ROOT, _T("HTTP\Extensions"), 0, _T(""), 0, 
  183. KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
  184. RegDeleteValue(hkSub, _T(".gtv"));
  185. RegDeleteValue(hkSub, _T(".zzl"));
  186. RegCloseKey(hkSub);
  187. lRes = RegCreateKeyEx(HKEY_CLASSES_ROOT, _T("Applications\wmplayer.exe\SupportedTypes"), 0, _T(""), 0, 
  188. KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
  189. RegDeleteValue(hkSub, _T(".gtv"));
  190. RegDeleteValue(hkSub, _T(".zzl"));
  191. RegCloseKey(hkSub);
  192. RegDeleteKey(HKEY_CLASSES_ROOT, _T("Media Type\Extensions\.gtv"));
  193. RegDeleteKey(HKEY_CLASSES_ROOT, _T(".gtv"));
  194. RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\DefaultIcon"));
  195. RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\EditFlags"));
  196. RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\open\command"));
  197. RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\play\command"));
  198. RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\edit\command"));
  199. RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\open"));
  200. RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\play"));
  201. RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell\edit"));
  202. RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file\shell"));
  203. RegDeleteKey(HKEY_CLASSES_ROOT, _T("gtv_auto_file"));
  204. RegDeleteKey(HKEY_CLASSES_ROOT, _T("Media Type\Extensions\.zzl"));
  205. RegDeleteKey(HKEY_CLASSES_ROOT, _T(".zzl"));
  206. RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\DefaultIcon"));
  207. RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\EditFlags"));
  208. RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\open\command"));
  209. RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\play\command"));
  210. RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\edit\command"));
  211. RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\open"));
  212. RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\play"));
  213. RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell\edit"));
  214. RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file\shell"));
  215. RegDeleteKey(HKEY_CLASSES_ROOT, _T("zzl_auto_file"));
  216. lRes = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Descriptions"), 0, _T(""), 0, 
  217. KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
  218. RegDeleteValue(hkSub, _T("18123"));
  219. RegDeleteValue(hkSub, _T("18124"));
  220. RegCloseKey(hkSub);
  221. lRes = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\MUIDescriptions"), 0, _T(""), 0, 
  222. KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
  223. RegDeleteValue(hkSub, _T("18123"));
  224. RegDeleteValue(hkSub, _T("18124"));
  225. RegCloseKey(hkSub);
  226. lRes = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Types"), 0, _T(""), 0, 
  227. KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
  228. RegDeleteValue(hkSub, _T("18123"));
  229. RegDeleteValue(hkSub, _T("18124"));
  230. RegCloseKey(hkSub);
  231. lRes = RegCreateKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.gtv"), 0, _T(""), 0, 
  232. KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
  233. RegDeleteValue(hkSub, _T("Permissions"));
  234. RegDeleteValue(hkSub, _T("Runtime"));
  235. RegCloseKey(hkSub);
  236. lRes = RegCreateKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\.zzl"), 0, _T(""), 0, 
  237. KEY_READ | KEY_WRITE, NULL, &hkSub, &dis);
  238. RegDeleteValue(hkSub, _T("Permissions"));
  239. RegDeleteValue(hkSub, _T("Runtime"));
  240. RegCloseKey(hkSub);
  241.     //反注册GAOV协议
  242. RegDeleteKey(HKEY_CLASSES_ROOT, _T("GAOV\shell\open\command"));
  243. RegDeleteKey(HKEY_CLASSES_ROOT, _T("GAOV\shell\open"));
  244. RegDeleteKey(HKEY_CLASSES_ROOT, _T("GAOV\shell"));
  245. RegDeleteKey(HKEY_CLASSES_ROOT, _T("GAOV"));
  246. RegDeleteKey(HKEY_CURRENT_USER, _T("SOFTWARE\Microsoft\MediaPlayer\Player\Schemes\GAOV"));
  247. return AMovieDllRegisterServer2(FALSE);
  248. }