orgasm 0.0.1a1 → 0.0.1a2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/disorgasm +3 -0
- data/lib/orgasm/arch/i386/disassembler.rb +178 -0
- data/lib/orgasm/assembler.rb +43 -0
- data/lib/orgasm/common/address.rb +49 -0
- data/lib/orgasm/common/constant.rb +37 -0
- data/lib/orgasm/common/extensions.rb +22 -0
- data/lib/orgasm/common/instruction.rb +37 -0
- data/lib/orgasm/common/register.rb +37 -0
- data/lib/orgasm/common/unknown.rb +34 -0
- data/lib/orgasm/common.rb +36 -0
- data/lib/orgasm/disassembler/decoder.rb +127 -0
- data/lib/orgasm/disassembler.rb +79 -0
- data/lib/orgasm/format/elf.rb +28 -0
- data/lib/orgasm/format/pe.rb +28 -0
- data/lib/orgasm/format.rb +34 -0
- data/lib/orgasm/style.rb +19 -0
- data/lib/orgasm/version.rb +1 -1
- metadata +19 -4
data/bin/disorgasm
CHANGED
@@ -0,0 +1,178 @@
|
|
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
|
+
Disassembler.for('i386') {
|
23
|
+
reg = registers = Class.new(Hash) {
|
24
|
+
def initialize
|
25
|
+
merge!(
|
26
|
+
32 => {
|
27
|
+
EAX: 0x0,
|
28
|
+
ECX: 0x1,
|
29
|
+
EDX: 0x2,
|
30
|
+
EBX: 0x3,
|
31
|
+
ESP: 0x4,
|
32
|
+
EBP: 0x5,
|
33
|
+
ESI: 0x6,
|
34
|
+
EDI: 0x7
|
35
|
+
},
|
36
|
+
|
37
|
+
16 => {
|
38
|
+
AX: 0x0,
|
39
|
+
CX: 0x1,
|
40
|
+
DX: 0x2,
|
41
|
+
BX: 0x3,
|
42
|
+
SP: 0x4,
|
43
|
+
BP: 0x5,
|
44
|
+
SI: 0x6,
|
45
|
+
DI: 0x7
|
46
|
+
},
|
47
|
+
|
48
|
+
8 => {
|
49
|
+
AL: 0x0,
|
50
|
+
CL: 0x1,
|
51
|
+
DL: 0x2,
|
52
|
+
BL: 0x3,
|
53
|
+
AH: 0x4,
|
54
|
+
CH: 0x5,
|
55
|
+
DH: 0x6,
|
56
|
+
BH: 0x7
|
57
|
+
}
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def source (byte, bits=32)
|
62
|
+
self[bits].key((byte & 0x38) >> 3)
|
63
|
+
end
|
64
|
+
|
65
|
+
def destination (byte, bits=32)
|
66
|
+
self[bits].key(byte & 0x07)
|
67
|
+
end; alias dest destination
|
68
|
+
}.new
|
69
|
+
|
70
|
+
on ?\x01, ?\x09, ?\x11, ?\x19, ?\x21, ?\x25, ?\x29, ?\x31, ?\x39, ?\x85, ?\x86, ?\x87, ?\x89, ?\xA1, ?\xA3 do
|
71
|
+
increment = 1
|
72
|
+
|
73
|
+
seek 1 do
|
74
|
+
read 1 do |data|
|
75
|
+
increment += 1 if data.to_byte & 0x07 == reg[32][:ESP]
|
76
|
+
increment += 1 if (data.to_byte & 0xC0) >> 6 == 0x01
|
77
|
+
|
78
|
+
if (data.to_byte & 0xC0) >> 6 == 0x10
|
79
|
+
Unknown.new(1)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
on ?\x01 do
|
85
|
+
Instruction.new(:add) {|i|
|
86
|
+
seek +1
|
87
|
+
|
88
|
+
read 1 do |data|
|
89
|
+
i.parameters << Register.new(reg.source(data.to_byte), 32)
|
90
|
+
i.parameters << Register.new(reg.destination(data.to_byte), 32)
|
91
|
+
end
|
92
|
+
|
93
|
+
seek increment
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
on ?\x09 do
|
98
|
+
Instruction.new(:or) {
|
99
|
+
seek +1
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
on ?\x11 do
|
104
|
+
Instruction.new(:adc) {
|
105
|
+
seek +1
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
on ?\x19 do
|
110
|
+
Instruction.new(:sbb) {
|
111
|
+
seek +1
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
on ?\x21, ?\x25 do
|
116
|
+
Instruction.new(:ad) {
|
117
|
+
seek +1
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
on ?\x29 do
|
122
|
+
Instruction.new(:sub) {
|
123
|
+
seek +1
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
on ?\x31 do
|
128
|
+
Instruction.new(:xor) {
|
129
|
+
seek +1
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
on ?\x19 do
|
134
|
+
Instruction.new(:cmp) {
|
135
|
+
seek +1
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
on ?\x85 do
|
140
|
+
Instruction.new(:test) {
|
141
|
+
seek +1
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
on ?\x86 do
|
146
|
+
Instruction.new(:xchg) {
|
147
|
+
seek +1
|
148
|
+
|
149
|
+
# 8bit
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
on ?\x87 do
|
154
|
+
Instruction.new(:xchg) {
|
155
|
+
seek +1
|
156
|
+
}
|
157
|
+
end
|
158
|
+
|
159
|
+
on ?\x89 do
|
160
|
+
Instruction.new(:mov) {
|
161
|
+
seek +1
|
162
|
+
|
163
|
+
read 1 do |data|
|
164
|
+
increment = 5 if data.to_byte & 0x07 == 0x05 && data.to_byte < 0x40
|
165
|
+
end
|
166
|
+
}
|
167
|
+
end
|
168
|
+
|
169
|
+
on ?\xA1, ?\xA3 do
|
170
|
+
# increment = 4
|
171
|
+
Instruction.new(:mov) {
|
172
|
+
seek +1
|
173
|
+
}
|
174
|
+
end
|
175
|
+
end
|
176
|
+
}
|
177
|
+
|
178
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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 Assembler
|
23
|
+
@@archs = {}
|
24
|
+
|
25
|
+
def self.for (arch, &block)
|
26
|
+
if block
|
27
|
+
@@archs[arch] = self.new(arch, &block)
|
28
|
+
else
|
29
|
+
@@archs[arch]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_reader :architecture, :features
|
34
|
+
|
35
|
+
alias arch architecture
|
36
|
+
|
37
|
+
def initialize (architecture, features=[])
|
38
|
+
@architecture = architecture
|
39
|
+
@features = features
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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 Address
|
23
|
+
attr_reader :start
|
24
|
+
|
25
|
+
def initialize (value, offset=nil)
|
26
|
+
if offset
|
27
|
+
@start = value
|
28
|
+
@value = offset.to_i
|
29
|
+
else
|
30
|
+
@value = value.to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
yield self if block_given?
|
34
|
+
end
|
35
|
+
|
36
|
+
def offset?
|
37
|
+
!!start
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_i
|
41
|
+
@value
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
offset? ? "[#{start}+#{to_i}]" : "0x%x" % to_i
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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 Constant
|
23
|
+
attr_reader :size
|
24
|
+
|
25
|
+
def initialize (value, size)
|
26
|
+
@value = value.to_i
|
27
|
+
@size = size
|
28
|
+
|
29
|
+
yield self if block_given?
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_i
|
33
|
+
@value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
+
class String
|
21
|
+
alias to_byte ord
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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
|
23
|
+
attr_reader :name, :parameters
|
24
|
+
|
25
|
+
def initialize (name, *parameters)
|
26
|
+
@name = name.to_sym
|
27
|
+
@parameters = parameters.to_a
|
28
|
+
|
29
|
+
yield self if block_given?
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
"#{name.to_s.upcase} #{parameters.join(', ')}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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 Register
|
23
|
+
attr_reader :name, :size
|
24
|
+
|
25
|
+
def initialize (name, size)
|
26
|
+
@name = name.to_sym
|
27
|
+
@size = size.to_i
|
28
|
+
|
29
|
+
yield self if block_given?
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
name.to_s.upcase
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
23
|
+
def initialize (size)
|
24
|
+
@size = size.to_i
|
25
|
+
|
26
|
+
yield self if block_given?
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_i
|
30
|
+
@size
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -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
|
+
require 'orgasm/common/extensions'
|
21
|
+
|
22
|
+
require 'orgasm/common/unknown'
|
23
|
+
require 'orgasm/common/instruction'
|
24
|
+
require 'orgasm/common/address'
|
25
|
+
require 'orgasm/common/register'
|
26
|
+
require 'orgasm/common/constant'
|
27
|
+
|
28
|
+
module Orgasm
|
29
|
+
|
30
|
+
def self.object? (value)
|
31
|
+
[Unknown, Instruction, Address, Register, Constant].any? {|klass|
|
32
|
+
value.is_a?(klass)
|
33
|
+
} && value
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,127 @@
|
|
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; class Disassembler
|
21
|
+
|
22
|
+
class Decoder
|
23
|
+
def initialize (*args, &block)
|
24
|
+
@args = args
|
25
|
+
@block = block
|
26
|
+
end
|
27
|
+
|
28
|
+
def with (io)
|
29
|
+
@io = io
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def decode
|
34
|
+
return unless @io
|
35
|
+
|
36
|
+
return unless @args.any? {|arg|
|
37
|
+
matches(arg)
|
38
|
+
}
|
39
|
+
|
40
|
+
catch(:result) {
|
41
|
+
instance_eval &@block
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def matches (what)
|
46
|
+
return false unless @io
|
47
|
+
|
48
|
+
where, result = @io.tell, if what.is_a?(Regexp)
|
49
|
+
!!@io.read.match(what)
|
50
|
+
else
|
51
|
+
what = what.to_s
|
52
|
+
@io.read(what.length) == what
|
53
|
+
end
|
54
|
+
|
55
|
+
@io.seek where
|
56
|
+
|
57
|
+
result
|
58
|
+
end
|
59
|
+
|
60
|
+
def on (*args, &block)
|
61
|
+
return unless @io
|
62
|
+
|
63
|
+
return unless args.any? {|arg|
|
64
|
+
matches(arg)
|
65
|
+
}
|
66
|
+
|
67
|
+
result = instance_eval &block
|
68
|
+
|
69
|
+
if Orgasm.object?(result)
|
70
|
+
throw :result, result
|
71
|
+
end
|
72
|
+
|
73
|
+
result
|
74
|
+
end
|
75
|
+
|
76
|
+
def seek (amount, whence=IO::SEEK_CUR, &block)
|
77
|
+
return unless @io
|
78
|
+
|
79
|
+
if block
|
80
|
+
where, = @io.tell, @io.seek(amount, whence)
|
81
|
+
|
82
|
+
result = instance_eval &block
|
83
|
+
|
84
|
+
if Orgasm.object?(result)
|
85
|
+
throw :result, result
|
86
|
+
end
|
87
|
+
|
88
|
+
@io.seek(where)
|
89
|
+
|
90
|
+
result
|
91
|
+
else
|
92
|
+
@io.seek(amount, whence)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def read (amount, &block)
|
97
|
+
return unless @io
|
98
|
+
|
99
|
+
if block
|
100
|
+
data = @io.read(amount)
|
101
|
+
|
102
|
+
if data.nil? or data.length != amount
|
103
|
+
raise RuntimeError, 'The stream has not enough data :('
|
104
|
+
end
|
105
|
+
|
106
|
+
result = instance_exec data, &block
|
107
|
+
|
108
|
+
if Orgasm.object?(result)
|
109
|
+
throw :result, result
|
110
|
+
end
|
111
|
+
|
112
|
+
seek -amount
|
113
|
+
|
114
|
+
result
|
115
|
+
else
|
116
|
+
@io.read(amount)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def lookahead (amount)
|
121
|
+
read(amount) do |data|
|
122
|
+
data
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end; end
|
@@ -0,0 +1,79 @@
|
|
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/common'
|
21
|
+
require 'orgasm/disassembler/decoder'
|
22
|
+
|
23
|
+
module Orgasm
|
24
|
+
|
25
|
+
class Disassembler
|
26
|
+
@@archs = {}
|
27
|
+
|
28
|
+
def self.for (arch, &block)
|
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)
|
45
|
+
end
|
46
|
+
|
47
|
+
def disassemble (io)
|
48
|
+
if io.is_a?(String)
|
49
|
+
require 'stringio'
|
50
|
+
|
51
|
+
io = StringIO.new(io)
|
52
|
+
end
|
53
|
+
|
54
|
+
result = []
|
55
|
+
|
56
|
+
until io.eof?
|
57
|
+
where = io.tell
|
58
|
+
|
59
|
+
@decoders.each {|decoder|
|
60
|
+
if tmp = Orgasm.object?(decoder.with(io).decode)
|
61
|
+
result << tmp
|
62
|
+
break
|
63
|
+
end
|
64
|
+
}
|
65
|
+
|
66
|
+
if where == io.tell
|
67
|
+
raise RuntimeError, 'No input was read, something is wrong with the decoders'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
result.flatten.compact
|
72
|
+
end
|
73
|
+
|
74
|
+
def on (*args, &block)
|
75
|
+
@decoders << Decoder.new(*args, &block)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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; class Format
|
21
|
+
|
22
|
+
class ELF < Format
|
23
|
+
def initialize (path)
|
24
|
+
super(:elf, path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end; end
|
@@ -0,0 +1,28 @@
|
|
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; class Format
|
21
|
+
|
22
|
+
class ELF < Format
|
23
|
+
def initialize (path)
|
24
|
+
super(:pe, path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end; end
|
@@ -0,0 +1,34 @@
|
|
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/format/elf'
|
21
|
+
require 'orgasm/format/pe'
|
22
|
+
|
23
|
+
module Orgasm
|
24
|
+
|
25
|
+
class Format
|
26
|
+
attr_reader :name, :path
|
27
|
+
|
28
|
+
def initialize (name, path)
|
29
|
+
@name = name.to_sym
|
30
|
+
@path = path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/orgasm/style.rb
ADDED
@@ -0,0 +1,19 @@
|
|
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
|
+
|
data/lib/orgasm/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: orgasm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 5
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.1a2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- meh.
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-20 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description:
|
@@ -22,10 +22,25 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
+
- lib/orgasm/format/elf.rb
|
26
|
+
- lib/orgasm/format/pe.rb
|
27
|
+
- lib/orgasm/arch/i386/disassembler.rb
|
28
|
+
- lib/orgasm/assembler.rb
|
25
29
|
- lib/orgasm/version.rb
|
30
|
+
- lib/orgasm/common/register.rb
|
31
|
+
- lib/orgasm/common/unknown.rb
|
32
|
+
- lib/orgasm/common/address.rb
|
33
|
+
- lib/orgasm/common/extensions.rb
|
34
|
+
- lib/orgasm/common/constant.rb
|
35
|
+
- lib/orgasm/common/instruction.rb
|
36
|
+
- lib/orgasm/style.rb
|
37
|
+
- lib/orgasm/disassembler.rb
|
38
|
+
- lib/orgasm/disassembler/decoder.rb
|
39
|
+
- lib/orgasm/format.rb
|
40
|
+
- lib/orgasm/common.rb
|
26
41
|
- lib/orgasm.rb
|
27
42
|
- bin/disorgasm
|
28
|
-
homepage: http://github.com/meh/
|
43
|
+
homepage: http://github.com/meh/orgasm
|
29
44
|
licenses: []
|
30
45
|
|
31
46
|
post_install_message:
|
@@ -51,6 +66,6 @@ rubyforge_project:
|
|
51
66
|
rubygems_version: 1.8.5
|
52
67
|
signing_key:
|
53
68
|
specification_version: 3
|
54
|
-
summary: A Ruby
|
69
|
+
summary: A Ruby (dis)?assembler library.
|
55
70
|
test_files: []
|
56
71
|
|