mirror of
https://github.com/bettercap/bettercap
synced 2025-07-06 04:52:10 -07:00
Fix float64/int64 to uint64 conversion from JS environment
This commit is contained in:
parent
876449e105
commit
4eb923f972
1 changed files with 20 additions and 5 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/v2/log"
|
"github.com/bettercap/bettercap/v2/log"
|
||||||
"github.com/bettercap/bettercap/v2/session"
|
"github.com/bettercap/bettercap/v2/session"
|
||||||
|
@ -139,13 +140,27 @@ func jsPropToUint32(obj map[string]interface{}, key string) uint32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsPropToUint64(obj map[string]interface{}, key string) uint64 {
|
func jsPropToUint64(obj map[string]interface{}, key string) uint64 {
|
||||||
if f, ok := obj[key].(float64); ok {
|
prop, found := obj[key]
|
||||||
|
if found {
|
||||||
|
switch reflect.TypeOf(prop).String() {
|
||||||
|
case "float64":
|
||||||
|
if f, ok := prop.(float64); ok {
|
||||||
bigInt := new(big.Float).SetFloat64(f)
|
bigInt := new(big.Float).SetFloat64(f)
|
||||||
v, _ := bigInt.Uint64()
|
v, _ := bigInt.Uint64()
|
||||||
if v >= 0 {
|
if v >= 0 {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
case "int64":
|
||||||
|
if v, ok := prop.(int64); ok {
|
||||||
|
if v >= 0 {
|
||||||
|
return uint64(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
log.Error("error converting JS property to uint64 where key is: %s", key)
|
log.Error("error converting JS property to uint64 where key is: %s", key)
|
||||||
return uint64(0)
|
return uint64(0)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue