pwn 0.5.774 → 0.5.776

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcf08f4e689259063fd8b459d824890336bda15e3756416871cff38a21135730
4
- data.tar.gz: cf3c78ae724f5fbf5702510ef6d7cd13800bbdba292a8613cf25d5216200da5d
3
+ metadata.gz: 2a6df0a18952a14c2cd3acf7263a3e3393fb1406bf04d742fb80706b094a73df
4
+ data.tar.gz: abbe212e8cdfa3e4bc042b817092f05fa68ce20518587f432120563822049544
5
5
  SHA512:
6
- metadata.gz: 7bbf2b429a197fc2a5157764d50bc7e3c890351035f306fe46426362b5dd9925890135168ff6b6a49af0fa75f18943b6929dfa2b83c21f017d3560dc294cbb4b
7
- data.tar.gz: '08eb6976dc48727a1baab7625500b214b30f1f1ffe3185c561b7bd9b8ceed18a827017b797280f67c986f29ad70d28c2c46c0c77168193b0aaeae7d054f84ac2'
6
+ metadata.gz: 19dea9476ce02f9c29d35783856054e8a4910dbe6e1366a96c280e9e76864274e5fe5b119f8d17d76937dba828f16407ebd4ab1be50e7bdbec11be39e7e6cb69
7
+ data.tar.gz: b7d5a2ae8f764dd3ffbf3cf2d73aa3a995f896b722279bae74e438ccabef6ac9571ace8f3bb5eddbf227cd2af105a847fa1b8967902de23030151ce4fe2d9bc7
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: pwn-jsontext
3
+ description: Drive PWN::JSONText from pwn_eval.
4
+ license: MIT
5
+ allowed-tools: [pwn, pwn_eval]
6
+ metadata:
7
+ bundled: true
8
+ generated: true
9
+ module: PWN::JSONText
10
+ source: pwn/json_text.rb
11
+ ---
12
+
13
+ # PWN::JSONText
14
+
15
+ Retag or scrub strings before the JSON generator sees them.
16
+
17
+ ## When to use
18
+
19
+ Call `PWN::JSONText` from `pwn_eval` when the task needs this module.
20
+ Do not reimplement it in shell.
21
+
22
+ ## Methodologies
23
+
24
+ Generated from `pwn/json_text.rb`. Prefer the public class methods below.
25
+ Class methods take `(opts = {})` and read `opts`.
26
+
27
+ ## How to call
28
+
29
+ ```ruby
30
+ PWN::JSONText.help
31
+ PWN::JSONText.prepare(opts)
32
+ ```
33
+
34
+ ## Public methods
35
+
36
+ - `prepare`
37
+ - `authors`
38
+ - `help`
39
+
40
+ ## Source
41
+
42
+ `pwn/json_text.rb`
43
+
44
+ ## Verification
45
+
46
+ `PWN::JSONText.respond_to?(:prepare)` after the
47
+ module is loaded. Read the source for parameter names.
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Retag or scrub strings before the JSON generator sees them.
4
+ module PWN
5
+ # json 2.21 warns when valid UTF-8 is still tagged BINARY, and raises
6
+ # JSON::GeneratorError on a malformed sequence. Both show up in the session pane.
7
+ module JSONText
8
+ # Supported Method Parameters::
9
+ # safe = PWN::JSONText.prepare(
10
+ # value: 'required - string, hash, or array that may contain binary-tagged text',
11
+ # depth: 'optional - nesting already walked; containers stop at 100'
12
+ # )
13
+
14
+ public_class_method def self.prepare(opts = {})
15
+ value = opts[:value]
16
+ depth = opts[:depth].to_i
17
+ case value
18
+ when String
19
+ utf = value.dup.force_encoding(Encoding::UTF_8)
20
+ utf.valid_encoding? ? utf : utf.scrub
21
+ when Hash
22
+ return value if depth >= 100
23
+
24
+ value.each_with_object({}) do |(key, item), out|
25
+ out[key.is_a?(String) ? prepare(value: key, depth: depth + 1) : key] = prepare(value: item, depth: depth + 1)
26
+ end
27
+ when Array
28
+ return value if depth >= 100
29
+
30
+ value.map { |item| prepare(value: item, depth: depth + 1) }
31
+ else
32
+ value
33
+ end
34
+ end
35
+
36
+ # Author(s):: 0day Inc. <support@0dayinc.com>
37
+
38
+ public_class_method def self.authors
39
+ "AUTHOR(S):\n 0day Inc. <support@0dayinc.com>\n"
40
+ end
41
+
42
+ # Display Usage for this Module.
43
+
44
+ public_class_method def self.help
45
+ puts "USAGE:
46
+ # Retag valid UTF-8 that is still tagged binary, or scrub an illegal sequence.
47
+ #{self}.prepare(
48
+ value: 'required - string, hash, or array that may contain binary-tagged text',
49
+ depth: 'optional - nesting already walked; containers stop at 100'
50
+ )
51
+
52
+ # Print the AUTHOR(S) string for this module.
53
+ #{self}.authors
54
+ "
55
+ constants.sort
56
+ end
57
+ end
58
+ end
59
+
60
+ # json 2.21 warns inside JSON.generate before State.generate. json 2.18 warns
61
+ # inside the C to_json methods. Retag at both doors.
62
+ class << JSON
63
+ %i[generate fast_generate pretty_generate dump].each do |name|
64
+ alias_method :"#{name}_without_json_text", name
65
+ define_method(name) do |obj, *rest|
66
+ public_send(:"#{name}_without_json_text", PWN::JSONText.prepare(value: obj), *rest)
67
+ end
68
+ end
69
+ end
70
+
71
+ if defined?(JSON::Ext::Generator::GeneratorMethods)
72
+ JSON::Ext::Generator::GeneratorMethods.constants.each do |kind|
73
+ mod = JSON::Ext::Generator::GeneratorMethods.const_get(kind)
74
+ next unless mod.is_a?(Module) && mod.method_defined?(:to_json)
75
+
76
+ mod.class_eval do
77
+ alias_method :to_json_without_json_text, :to_json unless method_defined?(:to_json_without_json_text)
78
+ define_method(:to_json) do |*rest|
79
+ prepared = PWN::JSONText.prepare(value: self)
80
+ mod.instance_method(:to_json_without_json_text).bind_call(prepared, *rest)
81
+ end
82
+ end
83
+ end
84
+ end
data/lib/pwn/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PWN
4
- VERSION = '0.5.774'
4
+ VERSION = '0.5.776'
5
5
  end
data/lib/pwn.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
+ require 'pwn/json_text'
4
5
  require 'pwn/runtime_fingerprint'
5
6
  require 'pwn/version'
6
7
  require 'yaml'
@@ -40,6 +40,27 @@ describe PWN::AI::Agent::Result do
40
40
  expect(described_class.utf8_text(text: text)).to eq("status \u2022 ok")
41
41
  end
42
42
 
43
+ it 'does not warn or raise when JSON.generate sees binary-tagged or malformed text' do
44
+ require 'pwn'
45
+ binary = "status \u2022 ok".b
46
+ malformed = "\xff\xfe".b
47
+ err = +''
48
+ prev = $stderr
49
+ $stderr = StringIO.new
50
+ generated = JSON.generate(stdout: binary)
51
+ dumped = JSON.dump(stdout: binary.dup)
52
+ wired = { stdout: binary.dup }.to_json
53
+ scrubbed = JSON.generate(stdout: malformed)
54
+ err = $stderr.string
55
+ expect(err).not_to include('UTF-8 string passed as BINARY')
56
+ expect(generated).to include('status')
57
+ expect(dumped).to include('status')
58
+ expect(wired).to include('status')
59
+ expect { JSON.parse(scrubbed) }.not_to raise_error
60
+ ensure
61
+ $stderr = prev
62
+ end
63
+
43
64
  it 'preserves the JSON nesting boundary for finite valid results' do
44
65
  value = 'leaf'
45
66
  100.times { value = [value] }
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe PWN::JSONText do
6
+ it 'should display information for authors' do
7
+ expect(described_class).to respond_to :authors
8
+ end
9
+
10
+ it 'should display information for existing help method' do
11
+ expect(described_class).to respond_to :help
12
+ end
13
+
14
+ it 'retags binary UTF-8 and scrubs malformed bytes before JSON encode' do
15
+ binary = "status \u2022 ok".b
16
+ malformed = "\xff\xfe".b
17
+ prev = $stderr
18
+ $stderr = StringIO.new
19
+ generated = JSON.generate(stdout: binary)
20
+ dumped = JSON.dump(stdout: binary.dup)
21
+ wired = { stdout: binary.dup }.to_json
22
+ scrubbed = JSON.generate(stdout: malformed)
23
+ err = $stderr.string
24
+ expect(err).not_to include('UTF-8 string passed as BINARY')
25
+ expect(generated).to include('status')
26
+ expect(dumped).to include('status')
27
+ expect(wired).to include('status')
28
+ expect { JSON.parse(scrubbed) }.not_to raise_error
29
+ expect(described_class.prepare(value: binary)).to eq("status \u2022 ok")
30
+ ensure
31
+ $stderr = prev
32
+ end
33
+ end
@@ -818,6 +818,8 @@
818
818
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Result.spill_summary Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Result.spill_summary`: "}]}
819
819
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Result.token_limit Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Result.token_limit`: "}]}
820
820
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Result.transport_value Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Result.transport_value`: "}]}
821
+ {"messages":[{"role":"user","content":"PWN::AI::Agent::Result.utf8_text Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Result.utf8_text`: "}]}
822
+ {"messages":[{"role":"user","content":"PWN::AI::Agent::Result.utf8_value Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Result.utf8_value`: "}]}
821
823
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Reward.agent_flag Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Reward.agent_flag`: "}]}
822
824
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Reward.annotate_session Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Reward.annotate_session`: "}]}
823
825
  {"messages":[{"role":"user","content":"PWN::AI::Agent::Reward.atomic_write Usage"},{"role":"assistant","content":"`PWN::AI::Agent::Reward.atomic_write`: "}]}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.774
4
+ version: 0.5.776
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.
@@ -5234,6 +5234,7 @@ files:
5234
5234
  - etc/default_skills/pwn/ffi/soapy_sdr/SKILL.md
5235
5235
  - etc/default_skills/pwn/ffi/stdio/SKILL.md
5236
5236
  - etc/default_skills/pwn/ffi/volk/SKILL.md
5237
+ - etc/default_skills/pwn/json_text/SKILL.md
5237
5238
  - etc/default_skills/pwn/memory/SKILL.md
5238
5239
  - etc/default_skills/pwn/memory_index/SKILL.md
5239
5240
  - etc/default_skills/pwn/migrate/SKILL.md
@@ -6239,6 +6240,7 @@ files:
6239
6240
  - lib/pwn/ffi/soapy_sdr.rb
6240
6241
  - lib/pwn/ffi/stdio.rb
6241
6242
  - lib/pwn/ffi/volk.rb
6243
+ - lib/pwn/json_text.rb
6242
6244
  - lib/pwn/memory.rb
6243
6245
  - lib/pwn/memory_index.rb
6244
6246
  - lib/pwn/migrate.rb
@@ -6931,6 +6933,7 @@ files:
6931
6933
  - spec/lib/pwn/ffi/stdio_spec.rb
6932
6934
  - spec/lib/pwn/ffi/volk_spec.rb
6933
6935
  - spec/lib/pwn/ffi_spec.rb
6936
+ - spec/lib/pwn/json_text_spec.rb
6934
6937
  - spec/lib/pwn/memory_index_spec.rb
6935
6938
  - spec/lib/pwn/memory_spec.rb
6936
6939
  - spec/lib/pwn/migrate_spec.rb