Skip to content

Commit 6bf4673

Browse files
committed
Better handling of standard streams on Windows
1 parent 60105fe commit 6bf4673

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

qiling/os/windows/windows.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55

66
import ntpath
7-
from typing import Callable
7+
from typing import Callable, TextIO
88

99
from unicorn import UcError
1010

@@ -93,6 +93,39 @@ def __make_fcall_selector(atype: QL_ARCH) -> Callable[[int], QlFunctionCall]:
9393
self.services = {}
9494
self.load()
9595

96+
# only after handle manager has been set up we can assign the standard streams
97+
self.stdin = self._stdin
98+
self.stdout = self._stdout
99+
self.stderr = self._stderr
100+
101+
102+
@QlOs.stdin.setter
103+
def stdin(self, stream: TextIO) -> None:
104+
self._stdin = stream
105+
106+
handle = self.handle_manager.get(const.STD_INPUT_HANDLE)
107+
assert handle is not None
108+
109+
handle.obj = stream
110+
111+
@QlOs.stdout.setter
112+
def stdout(self, stream: TextIO) -> None:
113+
self._stdout = stream
114+
115+
handle = self.handle_manager.get(const.STD_OUTPUT_HANDLE)
116+
assert handle is not None
117+
118+
handle.obj = stream
119+
120+
@QlOs.stderr.setter
121+
def stderr(self, stream: TextIO) -> None:
122+
self._stderr = stream
123+
124+
handle = self.handle_manager.get(const.STD_ERROR_HANDLE)
125+
assert handle is not None
126+
127+
handle.obj = stream
128+
96129

97130
def load(self):
98131
self.setupGDT()

0 commit comments

Comments
 (0)