From f77726f01a3db4bb9979cd228bb13fa36505c909 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Fri, 16 Aug 2024 03:45:05 -0700 Subject: [PATCH] Added the `--php` option to `ronin encode` (closes #212). --- lib/ronin/cli/commands/decode.rb | 7 +++++++ lib/ronin/cli/commands/encode.rb | 7 +++++++ man/ronin-decode.1.md | 5 ++++- man/ronin-encode.1.md | 3 +++ spec/cli/commands/encode_spec.rb | 12 ++++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/ronin/cli/commands/decode.rb b/lib/ronin/cli/commands/decode.rb index 4d8403ebe..a6796d14d 100644 --- a/lib/ronin/cli/commands/decode.rb +++ b/lib/ronin/cli/commands/decode.rb @@ -50,6 +50,7 @@ module Commands # --punycode Decodes the data as Punycode # -Q, --quoted-printable Decodes the data as Quoted Printable # -R, --ruby Ruby decodes the data + # -p, --php PHP decodes the data # --uudecode uudecodes the data # -x, --xml XML decodes the data # -h, --help Print help information @@ -155,6 +156,12 @@ class Decode < StringMethodsCommand @method_calls << :quoted_printable_decode end + option :php, short: '-p', + desc: 'PHP decodes the data' do + require 'ronin/support/encoding/php' + @method_calls << :php_decode + end + option :ruby, short: '-R', desc: 'Ruby decodes the data' do require 'ronin/support/encoding/ruby' diff --git a/lib/ronin/cli/commands/encode.rb b/lib/ronin/cli/commands/encode.rb index b03173ffa..a8585bd16 100644 --- a/lib/ronin/cli/commands/encode.rb +++ b/lib/ronin/cli/commands/encode.rb @@ -49,6 +49,7 @@ module Commands # -P, --powershell Encodes the data as a PowerShell String # --punycode Encodes the data as Punycode # -Q, --quoted-printable Encodes the data as Quoted Printable + # -p, --php Encodes the data as a PHP String # -R, --ruby Encodes the data as a Ruby String # --uuencode uuencodes the data # -x, --xml XML encodes the data @@ -155,6 +156,12 @@ class Encode < StringMethodsCommand @method_calls << :quoted_printable_encode end + option :php, short: '-p', + desc: 'Encodes the data as a PHP String' do + require 'ronin/support/encoding/php' + @method_calls << :php_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-decode.1.md b/man/ronin-decode.1.md index 171bfae52..36eb06b99 100644 --- a/man/ronin-decode.1.md +++ b/man/ronin-decode.1.md @@ -81,6 +81,9 @@ Decodes each character of the given data from a variety of formats. `-R`, `--ruby` : Ruby decodes the data. +`-p`, `--php` +: PHP decodes the data. + `--uudecode` : uudecodes the data. @@ -96,4 +99,4 @@ Postmodern ## SEE ALSO -[ronin-encode](ronin-encode.1.md) \ No newline at end of file +[ronin-encode](ronin-encode.1.md) diff --git a/man/ronin-encode.1.md b/man/ronin-encode.1.md index 226766df0..23490c9a2 100644 --- a/man/ronin-encode.1.md +++ b/man/ronin-encode.1.md @@ -81,6 +81,9 @@ Encodes each character of the given data into a variety of formats. `--uuencode` : uuencodes the data. +`-p`, `--php` +: Encodes the data as a PHP 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 7cd35b53e..41b3b4171 100644 --- a/spec/cli/commands/encode_spec.rb +++ b/spec/cli/commands/encode_spec.rb @@ -128,6 +128,18 @@ end end + describe "--php" do + let(:argv) { %w[--php] } + + it "must require 'ronin/support/encoding/php'" do + expect(require('ronin/support/encoding/php')).to be(false) + end + + it "must add :ruby_encode to #method_calls" do + expect(subject.method_calls.last).to eq(:php_encode) + end + end + describe "--ruby" do let(:argv) { %w[--ruby] }