Skip to content

Commit de6a17b

Browse files
committed
make const work with ostype, add ql.platform_os and ql.platform_arch
1 parent b945456 commit de6a17b

File tree

14 files changed

+203
-179
lines changed

14 files changed

+203
-179
lines changed

qiling/core.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def __init__(
3434
rootfs=None,
3535
env=None,
3636
code=None,
37-
shellcoder=None,
3837
ostype=None,
3938
archtype=None,
4039
bigendian=False,
@@ -52,6 +51,7 @@ def __init__(
5251
stdin=None,
5352
stdout=None,
5453
stderr=None,
54+
noneos=None,
5555
):
5656
""" Create a Qiling instance.
5757
@@ -67,9 +67,9 @@ def __init__(
6767
self._rootfs = rootfs
6868
self._env = env if env else {}
6969
self._code = code
70-
self._shellcoder = shellcoder
7170
self._ostype = ostype
7271
self._archtype = archtype
72+
self._noneos = None,
7373
self._archendian = None
7474
self._archbit = None
7575
self._pointersize = None
@@ -82,7 +82,8 @@ def __init__(
8282
self._log_override = log_override
8383
self._log_plain = log_plain
8484
self._filter = filter
85-
self._platform = ostype_convert(platform.system().lower())
85+
self._platform_os = ostype_convert(platform.system().lower())
86+
self._platform_arch = arch_convert(platform.machine().lower())
8687
self._internal_exception = None
8788
self._uc = None
8889
self._stop_options = QlStopOptions(stackpointer=stop_on_stackpointer, exit_trap=stop_on_exit_trap)
@@ -114,10 +115,6 @@ def __init__(
114115
# Shellcode? #
115116
##############
116117

117-
# for Legacy
118-
if self._shellcoder:
119-
self._code = self._shellcoder
120-
121118
if self._code or (self._archtype and type(self._archtype) == str):
122119
if (self._archtype and type(self._archtype) == str):
123120
self._archtype= arch_convert(self._archtype.lower())
@@ -476,20 +473,36 @@ def targetname(self) -> str:
476473
return self._targetname
477474

478475
@property
479-
def platform(self):
480-
""" Specify current platform where Qiling runs on.
476+
def platform_os(self):
477+
""" Specify current platform os where Qiling runs on.
478+
479+
Type: int
480+
Values: All possible values from platform.system()
481+
"""
482+
return self._platform_os
483+
484+
@platform_os.setter
485+
def platform_os(self, value):
486+
if type(value) is str:
487+
self._platform_os = ostype_convert(value.lower())
488+
else:
489+
self._platform_os = value
490+
491+
@property
492+
def platform_arch(self):
493+
""" Specify current platform arch where Qiling runs on.
481494
482495
Type: int
483496
Values: All possible values from platform.system()
484497
"""
485-
return self._platform
498+
return self._platform_arch
486499

487-
@platform.setter
488-
def platform(self, value):
500+
@platform_arch.setter
501+
def platform_arch(self, value):
489502
if type(value) is str:
490-
self._platform = ostype_convert(value.lower())
503+
self._platform_arch = arch_convert(value.lower())
491504
else:
492-
self._platform = value
505+
self._platform_arch = value
493506

494507
@property
495508
def internal_exception(self) -> Exception:

qiling/os/linux/const.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

qiling/os/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def convert_for_native_os(rootfs: Union[str, Path], cwd: str, path: str) -> Path
107107

108108
def convert_path(self, rootfs: Union[str, Path], cwd: str, path: str) -> Path:
109109
emulated_os = self.ql.ostype
110-
hosting_os = self.ql.platform
110+
hosting_os = self.ql.platform_os
111111

112112
# emulated os and hosting platform are of the same type
113113
if (emulated_os == hosting_os) or (emulated_os in QL_OS_POSIX and hosting_os in QL_OS_POSIX):

qiling/os/posix/const.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
44
#
55

6+
#!/usr/bin/env python3
7+
#
8+
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
9+
#
10+
611
from qiling.const import *
712

813
# OS Threading Constants
@@ -19,7 +24,7 @@
1924

2025
SOCK_TYPE_MASK = 0x0f
2126

22-
linux_socket_types = {
27+
x86_socket_types = {
2328
'SOCK_STREAM' : 0x1,
2429
'SOCK_DGRAM' : 0x2,
2530
'SOCK_RAW' : 0x3,
@@ -29,8 +34,7 @@
2934
'SOCK_PACKET' : 0xa,
3035
}
3136

32-
33-
linux_socket_domain = {
37+
x86_socket_domain = {
3438
'AF_UNSPEC' : 0x0,
3539
'AF_LOCAL' : 0x1,
3640
'AF_INET' : 0x2,
@@ -46,7 +50,7 @@
4650
}
4751

4852
# https://github.com/torvalds/linux/blob/master/include/uapi/linux/in.h
49-
linux_socket_level = {
53+
x86_socket_level = {
5054
'IPPROTO_IP' : 0x0000,
5155
'SOL_SOCKET' : 0x0001,
5256
'IPPROTO_TCP' : 0x0006,
@@ -56,7 +60,7 @@
5660
}
5761

5862

59-
linux_socket_options = {
63+
x86_socket_options = {
6064
"SO_DEBUG" : 0x0001,
6165
"SO_REUSEADDR" : 0x0002,
6266
"SO_KEEPALIVE" : 0x0009,
@@ -75,7 +79,7 @@
7579

7680
# https://man7.org/linux/man-pages/man7/ip.7.html
7781
# https://github.com/torvalds/linux/blob/master/include/uapi/linux/in.h
78-
linux_socket_ip_options = {
82+
posix_socket_ip_options = {
7983
"IP_TOS" : 0x0001,
8084
"IP_TTL" : 0x0002,
8185
"IP_HDRINCL" : 0x0003,
@@ -143,7 +147,7 @@
143147
}
144148

145149

146-
macos_socket_domain = {
150+
macos_x86_socket_domain = {
147151
'AF_UNSPEC' : 0x0,
148152
'AF_LOCAL' : 0x1,
149153
'AF_INET' : 0x2,
@@ -397,11 +401,9 @@
397401
"SO_TIMESTAMPING_NEW" : 0x0041,
398402
"SO_RCVTIMEO_NEW" : 0x0042,
399403
"SO_SNDTIMEO_NEW" : 0x0043,
400-
401404
}
402405

403-
404-
mac_open_flags = {
406+
macos_x86_open_flags = {
405407
"O_RDONLY" : 0x0000,
406408
"O_WRONLY" : 0x0001,
407409
"O_RDWR" : 0x0002,
@@ -417,8 +419,23 @@
417419
"O_DIRECTORY": 0x100000
418420
}
419421

422+
macos_arm64_open_flags = {
423+
"O_RDONLY" : 0x0000,
424+
"O_WRONLY" : 0x0001,
425+
"O_RDWR" : 0x0002,
426+
"O_NONBLOCK" : 0x0004,
427+
"O_APPEND" : 0x0008,
428+
"O_ASYNC" : 0x0040,
429+
"O_SYNC" : 0x0080,
430+
"O_NOFOLLOW" : 0x0100,
431+
"O_CREAT" : 0x0200,
432+
"O_TRUNC" : 0x0400,
433+
"O_EXCL" : 0x0800,
434+
"O_NOCTTY" : 0x20000,
435+
"O_DIRECTORY": 0x100000
436+
}
420437

421-
linux_open_flags = {
438+
x86_open_flags = {
422439
'O_RDONLY' : 0o000000000,
423440
'O_WRONLY' : 0o000000001,
424441
'O_RDWR' : 0o000000002,

0 commit comments

Comments
 (0)