Skip to content

Commit 064b22f

Browse files
committed
Still improving tests for ARM64
1 parent 9096693 commit 064b22f

5 files changed

Lines changed: 21 additions & 6 deletions

File tree

tests/pfwtest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
process_syswow_only = pytest.mark.skipif(not is_process_syswow, reason="Test for syswow process only")
2525
require_admin = pytest.mark.skipif(not is_admin, reason="Test must be launched as admin")
2626

27+
def process_architecture_only(target_archi):
28+
return pytest.mark.skipif(windows.current_process.architecture != target_archi,
29+
reason="Test for {0} architecture process only".format(target_archi))
30+
2731

2832
check_for_gc_garbage = pytest.mark.usefixtures("check_for_gc_garbage")
2933
check_for_handle_leak = pytest.mark.usefixtures("check_for_handle_leak")

tests/test_cpuid.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import pytest
2+
13
import windows
4+
import windows.generated_def as gdef
25
import windows.native_exec.cpuid
36

47
def test_native_exec_cpuid():
8+
if windows.current_process.architecture == gdef.IMAGE_FILE_MACHINE_ARM64:
9+
pytest.skip("CPUID not testable on ARM64")
510
assert windows.native_exec.cpuid.do_cpuid(0)
611
assert windows.native_exec.cpuid.get_proc_family_model()

tests/test_native_utils.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@
88

99
from .pfwtest import *
1010

11+
12+
1113
@check_for_gc_garbage
1214
class TestNativeUtils(object):
13-
@process_64bit_only
15+
@process_architecture_only(gdef.IMAGE_FILE_MACHINE_AMD64)
1416
def test_strlenw64(self):
1517
strlenw64 = windows.native_exec.create_function(nativeutils.StrlenW64.get_code(), [gdef.UINT, gdef.LPCWSTR])
1618
assert strlenw64("YOLO") == 4
1719
assert strlenw64("") == 0
1820

19-
@process_64bit_only
21+
@process_architecture_only(gdef.IMAGE_FILE_MACHINE_AMD64)
2022
def test_strlena64(self):
2123
strlena64 = windows.native_exec.create_function(nativeutils.StrlenA64.get_code(), [gdef.UINT, gdef.LPCSTR])
2224
assert strlena64(b"YOLO") == 4
2325
assert strlena64(b"") == 0
2426

25-
@process_64bit_only
27+
@process_architecture_only(gdef.IMAGE_FILE_MACHINE_AMD64)
2628
def test_getprocaddr64(self):
2729
getprocaddr64 = windows.native_exec.create_function(nativeutils.GetProcAddress64.get_code(), [gdef.ULONG64, gdef.LPCWSTR, gdef.LPCSTR])
2830
k32 = [mod for mod in windows.current_process.peb.modules if mod.name == "kernel32.dll"][0]
@@ -37,19 +39,19 @@ def test_getprocaddr64(self):
3739
assert getprocaddr64("YOLO.DLL", b"whatever") == 0xfffffffffffffffe
3840
assert getprocaddr64("KERNEL32.DLL", b"YOLOAPI") == 0xffffffffffffffff
3941

40-
@process_32bit_only
42+
@process_architecture_only(gdef.IMAGE_FILE_MACHINE_I386)
4143
def test_strlenw32(self):
4244
strlenw32 = windows.native_exec.create_function(nativeutils.StrlenW32.get_code(), [gdef.UINT, gdef.LPCWSTR])
4345
assert strlenw32("YOLO") == 4
4446
assert strlenw32("") == 0
4547

46-
@process_32bit_only
48+
@process_architecture_only(gdef.IMAGE_FILE_MACHINE_I386)
4749
def test_strlena32(self):
4850
strlena32 = windows.native_exec.create_function(nativeutils.StrlenA32.get_code(), [gdef.UINT, gdef.LPCSTR])
4951
assert strlena32(b"YOLO") == 4
5052
assert strlena32(b"") == 0
5153

52-
@process_32bit_only
54+
@process_architecture_only(gdef.IMAGE_FILE_MACHINE_I386)
5355
def test_getprocaddr32(self):
5456
getprocaddr32 = windows.native_exec.create_function(nativeutils.GetProcAddress32.get_code(), [gdef.UINT, gdef.LPCWSTR, gdef.LPCSTR])
5557
k32 = [mod for mod in windows.current_process.peb.modules if mod.name == "kernel32.dll"][0]

tests/test_process.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def test_execute_to_proc32(self, proc32):
195195

196196
@windows_64bit_only
197197
def test_execute_to_64(self, proc64):
198+
assert proc64.architecture == gdef.IMAGE_FILE_MACHINE_AMD64, "TODO: better machine fixture for ARM64"
198199
with proc64.allocated_memory(0x1000) as addr:
199200
shellcode = x64.MultipleInstr()
200201
shellcode += x64.Mov('RAX', 0x4242424243434343)
@@ -351,6 +352,7 @@ def test_set_thread_context_32(self, proc32):
351352

352353
@windows_64bit_only
353354
def test_set_thread_context_64(self, proc64):
355+
assert proc64.architecture == gdef.IMAGE_FILE_MACHINE_AMD64, "TODO: better machine fixture for ARM64"
354356
code = x64.MultipleInstr()
355357
code += x64.Label(":LOOP")
356358
code += x64.Jmp(":LOOP")

tests/test_syswow.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def test_getset_syswow_context(self, proc32):
6969
windows.current_process.write_qword({0}, res)
7070
""".format(addr)
7171

72+
# Execute the import safely so that the test will not hang if import fails
73+
proc32.execute_python("import windows")
7274
t = proc32.execute_python_unsafe(textwrap.dedent(remote_python_code))
7375
# Wait for python execution
7476
while proc32.read_qword(addr) != 0x8877665544332211:

0 commit comments

Comments
 (0)