From 2886aa61ef6eabfd7af8dba01206c08371807856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 15 Mar 2024 16:11:02 +0800 Subject: [PATCH] Remove dependency on comshim --- go.mod | 1 - go.sum | 2 -- internal/winfw/winfw.go | 8 +++++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 5f6e967..61367e8 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/sagernet/gvisor v0.0.0-20240315080113-799fb6b6d311 github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97 github.com/sagernet/sing v0.3.6 - github.com/scjalliance/comshim v0.0.0-20230315213746-5e51f40bd3b9 go4.org/netipx v0.0.0-20231129151722-fdeea329fbba golang.org/x/net v0.22.0 golang.org/x/sys v0.18.0 diff --git a/go.sum b/go.sum index 2670aa1..8b1390b 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,6 @@ github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97 h1:iL5gZI3uFp0X6E github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM= github.com/sagernet/sing v0.3.6 h1:dsEdYLKBQlrxUfw1a92x0VdPvR1/BOxQ+HIMyaoEJsQ= github.com/sagernet/sing v0.3.6/go.mod h1:+60H3Cm91RnL9dpVGWDPHt0zTQImO9Vfqt9a4rSambI= -github.com/scjalliance/comshim v0.0.0-20230315213746-5e51f40bd3b9 h1:rc/CcqLH3lh8n+csdOuDfP+NuykE0U6AeYSJJHKDgSg= -github.com/scjalliance/comshim v0.0.0-20230315213746-5e51f40bd3b9/go.mod h1:a/83NAfUXvEuLpmxDssAXxgUgrEy12MId3Wd7OTs76s= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 h1:gga7acRE695APm9hlsSMoOoE65U4/TcqNj90mc69Rlg= github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= diff --git a/internal/winfw/winfw.go b/internal/winfw/winfw.go index 7798fcb..f8f17bb 100644 --- a/internal/winfw/winfw.go +++ b/internal/winfw/winfw.go @@ -12,7 +12,6 @@ import ( "github.com/go-ole/go-ole" "github.com/go-ole/go-ole/oleutil" - "github.com/scjalliance/comshim" ) // Firewall related API constants. @@ -250,7 +249,10 @@ func FirewallRuleExistsByName(rules *ole.IDispatch, name string) (bool, error) { // then: // dispatch firewallAPIRelease(u, fwp) func firewallAPIInit() (*ole.IUnknown, *ole.IDispatch, error) { - comshim.Add(1) + err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED) + if err != nil { + return nil, nil, fmt.Errorf("Failed to initialize COM: %s", err) + } unknown, err := oleutil.CreateObject("HNetCfg.FwPolicy2") if err != nil { @@ -270,5 +272,5 @@ func firewallAPIInit() (*ole.IUnknown, *ole.IDispatch, error) { func firewallAPIRelease(u *ole.IUnknown, fwp *ole.IDispatch) { fwp.Release() u.Release() - comshim.Done() + ole.CoUninitialize() }