Skip to content

Commit

Permalink
Improve Process selection to indicate actual implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jptomoya committed Apr 8, 2024
1 parent a87f787 commit ff6455a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
10 changes: 2 additions & 8 deletions ptrlib/connection/proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
logger = getLogger(__name__)


def Process(*args, **kwargs) -> Tube:
if _is_windows:
return WinProcess(*args, **kwargs)
else:
return UnixProcess(*args, **kwargs)

class UnixProcess(Tube):
def __init__(
self,
Expand Down Expand Up @@ -241,5 +235,5 @@ def wait(self) -> int:
def __del__(self):
self.close()

# alias
process = Process
Process = WinProcess if _is_windows else UnixProcess
process = Process # alias for the Process
11 changes: 7 additions & 4 deletions tests/connection/test_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest
from logging import FATAL, getLogger

from ptrlib import Process, UnixProcess, is_scanf_safe
from ptrlib import Process, is_scanf_safe

_is_windows = os.name == 'nt'

Expand All @@ -16,7 +16,7 @@ def setUp(self):
self.skipTest("This test is intended for the Linux platform")

def test_basic(self):
module_name = inspect.getmodule(UnixProcess).__name__
module_name = inspect.getmodule(Process).__name__

while True:
msg = os.urandom(16)
Expand Down Expand Up @@ -67,10 +67,13 @@ def test_basic(self):
# wait
self.assertEqual(p.wait(), 0)

p.close()
with self.assertLogs(module_name) as cm:
p.close()
self.assertEqual(len(cm.output), 1)
self.assertRegex(cm.output[0], fr'^INFO:{module_name}:.+ \(PID=\d+\) has already exited$')

def test_timeout(self):
module_name = inspect.getmodule(UnixProcess).__name__
module_name = inspect.getmodule(Process).__name__

with self.assertLogs(module_name) as cm:
p = Process("./tests/test.bin/test_echo.x64")
Expand Down
6 changes: 3 additions & 3 deletions tests/connection/test_windows_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import unittest
from logging import FATAL, getLogger

from ptrlib import Process, WinProcess, is_scanf_safe
from ptrlib import Process, is_scanf_safe

_is_windows = os.name == 'nt'

Expand All @@ -17,7 +17,7 @@ def setUp(self):
self.skipTest("This test is for Windows architecture")

def test_basic(self):
module_name = inspect.getmodule(WinProcess).__name__
module_name = inspect.getmodule(Process).__name__

while True:
msg = os.urandom(16)
Expand Down Expand Up @@ -53,7 +53,7 @@ def test_basic(self):
self.assertFalse(str(pid) in subprocess.getoutput(f'tasklist /FI "PID eq {pid}"').split())

def test_timeout(self):
module_name = inspect.getmodule(WinProcess).__name__
module_name = inspect.getmodule(Process).__name__

with self.assertLogs(module_name) as cm:
p = Process("./tests/test.bin/test_echo.pe.exe")
Expand Down
6 changes: 3 additions & 3 deletions tests/pwn/test_fsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest
from logging import FATAL, getLogger

from ptrlib import Process, UnixProcess, fsb
from ptrlib import Process, fsb

_is_windows = os.name == 'nt'

Expand All @@ -16,7 +16,7 @@ def setUp(self):
self.skipTest("This test has not been implemented for Windows yet")

def test_fsb32(self):
module_name = inspect.getmodule(UnixProcess).__name__
module_name = inspect.getmodule(Process).__name__

# test 1
for i in range(3):
Expand Down Expand Up @@ -58,7 +58,7 @@ def test_fsb32(self):
p.close()

def test_fsb64(self):
module_name = inspect.getmodule(UnixProcess).__name__
module_name = inspect.getmodule(Process).__name__

# test 3
for i in range(3):
Expand Down

0 comments on commit ff6455a

Please sign in to comment.