CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/unixasm/aix-power.rb
Views: 11766
1
#!/usr/bin/env ruby
2
3
require 'erb'
4
5
class Template
6
attr_accessor :template, :result
7
8
def initialize(filename)
9
begin
10
f = File.new(filename)
11
@template = f.read
12
rescue Errno::ENOENT
13
end
14
end
15
16
def parse
17
@result = ERB.new(@template).result(binding)
18
end
19
20
def get_result
21
result
22
end
23
end
24
25
class Source < Template
26
attr_accessor :__CAL
27
attr_accessor :__NR_execve
28
attr_accessor :__NR_getpeername
29
attr_accessor :__NR_accept
30
attr_accessor :__NR_listen
31
attr_accessor :__NR_bind
32
attr_accessor :__NR_socket
33
attr_accessor :__NR_connect
34
attr_accessor :__NR_close
35
attr_accessor :__NR_kfcntl
36
attr_accessor :__cal
37
attr_accessor :_cal
38
attr_accessor :cal
39
attr_accessor :ver
40
41
def initialize(filename)
42
@__CAL = 2047
43
@__cal = "\x38\x5d"
44
@_cal = Hash.new
45
@cal = Hash.new
46
@ver = String.new
47
48
@execve = ''
49
@getpeername = ''
50
@accept = ''
51
@listen = ''
52
@bind = ''
53
@socket = ''
54
@connect = ''
55
@close = ''
56
@kfcntl = ''
57
58
super(filename)
59
end
60
61
def parse
62
__NC_execve = -(__CAL - __NR_execve)
63
__NC_getpeername = -(__CAL - __NR_getpeername)
64
__NC_accept = -(__CAL - __NR_accept)
65
__NC_listen = -(__CAL - __NR_listen)
66
__NC_bind = -(__CAL - __NR_bind)
67
__NC_socket = -(__CAL - __NR_socket)
68
__NC_connect = -(__CAL - __NR_connect)
69
__NC_close = -(__CAL - __NR_close)
70
__NC_kfcntl = -(__CAL - __NR_kfcntl)
71
72
_cal[ver] = {
73
:execve => __cal + [__NC_execve].pack('n'),
74
:getpeername => __cal + [__NC_getpeername].pack('n'),
75
:accept => __cal + [__NC_accept].pack('n'),
76
:listen => __cal + [__NC_listen].pack('n'),
77
:bind => __cal + [__NC_bind].pack('n'),
78
:socket => __cal + [__NC_socket].pack('n'),
79
:connect => __cal + [__NC_connect].pack('n'),
80
:close => __cal + [__NC_close].pack('n'),
81
:kfcntl => __cal + [__NC_kfcntl].pack('n'),
82
}
83
84
cal = Hash.new
85
cal[ver] = Hash.new
86
87
_cal[ver].each_pair do |key, value|
88
cal[ver][key] = Array.new
89
cal[ver][key] << String.new
90
cal[ver][key][-1] << '#ifdef AIX%s' % ver.delete('.')
91
cal[ver][key][-1] << "\n"
92
cal[ver][key][-1] << '"'.rjust(5)
93
value.each_byte do |c|
94
cal[ver][key][-1] << '\x%02x' % c
95
end
96
cal[ver][key][-1] << '"'.ljust(7)
97
cal[ver][key][-1] << '/* cal r2,-%d(r29)' %
98
(65536 - value.unpack('nn')[1])
99
cal[ver][key][-1] << '*/'.rjust(15)
100
cal[ver][key][-1] << "\n"
101
cal[ver][key][-1] << "#endif"
102
cal[ver][key][-1] << "\n"
103
end
104
105
cal.each_pair do |key, ver|
106
ver.each_pair do |key, value|
107
instance_variable_get("@#{key}").concat(value[-1])
108
end
109
end
110
111
super
112
end
113
end
114
115
class Parser
116
def initialize(filename)
117
@src = Source.new(filename)
118
end
119
120
def parse
121
vers = [
122
'6.1.4',
123
'6.1.3',
124
'6.1.2',
125
'6.1.1',
126
'6.1.0',
127
'5.3.10',
128
'5.3.9',
129
'5.3.8',
130
'5.3.7',
131
]
132
133
vers.each do |ver|
134
case ver
135
when '6.1.4'
136
__NR_execve = 7
137
__NR_getpeername = 211
138
__NR_accept = 237
139
__NR_listen = 240
140
__NR_bind = 242
141
__NR_socket = 243
142
__NR_connect = 244
143
__NR_close = 278
144
__NR_kfcntl = 658
145
146
when '6.1.3'
147
__NR_execve = 7
148
__NR_getpeername = 205
149
__NR_accept = 232
150
__NR_listen = 235
151
__NR_bind = 237
152
__NR_socket = 238
153
__NR_connect = 239
154
__NR_close = 272
155
__NR_kfcntl = 644
156
157
when '6.1.2'
158
__NR_execve = 7
159
__NR_getpeername = 205
160
__NR_accept = 232
161
__NR_listen = 235
162
__NR_bind = 237
163
__NR_socket = 238
164
__NR_connect = 239
165
__NR_close = 272
166
__NR_kfcntl = 635
167
168
when '6.1.1'
169
__NR_execve = 7
170
__NR_getpeername = 202
171
__NR_accept = 229
172
__NR_listen = 232
173
__NR_bind = 234
174
__NR_socket = 235
175
__NR_connect = 236
176
__NR_close = 269
177
__NR_kfcntl = 614
178
179
when '6.1.0'
180
__NR_execve = 6
181
__NR_getpeername = 203
182
__NR_accept = 229
183
__NR_listen = 232
184
__NR_bind = 234
185
__NR_socket = 235
186
__NR_connect = 236
187
__NR_close = 269
188
__NR_kfcntl = 617
189
190
when '5.3.10', '5.3.9', '5.3.8', '5.3.7'
191
__NR_execve = 6
192
__NR_getpeername = 198
193
__NR_accept = 214
194
__NR_listen = 215
195
__NR_bind = 216
196
__NR_socket = 217
197
__NR_connect = 218
198
__NR_close = 245
199
__NR_kfcntl = 493
200
201
end
202
203
@src.__NR_execve = __NR_execve
204
@src.__NR_getpeername = __NR_getpeername
205
@src.__NR_accept = __NR_accept
206
@src.__NR_listen = __NR_listen
207
@src.__NR_bind = __NR_bind
208
@src.__NR_socket = __NR_socket
209
@src.__NR_connect = __NR_connect
210
@src.__NR_close = __NR_close
211
@src.__NR_kfcntl = __NR_kfcntl
212
213
@src.ver = ver
214
@src.parse
215
end
216
end
217
218
def get_result
219
@src.get_result
220
end
221
end
222
223
filename = ARGV.shift || exit
224
225
parser = Parser.new(filename)
226
parser.parse
227
print parser.get_result
228
229
230