parseShellcodeFile parses a path, evaluates the file's contents, and returns a byte array of shellcode
(filePath string)
| 149 | |
| 150 | // parseShellcodeFile parses a path, evaluates the file's contents, and returns a byte array of shellcode |
| 151 | func 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 | } |
no test coverage detected