Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ziglang): add buffer/comment support #69

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading