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

Function parseHex

pkg/modules/shellcode/shellcode.go:121–148  ·  view source on GitHub ↗

parseHex evaluates a string array to determine its format and returns a byte array of the hex

(str []string)

Source from the content-addressed store, hash-verified

119
120// parseHex evaluates a string array to determine its format and returns a byte array of the hex
121func 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
151func parseShellcodeFile(filePath string) ([]byte, error) {

Callers 3

ParseFunction · 0.85
ParseShellcodeFunction · 0.85
parseShellcodeFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected