sfvm

package
v1.4.4-alpha1202-diff-... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License: AGPL-3.0 Imports: 35 Imported by: 5

Documentation

Index

Constants

View Source
const (
	RecursiveConfig_NULL     RecursiveConfigKey = ""
	RecursiveConfig_Depth                       = "depth"
	RecursiveConfig_DepthMin                    = "depth_min"
	RecursiveConfig_DepthMax                    = "depth_max"
	// RecursiveConfig_Exclude 在匹配到不符合配置项的Value后,数据流继续流动,以匹配其它Value。
	RecursiveConfig_Exclude = "exclude"
	// RecursiveConfig_Include 在匹配到符合配置项的Value后,数据流继续流动,以匹配其它Value。
	RecursiveConfig_Include = "include"
	// RecursiveConfig_Until 会沿着数据流匹配每个Value,知道匹配到符合配置项的Value的时候,数据流停止流动。
	RecursiveConfig_Until = "until"
	// RecursiveConfig_Hook 会对匹配到的每个Value执行配置项的sfRule,但是不会影响最终结果,其数据流会持续流动。
	RecursiveConfig_Hook = "hook"
	// un-used now
	RecursiveConfig_Filter = "filter"
)
View Source
const (
	NameMatch int = 1
	KeyMatch      = 1 << 1
	BothMatch     = NameMatch | KeyMatch
)

type MatchMode int

View Source
const RecursiveMagicVariable = "__next__"

Variables

View Source
var AbortError = utils.Error("AbortError(Normal Abort)")
View Source
var CriticalError = utils.Error("CriticalError(Immediately Abort)")
View Source
var Opcode2String = map[SFVMOpCode]string{
	OpPass:                  "OpPass",
	OpEnterStatement:        "OpEnterStatement",
	OpExitStatement:         "OpExitStatement",
	OpDuplicate:             "OpDuplicate",
	OpPushSearchExact:       "OpPushSearchExact",
	OpPushSearchGlob:        "OpPushSearchGlob",
	OpPushSearchRegexp:      "OpPushSearchRegexp",
	OpRecursiveSearchExact:  "OpRecursiveSearchExact",
	OpRecursiveSearchGlob:   "OpRecursiveSearchGlob",
	OpRecursiveSearchRegexp: "OpRecursiveSearchRegexp",
	OpGetCall:               "OpGetCall",
	OpGetCallArgs:           "OpGetCallArgs",
	OpGetUsers:              "OpGetUsers",
	OpGetBottomUsers:        "OpGetBottomUsers",
	OpGetDefs:               "OpGetDefs",
	OpGetTopDefs:            "OpGetTopDefs",
	OpListIndex:             "OpListIndex",
	OpNewRef:                "OpNewRef",
	OpUpdateRef:             "OpUpdateRef",
	OpPushNumber:            "OpPushNumber",
	OpPushString:            "OpPushString",
	OpPushBool:              "OpPushBool",
	OpPop:                   "OpPop",
	OpCondition:             "OpCondition",
	OpCompareOpcode:         "OpCompareOpcode",
	OpCompareString:         "OpCompareString",
	OpVersionIn:             "OpVersionIn",
	OpEq:                    "OpEq",
	OpNotEq:                 "OpNotEq",
	OpGt:                    "OpGt",
	OpGtEq:                  "OpGtEq",
	OpLt:                    "OpLt",
	OpLtEq:                  "OpLtEq",
	OpLogicAnd:              "OpLogicAnd",
	OpLogicOr:               "OpLogicOr",
	OpLogicBang:             "OpLogicBang",
	OpReMatch:               "OpReMatch",
	OpGlobMatch:             "OpGlobMatch",
	OpNot:                   "OpNot",
	OpAlert:                 "OpAlert",
	OpCheckParams:           "OpCheckParams",
	OpAddDescription:        "OpAddDescription",
	OpCreateIter:            "OpCreateIter",
	OpIterNext:              "OpIterNext",
	OpIterLatch:             "OpIterLatch",
	OpIterEnd:               "OpIterEnd",
	OpCheckStackTop:         "OpCheckStackTop",
	OpMergeRef:              "OpMergeRef",
	OpRemoveRef:             "OpRemoveRef",
	OpIntersectionRef:       "OpIntersectionRef",
	OpNativeCall:            "OpNativeCall",
	OpFileFilterReg:         "OpFileFilterReg",
	OpFileFilterXpath:       "OpFileFilterXpath",
	OpFileFilterJsonPath:    "OpFileFilterJsonPath",
	OpCheckEmpty:            "OpCheckEmpty",
	OpPopDuplicate:          "OpPopDuplicate",
	OpEmptyCompare:          "OpEmptyCompare",
}

Functions

func FormatRule

func FormatRule(ruleContent string, opts ...RuleFormatOption) (rule string, err error)

func GetEndPosition

func GetEndPosition(t antlr.Token) (int, int)

func GetText

func GetText(editor *memedit.MemEditor, token CanStartStopToken) string

func IsComplexDescType

func IsComplexDescType(typ SFDescKeyType) bool

func IsTestCaseKey

func IsTestCaseKey(key string) bool

IsTestCaseKey 判断是否是测试用例key

func MatchModeString

func MatchModeString(mode int) string

func RegisterNativeCall

func RegisterNativeCall(name string, f NativeCallFunc)

func ValuesLen

func ValuesLen(i ValueOperator) int

Types

type AnalysisContext

type AnalysisContext struct {
	Step  int
	Label string
}

func NewDefaultAnalysisContext

func NewDefaultAnalysisContext() *AnalysisContext

type AnalysisContextOption

type AnalysisContextOption func(*AnalysisContext)

func WithAnalysisContext_Label

func WithAnalysisContext_Label(label string) AnalysisContextOption

func WithAnalysisContext_Step

func WithAnalysisContext_Step(step int) AnalysisContextOption

type BinaryCondition

type BinaryCondition string
const (
	BinaryConditionEqual    BinaryCondition = "==" // OpEq
	BinaryConditionNotEqual BinaryCondition = "!=" // OpNotEq
	BinaryConditionGt       BinaryCondition = ">"  // OpGt
	BinaryConditionGtEq     BinaryCondition = ">=" // OpGtEq
	BinaryConditionLt       BinaryCondition = "<"  // OpLt
	BinaryConditionLtEq     BinaryCondition = "<=" // OpLtEq
)

type CanStartStopToken

type CanStartStopToken interface {
	GetStop() antlr.Token
	GetStart() antlr.Token
	GetText() string
}

type CheckBinOrUnaryOpcode

type CheckBinOrUnaryOpcode func(opcode string) bool

type CheckOpcode

type CheckOpcode func(opcode ssa.Opcode) bool

type CompareMode

type CompareMode int
const (
	CompareModeString CompareMode = iota
	CompareModeOpcode
)

type ConditionFilterMode

type ConditionFilterMode int
const (
	ExactConditionFilter ConditionFilterMode = iota
	RegexpConditionFilter
	GlobalConditionFilter
)

func ValidConditionFilter

func ValidConditionFilter(mode int) ConditionFilterMode

type Config added in v1.3.3

type Config struct {
	StrictMatch bool
	FailFast    bool

	Mutex sync.Mutex
	// contains filtered or unexported fields
}

func NewConfig added in v1.3.3

func NewConfig(opts ...Option) *Config

func (*Config) Copy

func (c *Config) Copy() *Config

func (*Config) GetContext

func (c *Config) GetContext() context.Context

type ConstComparator

type ConstComparator struct {
	ToCompared      string
	BinaryCondition BinaryCondition
}

func NewConstComparator

func NewConstComparator(toComparedConst string, condition BinaryCondition) *ConstComparator

func (*ConstComparator) Matches

func (c *ConstComparator) Matches(target string) bool

type IterContext

type IterContext struct {
	// contains filtered or unexported fields
}

type IterIndex

type IterIndex struct {
	// static
	Start int `json:"start"`
	Next  int `json:"next"`
	Latch int `json:"latch"`
	End   int `json:"end"`
	// contains filtered or unexported fields
}

func (*IterIndex) CalcHash

func (i *IterIndex) CalcHash() string

type NativeCallActualParams

type NativeCallActualParams struct {
	// contains filtered or unexported fields
}

func NewNativeCallActualParams

func NewNativeCallActualParams(items ...*RecursiveConfigItem) *NativeCallActualParams

func (*NativeCallActualParams) Existed

func (n *NativeCallActualParams) Existed(index any) bool

func (*NativeCallActualParams) GetInt

func (n *NativeCallActualParams) GetInt(index any, extra ...any) int

func (*NativeCallActualParams) GetString

func (n *NativeCallActualParams) GetString(index any, extra ...any) string

type NativeCallFunc

type NativeCallFunc func(v ValueOperator, frame *SFFrame, params *NativeCallActualParams) (bool, ValueOperator, error)

func GetNativeCall

func GetNativeCall(name string) (NativeCallFunc, error)

type OpCodes

type OpCodes struct {
	Version string `json:"version"`
	Opcode  []*SFI `json:"opcode"`
}

func ToOpCodes

func ToOpCodes(code string) (*OpCodes, bool)

type OpcodeComparator

type OpcodeComparator struct {
	Context        context.Context
	Opcodes        []ssa.Opcode
	BinAndUnarayOp []string
}

func NewOpcodeComparator

func NewOpcodeComparator(ctx context.Context) *OpcodeComparator

func (*OpcodeComparator) AddBinOrUnaryOpcode

func (c *OpcodeComparator) AddBinOrUnaryOpcode(op string)

func (*OpcodeComparator) AddOpcode

func (c *OpcodeComparator) AddOpcode(opcode ssa.Opcode)

func (*OpcodeComparator) AllSatisfy

func (c *OpcodeComparator) AllSatisfy(opcodeCheck CheckOpcode, check CheckBinOrUnaryOpcode) bool

type Option added in v1.3.3

type Option func(*Config)

func WithConfig

func WithConfig(other *Config) Option

func WithContext

func WithContext(ctx context.Context) Option

func WithEnableDebug added in v1.3.3

func WithEnableDebug(b ...bool) Option

func WithFailFast

func WithFailFast(b ...bool) Option

func WithInitialContextVars added in v1.3.3

func WithInitialContextVars(o *omap.OrderedMap[string, ValueOperator]) Option

func WithProcessCallback

func WithProcessCallback(p func(int, string)) Option

func WithResultCaptured added in v1.3.3

func WithResultCaptured(c ResultCapturedCallback) Option

func WithStrictMatch

func WithStrictMatch(b ...bool) Option

type RecursiveConfigItem added in v1.3.3

type RecursiveConfigItem struct {
	Key            string
	Value          string
	SyntaxFlowRule bool
}

type RecursiveConfigKey added in v1.3.3

type RecursiveConfigKey string

func FormatRecursiveConfigKey added in v1.3.3

func FormatRecursiveConfigKey(i string) RecursiveConfigKey

type ResultCapturedCallback added in v1.3.3

type ResultCapturedCallback func(name string, results ValueOperator) error

type RuleFormat

type RuleFormat struct {
	// contains filtered or unexported fields
}

func NewRuleFormat

func NewRuleFormat(w io.Writer) *RuleFormat

func (*RuleFormat) GetTextFromToken

func (f *RuleFormat) GetTextFromToken(token CanStartStopToken) string

func (*RuleFormat) Visit

func (f *RuleFormat) Visit(flow sf.IFlowContext, editor *memedit.MemEditor)

func (*RuleFormat) VisitAlertStatement

func (f *RuleFormat) VisitAlertStatement(alert sf.IAlertStatementContext)

func (*RuleFormat) VisitCrlfHereDoc

func (f *RuleFormat) VisitCrlfHereDoc(raw sf.ICrlfHereDocContext) string

func (*RuleFormat) VisitHereDoc

func (f *RuleFormat) VisitHereDoc(raw sf.IHereDocContext) string

func (*RuleFormat) VisitInfoDescription

func (f *RuleFormat) VisitInfoDescription(desc sf.IDescriptionStatementContext)

VisitInfoDescription 针对第一个desc语句进行处理,主要补全一些规则描述性信息

func (*RuleFormat) VisitLfHereDoc

func (f *RuleFormat) VisitLfHereDoc(raw sf.ILfHereDocContext) string

func (*RuleFormat) VisitStringLiteral

func (f *RuleFormat) VisitStringLiteral(raw sf.IStringLiteralContext) string

func (*RuleFormat) VisitTestDescription

func (f *RuleFormat) VisitTestDescription(desc sf.IDescriptionStatementContext)

VisitTestDescription 处理除了第一个以外的desc,也就是测试

func (*RuleFormat) Write

func (f *RuleFormat) Write(format string, args ...any) error

type RuleFormatOption

type RuleFormatOption func(*RuleFormat)

func RuleFormatWithAlertHandler

func RuleFormatWithAlertHandler(h func(name, key, value string) string) RuleFormatOption

func RuleFormatWithDescHandler

func RuleFormatWithDescHandler(handler func(key, value string) string) RuleFormatOption

func RuleFormatWithRequireAlertDescKeyType

func RuleFormatWithRequireAlertDescKeyType(typ ...SFDescKeyType) RuleFormatOption

RuleFormatWithRequireAlertDescKeyType 指定alert desc必须要有的key,没有的话会使用ai补全

func RuleFormatWithRequireInfoDescKeyType

func RuleFormatWithRequireInfoDescKeyType(typ ...SFDescKeyType) RuleFormatOption

RuleFormatWithRequireInfoDescKeyType 指定info desc必须要有的key,没有的话会使用ai补全

func RuleFormatWithRuleID

func RuleFormatWithRuleID(ruleID string) RuleFormatOption

type SFDescKeyType

type SFDescKeyType string
const (
	SFDescKeyType_Unknown   SFDescKeyType = "unknown"
	SFDescKeyType_Title     SFDescKeyType = "title"
	SFDescKeyType_Title_ZH  SFDescKeyType = "title_zh"
	SFDescKeyType_Desc      SFDescKeyType = "desc"
	SFDescKeyType_Type      SFDescKeyType = "type"
	SFDescKeyType_Lib       SFDescKeyType = "lib"
	SFDescKeyType_Level     SFDescKeyType = "level"
	SFDescKeyType_Lang      SFDescKeyType = "language"
	SFDescKeyType_CVE       SFDescKeyType = "cve"
	SFDescKeyType_CWE       SFDescKeyType = "cwe"
	SFDescKeyType_Risk      SFDescKeyType = "risk"
	SFDescKeyType_Solution  SFDescKeyType = "solution"
	SFDescKeyType_Rule_Id   SFDescKeyType = "rule_id"
	SFDescKeyType_Reference SFDescKeyType = "reference"
	SFDescKeyType_Message   SFDescKeyType = "message"
	SFDescKeyType_Name      SFDescKeyType = "name"
)

func GetAlertDescKeyType

func GetAlertDescKeyType() []SFDescKeyType

func GetSupplyInfoDescKeyType

func GetSupplyInfoDescKeyType() []SFDescKeyType

GetSupplyInfoDescKeyType 拿到所有desc item中, 用于给规则扩充提示信息的key

func ValidDescItemKeyType

func ValidDescItemKeyType(key string) SFDescKeyType

type SFFrame

type SFFrame struct {
	VerifyFsInfo []*VerifyFsInfo

	Text  string
	Codes []*SFI // code list
	// contains filtered or unexported fields
}

func CompileRule

func CompileRule(rule string) (*SFFrame, error)

func NewSFFrame

func NewSFFrame(vars *omap.OrderedMap[string, ValueOperator], text string, codes []*SFI) *SFFrame

func (*SFFrame) ExtractNegativeFilesystemAndLanguage

func (s *SFFrame) ExtractNegativeFilesystemAndLanguage() ([]*VerifyFileSystem, error)

func (*SFFrame) ExtractVerifyFilesystemAndLanguage

func (s *SFFrame) ExtractVerifyFilesystemAndLanguage() ([]*VerifyFileSystem, error)

func (*SFFrame) Feed

func (frame *SFFrame) Feed(i ValueOperator, opt ...Option) (*SFFrameResult, error)

func (*SFFrame) Flush

func (s *SFFrame) Flush()

func (*SFFrame) GetConfig

func (s *SFFrame) GetConfig() *Config

func (*SFFrame) GetContext

func (s *SFFrame) GetContext() context.Context

func (*SFFrame) GetResult

func (s *SFFrame) GetResult() *SFFrameResult

func (*SFFrame) GetRule

func (s *SFFrame) GetRule() *schema.SyntaxFlowRule

func (*SFFrame) GetSFResult

func (s *SFFrame) GetSFResult() (*SFFrameResult, error)

func (*SFFrame) GetSymbol

func (s *SFFrame) GetSymbol(sfi *SFI) (ValueOperator, bool)

func (*SFFrame) GetSymbolByName

func (s *SFFrame) GetSymbolByName(name string) (ValueOperator, bool)

func (*SFFrame) GetSymbolTable

func (s *SFFrame) GetSymbolTable() *omap.OrderedMap[string, ValueOperator]

func (*SFFrame) GetVM

func (s *SFFrame) GetVM() *SyntaxFlowVirtualMachine

func (*SFFrame) IterEnd

func (s *SFFrame) IterEnd() error

end iter, pop and collect results to conditionStack

func (*SFFrame) IterLatch

func (s *SFFrame) IterLatch(val ValueOperator) error

check value, and set result

func (*SFFrame) IterNext

func (s *SFFrame) IterNext() (ValueOperator, bool, error)

get next value, or return false if no more value, jump to end

func (*SFFrame) IterStart

func (s *SFFrame) IterStart(vs ValueOperator)

start iter

func (*SFFrame) ProcessCallback

func (s *SFFrame) ProcessCallback(msg string, args ...any)

func (*SFFrame) SetSFResult

func (s *SFFrame) SetSFResult(sfResult *SFFrameResult)

func (*SFFrame) Show

func (f *SFFrame) Show()

func (*SFFrame) ToLeft

func (s *SFFrame) ToLeft() bool

func (*SFFrame) ToRight

func (s *SFFrame) ToRight() bool

func (*SFFrame) WithPredecessorContext

func (s *SFFrame) WithPredecessorContext(label string) AnalysisContextOption

type SFFrameResult

type SFFrameResult struct {

	// additional info
	Description *omap.OrderedMap[string, string]
	CheckParams []string
	Errors      []string
	// value
	SymbolTable      *omap.OrderedMap[string, ValueOperator]
	UnNameValue      ValueOperator
	AlertSymbolTable *utils.SafeMap[ValueOperator]
	// contains filtered or unexported fields
}

func NewSFResult

func NewSFResult(rule *schema.SyntaxFlowRule, config *Config) *SFFrameResult

func (*SFFrameResult) Copy

func (s *SFFrameResult) Copy() *SFFrameResult

func (*SFFrameResult) GetAlertInfo

func (s *SFFrameResult) GetAlertInfo(name string) (*schema.SyntaxFlowDescInfo, bool)

func (*SFFrameResult) GetDescription

func (s *SFFrameResult) GetDescription() string

func (*SFFrameResult) GetRule

func (s *SFFrameResult) GetRule() *schema.SyntaxFlowRule

func (*SFFrameResult) MergeByResult

func (s *SFFrameResult) MergeByResult(result *SFFrameResult)

func (*SFFrameResult) Name

func (s *SFFrameResult) Name() string

func (*SFFrameResult) Show

func (s *SFFrameResult) Show(opts ...ShowOption)

func (*SFFrameResult) String

func (s *SFFrameResult) String(opts ...ShowOption) string

func (*SFFrameResult) ToGRPCModel

func (s *SFFrameResult) ToGRPCModel() *ypb.SyntaxFlowResult

type SFI

type SFI struct {
	OpCode               SFVMOpCode             `json:"op_code"`
	UnaryInt             int                    `json:"unary_int"`
	UnaryStr             string                 `json:"unary_str"`
	UnaryBool            bool                   `json:"unary_bool"`
	Values               []string               `json:"values"`
	MultiOperator        []int                  `json:"multi_operator"`
	SyntaxFlowConfig     []*RecursiveConfigItem `json:"syntax_flow_config"`
	FileFilterMethodItem map[string]string      `json:"file_filter_method_item"`
	Iter                 *IterIndex             `json:"iter"`
}

func (*SFI) IsIterOpcode

func (s *SFI) IsIterOpcode() bool

func (*SFI) String

func (s *SFI) String() string

func (*SFI) ValueByIndex

func (s *SFI) ValueByIndex(i int) string

type SFVMOpCode

type SFVMOpCode int
const (
	OpPass SFVMOpCode = iota

	// enter/exit statement
	OpEnterStatement
	OpExitStatement

	// duplicate the top of stack
	OpDuplicate

	// OpPushSearchExact can push data from origin
	OpPushSearchExact
	OpPushSearchGlob
	OpPushSearchRegexp

	// OpRecursive... can fetch origin value (not program) push data from origin
	OpRecursiveSearchExact
	OpRecursiveSearchGlob
	OpRecursiveSearchRegexp

	// handle function call
	OpGetCall
	OpGetCallArgs

	// use def chain
	OpGetUsers
	OpGetBottomUsers
	OpGetDefs
	OpGetTopDefs

	// ListOperation
	OpListIndex

	// => variable
	OpNewRef
	OpUpdateRef

	// OpPushNumber and OpPushString and OpPushBool can push literal into stack
	OpPushNumber
	OpPushString
	OpPushBool
	OpPop

	OpCondition
	OpCompareOpcode
	OpCompareString
	OpEmptyCompare

	OpVersionIn
	//OpPopDuplicate is copy popStack to stack
	OpPopDuplicate
	//OpCheckEmpty check the stack top, if empty, push false
	OpCheckEmpty

	OpEq
	OpNotEq
	OpGt
	OpGtEq
	OpLt
	OpLtEq
	OpLogicAnd
	OpLogicOr
	OpLogicBang

	/*
		Unary Operator: Fetch ONE in STACK, calc result, push result into stack
	*/
	OpReMatch
	OpGlobMatch
	OpNot

	OpAlert // echo variable

	// OpCheckParams check the params in vm context
	// if not match, record error
	// matched, use 'then expr' (if exists)
	OpCheckParams

	// OpAddDescription add description to current context
	OpAddDescription

	// OpCreateIter will create iterator for current context
	// the context contains origin values(list) and channel for elements
	OpCreateIter
	// OpIterNext will get next value from iterator
	// if the channel from iter context has a next element, push into stack and execute filter
	// if not, exit
	OpIterNext  // check next to end or end
	OpIterLatch // jump to next
	OpIterEnd   // end

	OpCheckStackTop // check the top of stack, if empty, push input into stack

	OpMergeRef
	OpRemoveRef
	OpIntersectionRef

	OpNativeCall

	//fileFilter
	OpFileFilterReg
	OpFileFilterXpath
	OpFileFilterJsonPath
)

type ShowOption

type ShowOption func(config *showConfig)

func WithShowAll

func WithShowAll(show ...bool) ShowOption

func WithShowCode

func WithShowCode(show ...bool) ShowOption

func WithShowDot

func WithShowDot(show ...bool) ShowOption

type StringComparator

type StringComparator struct {
	Context    context.Context
	MatchMode  StringMatchMode
	Conditions []*StringCondition
}

func NewStringComparator

func NewStringComparator(mode StringMatchMode, ctx context.Context) *StringComparator

func (*StringComparator) AddCondition

func (c *StringComparator) AddCondition(pattern string, filterMode ConditionFilterMode)

func (*StringComparator) Matches

func (c *StringComparator) Matches(targets ...string) bool

func (*StringComparator) String

func (c *StringComparator) String() string

type StringCondition

type StringCondition struct {
	Pattern    string
	FilterMode ConditionFilterMode
}

func (*StringCondition) Matches

func (c *StringCondition) Matches(target []string) bool

type StringMatchMode

type StringMatchMode int
const (
	MatchHaveAny StringMatchMode = iota
	MatchHave
)

func ValidStringMatchMode

func ValidStringMatchMode(mode int) StringMatchMode

func (StringMatchMode) String

func (m StringMatchMode) String() string

type SyntaxFlowVirtualMachine

type SyntaxFlowVirtualMachine struct {
	// contains filtered or unexported fields
}

func NewSyntaxFlowVirtualMachine

func NewSyntaxFlowVirtualMachine(opts ...Option) *SyntaxFlowVirtualMachine

func (*SyntaxFlowVirtualMachine) Compile

func (s *SyntaxFlowVirtualMachine) Compile(text string) (frame *SFFrame, ret error)

func (*SyntaxFlowVirtualMachine) Debug

func (*SyntaxFlowVirtualMachine) Feed

func (*SyntaxFlowVirtualMachine) ForEachFrame added in v1.3.3

func (s *SyntaxFlowVirtualMachine) ForEachFrame(h func(frame *SFFrame))

func (*SyntaxFlowVirtualMachine) GetCompileErrors

func (*SyntaxFlowVirtualMachine) GetConfig

func (s *SyntaxFlowVirtualMachine) GetConfig() *Config

func (*SyntaxFlowVirtualMachine) GetErrors

func (*SyntaxFlowVirtualMachine) Load

func (*SyntaxFlowVirtualMachine) SetConfig

func (s *SyntaxFlowVirtualMachine) SetConfig(config *Config)

func (*SyntaxFlowVirtualMachine) Show added in v1.3.3

func (s *SyntaxFlowVirtualMachine) Show()

func (*SyntaxFlowVirtualMachine) Snapshot

type SyntaxFlowVisitor

type SyntaxFlowVisitor struct {
	// contains filtered or unexported fields
}

func NewSyntaxFlowVisitor

func NewSyntaxFlowVisitor() *SyntaxFlowVisitor

func (*SyntaxFlowVisitor) CreateFrame

func (v *SyntaxFlowVisitor) CreateFrame(vars *omap.OrderedMap[string, ValueOperator]) *SFFrame

func (*SyntaxFlowVisitor) EmitAddDescription

func (y *SyntaxFlowVisitor) EmitAddDescription(key string, value string)

func (*SyntaxFlowVisitor) EmitAlert

func (y *SyntaxFlowVisitor) EmitAlert(ref string)

func (*SyntaxFlowVisitor) EmitCheckParam

func (y *SyntaxFlowVisitor) EmitCheckParam(ref string, then string, elseString string)

func (*SyntaxFlowVisitor) EmitCheckStackTop

func (y *SyntaxFlowVisitor) EmitCheckStackTop()

func (*SyntaxFlowVisitor) EmitCompareOpcode

func (v *SyntaxFlowVisitor) EmitCompareOpcode(i []string)

func (*SyntaxFlowVisitor) EmitCompareString

func (v *SyntaxFlowVisitor) EmitCompareString(i []func() (string, ConditionFilterMode), compareMode StringMatchMode)

func (*SyntaxFlowVisitor) EmitCondition

func (v *SyntaxFlowVisitor) EmitCondition()

func (*SyntaxFlowVisitor) EmitCreateIterator

func (v *SyntaxFlowVisitor) EmitCreateIterator() *IterIndex

func (*SyntaxFlowVisitor) EmitDuplicate added in v1.3.3

func (v *SyntaxFlowVisitor) EmitDuplicate()

func (*SyntaxFlowVisitor) EmitEnterStatement added in v1.3.3

func (y *SyntaxFlowVisitor) EmitEnterStatement() *SFI

func (*SyntaxFlowVisitor) EmitEqual

func (v *SyntaxFlowVisitor) EmitEqual(i any)

func (*SyntaxFlowVisitor) EmitExitStatement added in v1.3.3

func (y *SyntaxFlowVisitor) EmitExitStatement(c *SFI)

func (*SyntaxFlowVisitor) EmitFileFilterJsonPath

func (y *SyntaxFlowVisitor) EmitFileFilterJsonPath(i string, m map[string]string, s []string)

func (*SyntaxFlowVisitor) EmitFileFilterReg

func (y *SyntaxFlowVisitor) EmitFileFilterReg(i string, m map[string]string, s []string)

func (*SyntaxFlowVisitor) EmitFileFilterXpath

func (y *SyntaxFlowVisitor) EmitFileFilterXpath(i string, m map[string]string, s []string)

func (*SyntaxFlowVisitor) EmitGetBottomUsers added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetBottomUsers(config ...*RecursiveConfigItem)

func (*SyntaxFlowVisitor) EmitGetCall added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetCall()

func (*SyntaxFlowVisitor) EmitGetDefs added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetDefs()

func (*SyntaxFlowVisitor) EmitGetTopDefs added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetTopDefs(config ...*RecursiveConfigItem)

func (*SyntaxFlowVisitor) EmitGetUsers added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetUsers()

func (*SyntaxFlowVisitor) EmitIntersectionRef

func (y *SyntaxFlowVisitor) EmitIntersectionRef(i string)

func (*SyntaxFlowVisitor) EmitIterEnd

func (v *SyntaxFlowVisitor) EmitIterEnd(i *IterIndex)

func (*SyntaxFlowVisitor) EmitLatchIterator

func (v *SyntaxFlowVisitor) EmitLatchIterator(i *IterIndex)

func (*SyntaxFlowVisitor) EmitListIndex added in v1.3.3

func (y *SyntaxFlowVisitor) EmitListIndex(i int)

func (*SyntaxFlowVisitor) EmitMergeRef

func (y *SyntaxFlowVisitor) EmitMergeRef(i string)

func (*SyntaxFlowVisitor) EmitNativeCall

func (y *SyntaxFlowVisitor) EmitNativeCall(i string, results ...*RecursiveConfigItem)

func (*SyntaxFlowVisitor) EmitNewRef

func (y *SyntaxFlowVisitor) EmitNewRef(i string)

func (*SyntaxFlowVisitor) EmitNextIterator

func (v *SyntaxFlowVisitor) EmitNextIterator(i *IterIndex)

func (*SyntaxFlowVisitor) EmitOpCheckEmpty

func (y *SyntaxFlowVisitor) EmitOpCheckEmpty(index *IterIndex)

func (*SyntaxFlowVisitor) EmitOpEmptyCompare

func (y *SyntaxFlowVisitor) EmitOpEmptyCompare()

func (*SyntaxFlowVisitor) EmitOpPopDuplicate

func (y *SyntaxFlowVisitor) EmitOpPopDuplicate()

func (*SyntaxFlowVisitor) EmitOperator

func (y *SyntaxFlowVisitor) EmitOperator(i string)

func (*SyntaxFlowVisitor) EmitPass added in v1.3.3

func (v *SyntaxFlowVisitor) EmitPass()

func (*SyntaxFlowVisitor) EmitPop

func (y *SyntaxFlowVisitor) EmitPop()

func (*SyntaxFlowVisitor) EmitPushCallArgs added in v1.3.3

func (v *SyntaxFlowVisitor) EmitPushCallArgs(startIndex int, containOther bool)

func (*SyntaxFlowVisitor) EmitPushGlob

func (v *SyntaxFlowVisitor) EmitPushGlob(i string)

func (*SyntaxFlowVisitor) EmitPushLiteral

func (v *SyntaxFlowVisitor) EmitPushLiteral(i any)

func (*SyntaxFlowVisitor) EmitRecursiveSearchExact

func (v *SyntaxFlowVisitor) EmitRecursiveSearchExact(mod int, i string) *SFI

func (*SyntaxFlowVisitor) EmitRecursiveSearchGlob

func (v *SyntaxFlowVisitor) EmitRecursiveSearchGlob(mod int, i string) *SFI

func (*SyntaxFlowVisitor) EmitRecursiveSearchRegexp

func (v *SyntaxFlowVisitor) EmitRecursiveSearchRegexp(mod int, i string) *SFI

func (*SyntaxFlowVisitor) EmitRegexpMatch

func (y *SyntaxFlowVisitor) EmitRegexpMatch(i string)

func (*SyntaxFlowVisitor) EmitRemoveRef

func (y *SyntaxFlowVisitor) EmitRemoveRef(i string)

func (*SyntaxFlowVisitor) EmitSearchExact added in v1.3.3

func (v *SyntaxFlowVisitor) EmitSearchExact(mod int, i string) *SFI

func (*SyntaxFlowVisitor) EmitSearchGlob added in v1.3.3

func (v *SyntaxFlowVisitor) EmitSearchGlob(mod int, i string) *SFI

func (*SyntaxFlowVisitor) EmitSearchRegexp added in v1.3.3

func (v *SyntaxFlowVisitor) EmitSearchRegexp(mod int, i string) *SFI

func (*SyntaxFlowVisitor) EmitUpdate

func (y *SyntaxFlowVisitor) EmitUpdate(i string)

func (*SyntaxFlowVisitor) EmitVersionIn

func (y *SyntaxFlowVisitor) EmitVersionIn(results ...*RecursiveConfigItem)

func (*SyntaxFlowVisitor) FormatStringOrGlob

func (y *SyntaxFlowVisitor) FormatStringOrGlob(text string) (string, bool)

func (*SyntaxFlowVisitor) Show

func (v *SyntaxFlowVisitor) Show()

func (*SyntaxFlowVisitor) ToString

func (y *SyntaxFlowVisitor) ToString() string

func (*SyntaxFlowVisitor) VisitActualParam added in v1.3.3

func (y *SyntaxFlowVisitor) VisitActualParam(i sf.IActualParamContext, haveQuestion bool) error

func (*SyntaxFlowVisitor) VisitAlertStatement

func (y *SyntaxFlowVisitor) VisitAlertStatement(raw sf.IAlertStatementContext)

func (*SyntaxFlowVisitor) VisitChainFilter

func (y *SyntaxFlowVisitor) VisitChainFilter(raw sf.IChainFilterContext) interface{}

func (*SyntaxFlowVisitor) VisitCheckStatement

func (y *SyntaxFlowVisitor) VisitCheckStatement(raw sf.ICheckStatementContext) interface{}

func (*SyntaxFlowVisitor) VisitConditionExpression

func (y *SyntaxFlowVisitor) VisitConditionExpression(raw sf.IConditionExpressionContext) any

func (*SyntaxFlowVisitor) VisitDescriptionStatement

func (y *SyntaxFlowVisitor) VisitDescriptionStatement(raw sf.IDescriptionStatementContext) interface{}

func (*SyntaxFlowVisitor) VisitFileFilterContent

func (y *SyntaxFlowVisitor) VisitFileFilterContent(raw sf.IFileFilterContentStatementContext) error

func (*SyntaxFlowVisitor) VisitFileFilterContentInput

func (y *SyntaxFlowVisitor) VisitFileFilterContentInput(raw sf.IFileFilterContentInputContext) (string, error)

func (*SyntaxFlowVisitor) VisitFileFilterContentMethod

func (y *SyntaxFlowVisitor) VisitFileFilterContentMethod(raw sf.IFileFilterContentMethodContext, fileInput string) error

func (*SyntaxFlowVisitor) VisitFileFilterContentMethodParam

func (y *SyntaxFlowVisitor) VisitFileFilterContentMethodParam(raw sf.IFileFilterContentMethodParamContext) (map[string]string, []string)

func (*SyntaxFlowVisitor) VisitFileFilterContentMethodParamValue

func (y *SyntaxFlowVisitor) VisitFileFilterContentMethodParamValue(raw sf.IFileFilterContentMethodParamValueContext) (res string)

func (*SyntaxFlowVisitor) VisitFilterExpr

func (y *SyntaxFlowVisitor) VisitFilterExpr(raw sf.IFilterExprContext) error

func (*SyntaxFlowVisitor) VisitFilterItem

func (y *SyntaxFlowVisitor) VisitFilterItem(raw sf.IFilterItemContext) error

func (*SyntaxFlowVisitor) VisitFilterItemFirst

func (y *SyntaxFlowVisitor) VisitFilterItemFirst(raw sf.IFilterItemFirstContext) error

func (*SyntaxFlowVisitor) VisitFilterStatement

func (y *SyntaxFlowVisitor) VisitFilterStatement(raw sf.IFilterStatementContext)

func (*SyntaxFlowVisitor) VisitFlow

func (y *SyntaxFlowVisitor) VisitFlow(raw sf.IFlowContext)

func (*SyntaxFlowVisitor) VisitHereDoc

func (v *SyntaxFlowVisitor) VisitHereDoc(i any) string

func (*SyntaxFlowVisitor) VisitNameFilter added in v1.3.3

func (y *SyntaxFlowVisitor) VisitNameFilter(isMember bool, i sf.INameFilterContext) (err error)

func (*SyntaxFlowVisitor) VisitNativeCallActualParams

func (v *SyntaxFlowVisitor) VisitNativeCallActualParams(i *sf.NativeCallActualParamsContext) []*RecursiveConfigItem

func (*SyntaxFlowVisitor) VisitNumberLiteral

func (y *SyntaxFlowVisitor) VisitNumberLiteral(raw sf.INumberLiteralContext) int

func (*SyntaxFlowVisitor) VisitRecursiveConfig added in v1.3.3

func (v *SyntaxFlowVisitor) VisitRecursiveConfig(i *sf.ConfigContext) []*RecursiveConfigItem

func (*SyntaxFlowVisitor) VisitRecursiveNameFilter

func (y *SyntaxFlowVisitor) VisitRecursiveNameFilter(recursive bool, isMember bool, i sf.INameFilterContext) error

func (*SyntaxFlowVisitor) VisitRefVariable

func (y *SyntaxFlowVisitor) VisitRefVariable(raw sf.IRefVariableContext) string

func (*SyntaxFlowVisitor) VisitStatement

func (y *SyntaxFlowVisitor) VisitStatement(raw sf.IStatementContext)

func (*SyntaxFlowVisitor) VisitStringLiteral

func (y *SyntaxFlowVisitor) VisitStringLiteral(raw sf.IStringLiteralContext) (string, bool)

func (*SyntaxFlowVisitor) VisitStringLiteralWithoutStarGroup

func (y *SyntaxFlowVisitor) VisitStringLiteralWithoutStarGroup(raw sf.IStringLiteralWithoutStarGroupContext) []func() (string, ConditionFilterMode)

func (*SyntaxFlowVisitor) VisitVersionInExpression

func (y *SyntaxFlowVisitor) VisitVersionInExpression(raw sf.IVersionInExpressionContext)

func (*SyntaxFlowVisitor) VisitVersionInterval

func (y *SyntaxFlowVisitor) VisitVersionInterval(raw sf.IVersionIntervalContext)

func (*SyntaxFlowVisitor) VisitVersionString

func (y *SyntaxFlowVisitor) VisitVersionString(raw sf.IVersionStringContext) string

type ValueList added in v1.3.3

type ValueList struct {
	Values []ValueOperator
}

func (*ValueList) AppendPredecessor

func (v *ValueList) AppendPredecessor(value ValueOperator, opts ...AnalysisContextOption) error

func (*ValueList) CompareConst

func (v *ValueList) CompareConst(comparator *ConstComparator) []bool

func (*ValueList) CompareOpcode

func (v *ValueList) CompareOpcode(comparator *OpcodeComparator) (ValueOperator, []bool)

func (*ValueList) CompareString

func (v *ValueList) CompareString(comparator *StringComparator) (ValueOperator, []bool)

func (*ValueList) Count

func (v *ValueList) Count() int

func (*ValueList) ExactMatch added in v1.3.3

func (v *ValueList) ExactMatch(ctx context.Context, mod int, s string) (bool, ValueOperator, error)

func (*ValueList) FileFilter

func (v *ValueList) FileFilter(path string, mode string, rule1 map[string]string, rule2 []string) (ValueOperator, error)

func (*ValueList) GetBinaryOperator

func (v *ValueList) GetBinaryOperator() string

func (*ValueList) GetCallActualParams added in v1.3.3

func (v *ValueList) GetCallActualParams(i int, b bool) (ValueOperator, error)

func (*ValueList) GetCalled added in v1.3.3

func (v *ValueList) GetCalled() (ValueOperator, error)

func (*ValueList) GetFields

func (v *ValueList) GetFields() (ValueOperator, error)

func (*ValueList) GetOpcode

func (v *ValueList) GetOpcode() string

func (*ValueList) GetSyntaxFlowBottomUse added in v1.3.3

func (v *ValueList) GetSyntaxFlowBottomUse(sfResult *SFFrameResult, sfConfig *Config, config ...*RecursiveConfigItem) (ValueOperator, error)

func (*ValueList) GetSyntaxFlowDef added in v1.3.3

func (v *ValueList) GetSyntaxFlowDef() (ValueOperator, error)

func (*ValueList) GetSyntaxFlowTopDef added in v1.3.3

func (v *ValueList) GetSyntaxFlowTopDef(sfResult *SFFrameResult, sfConfig *Config, config ...*RecursiveConfigItem) (ValueOperator, error)

func (*ValueList) GetSyntaxFlowUse added in v1.3.3

func (v *ValueList) GetSyntaxFlowUse() (ValueOperator, error)

func (*ValueList) GetUnaryOperator

func (v *ValueList) GetUnaryOperator() string

func (*ValueList) GlobMatch added in v1.3.3

func (v *ValueList) GlobMatch(ctx context.Context, mod int, s string) (bool, ValueOperator, error)

func (*ValueList) IsEmpty

func (v *ValueList) IsEmpty() bool

func (*ValueList) IsList added in v1.3.3

func (v *ValueList) IsList() bool

func (*ValueList) IsMap added in v1.3.3

func (v *ValueList) IsMap() bool

func (*ValueList) ListIndex added in v1.3.3

func (v *ValueList) ListIndex(i int) (ValueOperator, error)

func (*ValueList) Merge

func (v *ValueList) Merge(values ...ValueOperator) (ValueOperator, error)

func (*ValueList) NewConst

func (v *ValueList) NewConst(i any, rng ...*memedit.Range) ValueOperator

func (*ValueList) Recursive added in v1.3.3

func (v *ValueList) Recursive(f func(operator ValueOperator) error) error

func (*ValueList) RegexpMatch added in v1.3.3

func (v *ValueList) RegexpMatch(ctx context.Context, mod int, regexp string) (bool, ValueOperator, error)

func (*ValueList) Remove

func (v *ValueList) Remove(values ...ValueOperator) (ValueOperator, error)

func (*ValueList) String added in v1.3.3

func (v *ValueList) String() string

type ValueOperator added in v1.3.3

type ValueOperator interface {
	String() string
	IsMap() bool
	IsList() bool
	IsEmpty() bool
	GetOpcode() string
	GetBinaryOperator() string
	GetUnaryOperator() string

	// Recursive will execute with handler for every list or map
	Recursive(func(ValueOperator) error) error

	// ExactMatch return ops, for OpPushSearchExact
	ExactMatch(context.Context, int, string) (bool, ValueOperator, error)
	// GlobMatch return opts, for OpPushSearchGlob
	GlobMatch(context.Context, int, string) (bool, ValueOperator, error)
	// RegexpMatch for OpPushSearchRegexp
	RegexpMatch(context.Context, int, string) (bool, ValueOperator, error)

	GetCalled() (ValueOperator, error)
	GetCallActualParams(int, bool) (ValueOperator, error)
	GetFields() (ValueOperator, error)

	// GetTopDef and GetBottomUse is for OpBottomUse
	// use and def
	GetSyntaxFlowUse() (ValueOperator, error)
	GetSyntaxFlowDef() (ValueOperator, error)
	// top and bottom
	GetSyntaxFlowTopDef(*SFFrameResult, *Config, ...*RecursiveConfigItem) (ValueOperator, error)
	GetSyntaxFlowBottomUse(*SFFrameResult, *Config, ...*RecursiveConfigItem) (ValueOperator, error)

	// ListIndex for OpListIndex, like a[1] a must be list...
	ListIndex(i int) (ValueOperator, error)

	Merge(...ValueOperator) (ValueOperator, error)
	Remove(...ValueOperator) (ValueOperator, error)

	AppendPredecessor(ValueOperator, ...AnalysisContextOption) error

	// fileFilter
	FileFilter(string, string, map[string]string, []string) (ValueOperator, error)

	CompareString(*StringComparator) (ValueOperator, []bool)
	CompareOpcode(*OpcodeComparator) (ValueOperator, []bool)
	CompareConst(*ConstComparator) []bool
	NewConst(any, ...*memedit.Range) ValueOperator
}

func AutoValue added in v1.3.3

func AutoValue(i any) ValueOperator

func NewEmptyValues

func NewEmptyValues() ValueOperator

func NewValues added in v1.3.3

func NewValues(values []ValueOperator) ValueOperator

type ValueSet

type ValueSet struct {
	// contains filtered or unexported fields
}

func NewValueSet

func NewValueSet() *ValueSet

func (*ValueSet) Add

func (v *ValueSet) Add(id int64, value ValueOperator)

func (*ValueSet) And

func (v *ValueSet) And(other *ValueSet) *ValueSet

func (*ValueSet) Has

func (v *ValueSet) Has(id int64) bool

func (*ValueSet) List

func (v *ValueSet) List() []ValueOperator

type VerifyFileSystem

type VerifyFileSystem struct {
	// contains filtered or unexported fields
}

func (*VerifyFileSystem) GetExtraInfo

func (v *VerifyFileSystem) GetExtraInfo(key string, backup ...string) string

func (*VerifyFileSystem) GetExtraInfoInt

func (v *VerifyFileSystem) GetExtraInfoInt(key string, backup ...string) int

func (*VerifyFileSystem) GetLanguage

func (v *VerifyFileSystem) GetLanguage() ssaconfig.Language

func (*VerifyFileSystem) GetVirtualFs

func (v *VerifyFileSystem) GetVirtualFs() filesys_interface.FileSystem

type VerifyFsInfo

type VerifyFsInfo struct {
	// contains filtered or unexported fields
}

func NewExtraDesc

func NewExtraDesc() *VerifyFsInfo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL