MCPcopy Create free account
hub / github.com/codeyourweb/irma / recursiveCompressFolder

Function recursiveCompressFolder

sfxbuilder.go:38–136  ·  view source on GitHub ↗
(yaraPath string, rc4key string, config Configuration)

Source from the content-addressed store, hash-verified

36}
37
38func recursiveCompressFolder(yaraPath string, rc4key string, config Configuration) bytes.Buffer {
39 var buffer bytes.Buffer
40 archive := zip.NewWriter(&buffer)
41
42 files := SearchForYaraFiles(yaraPath, true)
43
44 // embed irma.exe executable
45 zipFile, err := archive.Create("irma.exe")
46 if err != nil {
47 log.Fatal("[ERROR] ", err)
48 }
49
50 fsFile, err := os.ReadFile(os.Args[0])
51 if err != nil {
52 log.Fatal("[ERROR] ", err)
53 }
54
55 r := bytes.NewReader(fsFile)
56 _, err = io.Copy(zipFile, r)
57 if err != nil {
58 log.Fatal("[ERROR] ", err)
59 }
60
61 // embed configuration file
62 zipFile, err = archive.Create("configuration.yaml")
63 if err != nil {
64 log.Fatal("[ERROR] ", err)
65 }
66
67 config.Yara.Path = "yara-signatures/"
68 d, err := yaml.Marshal(&config)
69 r = bytes.NewReader(d)
70 _, err = io.Copy(zipFile, r)
71 if err != nil {
72 log.Fatal("[ERROR] ", err)
73 }
74
75 // embed yara rules
76 for _, f := range files {
77 fileName := filepath.Base(f)
78 zipFile, err := archive.Create("yara-signatures/" + fileName)
79 if err != nil {
80 log.Fatal("[ERROR] ", err)
81 }
82
83 fsFile, err := os.ReadFile(f)
84 if err != nil {
85 log.Fatal("[ERROR] ", err)
86 }
87
88 // yara rule RC4 cipher
89 if len(rc4key) > 0 {
90 c, err := rc4.NewCipher([]byte(rc4key))
91 if err != nil {
92 log.Fatal("[ERROR] ", err)
93 }
94
95 c.XORKeyStream(fsFile, fsFile)

Callers 1

BuildSFXFunction · 0.85

Calls 1

SearchForYaraFilesFunction · 0.85

Tested by

no test coverage detected