Documentation
¶
Index ¶
- Constants
- Variables
- func AnalyzeSCEV(info *LoopInfo)
- func BuildSSAFromPackages(initialPkgs []*packages.Package) (*ssa.Program, *ssa.Package, error)
- func CalculateEntropy(data []byte) float64
- func CalculateEntropyNormalized(data []byte) float64
- func CheckIRPattern(t *testing.T, ir string, pattern string)
- func ComputeTopologySimilarityExported(topo *FunctionTopology, sig Signature) float64
- func EntropyDistance(e1, e2 float64) float64
- func EntropyMatch(e1, e2, tolerance float64) bool
- func FormatEntropyKeyExported(entropy float64, id string) string
- func GenerateFuzzyHash(t *FunctionTopology) string
- func GenerateTopologyHashExported(topo *FunctionTopology) string
- func GetFunctionNames(results []FingerprintResult) []string
- func MatchCallsExported(topo *FunctionTopology, required []string) (score float64, matched, missing []string)
- func MatchFunctionsByTopology(oldResults, newResults []FingerprintResult, threshold float64) (matched []TopologyMatch, addedFuncs []FingerprintResult, ...)
- func ReleaseCanonicalizer(c *Canonicalizer)
- func SetupTestEnv(t *testing.T, dirPrefix string) (string, func())
- func ShortFuncName(fullName string) string
- func TopologyFingerprint(t *FunctionTopology) string
- func TopologySimilarity(a, b *FunctionTopology) float64
- type BoltScanner
- func (s *BoltScanner) AddSignature(sig Signature) error
- func (s *BoltScanner) AddSignatures(sigs []Signature) error
- func (s *BoltScanner) Close() error
- func (s *BoltScanner) Compact(destPath string) error
- func (s *BoltScanner) CountSignatures() (int, error)
- func (s *BoltScanner) DeleteSignature(id string) error
- func (s *BoltScanner) ExportToJSON(jsonPath string) error
- func (s *BoltScanner) GetSignature(id string) (*Signature, error)
- func (s *BoltScanner) GetSignatureByTopology(topoHash string) (*Signature, error)
- func (s *BoltScanner) ListSignatureIDs() ([]string, error)
- func (s *BoltScanner) MarkFalsePositive(id string, notes string) error
- func (s *BoltScanner) MigrateFromJSON(jsonPath string) (int, error)
- func (s *BoltScanner) RebuildIndexes() error
- func (s *BoltScanner) ScanTopology(topo *FunctionTopology, funcName string) []ScanResult
- func (s *BoltScanner) ScanTopologyExact(topo *FunctionTopology, funcName string) *ScanResult
- func (s *BoltScanner) SetEntropyTolerance(tolerance float64)
- func (s *BoltScanner) SetThreshold(threshold float64)
- func (s *BoltScanner) Stats() (*BoltScannerStats, error)
- type BoltScannerOptions
- type BoltScannerStats
- type Canonicalizer
- type ControlFlowHints
- type EntropyClass
- type EntropyProfile
- type FingerprintResult
- func CompileAndGetFunction(t *testing.T, src, funcName string) *FingerprintResult
- func FindResult(results []FingerprintResult, name string) *FingerprintResult
- func FingerprintPackages(initialPkgs []*packages.Package, policy LiteralPolicy, strictMode bool) ([]FingerprintResult, error)
- func FingerprintSource(filename string, src string, policy LiteralPolicy) ([]FingerprintResult, error)
- func FingerprintSourceAdvanced(filename string, src string, policy LiteralPolicy, strictMode bool) ([]FingerprintResult, error)
- func GenerateFingerprint(fn *ssa.Function, policy LiteralPolicy, strictMode bool) FingerprintResult
- type FunctionTopology
- type IVType
- type IdentifyingFeatures
- type InductionVariable
- type LiteralPolicy
- type Loop
- type LoopInfo
- type MatchDetails
- type Renamer
- type SCEV
- type SCEVAddRec
- func (s *SCEVAddRec) EvaluateAt(k *big.Int) *big.Int
- func (s *SCEVAddRec) IsLoopInvariant(loop *Loop) bool
- func (s *SCEVAddRec) Name() string
- func (s *SCEVAddRec) Parent() *ssa.Function
- func (s *SCEVAddRec) Pos() token.Pos
- func (s *SCEVAddRec) Referrers() *[]ssa.Instruction
- func (s *SCEVAddRec) String() string
- func (s *SCEVAddRec) StringWithRenamer(r Renamer) string
- func (s *SCEVAddRec) Type() types.Type
- type SCEVConstant
- func (s *SCEVConstant) EvaluateAt(k *big.Int) *big.Int
- func (s *SCEVConstant) IsLoopInvariant(loop *Loop) bool
- func (s *SCEVConstant) Name() string
- func (s *SCEVConstant) Parent() *ssa.Function
- func (s *SCEVConstant) Pos() token.Pos
- func (s *SCEVConstant) Referrers() *[]ssa.Instruction
- func (s *SCEVConstant) String() string
- func (s *SCEVConstant) StringWithRenamer(r Renamer) string
- func (s *SCEVConstant) Type() types.Type
- type SCEVGenericExpr
- func (s *SCEVGenericExpr) EvaluateAt(k *big.Int) *big.Int
- func (s *SCEVGenericExpr) IsLoopInvariant(loop *Loop) bool
- func (s *SCEVGenericExpr) Name() string
- func (s *SCEVGenericExpr) Parent() *ssa.Function
- func (s *SCEVGenericExpr) Pos() token.Pos
- func (s *SCEVGenericExpr) Referrers() *[]ssa.Instruction
- func (s *SCEVGenericExpr) String() string
- func (s *SCEVGenericExpr) StringWithRenamer(r Renamer) string
- func (s *SCEVGenericExpr) Type() types.Type
- type SCEVUnknown
- func (s *SCEVUnknown) EvaluateAt(k *big.Int) *big.Int
- func (s *SCEVUnknown) IsLoopInvariant(loop *Loop) bool
- func (s *SCEVUnknown) Name() string
- func (s *SCEVUnknown) Parent() *ssa.Function
- func (s *SCEVUnknown) Pos() token.Pos
- func (s *SCEVUnknown) Referrers() *[]ssa.Instruction
- func (s *SCEVUnknown) String() string
- func (s *SCEVUnknown) StringWithRenamer(r Renamer) string
- func (s *SCEVUnknown) Type() types.Type
- type ScanResult
- type Scanner
- func (s *Scanner) AddSignature(sig Signature)
- func (s *Scanner) GetDatabase() *SignatureDatabase
- func (s *Scanner) LoadDatabase(path string) error
- func (s *Scanner) SaveDatabase(path string) error
- func (s *Scanner) ScanTopology(topo *FunctionTopology, funcName string) []ScanResult
- func (s *Scanner) SetThreshold(threshold float64)
- type Signature
- type SignatureDatabase
- type SignatureMetadata
- type TopologyMatch
- type Zipper
- type ZipperArtifacts
Constants ¶
const MaxCandidates = 100
Limits comparison candidates per fingerprint bucket. Prevents algorithmic DoS where malicious inputs with thousands of identical operations could cause O(N*M) comparisons. With this limit, worst case becomes O(N * MaxCandidates) which is linear.
const MaxRenamerDepth = 100
Limits recursion depth in SCEV renaming to prevent stack overflow. A depth of 100 is sufficient for legitimate nested expressions while preventing malicious deeply nested chains (e.g., v1 = v2, v2 = v3, ... v10000 = C) or exponential "Billion Laughs" expansion attacks (e.g., A -> {B, +, B}).
Variables ¶
var DefaultLiteralPolicy = LiteralPolicy{ AbstractControlFlowComparisons: true, KeepSmallIntegerIndices: true, KeepReturnStatusValues: true, KeepStringLiterals: false, SmallIntMin: -16, SmallIntMax: 16, AbstractOtherTypes: true, }
Standard policy for fingerprinting. Preserves small integers used for indexing and status codes while masking magic numbers and large constants.
var KeepAllLiteralsPolicy = LiteralPolicy{ AbstractControlFlowComparisons: false, KeepSmallIntegerIndices: true, KeepReturnStatusValues: true, KeepStringLiterals: true, SmallIntMin: math.MinInt64, SmallIntMax: math.MaxInt64, AbstractOtherTypes: false, }
Designed for testing or exact matching by disabling most abstractions and expanding the "small" integer range to the full int64 spectrum.
Functions ¶
func AnalyzeSCEV ¶
func AnalyzeSCEV(info *LoopInfo)
Main entry point for SCEV analysis on a LoopInfo.
func BuildSSAFromPackages ¶
Constructs Static Single Assignment form from loaded Go packages. Returns the complete program and the target package for analysis.
func CalculateEntropy ¶
Returns the Shannon entropy of a byte slice. Result ranges from 0.0 (completely uniform/predictable) to 8.0 (maximum randomness). High entropy (>7.0) often indicates packed/encrypted code. Normal code typically has entropy between 4.5 and 6.5.
func CalculateEntropyNormalized ¶
Returns entropy normalized to 0.0-1.0 range. Useful for direct comparison and threshold checks.
func CheckIRPattern ¶
CheckIRPattern checks IR against a pattern using regex, abstracting register names. Exported for use in external test packages.
func ComputeTopologySimilarityExported ¶
func ComputeTopologySimilarityExported(topo *FunctionTopology, sig Signature) float64
ComputeTopologySimilarityExported exports the computeTopologySimilarity function for testing.
func EntropyDistance ¶
Calculates the absolute difference between two entropy values. Used for fuzzy matching: two functions with similar entropy are more likely related.
func EntropyMatch ¶
Returns true if two entropy values are within the given tolerance. Default tolerance of 0.5 is recommended for malware family matching.
func FormatEntropyKeyExported ¶
FormatEntropyKeyExported exports the formatEntropyKey function for testing.
func GenerateFuzzyHash ¶
func GenerateFuzzyHash(t *FunctionTopology) string
REMEDIATION: O(1) Topology Trap Fix GenerateFuzzyHash creates a locality-sensitive hash for bucket indexing. Buckets: Blocks (Log2), Loops (Exact/Capped), Branches (Log2).
func GenerateTopologyHashExported ¶
func GenerateTopologyHashExported(topo *FunctionTopology) string
GenerateTopologyHashExported exports the generateTopologyHash function for testing.
func GetFunctionNames ¶
func GetFunctionNames(results []FingerprintResult) []string
GetFunctionNames extracts function names from results for easier verification. Exported for use in external test packages.
func MatchCallsExported ¶
func MatchCallsExported(topo *FunctionTopology, required []string) (score float64, matched, missing []string)
MatchCallsExported exports the matchCalls function for testing.
func MatchFunctionsByTopology ¶
func MatchFunctionsByTopology(oldResults, newResults []FingerprintResult, threshold float64) ( matched []TopologyMatch, addedFuncs []FingerprintResult, removedFuncs []FingerprintResult, )
Performs topology based function matching between two sets of fingerprint results. This is the "unobfuscator" that finds renamed functions.
Strategy: 1. First, try to match by exact name (preserves intentional naming) 2. For unmatched functions, compute topology similarity matrix 3. Use greedy matching to pair functions by structural similarity 4. Report matches above a confidence threshold
func ReleaseCanonicalizer ¶
func ReleaseCanonicalizer(c *Canonicalizer)
func SetupTestEnv ¶
SetupTestEnv creates an isolated test environment for packages loader. Exported for use in external test packages.
func ShortFuncName ¶
ShortFuncName returns the short function name without package prefix. Exported for use in external test packages.
func TopologyFingerprint ¶
func TopologyFingerprint(t *FunctionTopology) string
Generates a short structural fingerprint for display purposes. This is a human readable summary of the function's shape.
func TopologySimilarity ¶
func TopologySimilarity(a, b *FunctionTopology) float64
Computes a similarity score between two function topologies. Returns a value between 0.0 (completely different) and 1.0 (identical structure).
Types ¶
type BoltScanner ¶
type BoltScanner struct {
// contains filtered or unexported fields
}
Performs semantic malware detection using BoltDB for persistent storage. Supports O(1) exact topology matching and O(M) fuzzy entropy range scans.
func NewBoltScanner ¶
func NewBoltScanner(dbPath string, opts BoltScannerOptions) (*BoltScanner, error)
Opens or creates a BoltDB backed signature database. The database file will be created if it doesn't exist.
func (*BoltScanner) AddSignature ¶
func (s *BoltScanner) AddSignature(sig Signature) error
Atomically saves a signature and updates all indexes. Safe for concurrent use.
func (*BoltScanner) AddSignatures ¶
func (s *BoltScanner) AddSignatures(sigs []Signature) error
Atomically adds multiple signatures in a single transaction. Much faster than calling AddSignature in a loop for bulk imports.
func (*BoltScanner) Close ¶
func (s *BoltScanner) Close() error
Flushes all pending writes and closes the database. Always call this when done to prevent data loss.
func (*BoltScanner) Compact ¶
func (s *BoltScanner) Compact(destPath string) error
Forces a compaction of the database file to reclaim space. BoltDB doesn't automatically shrink, so call this after large deletions.
func (*BoltScanner) CountSignatures ¶
func (s *BoltScanner) CountSignatures() (int, error)
Returns the total number of signatures in the database.
func (*BoltScanner) DeleteSignature ¶
func (s *BoltScanner) DeleteSignature(id string) error
Removes a signature and its index entries.
func (*BoltScanner) ExportToJSON ¶
func (s *BoltScanner) ExportToJSON(jsonPath string) error
Exports all signatures to a JSON file (backup/compatibility).
func (*BoltScanner) GetSignature ¶
func (s *BoltScanner) GetSignature(id string) (*Signature, error)
Retrieves a single signature by ID.
func (*BoltScanner) GetSignatureByTopology ¶
func (s *BoltScanner) GetSignatureByTopology(topoHash string) (*Signature, error)
Retrieves a signature by its topology hash.
func (*BoltScanner) ListSignatureIDs ¶
func (s *BoltScanner) ListSignatureIDs() ([]string, error)
Returns all signature IDs in the database.
func (*BoltScanner) MarkFalsePositive ¶
func (s *BoltScanner) MarkFalsePositive(id string, notes string) error
Updates a signature to record that it caused a false positive. Enables learning feedback loops without rewriting the entire database.
func (*BoltScanner) MigrateFromJSON ¶
func (s *BoltScanner) MigrateFromJSON(jsonPath string) (int, error)
Imports signatures from a legacy JSON database file. One time migration utility.
func (*BoltScanner) RebuildIndexes ¶
func (s *BoltScanner) RebuildIndexes() error
Rebuilds all secondary indexes from the master signatures bucket. Use this to recover from index corruption or after manual edits.
func (*BoltScanner) ScanTopology ¶
func (s *BoltScanner) ScanTopology(topo *FunctionTopology, funcName string) []ScanResult
Checks a function topology against the signature database using two phases:
- Phase A (O(1)): Exact topology hash lookup
- Phase B (O(1)): Fuzzy bucket index lookup (LSH-lite)
func (*BoltScanner) ScanTopologyExact ¶
func (s *BoltScanner) ScanTopologyExact(topo *FunctionTopology, funcName string) *ScanResult
Performs only exact topology hash matching (fastest). Use this when you only want exact matches without fuzzy entropy scanning.
func (*BoltScanner) SetEntropyTolerance ¶
func (s *BoltScanner) SetEntropyTolerance(tolerance float64)
Updates the entropy fuzzy match window.
func (*BoltScanner) SetThreshold ¶
func (s *BoltScanner) SetThreshold(threshold float64)
Updates the minimum confidence threshold for alerts.
func (*BoltScanner) Stats ¶
func (s *BoltScanner) Stats() (*BoltScannerStats, error)
type BoltScannerOptions ¶
type BoltScannerOptions struct {
MatchThreshold float64 // Minimum confidence for alerts (default: 0.75)
EntropyTolerance float64 // Entropy fuzzy match window (default: 0.5)
Timeout time.Duration // DB open timeout (default: 5s)
ReadOnly bool // Open DB in read-only mode for scanning only
}
Configures the BoltScanner initialization.
func DefaultBoltScannerOptions ¶
func DefaultBoltScannerOptions() BoltScannerOptions
Returns sensible defaults for production use.
type BoltScannerStats ¶
type BoltScannerStats struct {
SignatureCount int
TopoIndexCount int
EntropyIndexSize int64
FileSize int64
}
Returns database statistics for monitoring.
type Canonicalizer ¶
type Canonicalizer struct {
Policy LiteralPolicy
StrictMode bool
// contains filtered or unexported fields
}
Transforms an SSA function into a deterministic string representation.
func AcquireCanonicalizer ¶
func AcquireCanonicalizer(policy LiteralPolicy) *Canonicalizer
func NewCanonicalizer ¶
func NewCanonicalizer(policy LiteralPolicy) *Canonicalizer
func (*Canonicalizer) ApplyVirtualControlFlowFromState ¶
func (c *Canonicalizer) ApplyVirtualControlFlowFromState(swappedBlocks map[*ssa.BasicBlock]bool, virtualBinOps map[*ssa.BinOp]token.Token)
func (*Canonicalizer) CanonicalizeFunction ¶
func (c *Canonicalizer) CanonicalizeFunction(fn *ssa.Function) string
type ControlFlowHints ¶
type ControlFlowHints struct {
HasInfiniteLoop bool `json:"has_infinite_loop,omitempty"`
HasReconnectLogic bool `json:"has_reconnect_logic,omitempty"`
}
Captures control flow patterns.
type EntropyClass ¶
type EntropyClass int
Categorizes entropy levels for quick analysis.
const ( EntropyLow EntropyClass = iota // < 4.0: Simple/sparse code EntropyNormal // 4.0-6.5: Typical compiled code EntropyHigh // 6.5-7.5: Potentially obfuscated EntropyPacked // > 7.5: Likely packed/encrypted )
func ClassifyEntropy ¶
func ClassifyEntropy(entropy float64) EntropyClass
Determines the entropy class from a raw entropy value.
func (EntropyClass) String ¶
func (c EntropyClass) String() string
type EntropyProfile ¶
type EntropyProfile struct {
// Overall entropy of the function body
Overall float64
// Entropy of string literals within the function
StringLiteralEntropy float64
// Entropy classification
Classification EntropyClass
}
Captures entropy characteristics for malware analysis.
func CalculateEntropyProfile ¶
func CalculateEntropyProfile(bodyBytes []byte, stringLiterals []string) EntropyProfile
Builds a complete entropy profile for analysis.
type FingerprintResult ¶
type FingerprintResult struct {
FunctionName string
Fingerprint string
CanonicalIR string
Pos token.Pos
Line int
Filename string
// contains filtered or unexported fields
}
Holds everything we learned from fingerprinting a single function: the hash, the canonical IR that produced it, and the source location for traceability.
func CompileAndGetFunction ¶
func CompileAndGetFunction(t *testing.T, src, funcName string) *FingerprintResult
CompileAndGetFunction is a helper to compile source and get a named SSA function. Exported for use in external test packages.
func FindResult ¶
func FindResult(results []FingerprintResult, name string) *FingerprintResult
FindResult searches for a FingerprintResult by function name. It supports both exact matches and suffix matches (e.g., "functionName" matches "pkg.functionName"). Exported for use in external test packages.
func FingerprintPackages ¶
func FingerprintPackages(initialPkgs []*packages.Package, policy LiteralPolicy, strictMode bool) ([]FingerprintResult, error)
Walks the loaded packages, builds SSA, and generates fingerprint results for every function we find. Handles methods, closures, and init functions.
func FingerprintSource ¶
func FingerprintSource(filename string, src string, policy LiteralPolicy) ([]FingerprintResult, error)
Analyzes a single Go source file provided as a string. Primary entry point for verifying code snippets or patch hunks.
func FingerprintSourceAdvanced ¶
func FingerprintSourceAdvanced(filename string, src string, policy LiteralPolicy, strictMode bool) ([]FingerprintResult, error)
Extended interface for source analysis that exposes strict mode control.
func GenerateFingerprint ¶
func GenerateFingerprint(fn *ssa.Function, policy LiteralPolicy, strictMode bool) FingerprintResult
Produces the SHA256 hash and canonical string representation for an SSA function. Pulls a Canonicalizer from the pool to keep allocations low and throughput high.
func (FingerprintResult) GetSSAFunction ¶
func (r FingerprintResult) GetSSAFunction() *ssa.Function
Exposes the underlying SSA function for consumers that need deeper analysis, like semantic diffing with the Zipper algorithm. Returns nil if unavailable.
type FunctionTopology ¶
type FunctionTopology struct {
// Fuzzy Hash for Bucket Indexing (LSH-lite)
// Used for O(1) candidate retrieval in large databases.
FuzzyHash string
// Basic metrics
ParamCount int
ReturnCount int
BlockCount int
InstrCount int
LoopCount int
BranchCount int // if statements
PhiCount int
// Call profile: map of "package.func" or "method" -> count
CallSignatures map[string]int
// Type signature (normalized)
ParamTypes []string
ReturnTypes []string
// Control flow features
HasDefer bool
HasRecover bool
HasPanic bool
HasGo bool
HasSelect bool
HasRange bool
// Operator profile
BinOpCounts map[string]int
UnOpCounts map[string]int
// String literal hashes (for behavioral matching)
StringLiterals []string
// Entropy analysis for obfuscation detection
EntropyScore float64 // Shannon entropy of function body (0.0-8.0)
EntropyProfile EntropyProfile // Full entropy analysis
// contains filtered or unexported fields
}
Captures the structural "shape" of a function independent of names. This enables matching functions that have been renamed or obfuscated.
func ExtractTopology ¶
func ExtractTopology(fn *ssa.Function) *FunctionTopology
Analyzes an SSA function and extracts its structural features.
type IdentifyingFeatures ¶
type IdentifyingFeatures struct {
RequiredCalls []string `json:"required_calls,omitempty"`
OptionalCalls []string `json:"optional_calls,omitempty"`
StringPatterns []string `json:"string_patterns,omitempty"`
ControlFlow *ControlFlowHints `json:"control_flow,omitempty"`
}
Captures behavioral markers for detection.
type InductionVariable ¶
type InductionVariable struct {
Phi *ssa.Phi
Type IVType
Start SCEV // Value at iteration 0
Step SCEV // Update stride
}
Describes a detected IV. Reference: Section 3.2 Classification Taxonomy.
type LiteralPolicy ¶
type LiteralPolicy struct {
AbstractControlFlowComparisons bool
KeepSmallIntegerIndices bool
KeepReturnStatusValues bool
KeepStringLiterals bool
SmallIntMin int64
SmallIntMax int64
AbstractOtherTypes bool
}
Defines the configurable strategy for determining which literal values should be abstracted into placeholders during canonicalization. Allows fine grained control over integer abstraction in different contexts.
func (*LiteralPolicy) ShouldAbstract ¶
func (p *LiteralPolicy) ShouldAbstract(c *ssa.Const, usageContext ssa.Instruction) bool
Decides whether a given constant should be replaced by a generic placeholder. Analyzes the constant's type, value, and immediate usage context in the SSA graph.
type Loop ¶
type Loop struct {
Header *ssa.BasicBlock
Latch *ssa.BasicBlock // Primary source of the backedge
// Blocks contains all basic blocks within the loop body.
Blocks map[*ssa.BasicBlock]bool
// Exits contains blocks inside the loop that have successors outside.
Exits []*ssa.BasicBlock
// Hierarchy
Parent *Loop
Children []*Loop
// Semantic Analysis (populated in scev.go)
Inductions map[*ssa.Phi]*InductionVariable
TripCount SCEV // Symbolic expression
// Memoization cache for SCEV analysis to prevent exponential complexity.
SCEVCache map[ssa.Value]SCEV
}
Represents a natural loop in the SSA graph. Reference: Section 2.3 Natural Loops.
type LoopInfo ¶
type LoopInfo struct {
Function *ssa.Function
Loops []*Loop // Top-level loops (roots of the hierarchy)
// Map from Header block to Loop object for O(1) lookup
LoopMap map[*ssa.BasicBlock]*Loop
}
Summarizes loop analysis for a single function.
func DetectLoops ¶
Reconstructs the loop hierarchy using dominance relations. Reference: Section 2.3.1 Algorithm: Detecting Natural Loops.
type MatchDetails ¶
type MatchDetails struct {
TopologyMatch bool `json:"topology_match"`
EntropyMatch bool `json:"entropy_match"`
CallsMatched []string `json:"calls_matched"`
CallsMissing []string `json:"calls_missing"`
StringsMatched []string `json:"strings_matched"`
TopologySimilarity float64 `json:"topology_similarity"`
EntropyDistance float64 `json:"entropy_distance"`
}
Provides granular information about the match.
type Renamer ¶
Maps an SSA value to its canonical name. Ensures deterministic output regardless of SSA register naming.
type SCEV ¶
type SCEV interface {
ssa.Value
EvaluateAt(k *big.Int) *big.Int
IsLoopInvariant(loop *Loop) bool
String() string
// Returns a canonical string using the provided renamer function to map
// SSA values to their canonical names (e.g., v0, v1). Critical for determinism:
// without it, raw SSA names (t0, t1) would leak into fingerprints, breaking
// semantic equivalence.
StringWithRenamer(r Renamer) string
}
Represents a scalar expression in the SCEV lattice.
type SCEVAddRec ¶
Represents an Add Recurrence: {Start, +, Step}_L Reference: Section 4.1 The Add Recurrence Abstraction.
func (*SCEVAddRec) EvaluateAt ¶
func (s *SCEVAddRec) EvaluateAt(k *big.Int) *big.Int
func (*SCEVAddRec) IsLoopInvariant ¶
func (s *SCEVAddRec) IsLoopInvariant(loop *Loop) bool
func (*SCEVAddRec) Parent ¶
func (s *SCEVAddRec) Parent() *ssa.Function
func (*SCEVAddRec) Pos ¶
func (s *SCEVAddRec) Pos() token.Pos
func (*SCEVAddRec) Referrers ¶
func (s *SCEVAddRec) Referrers() *[]ssa.Instruction
func (*SCEVAddRec) String ¶
func (s *SCEVAddRec) String() string
func (*SCEVAddRec) StringWithRenamer ¶
func (s *SCEVAddRec) StringWithRenamer(r Renamer) string
func (*SCEVAddRec) Type ¶
func (s *SCEVAddRec) Type() types.Type
type SCEVConstant ¶
Represents a literal integer constant.
func SCEVFromConst ¶
func SCEVFromConst(c *ssa.Const) *SCEVConstant
func (*SCEVConstant) EvaluateAt ¶
func (s *SCEVConstant) EvaluateAt(k *big.Int) *big.Int
func (*SCEVConstant) IsLoopInvariant ¶
func (s *SCEVConstant) IsLoopInvariant(loop *Loop) bool
func (*SCEVConstant) Parent ¶
func (s *SCEVConstant) Parent() *ssa.Function
func (*SCEVConstant) Pos ¶
func (s *SCEVConstant) Pos() token.Pos
func (*SCEVConstant) Referrers ¶
func (s *SCEVConstant) Referrers() *[]ssa.Instruction
func (*SCEVConstant) String ¶
func (s *SCEVConstant) String() string
func (*SCEVConstant) StringWithRenamer ¶
func (s *SCEVConstant) StringWithRenamer(r Renamer) string
func (*SCEVConstant) Type ¶
func (s *SCEVConstant) Type() types.Type
type SCEVGenericExpr ¶
Represents binary operations like Add/Mul for formulas.
func (*SCEVGenericExpr) EvaluateAt ¶
func (s *SCEVGenericExpr) EvaluateAt(k *big.Int) *big.Int
func (*SCEVGenericExpr) IsLoopInvariant ¶
func (s *SCEVGenericExpr) IsLoopInvariant(loop *Loop) bool
func (*SCEVGenericExpr) Parent ¶
func (s *SCEVGenericExpr) Parent() *ssa.Function
func (*SCEVGenericExpr) Pos ¶
func (s *SCEVGenericExpr) Pos() token.Pos
func (*SCEVGenericExpr) Referrers ¶
func (s *SCEVGenericExpr) Referrers() *[]ssa.Instruction
func (*SCEVGenericExpr) String ¶
func (s *SCEVGenericExpr) String() string
func (*SCEVGenericExpr) StringWithRenamer ¶
func (s *SCEVGenericExpr) StringWithRenamer(r Renamer) string
func (*SCEVGenericExpr) Type ¶
func (s *SCEVGenericExpr) Type() types.Type
type SCEVUnknown ¶
type SCEVUnknown struct {
Value ssa.Value
IsInvariant bool // Explicitly tracks invariance relative to the analysis loop scope
}
Represents a symbolic value (e.g., parameter or unanalyzable instruction).
func (*SCEVUnknown) EvaluateAt ¶
func (s *SCEVUnknown) EvaluateAt(k *big.Int) *big.Int
func (*SCEVUnknown) IsLoopInvariant ¶
func (s *SCEVUnknown) IsLoopInvariant(loop *Loop) bool
func (*SCEVUnknown) Parent ¶
func (s *SCEVUnknown) Parent() *ssa.Function
func (*SCEVUnknown) Pos ¶
func (s *SCEVUnknown) Pos() token.Pos
func (*SCEVUnknown) Referrers ¶
func (s *SCEVUnknown) Referrers() *[]ssa.Instruction
func (*SCEVUnknown) String ¶
func (s *SCEVUnknown) String() string
func (*SCEVUnknown) StringWithRenamer ¶
func (s *SCEVUnknown) StringWithRenamer(r Renamer) string
func (*SCEVUnknown) Type ¶
func (s *SCEVUnknown) Type() types.Type
type ScanResult ¶
type ScanResult struct {
SignatureID string `json:"signature_id"`
SignatureName string `json:"signature_name"`
Severity string `json:"severity"`
MatchedFunction string `json:"matched_function"`
Confidence float64 `json:"confidence"` // 0.0 to 1.0
MatchDetails MatchDetails `json:"match_details"`
}
Represents a match between analyzed code and a signature.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Performs semantic malware detection.
func (*Scanner) AddSignature ¶
Adds a new signature to the database.
func (*Scanner) GetDatabase ¶
func (s *Scanner) GetDatabase() *SignatureDatabase
Returns the current signature database.
func (*Scanner) LoadDatabase ¶
Loads signatures from a JSON file.
func (*Scanner) SaveDatabase ¶
Writes the signature database to a JSON file.
func (*Scanner) ScanTopology ¶
func (s *Scanner) ScanTopology(topo *FunctionTopology, funcName string) []ScanResult
Checks a function topology against all signatures. This is the "Hunter Phase" where we scan unknown code for matches.
func (*Scanner) SetThreshold ¶
Sets the minimum confidence threshold for alerts.
type Signature ¶
type Signature struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Severity string `json:"severity"`
Category string `json:"category"`
TopologyHash string `json:"topology_hash"`
FuzzyHash string `json:"fuzzy_hash,omitempty"` // REMEDIATION: LSH bucket
EntropyScore float64 `json:"entropy_score"`
EntropyTolerance float64 `json:"entropy_tolerance"`
NodeCount int `json:"node_count"`
LoopDepth int `json:"loop_depth"`
IdentifyingFeatures IdentifyingFeatures `json:"identifying_features"`
Metadata SignatureMetadata `json:"metadata"`
}
Represents a single malware signature entry.
func IndexFunction ¶
func IndexFunction(topo *FunctionTopology, name, description, severity, category string) Signature
Generates a signature entry from a FunctionTopology. This is the "Lab Phase" where we analyze known malware to build the database.
type SignatureDatabase ¶
type SignatureDatabase struct {
Version string `json:"version"`
Description string `json:"description"`
Signatures []Signature `json:"signatures"`
}
Represents the malware signature database.
type SignatureMetadata ¶
type SignatureMetadata struct {
Author string `json:"author"`
Created string `json:"created"`
References []string `json:"references,omitempty"`
}
Contains provenance information.
type TopologyMatch ¶
type TopologyMatch struct {
OldResult FingerprintResult
NewResult FingerprintResult
OldTopology *FunctionTopology
NewTopology *FunctionTopology
Similarity float64
ByName bool // true if matched by name, false if by topology
}
Represents a potential function pairing with a confidence score.
type Zipper ¶
type Zipper struct {
// contains filtered or unexported fields
}
Implements the semantic delta analysis algorithm. Walks the use def chains of two functions in parallel, aligning equivalent nodes and isolating divergence.
func NewZipper ¶
func NewZipper(oldFn, newFn *ssa.Function, policy LiteralPolicy) (*Zipper, error)
Creates a new analysis session between two function versions.
func (*Zipper) ComputeDiff ¶
func (z *Zipper) ComputeDiff() (*ZipperArtifacts, error)
Runs through all four phases of the Zipper algorithm: semantic analysis, anchor alignment, forward propagation, and divergence isolation.