Skip to content

Commit 96cac07

Browse files
committed
cleaup mapping
1 parent f9fff53 commit 96cac07

File tree

2 files changed

+73
-74
lines changed

2 files changed

+73
-74
lines changed

qiling/os/posix/const.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
SOCK_TYPE_MASK = 0x0f
2626

27-
x86_socket_types = {
27+
linux_x86_socket_types = {
2828
'SOCK_STREAM' : 0x1,
2929
'SOCK_DGRAM' : 0x2,
3030
'SOCK_RAW' : 0x3,
@@ -34,7 +34,7 @@
3434
'SOCK_PACKET' : 0xa,
3535
}
3636

37-
x86_socket_domain = {
37+
linux_x86_socket_domain = {
3838
'AF_UNSPEC' : 0x0,
3939
'AF_LOCAL' : 0x1,
4040
'AF_INET' : 0x2,
@@ -50,7 +50,7 @@
5050
}
5151

5252
# https://github.com/torvalds/linux/blob/master/include/uapi/linux/in.h
53-
x86_socket_level = {
53+
linux_x86_socket_level = {
5454
'IPPROTO_IP' : 0x0000,
5555
'SOL_SOCKET' : 0x0001,
5656
'IPPROTO_TCP' : 0x0006,
@@ -60,7 +60,7 @@
6060
}
6161

6262

63-
x86_socket_options = {
63+
linux_x86_socket_options = {
6464
"SO_DEBUG" : 0x0001,
6565
"SO_REUSEADDR" : 0x0002,
6666
"SO_KEEPALIVE" : 0x0009,
@@ -79,7 +79,7 @@
7979

8080
# https://man7.org/linux/man-pages/man7/ip.7.html
8181
# https://github.com/torvalds/linux/blob/master/include/uapi/linux/in.h
82-
posix_socket_ip_options = {
82+
linux_socket_ip_options = {
8383
"IP_TOS" : 0x0001,
8484
"IP_TTL" : 0x0002,
8585
"IP_HDRINCL" : 0x0003,
@@ -167,7 +167,7 @@
167167

168168

169169
# https://gfiber.googlesource.com/toolchains/mindspeed/+/refs/heads/newkernel_dev/arm-unknown-linux-gnueabi/sysroot/usr/include/bits/socket.h
170-
arm_socket_types = {
170+
linux_arm_socket_types = {
171171
'SOCK_STREAM' : 0x1,
172172
'SOCK_DGRAM' : 0x2,
173173
'SOCK_RAW' : 0x3,
@@ -178,7 +178,7 @@
178178
}
179179

180180

181-
arm_socket_domain = {
181+
linux_arm_socket_domain = {
182182
'AF_UNSPEC' : 0x0,
183183
'AF_FILE' : 0x1,
184184
'AF_UNIX' : 0x1,
@@ -231,7 +231,7 @@
231231

232232

233233
# https://gfiber.googlesource.com/toolchains/mindspeed/+/refs/heads/newkernel_dev/arm-unknown-linux-gnueabi/sysroot/usr/include/asm/socket.h
234-
arm_socket_level = {
234+
linux_arm_socket_level = {
235235
'IPPROTO_IP' : 0x0000,
236236
'SOL_SOCKET' : 0x0001,
237237
'IPPROTO_TCP' : 0x0006,
@@ -241,7 +241,7 @@
241241
}
242242

243243
# https://gfiber.googlesource.com/toolchains/mindspeed/+/refs/heads/newkernel_dev/arm-unknown-linux-gnueabi/sysroot/usr/include/asm/socket.h
244-
arm_socket_options = {
244+
linux_arm_socket_options = {
245245
"SO_DEBUG" : 0x0001,
246246
"SO_REUSEADDR" : 0x0002,
247247
"SO_KEEPALIVE" : 0x0009,
@@ -259,7 +259,7 @@
259259
}
260260

261261

262-
mips_socket_types = {
262+
linux_mips_socket_types = {
263263
'SOCK_STREAM' : 0x2,
264264
'SOCK_DGRAM' : 0x1,
265265
'SOCK_RAW' : 0x3,
@@ -270,7 +270,7 @@
270270
}
271271

272272

273-
mips_socket_domain = {
273+
linux_mips_socket_domain = {
274274
'AF_UNSPEC' : 0x0,
275275
'AF_FILE' : 0x1,
276276
'AF_UNIX' : 0x1,
@@ -323,7 +323,7 @@
323323

324324
# https://docs.huihoo.com/doxygen/linux/kernel/3.7/arch_2mips_2include_2uapi_2asm_2socket_8h_source.html
325325
# https://android-review.linaro.org/plugins/gitiles/platform/prebuilts/gcc/darwin-x86/mips/mipsel-linux-android-4.4.3/+/78060bd30f50c43c7442f32e7740efcdb87ba587/sysroot/usr/include/linux/in.h
326-
mips_socket_level = {
326+
linux_mips_socket_level = {
327327
'SOL_SOCKET' : 0xffff,
328328
'IPPROTO_IP' : 0x0000,
329329
'IPPROTO_TCP' : 0x0006,
@@ -334,7 +334,7 @@
334334

335335
# https://docs.huihoo.com/doxygen/linux/kernel/3.7/arch_2mips_2include_2uapi_2asm_2socket_8h_source.html
336336
# https://github.com/torvalds/linux/blob/master/arch/mips/include/uapi/asm/socket.h
337-
mips_socket_options = {
337+
linux_mips_socket_options = {
338338
"SO_DEBUG" : 0x0001,
339339
"SO_REUSEADDR" : 0x0004,
340340
"SO_KEEPALIVE" : 0x0008,
@@ -360,7 +360,7 @@
360360
}
361361

362362

363-
mips_socket_ip_options = {
363+
linux_mips_socket_ip_options = {
364364
"IP_TOS" : 0x0001,
365365
"IP_TTL" : 0x0002,
366366
"IP_HDRINCL" : 0x0003,
@@ -435,7 +435,7 @@
435435
"O_DIRECTORY": 0x100000
436436
}
437437

438-
x86_open_flags = {
438+
linux_x86_open_flags = {
439439
'O_RDONLY' : 0o000000000,
440440
'O_WRONLY' : 0o000000001,
441441
'O_RDWR' : 0o000000002,
@@ -458,7 +458,7 @@
458458
}
459459

460460

461-
mips_open_flags = {
461+
linux_mips_open_flags = {
462462
'O_RDONLY' : 0x0,
463463
'O_WRONLY' : 0x1,
464464
'O_RDWR' : 0x2,
@@ -475,7 +475,7 @@
475475
}
476476

477477

478-
arm_open_flags = {
478+
linux_arm_open_flags = {
479479
'O_RDONLY' : 0x0,
480480
'O_WRONLY' : 0x1,
481481
'O_RDWR' : 0x2,

qiling/os/posix/const_mapping.py

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def flag_mapping(flags, mapping_name, mapping_from, mapping_to):
6161
"O_LARGEFILE"
6262
]
6363

64-
macos_x86_open_flags = {
64+
_macos_x86_open_flags = {
6565
"O_RDONLY": 0x0,
6666
"O_WRONLY": 0x1,
6767
"O_RDWR": 0x2,
@@ -79,7 +79,7 @@ def flag_mapping(flags, mapping_name, mapping_from, mapping_to):
7979
'O_LARGEFILE': None
8080
}
8181

82-
linux_x86_open_flags = {
82+
_linux_x86_open_flags = {
8383
'O_RDONLY': 0x0,
8484
'O_WRONLY': 0x1,
8585
'O_RDWR': 0x2,
@@ -97,7 +97,7 @@ def flag_mapping(flags, mapping_name, mapping_from, mapping_to):
9797
'O_LARGEFILE': 0x0
9898
}
9999

100-
linux_arm_open_flags = {
100+
_linux_arm_open_flags = {
101101
'O_RDONLY': 0x0,
102102
'O_WRONLY': 0x1,
103103
'O_RDWR': 0x2,
@@ -115,7 +115,7 @@ def flag_mapping(flags, mapping_name, mapping_from, mapping_to):
115115
'O_LARGEFILE': 0x20000
116116
}
117117

118-
linux_mips_open_flags = {
118+
_linux_mips_open_flags = {
119119
'O_RDONLY': 0x0,
120120
'O_WRONLY': 0x1,
121121
'O_RDWR': 0x2,
@@ -133,7 +133,7 @@ def flag_mapping(flags, mapping_name, mapping_from, mapping_to):
133133
'O_LARGEFILE': 0x2000
134134
}
135135

136-
freebsd_open_flags = {
136+
_freebsd_open_flags = {
137137
'O_RDONLY': 0x0,
138138
'O_WRONLY': 0x1,
139139
'O_RDWR': 0x2,
@@ -151,7 +151,7 @@ def flag_mapping(flags, mapping_name, mapping_from, mapping_to):
151151
'O_LARGEFILE': None
152152
}
153153

154-
qnx_open_flags = {
154+
_qnx_open_flags = {
155155
'O_RDONLY' : 0x00000,
156156
'O_WRONLY' : 0x00001,
157157
'O_RDWR' : 0x00002,
@@ -177,25 +177,25 @@ def flag_mapping(flags, mapping_name, mapping_from, mapping_to):
177177

178178
if ql.ostype == QL_OS.LINUX:
179179
if ql.archtype in (QL_ARCH.X86, QL_ARCH.X8664):
180-
f = linux_x86_open_flags
180+
f = _linux_x86_open_flags
181181
elif ql.archtype in (QL_ARCH.ARM, QL_ARCH.ARM_THUMB, QL_ARCH.ARM64):
182-
f = linux_arm_open_flags
182+
f = _linux_arm_open_flags
183183
elif ql.archtype == QL_ARCH.MIPS:
184-
f = linux_mips_open_flags
184+
f = _linux_mips_open_flags
185185
elif ql.ostype == QL_OS.MACOS:
186186
if ql.archtype in (QL_ARCH.X86, QL_ARCH.X8664):
187-
f = macos_x86_open_flags
187+
f = _macos_x86_open_flags
188188
elif ql.ostype == QL_OS.FREEBSD:
189-
f = freebsd_open_flags
189+
f = _freebsd_open_flags
190190
elif ql.ostype == QL_OS.QNX:
191-
f = qnx_open_flags
191+
f = _qnx_open_flags
192192

193193
if ql.platform_os == QL_OS.LINUX:
194-
t = linux_x86_open_flags
194+
t = _linux_x86_open_flags
195195
elif ql.platform_os == QL_OS.MACOS:
196-
t = macos_x86_open_flags
196+
t = _macos_x86_open_flags
197197
elif ql.platform_os == QL_OS.FREEBSD:
198-
t = freebsd_open_flags
198+
t = _freebsd_open_flags
199199

200200
if f == t:
201201
return flags
@@ -206,16 +206,15 @@ def open_flags_mapping(flags, archtype, ostype):
206206
if ostype == QL_OS.MACOS:
207207
mapping_dict = {
208208
QL_ARCH.X8664: macos_x86_open_flags,
209-
QL_ARCH.ARM64: arm_open_flags,
209+
QL_ARCH.ARM64: linux_arm_open_flags,
210210
}[archtype]
211211
else:
212212
mapping_dict = {
213-
QL_ARCH.X86: x86_open_flags,
214-
QL_ARCH.X8664: x86_open_flags,
215-
QL_ARCH.ARM: arm_open_flags,
216-
QL_ARCH.ARM64: arm_open_flags,
217-
QL_ARCH.MIPS: mips_open_flags,
218-
QL_OS.MACOS: macos_x86_open_flags,
213+
QL_ARCH.X86: linux_x86_open_flags,
214+
QL_ARCH.X8664: linux_x86_open_flags,
215+
QL_ARCH.ARM: linux_arm_open_flags,
216+
QL_ARCH.ARM64: linux_arm_open_flags,
217+
QL_ARCH.MIPS: linux_mips_open_flags,
219218
}[archtype]
220219
ret = ["O_RDONLY"]
221220
return _constant_mapping(flags, mapping_dict, ret)
@@ -260,17 +259,17 @@ def mmap_prot_mapping(prots):
260259
def socket_type_mapping(t, archtype, ostype):
261260
if ostype == QL_OS.MACOS:
262261
socket_type_map = {
263-
QL_ARCH.ARM64: arm_socket_types,
264-
QL_ARCH.X8664: x86_socket_types,
262+
QL_ARCH.ARM64: linux_arm_socket_types,
263+
QL_ARCH.X8664: linux_x86_socket_types,
265264
}[archtype]
266265
else:
267266
socket_type_map = {
268-
QL_ARCH.X86: x86_socket_types,
269-
QL_ARCH.X8664: x86_socket_types,
270-
QL_ARCH.ARM: arm_socket_types,
271-
QL_ARCH.ARM_THUMB: arm_socket_types,
272-
QL_ARCH.ARM64: arm_socket_types,
273-
QL_ARCH.MIPS: mips_socket_types,
267+
QL_ARCH.X86: linux_x86_socket_types,
268+
QL_ARCH.X8664: linux_x86_socket_types,
269+
QL_ARCH.ARM: linux_arm_socket_types,
270+
QL_ARCH.ARM_THUMB: linux_arm_socket_types,
271+
QL_ARCH.ARM64: linux_arm_socket_types,
272+
QL_ARCH.MIPS: linux_mips_socket_types,
274273
}[archtype]
275274

276275
# https://code.woboq.org/linux/linux/net/socket.c.html#1363
@@ -281,33 +280,33 @@ def socket_domain_mapping(p, archtype, ostype):
281280
if ostype == QL_OS.MACOS:
282281
socket_domain_map = {
283282
QL_ARCH.X8664: macos_x86_socket_domain,
284-
QL_ARCH.ARM64: arm_socket_domain,
283+
QL_ARCH.ARM64: linux_arm_socket_domain,
285284
}[archtype]
286285
else:
287286
socket_domain_map = {
288-
QL_ARCH.X86: x86_socket_domain,
289-
QL_ARCH.X8664: x86_socket_domain,
290-
QL_ARCH.ARM: arm_socket_domain,
291-
QL_ARCH.ARM_THUMB: arm_socket_domain,
292-
QL_ARCH.ARM64: arm_socket_domain,
293-
QL_ARCH.MIPS: mips_socket_domain,
287+
QL_ARCH.X86: linux_x86_socket_domain,
288+
QL_ARCH.X8664: linux_x86_socket_domain,
289+
QL_ARCH.ARM: linux_arm_socket_domain,
290+
QL_ARCH.ARM_THUMB: linux_arm_socket_domain,
291+
QL_ARCH.ARM64: linux_arm_socket_domain,
292+
QL_ARCH.MIPS: linux_mips_socket_domain,
294293
}[archtype]
295294
return _constant_mapping(p, socket_domain_map, single_mapping=True)
296295

297296
def socket_level_mapping(t, archtype, ostype):
298297
if ostype == QL_OS.MACOS:
299298
socket_level_map = {
300-
QL_ARCH.X8664: x86_socket_level,
301-
QL_ARCH.ARM64: arm_socket_level,
299+
QL_ARCH.X8664: linux_x86_socket_level,
300+
QL_ARCH.ARM64: linux_arm_socket_level,
302301
}[archtype]
303302
else:
304303
socket_level_map = {
305-
QL_ARCH.X86: x86_socket_level,
306-
QL_ARCH.X8664: x86_socket_level,
307-
QL_ARCH.ARM: arm_socket_level,
308-
QL_ARCH.ARM_THUMB: arm_socket_level,
309-
QL_ARCH.ARM64: arm_socket_level,
310-
QL_ARCH.MIPS: mips_socket_level,
304+
QL_ARCH.X86: linux_x86_socket_level,
305+
QL_ARCH.X8664: linux_x86_socket_level,
306+
QL_ARCH.ARM: linux_arm_socket_level,
307+
QL_ARCH.ARM_THUMB: linux_arm_socket_level,
308+
QL_ARCH.ARM64: linux_arm_socket_level,
309+
QL_ARCH.MIPS: linux_mips_socket_level,
311310
}[archtype]
312311
return _constant_mapping(t, socket_level_map, single_mapping=True)
313312

@@ -320,29 +319,29 @@ def socket_ip_option_mapping(t, archtype, ostype):
320319
}[archtype]
321320
else:
322321
socket_option_map = {
323-
QL_ARCH.X86: posix_socket_ip_options,
324-
QL_ARCH.X8664: posix_socket_ip_options,
325-
QL_ARCH.ARM: posix_socket_ip_options,
326-
QL_ARCH.ARM_THUMB: posix_socket_ip_options,
327-
QL_ARCH.ARM64: posix_socket_ip_options,
328-
QL_ARCH.MIPS: mips_socket_ip_options,
322+
QL_ARCH.X86: linux_socket_ip_options,
323+
QL_ARCH.X8664: linux_socket_ip_options,
324+
QL_ARCH.ARM: linux_socket_ip_options,
325+
QL_ARCH.ARM_THUMB: linux_socket_ip_options,
326+
QL_ARCH.ARM64: linux_socket_ip_options,
327+
QL_ARCH.MIPS: linux_socket_ip_options,
329328
}[archtype]
330329
return _constant_mapping(t, socket_option_map, single_mapping=True)
331330

332331

333332
def socket_option_mapping(t, archtype, ostype):
334333
if ostype == QL_OS.MACOS:
335334
socket_option_map = {
336-
QL_ARCH.X8664: x86_socket_options,
337-
QL_ARCH.ARM64: arm_socket_options,
335+
QL_ARCH.X8664: linux_x86_socket_options,
336+
QL_ARCH.ARM64: linux_arm_socket_options,
338337
}[archtype]
339338
else:
340339
socket_option_map = {
341340
QL_ARCH.X86: x86_socket_options,
342341
QL_ARCH.X8664: x86_socket_options,
343-
QL_ARCH.ARM: arm_socket_options,
344-
QL_ARCH.ARM_THUMB: arm_socket_options,
345-
QL_ARCH.ARM64: arm_socket_options,
346-
QL_ARCH.MIPS: mips_socket_options,
342+
QL_ARCH.ARM: linux_arm_socket_options,
343+
QL_ARCH.ARM_THUMB: linux_arm_socket_options,
344+
QL_ARCH.ARM64: linux_arm_socket_options,
345+
QL_ARCH.MIPS: linux_mips_socket_options,
347346
}[archtype]
348347
return _constant_mapping(t, socket_option_map, single_mapping=True)

0 commit comments

Comments
 (0)