Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix obfuscated build binding ordering #3071

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions v2/internal/binding/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package binding

import (
"encoding/json"
"sort"
"sync"
"unsafe"
)
Expand All @@ -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{},
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
5 changes: 3 additions & 2 deletions website/src/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading