MCPcopy Index your code
hub / github.com/codeyourweb/irma / PerformArchiveYaraScan

Function PerformArchiveYaraScan

yaraProcessing.go:25–73  ·  view source on GitHub ↗

PerformArchiveYaraScan try to decompress archive and YARA scan every file in it

(path string, rules *yara.Rules, verbose bool)

Source from the content-addressed store, hash-verified

23
24// PerformArchiveYaraScan try to decompress archive and YARA scan every file in it
25func PerformArchiveYaraScan(path string, rules *yara.Rules, verbose bool) (matchs yara.MatchRules) {
26 var buffer [][]byte
27
28 a, err := unarr.NewArchive(path)
29 if err != nil {
30 if verbose {
31 logMessage(LOG_ERROR, "[ERROR]", err)
32 }
33 return matchs
34 }
35 defer a.Close()
36
37 list, err := a.List()
38 if err != nil {
39 if verbose {
40 logMessage(LOG_ERROR, "[ERROR]", err)
41 }
42 return matchs
43 }
44 for _, f := range list {
45 err := a.EntryFor(f)
46 if err != nil {
47 if verbose {
48 logMessage(LOG_ERROR, "[ERROR]", err)
49 }
50 return matchs
51 }
52
53 data, err := a.ReadAll()
54 if err != nil {
55 if verbose {
56 logMessage(LOG_ERROR, "[ERROR]", err)
57 }
58 return matchs
59 }
60
61 buffer = append(buffer, data)
62 }
63
64 matchs, err = YaraScan(bytes.Join(buffer, []byte{}), rules)
65 if err != nil && verbose {
66 if verbose {
67 logMessage(LOG_ERROR, "[ERROR]", err)
68 }
69 return matchs
70 }
71
72 return matchs
73}
74
75// SearchForYaraFiles search *.yar file by walking recursively from specified input path
76func SearchForYaraFiles(path string, verbose bool) (rules []string) {

Callers 1

FileAnalysisFunction · 0.85

Calls 2

logMessageFunction · 0.85
YaraScanFunction · 0.85

Tested by

no test coverage detected