From 3cc980e0ce5764cdc152ccdc8841d03b3971e44a Mon Sep 17 00:00:00 2001 From: anotherdish Date: Sun, 22 Jan 2023 19:32:17 -0500 Subject: [PATCH 1/3] added a pipe that can be used when a user wants to run the emulation, but still be able to interact with stdin, similar to the pwntools interact() function --- qiling/extensions/pipe.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/qiling/extensions/pipe.py b/qiling/extensions/pipe.py index f88c27135..50c55a0bb 100644 --- a/qiling/extensions/pipe.py +++ b/qiling/extensions/pipe.py @@ -86,4 +86,21 @@ class SimpleBufferedStream(io.BytesIO): """ def __init__(self): - super.__init__() \ No newline at end of file + super.__init__() + +class InteractiveInStream(io.BytesIO): + def read(self, size): + ''' + We want read to get user input if theres no data left in the buffer + ''' + + #get the amount of bytes left in the buffer + bytes_left = self.getbuffer().nbytes - self.tell() + + #if theres no bytes left in the buffer, get user input + if bytes_left == 0: + user_data = input().encode()+ b'\x0a' + self.write(user_data) + self.seek(-len(user_data), io.SEEK_CUR) + + return super().read(size) \ No newline at end of file From da46fbe14ec90b53cc8ee442249ca5dc4398757f Mon Sep 17 00:00:00 2001 From: anotherdish Date: Sun, 22 Jan 2023 19:35:51 -0500 Subject: [PATCH 2/3] clarified documentation --- qiling/extensions/pipe.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/qiling/extensions/pipe.py b/qiling/extensions/pipe.py index 50c55a0bb..e00af1276 100644 --- a/qiling/extensions/pipe.py +++ b/qiling/extensions/pipe.py @@ -89,9 +89,14 @@ def __init__(self): super.__init__() class InteractiveInStream(io.BytesIO): - def read(self, size): + def read(self, size: int): ''' - We want read to get user input if theres no data left in the buffer + Read from the BytesIO buffer. If theres no data left in the buffer, get additional user input + + Args: + size (int): The amount of bytes to read from the buffer + Returns: + bytes: The data read from the buffer ''' #get the amount of bytes left in the buffer From 1602bc03d8f64b92b64076fa39e6a71682460457 Mon Sep 17 00:00:00 2001 From: me Date: Mon, 23 Jan 2023 11:50:10 -0500 Subject: [PATCH 3/3] forgot to type hint the return value --- qiling/extensions/pipe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiling/extensions/pipe.py b/qiling/extensions/pipe.py index e00af1276..f69d1e326 100644 --- a/qiling/extensions/pipe.py +++ b/qiling/extensions/pipe.py @@ -89,7 +89,7 @@ def __init__(self): super.__init__() class InteractiveInStream(io.BytesIO): - def read(self, size: int): + def read(self, size: int) -> bytes: ''' Read from the BytesIO buffer. If theres no data left in the buffer, get additional user input