Skip to content

Commit

Permalink
Merge pull request #25 from jptomoya/test-on-windows
Browse files Browse the repository at this point in the history
Add a workflow for testing on Windows
  • Loading branch information
ptr-yudai authored Feb 20, 2024
2 parents 2666e11 + 93471d0 commit 50bf0c6
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 2 deletions.
File renamed without changes.
31 changes: 31 additions & 0 deletions .github/workflows/test-on-pr-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python Test (Windows)

on: [push, pull_request]

jobs:
build:

runs-on: windows-latest
timeout-minutes: 10
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if( Test-Path .\requirements.txt ){ pip install -r requirements.txt }
- name: Test with pytest
run: |
'```' >> $env:GITHUB_STEP_SUMMARY
python -m unittest *>> $env:GITHUB_STEP_SUMMARY
'```' >> $env:GITHUB_STEP_SUMMARY
6 changes: 4 additions & 2 deletions ptrlib/connection/winproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def recv(self, size: int=4096, timeout: Optional[Union[int, float]]=None):

return self._recv(min(self.size, size))

def _send(self, data: bytes):
def send(self, data: bytes):
"""Send raw data
Send raw data through the socket
Expand Down Expand Up @@ -153,6 +153,7 @@ def __init__(self, args: Union[List[Union[str, bytes]], str], env: Optional[Mapp
self.stdout = WinPipe()
self.default_timeout = timeout
self.timeout = timeout
self.proc = None

# Create process
info = win32process.STARTUPINFO()
Expand Down Expand Up @@ -215,11 +216,12 @@ def is_alive(self) -> bool:

def close(self):
if self.proc:
win32api.TerminateProcess(self.proc, 0)
win32api.CloseHandle(self.proc)
self.proc = None
logger.info("Process killed (PID={0})".format(self.pid))

def send(self, data: bytes):
def _send(self, data: bytes):
"""Send raw data
Send raw data through the socket
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pycryptodome
pywin32; platform_system=='Windows'
4 changes: 4 additions & 0 deletions tests/connection/test_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
from ptrlib import Process, is_scanf_safe
from logging import getLogger, FATAL

_is_windows = os.name == 'nt'


class TestProcess(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)
if _is_windows:
self.skipTest("This test is intended for the Linux platform")

def test_basic(self):
while True:
Expand Down
3 changes: 3 additions & 0 deletions tests/connection/test_windows_proc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import os
import random
import subprocess
from ptrlib import Process, is_scanf_safe
from logging import getLogger, FATAL

Expand All @@ -20,6 +21,7 @@ def test_basic(self):
break

p = Process("./tests/test.bin/test_echo.pe.exe")
pid = p.pid

# send / recv
p.sendline(b"Message : " + msg)
Expand All @@ -41,6 +43,7 @@ def test_basic(self):
self.assertEqual(p.is_alive(), True)
p.close()
self.assertEqual(p.is_alive(), False)
self.assertFalse(str(pid) in subprocess.getoutput(f'tasklist /FI "PID eq {pid}"').split())

def test_timeout(self):
p = Process("./tests/test.bin/test_echo.pe.exe")
Expand Down
5 changes: 5 additions & 0 deletions tests/filestruct/elf/test_elf_1.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import unittest
import os
from ptrlib.filestruct.elf import ELF
from logging import getLogger, FATAL

_is_windows = os.name == 'nt'


PATH_ELF = "./tests/test.bin/libc-2.27.so"
BASE = 0x7fffdeadb000

class TestELF1(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)
if _is_windows:
self.skipTest("This test is intended for the Linux platform")
self.elf = ELF(PATH_ELF)

def test_symbol(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/filestruct/elf/test_elf_2.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import unittest
import os
from ptrlib.filestruct.elf import ELF
from logging import getLogger, FATAL

_is_windows = os.name == 'nt'


PATH_ELF = "./tests/test.bin/libc-2.31.so"
BASE = 0x7fffdeadb000

class TestELF2(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)
if _is_windows:
self.skipTest("This test is intended for the Linux platform")
self.elf = ELF(PATH_ELF)

def test_symbol(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/filestruct/elf/test_elf_3.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import unittest
import os
from ptrlib.filestruct.elf import ELF
from logging import getLogger, FATAL

_is_windows = os.name == 'nt'


PATH_ELF = "./tests/test.bin/libc-2.34.so"
BASE = 0x7fffdeadb000

class TestELF3(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)
if _is_windows:
self.skipTest("This test is intended for the Linux platform")
self.elf = ELF(PATH_ELF)

def test_symbol(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/filestruct/elf/test_elf_4.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import unittest
import os
from ptrlib.filestruct.elf import ELF
from logging import getLogger, FATAL

_is_windows = os.name == 'nt'


PATH_ELF = "./tests/test.bin/test_echo.x86"
BASE = 0x7fdea000

class TestELF4(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)
if _is_windows:
self.skipTest("This test is intended for the Linux platform")
self.elf = ELF(PATH_ELF)

def test_plt(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/filestruct/elf/test_elf_5.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import unittest
import os
from ptrlib.filestruct.elf import ELF
from logging import getLogger, FATAL

_is_windows = os.name == 'nt'


PATH_ELF = "./tests/test.bin/test_echo.x64"
BASE = 0x555555554000

class TestELF5(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)
if _is_windows:
self.skipTest("This test is intended for the Linux platform")
self.elf = ELF(PATH_ELF)

def test_plt(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/filestruct/elf/test_elf_6.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import unittest
import os
from ptrlib.filestruct.elf import ELF
from logging import getLogger, FATAL

_is_windows = os.name == 'nt'


PATH_ELF = "./tests/test.bin/test_fsb.x86"

class TestELF6(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)
if _is_windows:
self.skipTest("This test is intended for the Linux platform")
self.elf = ELF(PATH_ELF)

def test_plt(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/filestruct/elf/test_elf_7.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import unittest
import os
from ptrlib.filestruct.elf import ELF
from logging import getLogger, FATAL

_is_windows = os.name == 'nt'


PATH_ELF = "./tests/test.bin/test_fsb.x64"

class TestELF7(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)
if _is_windows:
self.skipTest("This test is intended for the Linux platform")
self.elf = ELF(PATH_ELF)

def test_plt(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/filestruct/elf/test_elf_8.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import unittest
import os
from ptrlib.filestruct.elf import ELF
from logging import getLogger, FATAL

_is_windows = os.name == 'nt'


PATH_ELF = "./tests/test.bin/test_plt.x64"

class TestELF8(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)
if _is_windows:
self.skipTest("This test is intended for the Linux platform")
self.elf = ELF(PATH_ELF)

def test_plt(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/filestruct/elf/test_elf_9.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import unittest
import os
from ptrlib.filestruct.elf import ELF
from logging import getLogger, FATAL

_is_windows = os.name == 'nt'


PATH_ELF = "./tests/test.bin/libc-2.35.so"
BASE = 0x7fffdeadb000

class TestELF9(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)
if _is_windows:
self.skipTest("This test is intended for the Linux platform")
self.elf = ELF(PATH_ELF)

def test_symbol(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/pwn/test_fsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
from ptrlib import Process, fsb
from logging import getLogger, FATAL

_is_windows = os.name == 'nt'


class TestFSB(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)
if _is_windows:
# TODO: Implement test for Windows
self.skipTest("This test has not been implemented for Windows yet")

def test_fsb32(self):
# test 1
Expand Down

0 comments on commit 50bf0c6

Please sign in to comment.