work on rule reqmod resmod codegen for serialization

This commit is contained in:
Kevin Pham
2023-12-03 23:34:46 -06:00
parent a83a95c5a5
commit 7883b32335
10 changed files with 454 additions and 25 deletions

View File

@@ -0,0 +1,49 @@
package ruleset_v2
import (
"encoding/json"
"fmt"
"ladder/proxychain"
)
type Rule struct {
Domains []string
RequestModifications []proxychain.RequestModification
ResponseModifications []proxychain.ResponseModification
}
// implement type encoding/json/Marshaler
func (rule *Rule) UnmarshalJSON(data []byte) error {
type Aux struct {
Domains []string `json:"domains"`
RequestModifications []string `json:"request_modifications"`
ResponseModifications []string `json:"response_modifications"`
}
aux := &Aux{}
if err := json.Unmarshal(data, aux); err != nil {
return err
}
//fmt.Println(aux.Domains)
rule.Domains = aux.Domains
// convert requestModification function call string into actual functional option
for _, resModStr := range aux.RequestModifications {
name, params, err := parseFuncCall(resModStr)
if err != nil {
return fmt.Errorf("Rule::UnmarshalJSON invalid function call syntax => '%s'", err)
}
f, exists := resModMap[name]
if !exists {
return fmt.Errorf("Rule::UnmarshalJSON => requestModifier '%s' does not exist, please check spelling", err)
}
rule.ResponseModifications = append(rule.ResponseModifications, f(params...))
}
return nil
}
func (r *Rule) MarshalJSON() ([]byte, error) {
return []byte{}, nil
}