Add decimal to hexadecimal helper function (#2076)

* Add decimal to hexadecimal auxiliary functions

* Fixed unit test

* Modify the helper function name and check the unit test.

* dsl function update

Co-authored-by: Sandeep Singh <sandeep@projectdiscovery.io>
This commit is contained in:
M4rtin Hsu 2022-06-03 04:47:35 +08:00 committed by GitHub
parent 841f2e8977
commit aebd32b198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -496,6 +496,13 @@ func init() {
"to_string": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
return types.ToString(args[0]), nil
}),
"dec_to_hex": makeDslFunction(1, func(args ...interface{}) (interface{}, error) {
if number, ok := args[0].(float64); ok {
hexNum := strconv.FormatInt(int64(number), 16)
return types.ToString(hexNum), nil
}
return nil, fmt.Errorf("invalid number: %T", args[0])
}),
}
dslFunctions = make(map[string]dslFunction, len(tempDslFunctions))

View File

@ -112,6 +112,7 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) {
concat(args ...interface{}) string
contains(arg1, arg2 interface{}) interface{}
date(arg1 interface{}) interface{}
dec_to_hex(arg1 interface{}) interface{}
generate_java_gadget(arg1, arg2, arg3 interface{}) interface{}
gzip(arg1 interface{}) interface{}
gzip_decode(arg1 interface{}) interface{}
@ -220,6 +221,7 @@ func TestDslExpressions(t *testing.T) {
`print_debug(1+2, "Hello")`: nil,
`to_number('4')`: float64(4),
`to_string(4)`: "4",
`dec_to_hex(7001)`: "1b59",
`compare_versions('v1.0.0', '<1.1.1')`: true,
`compare_versions('v1.1.1', '>v1.1.0')`: true,
`compare_versions('v1.0.0', '>v0.0.1,<v1.0.1')`: true,