Land #50, added golang support for output.

This commit is contained in:
Spencer McIntyre 2022-08-31 09:45:30 -04:00
commit 991e72c5e5
No known key found for this signature in database
GPG Key ID: 58101BA0D0D9C987
1 changed files with 22 additions and 0 deletions

View File

@ -38,6 +38,28 @@ module Rex
ret << " };\n" ret << " };\n"
end end
#
# Converts to a golang style array of bytes
#
def self.to_golang(str, wrap = DefaultWrap, name = "buf")
ret = "#{name} := []byte{"
i = -1;
while (i += 1) < str.length
ret << "\n" if i%(wrap/4) == 0
ret << "0x" << str[i].unpack("H*")[0] << ", "
end
ret = ret[0..ret.length-3] #cut off last comma
ret << " }\n"
end
#
# Creates a golang style comment
#
def self.to_golang_comment(str, wrap = DefaultWrap)
return "/*\n" + wordwrap(str, 0, wrap, '', '') + "*/\n"
end
# #
# Creates a c-style comment # Creates a c-style comment
# #