From 8f23846d1c5696b3b88b5d8d0924f093cf0399ab Mon Sep 17 00:00:00 2001 From: Alexandr Stelnykovych Date: Tue, 13 May 2025 18:13:32 +0300 Subject: [PATCH 1/3] fix: Save and apply profile icon if it hasn't been applied yet Icon saving was not working in situations where profile.Name had not changed. --- service/profile/profile.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/service/profile/profile.go b/service/profile/profile.go index 340b77cd..df9f54ab 100644 --- a/service/profile/profile.go +++ b/service/profile/profile.go @@ -538,13 +538,14 @@ func (profile *Profile) updateMetadataFromSystem(ctx context.Context, md Matchin } // Apply new icon if found. - if newIcon != nil { + if newIcon != nil && !profile.iconExists(newIcon) { if len(profile.Icons) == 0 { profile.Icons = []binmeta.Icon{*newIcon} } else { profile.Icons = append(profile.Icons, *newIcon) profile.Icons = binmeta.SortAndCompactIcons(profile.Icons) } + changed = true } }() @@ -559,3 +560,13 @@ func (profile *Profile) updateMetadataFromSystem(ctx context.Context, md Matchin return nil } + +// Checks if the given icon already assigned to the profile. +func (profile *Profile) iconExists(newIcon *binmeta.Icon) bool { + for _, icon := range profile.Icons { + if icon.Value == newIcon.Value && icon.Type == newIcon.Type && icon.Source == newIcon.Source { + return true + } + } + return false +} From 84a8f755fe2b3f898547e2779aa2fbd682950f67 Mon Sep 17 00:00:00 2001 From: Alexandr Stelnykovych Date: Wed, 14 May 2025 17:28:33 +0300 Subject: [PATCH 2/3] Remove temporary replacement for `winres` package dependency --- go.mod | 3 --- go.sum | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index bdc5fa96..078c07ac 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,6 @@ module github.com/safing/portmaster go 1.22.0 -// TODO: Remove when https://github.com/tc-hib/winres/pull/4 is released. -replace github.com/tc-hib/winres => github.com/dhaavi/winres v0.2.2 - require ( github.com/VictoriaMetrics/metrics v1.35.1 github.com/Xuanwo/go-locale v1.1.1 diff --git a/go.sum b/go.sum index 2d05e593..a49f0efb 100644 --- a/go.sum +++ b/go.sum @@ -53,8 +53,6 @@ github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWa github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= -github.com/dhaavi/winres v0.2.2 h1:SUago7FwhgLSMyDdeuV6enBZ+ZQSl0KwcnbWzvlfBls= -github.com/dhaavi/winres v0.2.2/go.mod h1:1NTs+/DtKP1BplIL1+XQSoq4X1PUfLczexS7gf3x9T4= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= @@ -286,6 +284,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tannerryan/ring v1.1.2 h1:iXayOjqHQOLzuy9GwSKuG3nhWfzQkldMlQivcgIr7gQ= github.com/tannerryan/ring v1.1.2/go.mod h1:DkELJEjbZhJBtFKR9Xziwj3HKZnb/knRgljNqp65vH4= +github.com/tc-hib/winres v0.3.1 h1:CwRjEGrKdbi5CvZ4ID+iyVhgyfatxFoizjPhzez9Io4= +github.com/tc-hib/winres v0.3.1/go.mod h1:C/JaNhH3KBvhNKVbvdlDWkbMDO9H4fKKDaN7/07SSuk= github.com/tevino/abool v1.2.0 h1:heAkClL8H6w+mK5md9dzsuohKeXHUpY7Vw0ZCKW+huA= github.com/tevino/abool v1.2.0/go.mod h1:qc66Pna1RiIsPa7O4Egxxs9OqkuxDX55zznh9K07Tzg= github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= From cacf6c552abda0fe9c2fe7bf72ceccb3475644e2 Mon Sep 17 00:00:00 2001 From: Alexandr Stelnykovych Date: Wed, 14 May 2025 17:49:24 +0300 Subject: [PATCH 3/3] fix: (Windows) Replace ICO decoder for improved icon extraction Implemented direct use of `sergeymakinen/go-ico` decoder instead of `mat/besticon/ico` for icon conversion. The standard `image.Decode()` and `mat/besticon/ico` approaches failed with certain ICO files, particularly those containing cursor data from Windows executable resources. This change ensures more reliable handling of various ICO format variants. --- go.mod | 4 +++- go.sum | 6 ++++-- service/profile/binmeta/convert.go | 17 +++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 078c07ac..e984aa57 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,6 @@ require ( github.com/jackc/puddle/v2 v2.2.1 github.com/lmittmann/tint v1.0.5 github.com/maruel/panicparse/v2 v2.3.1 - github.com/mat/besticon v3.12.0+incompatible github.com/mattn/go-colorable v0.1.13 github.com/mattn/go-isatty v0.0.20 github.com/miekg/dns v1.1.62 @@ -67,6 +66,8 @@ require ( zombiezen.com/go/sqlite v1.3.0 ) +require github.com/sergeymakinen/go-bmp v1.0.0 // indirect + require ( github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect github.com/aead/ecdh v0.2.0 // indirect @@ -98,6 +99,7 @@ require ( github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/satori/go.uuid v1.2.0 // indirect github.com/seehuhn/sha256d v1.0.0 // indirect + github.com/sergeymakinen/go-ico v1.0.0-beta.0 github.com/spf13/pflag v1.0.5 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect diff --git a/go.sum b/go.sum index a49f0efb..c4e3072e 100644 --- a/go.sum +++ b/go.sum @@ -171,8 +171,6 @@ github.com/magiconair/properties v1.7.4-0.20170902060319-8d7837e64d3c/go.mod h1: github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/maruel/panicparse/v2 v2.3.1 h1:NtJavmbMn0DyzmmSStE8yUsmPZrZmudPH7kplxBinOA= github.com/maruel/panicparse/v2 v2.3.1/go.mod h1:s3UmQB9Fm/n7n/prcD2xBGDkwXD6y2LeZnhbEXvs9Dg= -github.com/mat/besticon v3.12.0+incompatible h1:1KTD6wisfjfnX+fk9Kx/6VEZL+MAW1LhCkL9Q47H9Bg= -github.com/mat/besticon v3.12.0+incompatible/go.mod h1:mA1auQYHt6CW5e7L9HJLmqVQC8SzNk2gVwouO0AbiEU= github.com/mattn/go-colorable v0.0.10-0.20170816031813-ad5389df28cd/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -252,6 +250,10 @@ github.com/seehuhn/fortuna v1.0.1 h1:lu9+CHsmR0bZnx5Ay646XvCSRJ8PJTi5UYJwDBX68H0 github.com/seehuhn/fortuna v1.0.1/go.mod h1:LX8ubejCnUoT/hX+1aKUtbKls2H6DRkqzkc7TdR3iis= github.com/seehuhn/sha256d v1.0.0 h1:TXTsAuEWr02QjRm153Fnvvb6fXXDo7Bmy1FizxarGYw= github.com/seehuhn/sha256d v1.0.0/go.mod h1:PEuxg9faClSveVuFXacQmi+NtDI/PX8bpKjtNzf2+s4= +github.com/sergeymakinen/go-bmp v1.0.0 h1:SdGTzp9WvCV0A1V0mBeaS7kQAwNLdVJbmHlqNWq0R+M= +github.com/sergeymakinen/go-bmp v1.0.0/go.mod h1:/mxlAQZRLxSvJFNIEGGLBE/m40f3ZnUifpgVDlcUIEY= +github.com/sergeymakinen/go-ico v1.0.0-beta.0 h1:m5qKH7uPKLdrygMWxbamVn+tl2HfiA3K6MFJw4GfZvQ= +github.com/sergeymakinen/go-ico v1.0.0-beta.0/go.mod h1:wQ47mTczswBO5F0NoDt7O0IXgnV4Xy3ojrroMQzyhUk= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= diff --git a/service/profile/binmeta/convert.go b/service/profile/binmeta/convert.go index bd210332..cfdca9ab 100644 --- a/service/profile/binmeta/convert.go +++ b/service/profile/binmeta/convert.go @@ -3,17 +3,22 @@ package binmeta import ( "bytes" "fmt" - "image" - _ "image/png" // Register png support for image package "github.com/fogleman/gg" - _ "github.com/mat/besticon/ico" // Register ico support for image package + + // Import the specialized ICO decoder package + // This package seems to work better than "github.com/mat/besticon/ico" with ICO files + // extracted from Windows binaries, particularly those containing cursor-related data + ico "github.com/sergeymakinen/go-ico" ) // ConvertICOtoPNG converts a an .ico to a .png image. -func ConvertICOtoPNG(ico []byte) (png []byte, err error) { - // Decode the ICO. - icon, _, err := image.Decode(bytes.NewReader(ico)) +func ConvertICOtoPNG(icoBytes []byte) (png []byte, err error) { + // Decode ICO image. + // Note: The standard approach with `image.Decode(bytes.NewReader(icoBytes))` sometimes fails + // when processing certain ICO files (particularly those with cursor data), + // as it reads initial bytes for format detection before passing the stream to the decoder. + icon, err := ico.Decode(bytes.NewReader(icoBytes)) if err != nil { return nil, fmt.Errorf("failed to decode ICO: %w", err) }