From 674042df36ac3e98d788001d81f3765e2b03cbc0 Mon Sep 17 00:00:00 2001 From: Andrey Pshenkin Date: Sat, 25 Nov 2023 20:16:24 +0000 Subject: [PATCH] fix obfuscated build binding ordering (#3071) * fix obfuscated build binding ordering * remove unused string method * add to changelog --------- Co-authored-by: Lea Anthony --- v2/internal/binding/db.go | 33 +++++++++++++++++---------------- website/src/pages/changelog.mdx | 5 +++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/v2/internal/binding/db.go b/v2/internal/binding/db.go index 1fc7e8c66..f7b793839 100644 --- a/v2/internal/binding/db.go +++ b/v2/internal/binding/db.go @@ -2,7 +2,6 @@ package binding import ( "encoding/json" - "sort" "sync" "unsafe" ) @@ -17,17 +16,22 @@ type DB struct { methodMap map[string]*BoundMethod // This uses ids to reference bound methods at runtime - obfuscatedMethodMap map[int]*BoundMethod + obfuscatedMethodArray []*ObfuscatedMethod // Lock to ensure sync access to the data lock sync.RWMutex } +type ObfuscatedMethod struct { + method *BoundMethod + methodName string +} + func newDB() *DB { return &DB{ - store: make(map[string]map[string]map[string]*BoundMethod), - methodMap: make(map[string]*BoundMethod), - obfuscatedMethodMap: make(map[int]*BoundMethod), + store: make(map[string]map[string]map[string]*BoundMethod), + methodMap: make(map[string]*BoundMethod), + obfuscatedMethodArray: []*ObfuscatedMethod{}, } } @@ -65,7 +69,11 @@ func (d *DB) GetObfuscatedMethod(id int) *BoundMethod { d.lock.RLock() defer d.lock.RUnlock() - return d.obfuscatedMethodMap[id] + if len(d.obfuscatedMethodArray) <= id { + return nil + } + + return d.obfuscatedMethodArray[id].method } // AddMethod adds the given method definition to the db using the given qualified path: packageName.structName.methodName @@ -96,6 +104,7 @@ func (d *DB) AddMethod(packageName string, structName string, methodName string, // Store in the methodMap key := packageName + "." + structName + "." + methodName d.methodMap[key] = methodDefinition + d.obfuscatedMethodArray = append(d.obfuscatedMethodArray, &ObfuscatedMethod{method: methodDefinition, methodName: key}) } // ToJSON converts the method map to JSON @@ -117,17 +126,9 @@ func (d *DB) ToJSON() (string, error) { func (d *DB) UpdateObfuscatedCallMap() map[string]int { mappings := make(map[string]int) - // Iterate map keys and sort them - keys := make([]string, 0, len(d.methodMap)) - for k := range d.methodMap { - keys = append(keys, k) + for id, k := range d.obfuscatedMethodArray { + mappings[k.methodName] = id } - sort.Strings(keys) - // Iterate sorted keys and add to obfuscated method map - for id, k := range keys { - mappings[k] = id - d.obfuscatedMethodMap[id] = d.methodMap[k] - } return mappings } diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index c6d637506..b539d5ef1 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -41,8 +41,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Fixed - Fixed typo on docs/reference/options page. Added by [@pylotlight](https://github.com/pylotlight) in [PR](https://github.com/wailsapp/wails/pull/2887) -- Fixed issue with npm being called npm20 on openSUSE-Tumbleweed. Fixed by @TuffenDuffen in [PR] in (https://github.com/wailsapp/wails/pull/2941) -- Fixed memory corruption on Windows when using accelerator keys. Fixed by @stffabi in [PR] in (https://github.com/wailsapp/wails/pull/3002) +- Fixed issue with npm being called npm20 on openSUSE-Tumbleweed. Fixed by @TuffenDuffen in [PR](https://github.com/wailsapp/wails/pull/2941) +- Fixed memory corruption on Windows when using accelerator keys. Fixed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/3002) +- Fixed binding mapping for obfuscated build, when binding are in different structs. Fixed by @APshenkin in [PR](https://github.com/wailsapp/wails/pull/3071) ## v2.6.0 - 2023-09-06