parseHex evaluates a string array to determine its format and returns a byte array of the hex
(str []string)
| 119 | |
| 120 | // parseHex evaluates a string array to determine its format and returns a byte array of the hex |
| 121 | func parseHex(str []string) ([]byte, error) { |
| 122 | hexString := strings.Join(str, "") |
| 123 | |
| 124 | // see if it is Base64 encoded |
| 125 | data, err := base64.StdEncoding.DecodeString(hexString) |
| 126 | if err == nil { |
| 127 | return data, err |
| 128 | } |
| 129 | |
| 130 | // see if string is prefixed with 0x |
| 131 | if hexString[0:2] == "0x" { |
| 132 | hexString = strings.Replace(hexString, "0x", "", -1) |
| 133 | hexString = strings.Replace(hexString, ",", "", -1) |
| 134 | hexString = strings.Replace(hexString, " ", "", -1) |
| 135 | } |
| 136 | |
| 137 | // see if string is prefixed with \x |
| 138 | if hexString[0:2] == "\\x" { |
| 139 | hexString = strings.Replace(hexString, "\\x", "", -1) |
| 140 | hexString = strings.Replace(hexString, ",", "", -1) |
| 141 | hexString = strings.Replace(hexString, " ", "", -1) |
| 142 | } |
| 143 | |
| 144 | h, errH := hex.DecodeString(hexString) |
| 145 | |
| 146 | return h, errH |
| 147 | |
| 148 | } |
| 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) { |
no outgoing calls
no test coverage detected