mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 22:49:31 +08:00
fix obfuscated build binding ordering (#3071)
* fix obfuscated build binding ordering * remove unused string method * add to changelog --------- Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
parent
b9de31e38e
commit
674042df36
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user