MCPcopy
hub / github.com/Ne0nd0g/merlin / parseShellcodeFile

Function parseShellcodeFile

pkg/modules/shellcode/shellcode.go:151–172  ·  view source on GitHub ↗

parseShellcodeFile parses a path, evaluates the file's contents, and returns a byte array of shellcode

(filePath string)

Source from the content-addressed store, hash-verified

149
150// parseShellcodeFile parses a path, evaluates the file's contents, and returns a byte array of shellcode
151func parseShellcodeFile(filePath string) ([]byte, error) {
152
153 fileContents, err := os.ReadFile(filePath) // #nosec G304 Users can include any file from anywhere
154 if err != nil {
155 return nil, err
156 }
157
158 hexBytes, errHex := parseHex([]string{string(fileContents)})
159
160 // If there was an error parsing the bytes then it probably wasn't ASCII hex, therefore continue on
161 if errHex == nil {
162 return hexBytes, nil
163 }
164
165 // See if it is Base64 encoded binary blob
166 base64Data, errB64 := base64.StdEncoding.DecodeString(string(fileContents))
167 if errB64 == nil {
168 return base64Data, nil
169 }
170
171 return fileContents, nil
172}

Callers 2

ParseFunction · 0.85
ParseShellcodeFunction · 0.85

Calls 1

parseHexFunction · 0.85

Tested by

no test coverage detected