Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/extractor/magic.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func GetFileRange(size int64, multiplier int) string {
if size <= 0 {
return ""
}
if multiplier <= 0 {
multiplier = 3
}

maxSize := size * int64(multiplier)
if maxSize < 1024 {
Expand Down
4 changes: 4 additions & 0 deletions internal/rules/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ func getMagicCondition(magic string) string {
}

func getFilesizeCondition(size int64, multiplier int) string {
if multiplier <= 0 {
multiplier = 3
}

maxSize := size * int64(multiplier)
if maxSize < 1024 {
maxSize = 1024
Expand Down
8 changes: 8 additions & 0 deletions internal/rules/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ func TestGenerateSimpleRuleEscapesMetaValues(t *testing.T) {
t.Fatalf("expected escaped reference in generated rule, got:\n%s", rule)
}
}

func TestGetFilesizeCondition_DefaultsMultiplierWhenUnset(t *testing.T) {
got := getFilesizeCondition(49*1024, 0)

if got != "filesize < 200KB" {
t.Fatalf("unexpected filesize condition: got %q want %q", got, "filesize < 200KB")
}
}
31 changes: 18 additions & 13 deletions internal/web/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,20 @@ func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) {

// GenerateRequest contains parameters for rule generation.
type GenerateRequest struct {
JobID string `json:"job_id"`
Author string `json:"author"`
Reference string `json:"reference"`
ShowScores bool `json:"show_scores"`
ExcludeOpcodes bool `json:"exclude_opcodes"`
NoSuper bool `json:"no_super"`
ExcludeGoodware bool `json:"exclude_goodware"`
NoMagic bool `json:"no_magic"`
NoFilesize bool `json:"no_filesize"`
UseLLM bool `json:"use_llm"`
MinScore float64 `json:"min_score"`
MaxStrings int `json:"max_strings"`
Debug bool `json:"debug"`
JobID string `json:"job_id"`
Author string `json:"author"`
Reference string `json:"reference"`
ShowScores bool `json:"show_scores"`
ExcludeOpcodes bool `json:"exclude_opcodes"`
NoSuper bool `json:"no_super"`
ExcludeGoodware bool `json:"exclude_goodware"`
NoMagic bool `json:"no_magic"`
NoFilesize bool `json:"no_filesize"`
FilesizeMultiply int `json:"filesize_multiplier"`
UseLLM bool `json:"use_llm"`
MinScore float64 `json:"min_score"`
MaxStrings int `json:"max_strings"`
Debug bool `json:"debug"`
}

func (s *Server) handleGenerate(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -290,6 +291,7 @@ func (s *Server) handleGenerate(w http.ResponseWriter, r *http.Request) {
ExcludeGoodware: req.ExcludeGoodware,
NoMagic: req.NoMagic,
NoFilesize: req.NoFilesize,
FilesizeMultiply: req.FilesizeMultiply,
UseLLM: req.UseLLM,
MinScore: req.MinScore,
MaxStrings: req.MaxStrings,
Expand All @@ -305,6 +307,9 @@ func (s *Server) handleGenerate(w http.ResponseWriter, r *http.Request) {
if opts.Author == "" {
opts.Author = "yarGen"
}
if opts.FilesizeMultiply <= 0 {
opts.FilesizeMultiply = 3
}

result, err := s.yargen.Generate(ctx, opts)

Expand Down
1 change: 1 addition & 0 deletions internal/web/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function generateRules() {
exclude_goodware: document.getElementById('opt-exclude-good').checked,
no_magic: document.getElementById('opt-no-magic').checked,
no_filesize: document.getElementById('opt-no-filesize').checked,
filesize_multiplier: parseInt(document.getElementById('opt-fs-mult').value) || 3,
use_llm: document.getElementById('opt-llm').checked,
min_score: parseFloat(document.getElementById('opt-min-score').value) || 0,
max_strings: parseInt(document.getElementById('opt-max-strings').value) || 20,
Expand Down
Loading