From 209f2aca9c0ebbe2be40aa68b9d9e00c1663ac67 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Fri, 22 Nov 2024 21:55:24 -0800 Subject: [PATCH] Added the `--java` option to `ronin quote` (closes #243). --- lib/ronin/cli/commands/quote.rb | 7 +++++++ man/ronin-quote.1.md | 3 +++ spec/cli/commands/quote_spec.rb | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/lib/ronin/cli/commands/quote.rb b/lib/ronin/cli/commands/quote.rb index b189e03d5..7b463cd91 100644 --- a/lib/ronin/cli/commands/quote.rb +++ b/lib/ronin/cli/commands/quote.rb @@ -36,6 +36,7 @@ module Commands # -n, --keep-newlines Preserves newlines at the end of each line # -X, --hex Quotes the data as a Hex string # -c, --c Quotes the data as a C string + # -J, --java Quotes the data as a Java String # -j, --js JavaScript quotes the data # -S, --shell Quotes the data as a Shell String # -P, --powershell Quotes the data as a PowerShell String @@ -63,6 +64,12 @@ class Quote < StringMethodsCommand @method_calls << :c_string end + option :java, short: '-J', + desc: 'Quotes the data as a Java String' do + require 'ronin/support/encoding/java' + @method_calls << :java_string + end + option :js, short: '-j', desc: 'JavaScript quotes the data' do require 'ronin/support/encoding/js' diff --git a/man/ronin-quote.1.md b/man/ronin-quote.1.md index 209ec373f..3a0f0a8f7 100644 --- a/man/ronin-quote.1.md +++ b/man/ronin-quote.1.md @@ -38,6 +38,9 @@ Produces quoted a string for a variety of programming languages. `-c`, `--c` : Quotes the data as a C string. +`-J`, `--java` +: Quotes the data as a Java String. + `-j`, `--js` : quotes the data as a JavaScript string. diff --git a/spec/cli/commands/quote_spec.rb b/spec/cli/commands/quote_spec.rb index dec077fd9..8a5be4769 100644 --- a/spec/cli/commands/quote_spec.rb +++ b/spec/cli/commands/quote_spec.rb @@ -32,6 +32,18 @@ end end + describe "--java" do + let(:argv) { %w[--java] } + + it "must require 'ronin/support/encoding/java'" do + expect(require('ronin/support/encoding/java')).to be(false) + end + + it "must add :java_string to #method_calls" do + expect(subject.method_calls.last).to eq(:java_string) + end + end + describe "--js" do let(:argv) { %w[--js] }