nomeaning-ctf 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ctf.rb +1 -1
- data/lib/ctf/{socket.rb → io_with_echo.rb} +17 -13
- data/lib/ctf/version.rb +1 -1
- data/spec/io_with_echo_spec.rb +31 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b798e5a019552fa793d9ff1dd9227212345847e2
|
4
|
+
data.tar.gz: 900662a06d5586294292c6c387a821268c446d8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc70ee080590b76ece422feb4a44812c88f26580772208d62577b66eca1375165b692a533d59c7cf3a255251feadeb82b1fbcea9cb11451e80764037cb3a2b5c
|
7
|
+
data.tar.gz: 1ab010c57b77cf88057aa23d9f32cdff340f5dd629941df2173fa1f289949eb7da0b0ee43375127594451a660573c7862d7917e73df61c394c5022e5780e7f9a
|
data/lib/ctf.rb
CHANGED
@@ -5,7 +5,7 @@ require 'stringio'
|
|
5
5
|
require 'io/interactive'
|
6
6
|
|
7
7
|
module CTF
|
8
|
-
module
|
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
|
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
|
-
|
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 =
|
53
|
+
data = getc
|
52
54
|
break unless data
|
53
|
-
result
|
54
|
-
|
55
|
-
|
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
|
91
|
-
prepend CTF::
|
94
|
+
class IO
|
95
|
+
prepend CTF::IOWithEcho
|
92
96
|
end
|
data/lib/ctf/version.rb
CHANGED
@@ -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.
|
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
|