orgasm 0.0.1a2 → 0.0.1a3
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.
- data/bin/{disorgasm → ejaculate} +0 -0
- data/bin/swallow +0 -0
- data/lib/orgasm.rb +8 -2
- data/lib/orgasm/arch/i386.rb +27 -0
- data/lib/orgasm/{style.rb → arch/i386/base.rb} +4 -0
- data/lib/orgasm/{common → arch/i386/base}/address.rb +12 -19
- data/lib/orgasm/{common/unknown.rb → arch/i386/base/immediate.rb} +6 -10
- data/lib/orgasm/arch/i386/base/instruction.rb +41 -0
- data/lib/orgasm/arch/i386/base/register.rb +40 -0
- data/lib/orgasm/arch/i386/disassembler.rb +26 -154
- data/lib/orgasm/arch/i386/generator.rb +44 -0
- data/lib/orgasm/arch/i386/instructions.rb +150 -0
- data/lib/orgasm/arch/i386/instructions/dsl.rb +159 -0
- data/lib/orgasm/arch/i386/instructions/dsl/special.rb +75 -0
- data/lib/orgasm/arch/i386/instructions/instructions.rb +50 -0
- data/lib/orgasm/arch/i386/styles.rb +70 -0
- data/lib/orgasm/architecture.rb +103 -0
- data/lib/orgasm/assembler.rb +5 -16
- data/lib/orgasm/base.rb +50 -0
- data/lib/orgasm/{common/constant.rb → base/address.rb} +7 -6
- data/lib/orgasm/{common/register.rb → base/constant.rb} +11 -8
- data/lib/orgasm/base/instruction.rb +41 -0
- data/lib/orgasm/{common/instruction.rb → base/register.rb} +8 -8
- data/lib/orgasm/base/unknown.rb +36 -0
- data/lib/orgasm/disassembler.rb +25 -22
- data/lib/orgasm/disassembler/decoder.rb +26 -20
- data/lib/orgasm/{common/extensions.rb → extensions.rb} +12 -0
- data/lib/orgasm/generator.rb +46 -0
- data/lib/orgasm/generator/dsl.rb +60 -0
- data/lib/orgasm/piece.rb +49 -0
- data/lib/orgasm/styles.rb +64 -0
- data/lib/orgasm/styles/style.rb +55 -0
- data/lib/orgasm/version.rb +1 -1
- metadata +54 -14
- data/lib/orgasm/common.rb +0 -36
data/lib/orgasm/assembler.rb
CHANGED
@@ -19,25 +19,14 @@
|
|
19
19
|
|
20
20
|
module Orgasm
|
21
21
|
|
22
|
-
class Assembler
|
23
|
-
|
24
|
-
|
25
|
-
def self.for (arch, &block)
|
26
|
-
if block
|
27
|
-
@@archs[arch] = self.new(arch, &block)
|
28
|
-
else
|
29
|
-
@@archs[arch]
|
30
|
-
end
|
22
|
+
class Assembler < Piece
|
23
|
+
def initialize (*)
|
24
|
+
super
|
31
25
|
end
|
32
26
|
|
33
|
-
|
34
|
-
|
35
|
-
alias arch architecture
|
27
|
+
def assemble (instructions)
|
36
28
|
|
37
|
-
|
38
|
-
@architecture = architecture
|
39
|
-
@features = features
|
40
|
-
end
|
29
|
+
end; alias do assemble
|
41
30
|
end
|
42
31
|
|
43
32
|
end
|
data/lib/orgasm/base.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
3
|
+
#
|
4
|
+
# This file is part of orgasm.
|
5
|
+
#
|
6
|
+
# orgasm is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# orgasm is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with orgasm. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
require 'orgasm/extensions'
|
21
|
+
|
22
|
+
module Orgasm
|
23
|
+
|
24
|
+
def self.object? (value)
|
25
|
+
value.is_a?(Base) ? value : false
|
26
|
+
end
|
27
|
+
|
28
|
+
class Base
|
29
|
+
def initialize
|
30
|
+
yield self if block_given?
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
begin
|
35
|
+
raise LoadError unless respond_to? :arch
|
36
|
+
|
37
|
+
Architecture[arch].style.apply(self)
|
38
|
+
rescue LoadError
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'orgasm/base/unknown'
|
47
|
+
require 'orgasm/base/instruction'
|
48
|
+
require 'orgasm/base/address'
|
49
|
+
require 'orgasm/base/register'
|
50
|
+
require 'orgasm/base/constant'
|
@@ -19,19 +19,20 @@
|
|
19
19
|
|
20
20
|
module Orgasm
|
21
21
|
|
22
|
-
class
|
23
|
-
|
24
|
-
|
25
|
-
def initialize (value, size)
|
22
|
+
class Address < Base
|
23
|
+
def initialize (value=nil)
|
26
24
|
@value = value.to_i
|
27
|
-
@size = size
|
28
25
|
|
29
|
-
|
26
|
+
super()
|
30
27
|
end
|
31
28
|
|
32
29
|
def to_i
|
33
30
|
@value
|
34
31
|
end
|
32
|
+
|
33
|
+
def inspect
|
34
|
+
"#<Address: #{to_i}>"
|
35
|
+
end
|
35
36
|
end
|
36
37
|
|
37
38
|
end
|
@@ -19,18 +19,21 @@
|
|
19
19
|
|
20
20
|
module Orgasm
|
21
21
|
|
22
|
-
class
|
23
|
-
|
22
|
+
class Constant < Base
|
23
|
+
attr_accessor :value
|
24
24
|
|
25
|
-
def initialize (
|
26
|
-
@
|
27
|
-
@size = size.to_i
|
25
|
+
def initialize (value=nil)
|
26
|
+
@value = value.to_i if value
|
28
27
|
|
29
|
-
|
28
|
+
super()
|
30
29
|
end
|
31
30
|
|
32
|
-
def
|
33
|
-
|
31
|
+
def to_i
|
32
|
+
@value
|
33
|
+
end
|
34
|
+
|
35
|
+
def inspect
|
36
|
+
"#<Constant: #{to_i}>"
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
3
|
+
#
|
4
|
+
# This file is part of orgasm.
|
5
|
+
#
|
6
|
+
# orgasm is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# orgasm is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with orgasm. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
module Orgasm
|
21
|
+
|
22
|
+
class Instruction < Base
|
23
|
+
attr_reader :name, :parameters
|
24
|
+
|
25
|
+
def initialize (name=nil, *parameters)
|
26
|
+
self.name = name if name
|
27
|
+
@parameters = parameters.to_a.flatten.compact
|
28
|
+
|
29
|
+
super()
|
30
|
+
end
|
31
|
+
|
32
|
+
def name= (value)
|
33
|
+
@name = value.downcase.to_sym
|
34
|
+
end
|
35
|
+
|
36
|
+
def inspect
|
37
|
+
"#<Instruction(#{name})#{": #{parameters.map {|p| p.inspect}.join(', ')}" unless parameters.empty?}>"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -19,18 +19,18 @@
|
|
19
19
|
|
20
20
|
module Orgasm
|
21
21
|
|
22
|
-
class
|
23
|
-
|
22
|
+
class Register < Base
|
23
|
+
attr_accessor :name, :size
|
24
24
|
|
25
|
-
def initialize (name,
|
26
|
-
@name
|
27
|
-
@
|
25
|
+
def initialize (name=nil, size=nil)
|
26
|
+
@name = name.to_s.downcase.to_sym if name
|
27
|
+
@size = size.to_i if size
|
28
28
|
|
29
|
-
|
29
|
+
super()
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
"#{name
|
32
|
+
def inspect
|
33
|
+
"#<Register: #{@name}, #{@size} bits>"
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
3
|
+
#
|
4
|
+
# This file is part of orgasm.
|
5
|
+
#
|
6
|
+
# orgasm is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# orgasm is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with orgasm. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
module Orgasm
|
21
|
+
|
22
|
+
class Unknown < Base
|
23
|
+
attr_accessor :data
|
24
|
+
|
25
|
+
def initialize (data=nil)
|
26
|
+
@data = data
|
27
|
+
|
28
|
+
super()
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspect
|
32
|
+
"#<Unknown(#{data.length}): #{data.to_s.bytes.map {|x| '%02X' % x}.join(' ')}>"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/lib/orgasm/disassembler.rb
CHANGED
@@ -17,31 +17,15 @@
|
|
17
17
|
# along with orgasm. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
|
20
|
-
require 'orgasm/common'
|
21
20
|
require 'orgasm/disassembler/decoder'
|
22
21
|
|
23
22
|
module Orgasm
|
24
23
|
|
25
|
-
class Disassembler
|
26
|
-
|
24
|
+
class Disassembler < Piece
|
25
|
+
def initialize (*)
|
26
|
+
@decoders = []
|
27
27
|
|
28
|
-
|
29
|
-
if block
|
30
|
-
@@archs[arch] = self.new(arch, &block)
|
31
|
-
else
|
32
|
-
@@archs[arch]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
attr_reader :architecture
|
37
|
-
|
38
|
-
alias arch architecture
|
39
|
-
|
40
|
-
def initialize (architecture, &block)
|
41
|
-
@architecture = architecture
|
42
|
-
@decoders = []
|
43
|
-
|
44
|
-
instance_eval(&block)
|
28
|
+
super
|
45
29
|
end
|
46
30
|
|
47
31
|
def disassemble (io)
|
@@ -52,28 +36,47 @@ class Disassembler
|
|
52
36
|
end
|
53
37
|
|
54
38
|
result = []
|
39
|
+
junk = nil
|
55
40
|
|
56
41
|
until io.eof?
|
57
42
|
where = io.tell
|
58
43
|
|
59
44
|
@decoders.each {|decoder|
|
60
45
|
if tmp = Orgasm.object?(decoder.with(io).decode)
|
46
|
+
result << unknown(junk) and junk = nil if junk
|
61
47
|
result << tmp
|
48
|
+
|
62
49
|
break
|
63
50
|
end
|
64
51
|
}
|
65
52
|
|
66
53
|
if where == io.tell
|
67
|
-
|
54
|
+
(junk ||= '') << io.read(1)
|
68
55
|
end
|
69
56
|
end
|
70
57
|
|
58
|
+
result << unknown(junk) if junk
|
59
|
+
|
71
60
|
result.flatten.compact
|
72
|
-
end
|
61
|
+
end; alias do disassemble
|
73
62
|
|
74
63
|
def on (*args, &block)
|
75
64
|
@decoders << Decoder.new(*args, &block)
|
76
65
|
end
|
66
|
+
|
67
|
+
def unknown (data=nil, &block)
|
68
|
+
if block
|
69
|
+
@unknown = block
|
70
|
+
elsif data
|
71
|
+
if @unknown
|
72
|
+
instance_exec data, &@unknown
|
73
|
+
else
|
74
|
+
instance_exec data do |data|
|
75
|
+
Unknown.new(data)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
77
80
|
end
|
78
81
|
|
79
82
|
end
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# along with orgasm. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
|
20
|
-
module Orgasm; class Disassembler
|
20
|
+
module Orgasm; class Disassembler < Piece
|
21
21
|
|
22
22
|
class Decoder
|
23
23
|
def initialize (*args, &block)
|
@@ -33,12 +33,17 @@ class Decoder
|
|
33
33
|
def decode
|
34
34
|
return unless @io
|
35
35
|
|
36
|
-
return unless @args.
|
36
|
+
return unless match = @args.find {|arg|
|
37
37
|
matches(arg)
|
38
38
|
}
|
39
39
|
|
40
40
|
catch(:result) {
|
41
|
-
|
41
|
+
start = @io.tell
|
42
|
+
|
43
|
+
@io.seek start if catch(:skip) {
|
44
|
+
_result(instance_exec @args, match, &@block)
|
45
|
+
false
|
46
|
+
}
|
42
47
|
}
|
43
48
|
end
|
44
49
|
|
@@ -60,15 +65,11 @@ class Decoder
|
|
60
65
|
def on (*args, &block)
|
61
66
|
return unless @io
|
62
67
|
|
63
|
-
return unless args.
|
68
|
+
return unless match = args.find {|arg|
|
64
69
|
matches(arg)
|
65
70
|
}
|
66
71
|
|
67
|
-
result =
|
68
|
-
|
69
|
-
if Orgasm.object?(result)
|
70
|
-
throw :result, result
|
71
|
-
end
|
72
|
+
result = _result(instance_exec args, match, &block)
|
72
73
|
|
73
74
|
result
|
74
75
|
end
|
@@ -79,11 +80,7 @@ class Decoder
|
|
79
80
|
if block
|
80
81
|
where, = @io.tell, @io.seek(amount, whence)
|
81
82
|
|
82
|
-
result = instance_eval &block
|
83
|
-
|
84
|
-
if Orgasm.object?(result)
|
85
|
-
throw :result, result
|
86
|
-
end
|
83
|
+
result = _result(instance_eval &block)
|
87
84
|
|
88
85
|
@io.seek(where)
|
89
86
|
|
@@ -103,11 +100,7 @@ class Decoder
|
|
103
100
|
raise RuntimeError, 'The stream has not enough data :('
|
104
101
|
end
|
105
102
|
|
106
|
-
result = instance_exec data, &block
|
107
|
-
|
108
|
-
if Orgasm.object?(result)
|
109
|
-
throw :result, result
|
110
|
-
end
|
103
|
+
result = _result(instance_exec data, &block)
|
111
104
|
|
112
105
|
seek -amount
|
113
106
|
|
@@ -120,8 +113,21 @@ class Decoder
|
|
120
113
|
def lookahead (amount)
|
121
114
|
read(amount) do |data|
|
122
115
|
data
|
123
|
-
end
|
116
|
+
end rescue nil
|
117
|
+
end
|
118
|
+
|
119
|
+
def skip
|
120
|
+
throw :skip, true
|
124
121
|
end
|
122
|
+
|
123
|
+
private
|
124
|
+
def _result (value)
|
125
|
+
if Orgasm.object?(value)
|
126
|
+
throw :result, value
|
127
|
+
end
|
128
|
+
|
129
|
+
value
|
130
|
+
end
|
125
131
|
end
|
126
132
|
|
127
133
|
end; end
|
@@ -17,6 +17,18 @@
|
|
17
17
|
# along with orgasm. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
|
20
|
+
require 'forwardable'
|
21
|
+
require 'refining'
|
22
|
+
require 'memoized'
|
23
|
+
|
20
24
|
class String
|
21
25
|
alias to_byte ord
|
22
26
|
end
|
27
|
+
|
28
|
+
class Array
|
29
|
+
def to_syms
|
30
|
+
map {|x|
|
31
|
+
x.to_sym
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
3
|
+
#
|
4
|
+
# This file is part of orgasm.
|
5
|
+
#
|
6
|
+
# orgasm is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# orgasm is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with orgasm. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
|
20
|
+
require 'orgasm/generator/dsl'
|
21
|
+
|
22
|
+
module Orgasm
|
23
|
+
|
24
|
+
class Generator < Piece
|
25
|
+
def initialize (*)
|
26
|
+
@for = {}
|
27
|
+
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate (&block)
|
32
|
+
DSL.new(&block).execute(self)
|
33
|
+
end; alias do generate
|
34
|
+
|
35
|
+
def for (klass, &block)
|
36
|
+
if block
|
37
|
+
@for[klass] = block
|
38
|
+
else
|
39
|
+
@for[klass] or @for.find {|(what, block)|
|
40
|
+
what.ancestors.member?(klass)
|
41
|
+
}.last
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|