From a7175be425ad1fb28e2539b1e43979a05afe7929 Mon Sep 17 00:00:00 2001 From: hakril Date: Sun, 2 Feb 2020 18:11:13 +0100 Subject: [PATCH] Added/fixed some test --- tests/test_process.py | 4 ++-- tests/test_service.py | 4 ++-- tests/test_simple_x64.py | 2 +- tests/test_simple_x86.py | 18 +++++++++++++++++- tests/test_winproxy.py | 22 ++++++++++++++++++++-- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/tests/test_process.py b/tests/test_process.py index 0871626..adc84d6 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -12,7 +12,7 @@ import windows.generated_def as gdef import windows.native_exec.simple_x86 as x86 import windows.native_exec.simple_x64 as x64 -from pfwtest import * +from .pfwtest import * @check_for_gc_garbage class TestCurrentProcessWithCheckGarbage(object): @@ -330,7 +330,7 @@ class TestProcessWithCheckGarbage(object): assert len(dlls) == 1 injecteddll = dlls[0] # Check that the DLL is the one we asked to load - assert injecteddll.fullname == targetname + assert injecteddll.fullname.lower() == targetname.lower() # UNICODE_PATH_NAME = u'\u4e2d\u56fd\u94f6\u884c\u7f51\u94f6\u52a9\u624b' diff --git a/tests/test_service.py b/tests/test_service.py index 828d017..0676ce1 100644 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -5,10 +5,10 @@ import windows.generated_def as gdef def test_services_process(): - services_with_process = [s for s in windows.system.services if s.ServiceStatusProcess.dwProcessId] + services_with_process = [s for s in windows.system.services if s.status.dwProcessId] service = services_with_process[0] proc = service.process - assert proc.pid == service.ServiceStatusProcess.dwProcessId + assert proc.pid == service.status.dwProcessId def test_service_appinfo(): diff --git a/tests/test_simple_x64.py b/tests/test_simple_x64.py index 38f5531..01fb65f 100644 --- a/tests/test_simple_x64.py +++ b/tests/test_simple_x64.py @@ -15,7 +15,7 @@ if capstone: @pytest.fixture def need_capstone(): if capstone is None: - raise pytest.Skip("Capstone is not installed") + raise pytest.skip("Capstone is not installed") return True pytestmark = pytest.mark.usefixtures("need_capstone") diff --git a/tests/test_simple_x86.py b/tests/test_simple_x86.py index 224bd1b..c115fb0 100644 --- a/tests/test_simple_x86.py +++ b/tests/test_simple_x86.py @@ -9,6 +9,8 @@ import windows.native_exec.simple_x86 as x86 from windows.native_exec.simple_x86 import * del Test # Prevent pytest warning +VERBOSE = False + if capstone: disassembleur = capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_32) disassembleur.detail = True @@ -16,7 +18,7 @@ if capstone: @pytest.fixture def need_capstone(): if capstone is None: - raise pytest.Skip("Capstone is not installed") + raise pytest.skip("Capstone is not installed") return True pytestmark = pytest.mark.usefixtures("need_capstone") @@ -47,6 +49,9 @@ class CheckInstr(object): if len(res) != len(capres.bytes): raise AssertionError("Not all bytes have been used by the disassembler") + if VERBOSE: + print(" * [CODE] {0}".format(repr(res))) + print(" * [DISAS] {0} {1}".format(capres.mnemonic, capres.op_str)) if self.expected_result is not None: if "{0} {1}".format(capres.mnemonic, capres.op_str) == self.expected_result: @@ -129,6 +134,17 @@ def test_assembler(): CheckInstr(Mov)('AX', mem('fs:[0x30]')) CheckInstr(Mov)('AX', mem('fs:[EAX + 0x30]')) CheckInstr(Mov)('AX', mem('fs:[EAX + ECX * 4+0x30]')) + # Segment selector + CheckInstr(Mov)('SS', 'ECX') + CheckInstr(Mov)('ECX', 'SS') + CheckInstr(Mov)('EDX', 'es') + CheckInstr(Mov)('EDX', 'cs') + CheckInstr(Mov)('EDX', 'ds') + CheckInstr(Mov)('EDX', 'fs') + CheckInstr(Mov)('fs', 'eax') + CheckInstr(Mov)('fs', 'eax') + + CheckInstr(Add)('EAX', 8) CheckInstr(Add)('EAX', 0xffffffff) CheckInstr(Add)("ECX", mem("[EAX + 0xff]")) diff --git a/tests/test_winproxy.py b/tests/test_winproxy.py index 9b66bfa..ada46fb 100644 --- a/tests/test_winproxy.py +++ b/tests/test_winproxy.py @@ -3,7 +3,7 @@ import pytest import windows import windows.generated_def as gdef -from pfwtest import * +from .pfwtest import * pytestmark = pytest.mark.usefixtures('check_for_gc_garbage') @@ -15,4 +15,22 @@ def test_createfileA_fail(): def test_lstrcmpa(): assert windows.winproxy.lstrcmpA("LOL", "NO-LOL") - assert not windows.winproxy.lstrcmpA("LOL", "LOL") \ No newline at end of file + assert not windows.winproxy.lstrcmpA("LOL", "LOL") + +def test_getsystemmetrics(): + """Test nothing is raised when GetSystemMetrics() returns 0""" + # Using a suit of value that may return 0 + windows.winproxy.GetSystemMetrics(gdef.SM_DIGITIZER) + windows.winproxy.GetSystemMetrics(gdef.SM_CLEANBOOT) + windows.winproxy.GetSystemMetrics(gdef.SM_MOUSEHORIZONTALWHEELPRESENT) + windows.winproxy.GetSystemMetrics(gdef.SM_SERVERR2) + windows.winproxy.GetSystemMetrics(gdef.SM_SLOWMACHINE) + windows.winproxy.GetSystemMetrics(gdef.SM_SWAPBUTTON) + windows.winproxy.GetSystemMetrics(gdef.SM_TABLETPC) + + +def test_resolve(): + ntdll = windows.current_process.peb.modules[1] + assert ntdll.name == "ntdll.dll" + assert ntdll.pe.exports["NtCreateFile"] == windows.winproxy.resolve(windows.winproxy.NtCreateFile) +