This commit adds support for C# byte arrays for the assembly payloads.

unstable
Brandon Perry 2013-06-11 19:27:06 -05:00
parent fe32a747a3
commit d0e1e4df0a
3 changed files with 17 additions and 1 deletions

View File

@ -31,6 +31,8 @@ module Buffer
buf = Rex::Text.to_bash(buf)
when 'c'
buf = Rex::Text.to_c(buf)
when 'csharp'
buf = Rex::Text.to_csharp(buf)
when 'js_be'
buf = Rex::Text.to_unescape(buf, ENDIAN_BIG)
when 'js_le'
@ -59,6 +61,8 @@ module Buffer
buf = Rex::Text.to_bash_comment(buf)
when 'c'
buf = Rex::Text.to_c_comment(buf)
when 'csharp'
buf = Rex::Text.to_c_comment(buf)
when 'js_be', 'js_le'
buf = Rex::Text.to_js_comment(buf)
when 'java'
@ -74,7 +78,7 @@ module Buffer
# Returns the list of supported formats
#
def self.transform_formats
['raw','ruby','rb','perl','pl','bash','sh','c','js_be','js_le','java','python','py']
['raw','ruby','rb','perl','pl','bash','sh','c','csharp','js_be','js_le','java','python','py']
end
end

View File

@ -82,6 +82,17 @@ module Text
return hexify(str, wrap, '"', '"', "unsigned char #{name}[] = \n", '";')
end
def self.to_csharp(str, wrap = DefaultWrap, name = "buf")
ret = "byte[] #{name} = new byte[#{str.length}] {"
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-2] #cut off last comma
ret << " };\n"
end
#
# Creates a c-style comment
#

View File

@ -125,6 +125,7 @@ if (cmd =~ /^(p|y|r|d|c|j|x|b|v|w|n)/)
fmt = 'raw' if (cmd =~ /^(r|x|d)/)
fmt = 'raw' if (cmd =~ /^v/)
fmt = 'c' if (cmd == 'c')
fmt = 'csharp' if (cmd == 'csharp')
fmt = 'js_be' if (cmd =~ /^j/ and Rex::Arch.endian(payload.arch) == ENDIAN_BIG)
fmt = 'js_le' if (cmd =~ /^j/ and ! fmt)
fmt = 'java' if (cmd =~ /^b/)