Skip to content

Commit bc8bd60

Browse files
committed
Merge branch 'change-to-v3' of github.com:ptr-yudai/ptrlib into change-to-v3
2 parents b642a5d + 098706f commit bc8bd60

7 files changed

Lines changed: 91 additions & 50 deletions

File tree

.github/workflows/test-on-pr-ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
22+
python-version: ["3.10", "3.11", "3.12"]
2323

2424
steps:
2525
- uses: actions/checkout@v4

.github/workflows/test-on-pr-windows.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
- 'ptrlib/**'
1212
- 'tests/**'
1313
pull_request:
14+
workflow_dispatch:
1415

1516
jobs:
1617
build:
@@ -31,6 +32,7 @@ jobs:
3132
run: |
3233
python -m pip install --upgrade pip
3334
if( Test-Path .\requirements.txt ){ pip install -r requirements.txt }
35+
pip install capstone keystone-engine
3436
- name: Test with pytest
3537
run: |
3638
'```' >> $env:GITHUB_STEP_SUMMARY

ptrlib/debugger/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
from .unix import *
2-
#from .windows import *
1+
import os
2+
3+
if os.name == 'nt':
4+
#from .windows import *
5+
pass
6+
else:
7+
from .unix import *

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='ptrlib',
13-
version='2.5.0',
13+
version='3.0.0',
1414
description='CTF library',
1515
long_description=long_description,
1616
long_description_content_type='text/markdown',
@@ -19,14 +19,14 @@
1919
author_email='ptr.yudai+dev@gmail.com',
2020
classifiers=[
2121
'License :: OSI Approved :: MIT License',
22-
'Programming Language :: Python :: 3.8',
23-
'Programming Language :: Python :: 3.9',
2422
'Programming Language :: Python :: 3.10',
2523
'Programming Language :: Python :: 3.11',
24+
'Programming Language :: Python :: 3.12',
25+
'Programming Language :: Python :: 3.13',
2626
],
2727
keywords='pwn crypto algorithm',
2828
packages=find_packages(exclude=['examples', 'tests']),
29-
python_requires='>=3.8',
29+
python_requires='>=3.10',
3030
install_requires=['pycryptodome', "pywin32; platform_system=='Windows'"],
3131
entry_points={
3232
'console_scripts': [

tests/cpu/intel/test_assembler.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1+
import os
12
import unittest
2-
from ptrlib.cpu import CPU
33
from logging import getLogger, FATAL
4+
from ptrlib.cpu import CPU
5+
6+
_is_windows = os.name == 'nt'
47

58
# TODO: Test AT&T syntax
69

7-
const_gcc = '.byte 0; .word 1; .long 2; .quad 3; .asciz "/bin/sh"; .ascii "/bin/sh"'
8-
const_gcc_bytes = \
10+
CONST_GCC = '.byte 0; .word 1; .long 2; .quad 3; .asciz "/bin/sh"; .ascii "/bin/sh"'
11+
CONST_GCC_BYTES = \
912
b'\x00\x01\x00\x02\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00' \
1013
b'/bin/sh\0/bin/sh'
1114

12-
const_nasm = 'db 0; dw 1; dd 2; dq 3; db "/bin/sh", 0; db "/bin/sh"'
13-
const_nasm_bytes = \
15+
CONST_NASM = 'db 0; dw 1; dd 2; dq 3; db "/bin/sh", 0; db "/bin/sh"'
16+
CONST_NASM_BYTES = \
1417
b'\x00\x01\x00\x02\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00' \
1518
b'/bin/sh\0/bin/sh'
1619

17-
shellcode_32 = """
20+
SHELLCODE_32 = """
1821
push 0x30
1922
pop eax
2023
xor al, 0x30 // omit eax, ecx
@@ -27,9 +30,9 @@
2730
popad
2831
dec edx /* edx = 0xffffffff */
2932
"""
30-
shellcode_32_bytes = b'j0X40PPPPQPaJ'
33+
SHELLCODE_32_BYTES = b'j0X40PPPPQPaJ'
3134

32-
shellcode_64 = """
35+
SHELLCODE_64 = """
3336
movabs rax, qword ptr gs:[0x188] // Prcb.CurrentThread
3437
mov rax, qword ptr [rax + 0xb8] // ApcState.Process
3538
mov rcx, rax
@@ -63,7 +66,7 @@
6366
swapgs
6467
sysretq
6568
"""
66-
shellcode_64_bytes = \
69+
SHELLCODE_64_BYTES = \
6770
b"\x65\x48\xa1\x88\x01\x00\x00\x00\x00\x00\x00" \
6871
b"\x48\x8b\x80\xb8\x00\x00\x00" \
6972
b"\x48\x89\xc1" \
@@ -92,12 +95,17 @@
9295
b"\x48\x0f\x07"
9396

9497
class TestIntelAssembler(unittest.TestCase):
98+
"""Test Intel assembler
99+
"""
95100
def setUp(self):
96101
getLogger("ptrlib").setLevel(FATAL)
97102

98103
def test_32bit_gcc(self):
99104
"""Test assembler for Intel 32-bit GCC
100105
"""
106+
if _is_windows:
107+
return # Skip windows
108+
101109
cpu = CPU('intel', 32)
102110
cpu.assembler = 'gcc'
103111

@@ -116,10 +124,10 @@ def test_32bit_gcc(self):
116124
self.assertEqual(cpu.assemble('call far [esp]'), b'\xff\x94$\x06\xff\x00\x00')
117125

118126
# Test long code
119-
self.assertEqual(cpu.assemble(shellcode_32), shellcode_32_bytes)
127+
self.assertEqual(cpu.assemble(SHELLCODE_32), SHELLCODE_32_BYTES)
120128

121129
# Test constant
122-
self.assertEqual(cpu.assemble(const_gcc), const_gcc_bytes)
130+
self.assertEqual(cpu.assemble(CONST_GCC), CONST_GCC_BYTES)
123131

124132
# Test exception
125133
with self.assertRaises(OSError):
@@ -130,6 +138,9 @@ def test_32bit_gcc(self):
130138
def test_64bit_gcc(self):
131139
"""Test assembler for Intel 64-bit GCC
132140
"""
141+
if _is_windows:
142+
return # Skip windows
143+
133144
cpu = CPU('intel', 64)
134145
cpu.assembler = 'gcc'
135146

@@ -148,10 +159,10 @@ def test_64bit_gcc(self):
148159
self.assertEqual(cpu.assemble('call far [rsp]'), b'\xff\x94$\x06\xff\x00\x00')
149160

150161
# Test long code
151-
self.assertEqual(cpu.assemble(shellcode_64), shellcode_64_bytes)
162+
self.assertEqual(cpu.assemble(SHELLCODE_64), SHELLCODE_64_BYTES)
152163

153164
# Test constant
154-
self.assertEqual(cpu.assemble(const_gcc), const_gcc_bytes)
165+
self.assertEqual(cpu.assemble(CONST_GCC), CONST_GCC_BYTES)
155166

156167
# Test exception
157168
with self.assertRaises(OSError):
@@ -179,10 +190,10 @@ def test_32bit_keystone(self):
179190
self.assertEqual(cpu.assemble('A: /* infinite call */ call A'), b'\xe8\xfb\xff\xff\xff')
180191

181192
# Test long code
182-
self.assertEqual(cpu.assemble(shellcode_32), shellcode_32_bytes)
193+
self.assertEqual(cpu.assemble(SHELLCODE_32), SHELLCODE_32_BYTES)
183194

184195
# Test constant
185-
self.assertEqual(cpu.assemble(const_gcc), const_gcc_bytes)
196+
self.assertEqual(cpu.assemble(CONST_GCC), CONST_GCC_BYTES)
186197

187198
# Test exception
188199
with self.assertRaises(OSError):
@@ -211,7 +222,7 @@ def test_64bit_keystone(self):
211222
self.assertEqual(cpu.assemble('A: /* infinite call */ call A'), b'\xe8\xfb\xff\xff\xff')
212223

213224
# Test constant
214-
self.assertEqual(cpu.assemble(const_gcc), const_gcc_bytes)
225+
self.assertEqual(cpu.assemble(CONST_GCC), CONST_GCC_BYTES)
215226

216227
# Test exception
217228
with self.assertRaises(OSError):
@@ -222,6 +233,9 @@ def test_64bit_keystone(self):
222233
def test_32bit_nasm(self):
223234
"""Test assembler for Intel 32-bit nasm
224235
"""
236+
if _is_windows:
237+
return # Skip windows
238+
225239
cpu = CPU('intel', 32)
226240
cpu.assembler = 'nasm'
227241

@@ -238,10 +252,10 @@ def test_32bit_nasm(self):
238252
self.assertEqual(cpu.assemble('A: /* infinite call */ call A'), b'\xe8\xfb\xff\xff\xff')
239253

240254
# Test long code
241-
self.assertEqual(cpu.assemble(shellcode_32), shellcode_32_bytes)
255+
self.assertEqual(cpu.assemble(SHELLCODE_32), SHELLCODE_32_BYTES)
242256

243257
# Test constant
244-
self.assertEqual(cpu.assemble(const_nasm), const_nasm_bytes)
258+
self.assertEqual(cpu.assemble(CONST_NASM), CONST_NASM_BYTES)
245259

246260
# Test exception
247261
with self.assertRaises(OSError):
@@ -252,6 +266,9 @@ def test_32bit_nasm(self):
252266
def test_64bit_nasm(self):
253267
"""Test assembler for Intel 64-bit nasm
254268
"""
269+
if _is_windows:
270+
return # Skip windows
271+
255272
cpu = CPU('intel', 64)
256273
cpu.assembler = 'nasm'
257274

@@ -269,7 +286,7 @@ def test_64bit_nasm(self):
269286
self.assertEqual(cpu.assemble('A: /* infinite call */ call A'), b'\xe8\xfb\xff\xff\xff')
270287

271288
# Test constant
272-
self.assertEqual(cpu.assemble(const_nasm), const_nasm_bytes)
289+
self.assertEqual(cpu.assemble(CONST_NASM), CONST_NASM_BYTES)
273290

274291
# Test exception
275292
with self.assertRaises(OSError):

0 commit comments

Comments
 (0)