Skip to content

Commit

Permalink
land #69, add buffer/comment support
Browse files Browse the repository at this point in the history
  • Loading branch information
adfoster-r7 authored Mar 28, 2024
2 parents e1930af + 460ce48 commit 1ec13f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/rex/text/lang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,19 @@ def self.to_psh_comment(str, wrap = DefaultWrap)
return wordwrap(str, 0, wrap, '', '# ')
end

#
# Converts to a zig style array of bytes
#
def self.to_zig(str, wrap = DefaultWrap, name = "buf")
return numhexify(str, wrap, '', '', "\nconst #{name}: []const u8 = \&.{\n", "};", ',')
end

#
# Creates a zig-style comment
#
def self.to_zig_comment(str, wrap = DefaultWrap)
return wordwrap(str, 0, wrap, '', '// ')
end

end
end
11 changes: 10 additions & 1 deletion spec/rex/text/lang_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe Rex::Text do

LANGUAGES = %w[ bash c csharp golang masm nim rust perl python ruby ]
LANGUAGES = %w[ bash c csharp golang masm nim rust perl python ruby zig ]

describe "languages match expected output" do
let(:expected_bash) do
Expand Down Expand Up @@ -43,6 +43,10 @@
"buf = \n\"\\x41\\x41\\x41\\x41\\x41\\x41\" +\n\"\\x41\\x41\\x41\\x41\"\n"
end

let(:expected_zig) do
"\nconst buf: []const u8 = &.{\n0x41,0x41,0x41,0x41,0x41,0x41,\n0x41,0x41,0x41,0x41};\n"
end

it "bash is as expected" do
output = described_class.to_bash('A' * 10, 30)
expect(output).to eq(expected_bash)
Expand Down Expand Up @@ -113,6 +117,11 @@
output = described_class.to_ruby('A' * 10, 30)
expect(output).to eq(expected_ruby)
end

it "zig is as expected" do
output = described_class.to_zig('A' * 10, 30)
expect(output).to eq(expected_zig)
end
end


Expand Down

0 comments on commit 1ec13f7

Please sign in to comment.