-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support addition on dicts This results in a merge of the two dicts dict(A=1, B=2) + dict(A=3, X=1) -> {B:2,A:3,X:1} * Hash VQL function should return a dict.
- Loading branch information
Showing
6 changed files
with
120 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package protocols | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
|
||
"github.com/Velocidex/ordereddict" | ||
vql_subsystem "www.velocidex.com/golang/velociraptor/vql" | ||
"www.velocidex.com/golang/vfilter" | ||
"www.velocidex.com/golang/vfilter/types" | ||
) | ||
|
||
type _BoolDict struct{} | ||
|
||
func (self _BoolDict) Applicable(a vfilter.Any) bool { | ||
switch a.(type) { | ||
case ordereddict.Dict, *ordereddict.Dict: | ||
return true | ||
} | ||
|
||
rt := reflect.TypeOf(a) | ||
if rt == nil { | ||
return false | ||
} | ||
return rt.Kind() == reflect.Slice || rt.Kind() == reflect.Map | ||
} | ||
|
||
func (self _BoolDict) Bool(ctx context.Context, scope vfilter.Scope, a vfilter.Any) bool { | ||
switch t := a.(type) { | ||
case ordereddict.Dict: | ||
return t.Len() > 0 | ||
case *ordereddict.Dict: | ||
return t.Len() > 0 | ||
} | ||
|
||
rt := reflect.TypeOf(a) | ||
if rt == nil { | ||
return false | ||
} | ||
if rt.Kind() == reflect.Slice || rt.Kind() == reflect.Map { | ||
a_slice := reflect.ValueOf(a) | ||
return a_slice.Len() > 0 | ||
} | ||
|
||
return false | ||
} | ||
|
||
type _AddDict struct{} | ||
|
||
func (self _AddDict) Applicable(a types.Any, b types.Any) bool { | ||
_, a_ok := a.(*ordereddict.Dict) | ||
_, b_ok := b.(*ordereddict.Dict) | ||
return a_ok && b_ok | ||
} | ||
|
||
func (self _AddDict) Add(scope types.Scope, a types.Any, b types.Any) types.Any { | ||
a_dict, a_ok := a.(*ordereddict.Dict) | ||
if !a_ok { | ||
return &vfilter.Null{} | ||
} | ||
b_dict, b_ok := b.(*ordereddict.Dict) | ||
if !b_ok { | ||
return &vfilter.Null{} | ||
} | ||
|
||
res := ordereddict.NewDict() | ||
|
||
for _, k := range a_dict.Keys() { | ||
v, _ := a_dict.Get(k) | ||
res.Set(k, v) | ||
} | ||
|
||
for _, k := range b_dict.Keys() { | ||
v, _ := b_dict.Get(k) | ||
res.Set(k, v) | ||
} | ||
|
||
return res | ||
} | ||
|
||
func init() { | ||
vql_subsystem.RegisterProtocol(&_BoolDict{}) | ||
vql_subsystem.RegisterProtocol(&_AddDict{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters