ronin-code-asm 1.0.0.beta1
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 +7 -0
- data/.document +4 -0
- data/.editorconfig +11 -0
- data/.github/workflows/ruby.yml +31 -0
- data/.gitignore +11 -0
- data/.mailmap +1 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -0
- data/COPYING.txt +165 -0
- data/ChangeLog.md +44 -0
- data/Gemfile +25 -0
- data/README.md +166 -0
- data/Rakefile +39 -0
- data/data/os/freebsd/amd64/syscalls.yml +415 -0
- data/data/os/freebsd/x86/syscalls.yml +415 -0
- data/data/os/linux/amd64/syscalls.yml +306 -0
- data/data/os/linux/x86/syscalls.yml +339 -0
- data/gemspec.yml +26 -0
- data/lib/ronin/code/asm/archs/amd64.rb +100 -0
- data/lib/ronin/code/asm/archs/x86.rb +170 -0
- data/lib/ronin/code/asm/archs.rb +22 -0
- data/lib/ronin/code/asm/config.rb +33 -0
- data/lib/ronin/code/asm/immediate_operand.rb +84 -0
- data/lib/ronin/code/asm/instruction.rb +66 -0
- data/lib/ronin/code/asm/memory_operand.rb +119 -0
- data/lib/ronin/code/asm/os/freebsd.rb +35 -0
- data/lib/ronin/code/asm/os/linux.rb +35 -0
- data/lib/ronin/code/asm/os/os.rb +47 -0
- data/lib/ronin/code/asm/os.rb +57 -0
- data/lib/ronin/code/asm/program.rb +509 -0
- data/lib/ronin/code/asm/register.rb +111 -0
- data/lib/ronin/code/asm/shellcode.rb +75 -0
- data/lib/ronin/code/asm/syntax/att.rb +164 -0
- data/lib/ronin/code/asm/syntax/common.rb +241 -0
- data/lib/ronin/code/asm/syntax/intel.rb +150 -0
- data/lib/ronin/code/asm/syntax.rb +22 -0
- data/lib/ronin/code/asm/version.rb +28 -0
- data/lib/ronin/code/asm.rb +68 -0
- data/ronin-code-asm.gemspec +62 -0
- data/spec/asm_spec.rb +14 -0
- data/spec/config_spec.rb +10 -0
- data/spec/immediate_operand_spec.rb +79 -0
- data/spec/instruction_spec.rb +62 -0
- data/spec/memory_operand_spec.rb +80 -0
- data/spec/os_spec.rb +68 -0
- data/spec/program_spec.rb +439 -0
- data/spec/register_spec.rb +112 -0
- data/spec/shellcode_spec.rb +58 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/syntax/att_spec.rb +181 -0
- data/spec/syntax/common_spec.rb +42 -0
- data/spec/syntax/intel_spec.rb +174 -0
- metadata +143 -0
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-code-asm - A Ruby DSL for crafting Assembly programs and shellcode.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2007-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-code-asm is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-code-asm is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-code-asm. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/code/asm/archs/x86'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Code
|
25
|
+
module ASM
|
26
|
+
module Archs
|
27
|
+
#
|
28
|
+
# Contains AMD64 Archtecture information.
|
29
|
+
#
|
30
|
+
module AMD64
|
31
|
+
include X86
|
32
|
+
|
33
|
+
# Default word size
|
34
|
+
WORD_SIZE = 8
|
35
|
+
|
36
|
+
# AMD64 registers
|
37
|
+
REGISTERS = X86::REGISTERS.merge(
|
38
|
+
rax: Register.new(:rax, 8, true),
|
39
|
+
rbx: Register.new(:rbx, 8, true),
|
40
|
+
rcx: Register.new(:rcx, 8, true),
|
41
|
+
rdx: Register.new(:rdx, 8, true),
|
42
|
+
|
43
|
+
rsi: Register.new(:rsi, 8, true),
|
44
|
+
rdi: Register.new(:rdi, 8, true),
|
45
|
+
|
46
|
+
rsp: Register.new(:rsp, 8, true),
|
47
|
+
rbp: Register.new(:rbp, 8, true),
|
48
|
+
|
49
|
+
r8b: Register.new(:r8b, 1, true),
|
50
|
+
r8w: Register.new(:r8w, 2, true),
|
51
|
+
r8d: Register.new(:r8d, 4, true),
|
52
|
+
r8: Register.new(:r8, 8, true),
|
53
|
+
|
54
|
+
r9b: Register.new(:r9b, 1, true),
|
55
|
+
r9w: Register.new(:r9w, 2, true),
|
56
|
+
r9d: Register.new(:r9d, 4, true),
|
57
|
+
r9: Register.new(:r9, 8, true),
|
58
|
+
|
59
|
+
r10b: Register.new(:r10b, 1, true),
|
60
|
+
r10w: Register.new(:r10w, 2, true),
|
61
|
+
r10d: Register.new(:r10d, 4, true),
|
62
|
+
r10: Register.new(:r10, 8, true),
|
63
|
+
|
64
|
+
r11b: Register.new(:r11b, 1, true),
|
65
|
+
r11w: Register.new(:r11w, 2, true),
|
66
|
+
r11d: Register.new(:r11d, 4, true),
|
67
|
+
r11: Register.new(:r11, 8, true),
|
68
|
+
|
69
|
+
r12b: Register.new(:r12b, 1, true),
|
70
|
+
r12w: Register.new(:r12w, 2, true),
|
71
|
+
r12d: Register.new(:r12d, 4, true),
|
72
|
+
r12: Register.new(:r12, 8, true),
|
73
|
+
|
74
|
+
r13b: Register.new(:r13b, 1, true),
|
75
|
+
r13w: Register.new(:r13w, 2, true),
|
76
|
+
r13d: Register.new(:r13d, 4, true),
|
77
|
+
r13: Register.new(:r13, 8, true),
|
78
|
+
|
79
|
+
r14b: Register.new(:r14b, 1, true),
|
80
|
+
r14w: Register.new(:r14w, 2, true),
|
81
|
+
r14d: Register.new(:r14d, 4, true),
|
82
|
+
r14: Register.new(:r14, 8, true),
|
83
|
+
|
84
|
+
r15b: Register.new(:r15b, 1, true),
|
85
|
+
r15w: Register.new(:r15w, 2, true),
|
86
|
+
r15d: Register.new(:r15d, 4, true),
|
87
|
+
r15: Register.new(:r15, 8, true),
|
88
|
+
|
89
|
+
rip: Register.new(:rip, 8, true)
|
90
|
+
)
|
91
|
+
|
92
|
+
#
|
93
|
+
# Generates the instruction to invoke a syscall.
|
94
|
+
#
|
95
|
+
def syscall; instruction(:syscall); end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-code-asm - A Ruby DSL for crafting Assembly programs and shellcode.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2007-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-code-asm is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-code-asm is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-code-asm. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/code/asm/register'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Code
|
25
|
+
module ASM
|
26
|
+
module Archs
|
27
|
+
#
|
28
|
+
# Contains X86 Archtecture information.
|
29
|
+
#
|
30
|
+
module X86
|
31
|
+
# Default word size
|
32
|
+
WORD_SIZE = 4
|
33
|
+
|
34
|
+
# X86 registers
|
35
|
+
REGISTERS = {
|
36
|
+
al: Register.new(:al, 1),
|
37
|
+
ah: Register.new(:ah, 1),
|
38
|
+
ax: Register.new(:ax, 2),
|
39
|
+
eax: Register.new(:eax, 4, true),
|
40
|
+
|
41
|
+
bl: Register.new(:bl, 1),
|
42
|
+
bh: Register.new(:bh, 1),
|
43
|
+
bx: Register.new(:bx, 2),
|
44
|
+
ebx: Register.new(:ebx, 4, true),
|
45
|
+
|
46
|
+
cl: Register.new(:cl, 1),
|
47
|
+
ch: Register.new(:ch, 1),
|
48
|
+
cx: Register.new(:cx, 2),
|
49
|
+
ecx: Register.new(:ecx, 4, true),
|
50
|
+
|
51
|
+
dl: Register.new(:dl, 1),
|
52
|
+
dh: Register.new(:dh, 1),
|
53
|
+
dx: Register.new(:dx, 2),
|
54
|
+
edx: Register.new(:edx, 4, true),
|
55
|
+
|
56
|
+
bp: Register.new(:bp, 2),
|
57
|
+
ebp: Register.new(:ebp, 4),
|
58
|
+
|
59
|
+
sp: Register.new(:sp, 2),
|
60
|
+
esp: Register.new(:esp, 4),
|
61
|
+
|
62
|
+
ip: Register.new(:ip, 2),
|
63
|
+
eip: Register.new(:eip, 4),
|
64
|
+
|
65
|
+
sil: Register.new(:sil, 1),
|
66
|
+
si: Register.new(:si, 2),
|
67
|
+
esi: Register.new(:esi, 4, true),
|
68
|
+
|
69
|
+
dil: Register.new(:dil, 1),
|
70
|
+
di: Register.new(:di, 2),
|
71
|
+
edi: Register.new(:edi, 4, true),
|
72
|
+
|
73
|
+
cs: Register.new(:cs, 2),
|
74
|
+
ds: Register.new(:ds, 2),
|
75
|
+
es: Register.new(:es, 2),
|
76
|
+
fs: Register.new(:fs, 2),
|
77
|
+
gs: Register.new(:gs, 2),
|
78
|
+
ss: Register.new(:ss, 2)
|
79
|
+
}
|
80
|
+
|
81
|
+
#
|
82
|
+
# Generates the instruction to trigger an interrupt.
|
83
|
+
#
|
84
|
+
# @param [Integer] number
|
85
|
+
# The interrupt number.
|
86
|
+
#
|
87
|
+
def interrupt(number); instruction(:int,number); end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Generates the instruction to invoke a syscall.
|
91
|
+
#
|
92
|
+
def syscall; interrupt(0x80); end
|
93
|
+
|
94
|
+
#
|
95
|
+
# The Stack Base Pointer register.
|
96
|
+
#
|
97
|
+
# @see ebp
|
98
|
+
#
|
99
|
+
def stack_base; ebp; end
|
100
|
+
|
101
|
+
#
|
102
|
+
# The Stack Pointer register.
|
103
|
+
#
|
104
|
+
# @see esp
|
105
|
+
#
|
106
|
+
def stack_pointer; esp; end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Generates the instruction to push a value onto the Stack.
|
110
|
+
#
|
111
|
+
# @param [ImmediateOperand, MemoryOperand, Register, Integer, Symbol] op
|
112
|
+
# The value.
|
113
|
+
#
|
114
|
+
def stack_push(op); instruction(:push,op); end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Generates the instruction to pop a value off of the Stack.
|
118
|
+
#
|
119
|
+
# @param [Register] op
|
120
|
+
# The register operand to store the value.
|
121
|
+
#
|
122
|
+
def stack_pop(op); instruction(:pop,op); end
|
123
|
+
|
124
|
+
#
|
125
|
+
# Generates the instruction to clear a register.
|
126
|
+
#
|
127
|
+
# @param [Symbol] name
|
128
|
+
# The name of the register.
|
129
|
+
#
|
130
|
+
def register_clear(name)
|
131
|
+
instruction(:xor,register(name),register(name))
|
132
|
+
end
|
133
|
+
|
134
|
+
#
|
135
|
+
# Generates the instruction to set a register.
|
136
|
+
#
|
137
|
+
# @param [Symbol] name
|
138
|
+
# The name of the register.
|
139
|
+
#
|
140
|
+
# @param [ImmediateOperand, MemoryOperand, Register, Integer, Symbol] value
|
141
|
+
# The value to set.
|
142
|
+
#
|
143
|
+
def register_set(name,value)
|
144
|
+
instruction(:mov,value,register(name))
|
145
|
+
end
|
146
|
+
|
147
|
+
#
|
148
|
+
# Generates the instruction to save a register.
|
149
|
+
#
|
150
|
+
# @param [Symbol] name
|
151
|
+
# The name of the register.
|
152
|
+
#
|
153
|
+
def register_save(name)
|
154
|
+
stack_push(register(name))
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# Generates the instruction to restore a register.
|
159
|
+
#
|
160
|
+
# @param [Symbol] name
|
161
|
+
# The name of the register.
|
162
|
+
#
|
163
|
+
def register_load(name)
|
164
|
+
stack_pop(register(name))
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-code-asm - A Ruby DSL for crafting Assembly programs and shellcode.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2007-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-code-asm is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-code-asm is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-code-asm. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/code/asm/archs/x86'
|
22
|
+
require 'ronin/code/asm/archs/amd64'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-code-asm - A Ruby DSL for crafting Assembly programs and shellcode.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2007-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-code-asm is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-code-asm is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-code-asm. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Ronin
|
22
|
+
module Code
|
23
|
+
module ASM
|
24
|
+
#
|
25
|
+
# Handles configuration for ronin-code-asm.
|
26
|
+
#
|
27
|
+
module Config
|
28
|
+
# Data directory for ronin-code-asm
|
29
|
+
DATA_DIR = File.expand_path(File.join(__dir__,'..','..','..','..','data'))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-code-asm - A Ruby DSL for crafting Assembly programs and shellcode.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2007-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-code-asm is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-code-asm is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-code-asm. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Ronin
|
22
|
+
module Code
|
23
|
+
module ASM
|
24
|
+
#
|
25
|
+
# Represents an Immediate Data Operand.
|
26
|
+
#
|
27
|
+
# @see http://asm.sourceforge.net/articles/linasm.html#Prefixes
|
28
|
+
#
|
29
|
+
class ImmediateOperand < Struct.new(:value, :width)
|
30
|
+
|
31
|
+
#
|
32
|
+
# Initializes a new Immediate Operand.
|
33
|
+
#
|
34
|
+
# @param [Integer, nil] value
|
35
|
+
# The value.
|
36
|
+
#
|
37
|
+
# @param [nil, 1, 2, 4, 8] width
|
38
|
+
# The size in bytes of the value.
|
39
|
+
#
|
40
|
+
def initialize(value,width=nil)
|
41
|
+
super(value.to_i,width)
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# The width of the immediate operand.
|
46
|
+
#
|
47
|
+
# @return [8, 4, 2, 1]
|
48
|
+
# The width.
|
49
|
+
#
|
50
|
+
def width
|
51
|
+
super || case value
|
52
|
+
when (0x100000000..0xffffffffffffffff),
|
53
|
+
(-0x7fffffffffffffff..-0x800000000) then 8
|
54
|
+
when (0x10000..0xffffffff),
|
55
|
+
(-0x7fffffff..-0x80000) then 4
|
56
|
+
when (0x100..0xffff), (-0x7fff..-0x80) then 2
|
57
|
+
when (0..0xff), (-0x7f..0) then 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Converts the operand to an Integer.
|
63
|
+
#
|
64
|
+
# @return [Integer]
|
65
|
+
# The value.
|
66
|
+
#
|
67
|
+
def to_i
|
68
|
+
self.value
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Converts the operand to a String.
|
73
|
+
#
|
74
|
+
# @return [String]
|
75
|
+
# The value in String form.
|
76
|
+
#
|
77
|
+
def to_s
|
78
|
+
self.value.to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-code-asm - A Ruby DSL for crafting Assembly programs and shellcode.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2007-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-code-asm is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-code-asm is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-code-asm. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/code/asm/immediate_operand'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Code
|
25
|
+
module ASM
|
26
|
+
#
|
27
|
+
# Represents an instruction.
|
28
|
+
#
|
29
|
+
class Instruction < Struct.new(:name, :operands)
|
30
|
+
|
31
|
+
#
|
32
|
+
# Initializes the instruction.
|
33
|
+
#
|
34
|
+
# @param [Symbol] name
|
35
|
+
# The instruction name.
|
36
|
+
#
|
37
|
+
# @param [Array<MemoryOperand, Register, Symbol, Integer>] operands
|
38
|
+
# Operands for the instruction.
|
39
|
+
#
|
40
|
+
def initialize(name,operands)
|
41
|
+
operands = operands.map do |value|
|
42
|
+
case value
|
43
|
+
when Integer, nil then ImmediateOperand.new(value)
|
44
|
+
else value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
super(name,operands)
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# The word size of the instruction.
|
53
|
+
#
|
54
|
+
# @return [Integer, nil]
|
55
|
+
# The word size in bytes.
|
56
|
+
#
|
57
|
+
def width
|
58
|
+
self.operands.map { |op|
|
59
|
+
op.width if op.respond_to?(:width)
|
60
|
+
}.compact.max
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-code-asm - A Ruby DSL for crafting Assembly programs and shellcode.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2007-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-code-asm is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-code-asm is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-code-asm. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/code/asm/register'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Code
|
25
|
+
module ASM
|
26
|
+
#
|
27
|
+
# Represents a Memory Operand.
|
28
|
+
#
|
29
|
+
# @see http://asm.sourceforge.net/articles/linasm.html#Memory
|
30
|
+
#
|
31
|
+
class MemoryOperand < Struct.new(:base, :offset, :index, :scale, :width)
|
32
|
+
|
33
|
+
#
|
34
|
+
# Creates a new Memory Operand.
|
35
|
+
#
|
36
|
+
# @param [Register, nil] base
|
37
|
+
# The base of the value.
|
38
|
+
#
|
39
|
+
# @param [Integer] offset
|
40
|
+
# The fixed offset to add to the `base`.
|
41
|
+
#
|
42
|
+
# @param [Register, nil] index
|
43
|
+
# The variable index to multiple by `scale`, then add to `base.
|
44
|
+
#
|
45
|
+
# @param [Integer] scale
|
46
|
+
# The scale to multiple `index` by.
|
47
|
+
#
|
48
|
+
# @param [Integer, nil] width
|
49
|
+
# The optional width of the memory operand.
|
50
|
+
#
|
51
|
+
# @raise [TypeError]
|
52
|
+
# `base` or `index` was not a {Register} or `nil`.
|
53
|
+
#
|
54
|
+
def initialize(base=nil,offset=0,index=nil,scale=1,width=nil)
|
55
|
+
unless (base.nil? || base.kind_of?(Register))
|
56
|
+
raise(TypeError,"base must be a Register or nil")
|
57
|
+
end
|
58
|
+
|
59
|
+
unless offset.kind_of?(Integer)
|
60
|
+
raise(TypeError,"offset must be an Integer")
|
61
|
+
end
|
62
|
+
|
63
|
+
unless (index.nil? || index.kind_of?(Register))
|
64
|
+
raise(TypeError,"index must be a Register or nil")
|
65
|
+
end
|
66
|
+
|
67
|
+
unless scale.kind_of?(Integer)
|
68
|
+
raise(TypeError,"scale must be an Integer")
|
69
|
+
end
|
70
|
+
|
71
|
+
if base
|
72
|
+
width ||= base.width
|
73
|
+
end
|
74
|
+
|
75
|
+
super(base,offset,index,scale,width)
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# Adds to the offset of the Memory Operand.
|
80
|
+
#
|
81
|
+
# @param [Integer] offset
|
82
|
+
# The offset to add to the Memory Operand.
|
83
|
+
#
|
84
|
+
# @return [MemoryOperand]
|
85
|
+
# The new Memory Operand.
|
86
|
+
#
|
87
|
+
def +(offset)
|
88
|
+
MemoryOperand.new(
|
89
|
+
self.base,
|
90
|
+
self.offset + offset,
|
91
|
+
self.index,
|
92
|
+
self.scale,
|
93
|
+
self.width
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Subtracts from the offset of the Memory Operand.
|
99
|
+
#
|
100
|
+
# @param [Integer] offset
|
101
|
+
# The offset to subject from the Memory Operand.
|
102
|
+
#
|
103
|
+
# @return [MemoryOperand]
|
104
|
+
# The new Memory Operand.
|
105
|
+
#
|
106
|
+
def -(offset)
|
107
|
+
MemoryOperand.new(
|
108
|
+
self.base,
|
109
|
+
self.offset - offset,
|
110
|
+
self.index,
|
111
|
+
self.scale,
|
112
|
+
self.width
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-code-asm - A Ruby DSL for crafting Assembly programs and shellcode.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2007-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-code-asm is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-code-asm is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-code-asm. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/code/asm/config'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Code
|
25
|
+
module ASM
|
26
|
+
module OS
|
27
|
+
#
|
28
|
+
# Contains FreeBSD specific helper methods.
|
29
|
+
#
|
30
|
+
module FreeBSD
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-code-asm - A Ruby DSL for crafting Assembly programs and shellcode.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2007-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-code-asm is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# ronin-code-asm is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with ronin-code-asm. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/code/asm/config'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module Code
|
25
|
+
module ASM
|
26
|
+
module OS
|
27
|
+
#
|
28
|
+
# Contains Linux specific helper methods.
|
29
|
+
#
|
30
|
+
module Linux
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|