Skip to content

Commit 8fd20f5

Browse files
committed
Move root property from core to OS
1 parent 75ca9cd commit 8fd20f5

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

examples/netgear_6220_mips32el_linux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def my_bind(ql: Qiling):
5858

5959
def my_netgear(path, rootfs):
6060
ql = Qiling(path, rootfs, verbose=QL_VERBOSE.DEBUG, profile="netgear_6220.ql", multithread=False)
61-
ql.root = False
61+
ql.os.root = False
6262

6363
ql.add_fs_mapper('/proc', '/proc')
6464
ql.set_syscall(4004, my_syscall_write)

qiling/core.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ def __init__(
9595
self._patch_lib = []
9696
self._debug_stop = False
9797
self._debugger = None
98-
self._root = False
9998

10099
###############################
101100
# Properties configured later #
@@ -574,19 +573,6 @@ def debugger(self) -> Union[str, bool]:
574573
def debugger(self, dbger):
575574
self._debugger = dbger
576575

577-
@property
578-
def root(self) -> bool:
579-
""" Whether run current program as root?
580-
581-
Type: bool
582-
Examples: ql.root = True
583-
"""
584-
return self._root
585-
586-
@root.setter
587-
def root(self, root):
588-
self._root = root
589-
590576
@property
591577
def filter(self) -> str:
592578
""" Filter logs with regex.

qiling/os/os.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ def stdout(self, stream: TextIO) -> None:
123123
def stderr(self, stream: TextIO) -> None:
124124
self._stderr = stream
125125

126+
@property
127+
def root(self) -> bool:
128+
"""An indication whether the process is running as root.
129+
"""
130+
131+
# for this to work the os derivative should override this property
132+
# and implement the os logic. in case it is not, return False
133+
return False
134+
135+
@root.setter
136+
def root(self, enabled: bool) -> None:
137+
raise NotImplementedError('Running as root is not implemented for this OS')
138+
126139
def resolve_fcall_params(self, params: Mapping[str, Any]) -> Mapping[str, Any]:
127140
"""Transform function call raw parameters values into meaningful ones, according to
128141
their assigned type.

qiling/os/posix/syscall/socket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def ql_syscall_bind(ql: Qiling, bind_fd, bind_addr, bind_addrlen):
301301
port, host = struct.unpack(">HI", data[2:8])
302302
host = ql_bin_to_ip(host)
303303

304-
if ql.root == False and port <= 1024:
304+
if not ql.os.root and port <= 1024:
305305
port = port + 8000
306306

307307
if sin_family == 1:

0 commit comments

Comments
 (0)