tree

package
v0.0.0-...-06b8323 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2017 License: LGPL-3.0 Imports: 1 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ArithmeticNames = map[ArithmeticType]string{
	PLUS:   "+",
	MINUS:  "-",
	MULT:   "*",
	DIV:    "/",
	BINAND: "&",
	BINOR:  "|",
	BINXOR: "^",
	LSH:    "<<",
	RSH:    ">>",
	MOD:    "%",
}

ArithmeticNames maps the types to names for presentation

View Source
var ArithmeticSymbols = map[ArithmeticType]string{
	PLUS:   "plus",
	MINUS:  "minus",
	MULT:   "mul",
	DIV:    "div",
	BINAND: "binand",
	BINOR:  "binor",
	BINXOR: "binxor",
	LSH:    "lsh",
	RSH:    "rsh",
	MOD:    "mod",
}

ArithmeticSymbols maps the types to names for symbolic processing

View Source
var ComparisonNames = map[ComparisonType]string{
	EQL:    "==",
	NEQL:   "!=",
	GT:     ">",
	GTE:    ">=",
	LT:     "<",
	LTE:    "<=",
	BITSET: "&?",
}

ComparisonNames maps types to names for presentation

View Source
var ComparisonSymbols = map[ComparisonType]string{
	EQL:    "eq",
	NEQL:   "neq",
	GT:     "gt",
	GTE:    "gte",
	LT:     "lt",
	LTE:    "lte",
	BITSET: "bitset",
}

ComparisonSymbols maps types to names for symbolic processing

Functions

func ExpressionString

func ExpressionString(e Expression) string

ExpressionString returns a string for the given expression

Types

type And

type And struct {
	Left, Right Boolean
}

And represents an conjunction

func (And) Accept

func (v And) Accept(vs Visitor)

Accept implements Expression

type Any

type Any interface {
	Expression
}

Any represents either a boolean or numeric expression

type Argument

type Argument struct {
	Type  ArgumentType
	Index int
}

Argument represents an argment given to the syscall

func (Argument) Accept

func (v Argument) Accept(vs Visitor)

Accept implements Expression

type ArgumentType

type ArgumentType int

ArgumentType represents one of the three types of argument loads we can do

const (
	Full ArgumentType = iota
	Low
	Hi
)

The different types of argument loads that can happen

type Arithmetic

type Arithmetic struct {
	Op          ArithmeticType
	Left, Right Numeric
}

Arithmetic represents an arithmetic operation

func (Arithmetic) Accept

func (v Arithmetic) Accept(vs Visitor)

Accept implements Expression

type ArithmeticType

type ArithmeticType int

ArithmeticType specifies the different possible arithmetic operations

const (
	PLUS ArithmeticType = iota
	MINUS
	MULT
	DIV
	BINAND
	BINOR
	BINXOR
	LSH
	RSH
	MOD
)

Constants for the different possible types

type BinaryNegation

type BinaryNegation struct {
	Operand Numeric
}

BinaryNegation represents binary negation of a number

func (BinaryNegation) Accept

func (v BinaryNegation) Accept(vs Visitor)

Accept implements Expression

type Boolean

type Boolean interface {
	Expression
}

Boolean represents a boolean expression

type BooleanLiteral

type BooleanLiteral struct {
	Value bool
}

BooleanLiteral represents a boolean literal

func (BooleanLiteral) Accept

func (v BooleanLiteral) Accept(vs Visitor)

Accept implements Expression

type Call

type Call struct {
	Name string
	Args []Any
}

Call represents an application of a method/macro

func (Call) Accept

func (v Call) Accept(vs Visitor)

Accept implements Expression

type Comparison

type Comparison struct {
	Op          ComparisonType
	Left, Right Numeric
}

Comparison represents a comparison

func (Comparison) Accept

func (v Comparison) Accept(vs Visitor)

Accept implements Expression

type ComparisonType

type ComparisonType int

ComparisonType specifies the possible comparison types

const (
	EQL ComparisonType = iota
	NEQL
	GT
	GTE
	LT
	LTE
	BITSET
)

Contains all the comparison types

type EmptyTransformer

type EmptyTransformer struct {
	Result   Expression
	RealSelf Transformer
}

EmptyTransformer does nothing - it returns the same tree as given It can be useful as the base for other transformers

func (*EmptyTransformer) AcceptAnd

func (s *EmptyTransformer) AcceptAnd(v And)

AcceptAnd implements Visitor

func (*EmptyTransformer) AcceptArgument

func (s *EmptyTransformer) AcceptArgument(v Argument)

AcceptArgument implements Visitor

func (*EmptyTransformer) AcceptArithmetic

func (s *EmptyTransformer) AcceptArithmetic(v Arithmetic)

AcceptArithmetic implements Visitor

func (*EmptyTransformer) AcceptBinaryNegation

func (s *EmptyTransformer) AcceptBinaryNegation(v BinaryNegation)

AcceptBinaryNegation implements Visitor

func (*EmptyTransformer) AcceptBooleanLiteral

func (s *EmptyTransformer) AcceptBooleanLiteral(v BooleanLiteral)

AcceptBooleanLiteral implements Visitor

func (*EmptyTransformer) AcceptCall

func (s *EmptyTransformer) AcceptCall(v Call)

AcceptCall implements Visitor

func (*EmptyTransformer) AcceptComparison

func (s *EmptyTransformer) AcceptComparison(v Comparison)

AcceptComparison implements Visitor

func (*EmptyTransformer) AcceptInclusion

func (s *EmptyTransformer) AcceptInclusion(v Inclusion)

AcceptInclusion implements Visitor

func (*EmptyTransformer) AcceptNegation

func (s *EmptyTransformer) AcceptNegation(v Negation)

AcceptNegation implements Visitor

func (*EmptyTransformer) AcceptNumericLiteral

func (s *EmptyTransformer) AcceptNumericLiteral(v NumericLiteral)

AcceptNumericLiteral implements Visitor

func (*EmptyTransformer) AcceptOr

func (s *EmptyTransformer) AcceptOr(v Or)

AcceptOr implements Visitor

func (*EmptyTransformer) AcceptVariable

func (s *EmptyTransformer) AcceptVariable(v Variable)

AcceptVariable implements Visitor

func (*EmptyTransformer) Transform

func (s *EmptyTransformer) Transform(inp Expression) Expression

Transform implements Transformer

type EvaluatorVisitor

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

EvaluatorVisitor will generate an unambigious representation of an expression

func (*EvaluatorVisitor) AcceptAnd

func (sv *EvaluatorVisitor) AcceptAnd(v And)

AcceptAnd implements Visitor

func (*EvaluatorVisitor) AcceptArgument

func (sv *EvaluatorVisitor) AcceptArgument(v Argument)

AcceptArgument implements Visitor

func (*EvaluatorVisitor) AcceptArithmetic

func (sv *EvaluatorVisitor) AcceptArithmetic(v Arithmetic)

AcceptArithmetic implements Visitor

func (*EvaluatorVisitor) AcceptBinaryNegation

func (sv *EvaluatorVisitor) AcceptBinaryNegation(v BinaryNegation)

AcceptBinaryNegation implements Visitor

func (*EvaluatorVisitor) AcceptBooleanLiteral

func (sv *EvaluatorVisitor) AcceptBooleanLiteral(v BooleanLiteral)

AcceptBooleanLiteral implements Visitor

func (*EvaluatorVisitor) AcceptCall

func (sv *EvaluatorVisitor) AcceptCall(v Call)

AcceptCall implements Visitor

func (*EvaluatorVisitor) AcceptComparison

func (sv *EvaluatorVisitor) AcceptComparison(v Comparison)

AcceptComparison implements Visitor

func (*EvaluatorVisitor) AcceptInclusion

func (sv *EvaluatorVisitor) AcceptInclusion(v Inclusion)

AcceptInclusion implements Visitor

func (*EvaluatorVisitor) AcceptNegation

func (sv *EvaluatorVisitor) AcceptNegation(v Negation)

AcceptNegation implements Visitor

func (*EvaluatorVisitor) AcceptNumericLiteral

func (sv *EvaluatorVisitor) AcceptNumericLiteral(v NumericLiteral)

AcceptNumericLiteral implements Visitor

func (*EvaluatorVisitor) AcceptOr

func (sv *EvaluatorVisitor) AcceptOr(v Or)

AcceptOr implements Visitor

func (*EvaluatorVisitor) AcceptVariable

func (sv *EvaluatorVisitor) AcceptVariable(v Variable)

AcceptVariable implements Visitor

type Expression

type Expression interface {
	Accept(Visitor)
}

Expression is an AST expression

type Inclusion

type Inclusion struct {
	Positive bool
	Left     Numeric
	Rights   []Numeric
}

Inclusion represents either a positive or a negative inclusion operation

func (Inclusion) Accept

func (v Inclusion) Accept(vs Visitor)

Accept implements Expression

type Macro

type Macro struct {
	Name          string
	ArgumentNames []string
	Body          Expression
}

Macro represents either a simple variable or a more complicated macro/func expression

type Negation

type Negation struct {
	Operand Boolean
}

Negation represents a negation

func (Negation) Accept

func (v Negation) Accept(vs Visitor)

Accept implements Expression

type Numeric

type Numeric interface {
	Expression
}

Numeric represents a numeric expression

type NumericLiteral

type NumericLiteral struct {
	Value uint64
}

NumericLiteral represents a numeric literal

func (NumericLiteral) Accept

func (v NumericLiteral) Accept(vs Visitor)

Accept implements Expression

type Or

type Or struct {
	Left, Right Boolean
}

Or represents an alternative

func (Or) Accept

func (v Or) Accept(vs Visitor)

Accept implements Expression

type Policy

type Policy struct {
	DefaultPositiveAction string
	DefaultNegativeAction string
	DefaultPolicyAction   string
	ActionOnX32           string
	ActionOnAuditFailure  string
	Macros                map[string]Macro
	Rules                 []*Rule
}

Policy represents a complete policy file. It is possible to combine more than one policy file

type RawPolicy

type RawPolicy struct {
	RuleOrMacros []interface{}
}

RawPolicy represents the raw parsed rules and macros in the order they were encountered. This can be used to generate the final Policy

type Rule

type Rule struct {
	Name           string
	PositiveAction string
	NegativeAction string
	Body           Expression
}

Rule contains all the information for one specific rule

type StringVisitor

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

StringVisitor will generate an unambigious representation of an expression

func (*StringVisitor) AcceptAnd

func (sv *StringVisitor) AcceptAnd(v And)

AcceptAnd implements Visitor

func (*StringVisitor) AcceptArgument

func (sv *StringVisitor) AcceptArgument(v Argument)

AcceptArgument implements Visitor

func (*StringVisitor) AcceptArithmetic

func (sv *StringVisitor) AcceptArithmetic(v Arithmetic)

AcceptArithmetic implements Visitor

func (*StringVisitor) AcceptBinaryNegation

func (sv *StringVisitor) AcceptBinaryNegation(v BinaryNegation)

AcceptBinaryNegation implements Visitor

func (*StringVisitor) AcceptBooleanLiteral

func (sv *StringVisitor) AcceptBooleanLiteral(v BooleanLiteral)

AcceptBooleanLiteral implements Visitor

func (*StringVisitor) AcceptCall

func (sv *StringVisitor) AcceptCall(v Call)

AcceptCall implements Visitor

func (*StringVisitor) AcceptComparison

func (sv *StringVisitor) AcceptComparison(v Comparison)

AcceptComparison implements Visitor

func (*StringVisitor) AcceptInclusion

func (sv *StringVisitor) AcceptInclusion(v Inclusion)

AcceptInclusion implements Visitor

func (*StringVisitor) AcceptNegation

func (sv *StringVisitor) AcceptNegation(v Negation)

AcceptNegation implements Visitor

func (*StringVisitor) AcceptNumericLiteral

func (sv *StringVisitor) AcceptNumericLiteral(v NumericLiteral)

AcceptNumericLiteral implements Visitor

func (*StringVisitor) AcceptOr

func (sv *StringVisitor) AcceptOr(v Or)

AcceptOr implements Visitor

func (*StringVisitor) AcceptVariable

func (sv *StringVisitor) AcceptVariable(v Variable)

AcceptVariable implements Visitor

func (*StringVisitor) String

func (sv *StringVisitor) String() string

String returns the current string built up

type Transformer

type Transformer interface {
	Visitor
	Transform(Expression) Expression
}

Transformer is something that can transform expressions

type Variable

type Variable struct {
	Name string
}

Variable represents a variable used before

func (Variable) Accept

func (v Variable) Accept(vs Visitor)

Accept implements Expression

type Visitor

type Visitor interface {
	AcceptAnd(And)
	AcceptArgument(Argument)
	AcceptArithmetic(Arithmetic)
	AcceptBinaryNegation(BinaryNegation)
	AcceptBooleanLiteral(BooleanLiteral)
	AcceptCall(Call)
	AcceptComparison(Comparison)
	AcceptInclusion(Inclusion)
	AcceptNegation(Negation)
	AcceptNumericLiteral(NumericLiteral)
	AcceptOr(Or)
	AcceptVariable(Variable)
}

Visitor is a visitor for all parse nodes

Jump to

Keyboard shortcuts

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