nomeaning-ctf 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: c3a7148c4238a98d0574bc50be9b388b0548ed7e
4
- data.tar.gz: 367fe6f527bf7bc3a41d49234914ef6e21c9c374
3
+ metadata.gz: b798e5a019552fa793d9ff1dd9227212345847e2
4
+ data.tar.gz: 900662a06d5586294292c6c387a821268c446d8a
5
5
  SHA512:
6
- metadata.gz: 00af00ff18cb4c1b208ab194a69bd1daab0ccc61d9bf476fe59116e2b4f6564c03a810c1768f5753fc681bd2eff9fd3086f6017d6143ed7e565b669ca58357ca
7
- data.tar.gz: dedf64cbae558382b59f8d47fd5baadb1f3cb4485f5ea59e33132e89e5700bfb2628eb55d759f208798e65265134ab306f5b2f2707abb428964a355ec437df21
6
+ metadata.gz: dc70ee080590b76ece422feb4a44812c88f26580772208d62577b66eca1375165b692a533d59c7cf3a255251feadeb82b1fbcea9cb11451e80764037cb3a2b5c
7
+ data.tar.gz: 1ab010c57b77cf88057aa23d9f32cdff340f5dd629941df2173fa1f289949eb7da0b0ee43375127594451a660573c7862d7917e73df61c394c5022e5780e7f9a
data/lib/ctf.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "ctf/version"
2
- require 'ctf/socket'
2
+ require 'ctf/io_with_echo'
3
3
  require 'ctf/utils'
4
4
  require 'ctf/math'
5
5
  require 'ctf/rop'
@@ -5,7 +5,7 @@ require 'stringio'
5
5
  require 'io/interactive'
6
6
 
7
7
  module CTF
8
- module SocketWithEcho
8
+ module IOWithEcho
9
9
  attr_accessor :echo, :echo_input, :echo_output, :echo_color
10
10
  def echo_input
11
11
  @echo_input || STDOUT
@@ -24,10 +24,8 @@ module CTF
24
24
  super str
25
25
  end
26
26
 
27
- def read(length = nil, outbuf = '')
28
- result = super length, outbuf
29
- echo_input_print result if result
30
- result
27
+ def read(length = nil, outbuf = nil)
28
+ super(length, outbuf).tap {|result| echo_input_print(result || '') }
31
29
  end
32
30
 
33
31
  def interactive!(input = STDIN, output = STDOUT)
@@ -36,7 +34,11 @@ module CTF
36
34
  end
37
35
 
38
36
  def gets
39
- expect("\n")[0]
37
+ super.tap {|result| echo_input_print(result || '') }
38
+ end
39
+
40
+ def getc
41
+ super.tap {|result| echo_input_print(result || '') }
40
42
  end
41
43
 
42
44
  # TODO: Don't ignore timeout
@@ -48,15 +50,17 @@ module CTF
48
50
  else
49
51
  break if result && result.end_with?(pattern)
50
52
  end
51
- data = read(1)
53
+ data = getc
52
54
  break unless data
53
- result ||= ''
54
- result.force_encoding('ASCII-8BIT')
55
- result << data
55
+ if result
56
+ result << data.chr
57
+ else
58
+ result = data.chr
59
+ end
56
60
  end
57
61
  return result unless result
58
62
  if pattern.is_a?(Regexp)
59
- [result] + result.match(pattern).to_a[1..-1]
63
+ [result] + (result.match(pattern) || [nil]).to_a[1..-1]
60
64
  else
61
65
  [result]
62
66
  end
@@ -87,6 +91,6 @@ module CTF
87
91
  end
88
92
  end
89
93
 
90
- class BasicSocket
91
- prepend CTF::SocketWithEcho
94
+ class IO
95
+ prepend CTF::IOWithEcho
92
96
  end
data/lib/ctf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CTF
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,31 @@
1
+ # coding: UTF-8
2
+ require 'spec_helper'
3
+ require 'ctf'
4
+ require 'tempfile'
5
+
6
+ describe CTF::IOWithEcho do
7
+ describe '#read' do
8
+ let(:utf8_io) do
9
+ io = Tempfile.open
10
+ io.set_encoding(Encoding::UTF_8, Encoding::UTF_8)
11
+ io.puts 'ほげほげ'
12
+ io.seek 0
13
+ io
14
+ end
15
+
16
+ let(:ascii8bit_io) do
17
+ io = Tempfile.open
18
+ io.set_encoding(Encoding::ASCII_8BIT, Encoding::ASCII_8BIT)
19
+ io.puts 'ほげほげ'
20
+ io.seek 0
21
+ io
22
+ end
23
+
24
+ it 'returns with correct encoding' do
25
+ expect(utf8_io.read.encoding).to eq Encoding::UTF_8
26
+ expect(ascii8bit_io.read.encoding).to eq Encoding::ASCII_8BIT
27
+ ascii8bit_io.seek 0
28
+ expect(ascii8bit_io.read(1).encoding).to eq Encoding::ASCII_8BIT
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nomeaning-ctf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - nomeaning
@@ -109,12 +109,13 @@ files:
109
109
  - ctf.gemspec
110
110
  - examples/socket-example.rb
111
111
  - lib/ctf.rb
112
+ - lib/ctf/io_with_echo.rb
112
113
  - lib/ctf/math.rb
113
114
  - lib/ctf/rop.rb
114
115
  - lib/ctf/shellcode.rb
115
- - lib/ctf/socket.rb
116
116
  - lib/ctf/utils.rb
117
117
  - lib/ctf/version.rb
118
+ - spec/io_with_echo_spec.rb
118
119
  - spec/math_spec.rb
119
120
  - spec/spec_helper.rb
120
121
  homepage: https://bitbucket.org/nomeaning777/ctf
@@ -142,5 +143,6 @@ signing_key:
142
143
  specification_version: 4
143
144
  summary: Utils for CTF
144
145
  test_files:
146
+ - spec/io_with_echo_spec.rb
145
147
  - spec/math_spec.rb
146
148
  - spec/spec_helper.rb