From ccc35c966f8ea95533fa31e5f4ba0b8bcf18bbc1 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Fri, 22 Nov 2024 17:08:45 -0800 Subject: [PATCH] Added the `--python` option to `ronin encode` (closes #221). --- lib/ronin/cli/commands/encode.rb | 6 ++++++ man/ronin-encode.1.md | 3 +++ spec/cli/commands/encode_spec.rb | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/lib/ronin/cli/commands/encode.rb b/lib/ronin/cli/commands/encode.rb index 43873f743..d27e88094 100644 --- a/lib/ronin/cli/commands/encode.rb +++ b/lib/ronin/cli/commands/encode.rb @@ -51,6 +51,7 @@ module Commands # --punycode Encodes the data as Punycode # -Q, --quoted-printable Encodes the data as Quoted Printable # -p, --php Encodes the data as a PHP String + # --python Encodes the data as a Python String # -R, --ruby Encodes the data as a Ruby String # --uuencode uuencodes the data # -x, --xml XML encodes the data @@ -169,6 +170,11 @@ class Encode < StringMethodsCommand @method_calls << :php_encode end + option :python, desc: 'Encodes the data as a Python String' do + require 'ronin/support/encoding/python' + @method_calls << :python_encode + end + option :ruby, short: '-R', desc: 'Encodes the data as a Ruby String' do require 'ronin/support/encoding/ruby' diff --git a/man/ronin-encode.1.md b/man/ronin-encode.1.md index 18bed16ff..3cec0b34f 100644 --- a/man/ronin-encode.1.md +++ b/man/ronin-encode.1.md @@ -87,6 +87,9 @@ Encodes each character of the given data into a variety of formats. `-p`, `--php` : Encodes the data as a PHP String. +`--python` +: Encodes the data as a Python String. + `-R`, `--ruby` : Encodes the data as a Ruby String. diff --git a/spec/cli/commands/encode_spec.rb b/spec/cli/commands/encode_spec.rb index 59e6526f1..8bfc9776d 100644 --- a/spec/cli/commands/encode_spec.rb +++ b/spec/cli/commands/encode_spec.rb @@ -152,6 +152,18 @@ end end + describe "--python" do + let(:argv) { %w[--python] } + + it "must require 'ronin/support/encoding/python'" do + expect(require('ronin/support/encoding/python')).to be(false) + end + + it "must add :ruby_encode to #method_calls" do + expect(subject.method_calls.last).to eq(:python_encode) + end + end + describe "--ruby" do let(:argv) { %w[--ruby] }