More tests & unicode values

This commit is contained in:
hakril
2024-06-10 17:28:48 +02:00
parent 36b4bf38fc
commit 40f9420078
3 changed files with 43 additions and 34 deletions
+5 -1
View File
@@ -66,4 +66,8 @@ python_injection = pytest.mark.usefixtures("check_injected_python_installed")
if windows.pycompat.is_py3:
b64decode = base64.decodebytes
else:
b64decode = base64.decodestring
b64decode = base64.decodestring
def is_unicode(data):
return isinstance(data, windows.pycompat.unicode_type)
+25 -20
View File
@@ -9,34 +9,38 @@ from .pfwtest import *
@check_for_gc_garbage
class TestSystemWithCheckGarbage(object):
def test_version(self):
return windows.system.version
assert windows.system.version
def test_version_name(self):
return windows.system.version_name
assert is_unicode(windows.system.version_name)
def test_version_product_type(self):
return windows.system.product_type
assert windows.system.product_type
def test_version_edition(self):
return windows.system.edition
assert windows.system.edition
def test_version_windir(self):
return windows.system.windir
assert is_unicode(windows.system.windir)
def test_version_versionstr(self):
assert is_unicode(windows.system.windir)
def test_computer_name(self):
computer_name = windows.system.computer_name
assert computer_name
assert isinstance(computer_name, windows.pycompat.unicode_type) # Check unicode in both py2 / py3
assert is_unicode(computer_name)
def test_services(self):
return windows.system.services
assert windows.system.services
def test_logicaldrives(self):
for ldrive in windows.system.logicaldrives:
assert ldrive
assert ldrive.name
assert ldrive.path
assert is_unicode(ldrive.path)
try:
assert ldrive.volume_info
except WindowsError as e:
@@ -45,38 +49,42 @@ class TestSystemWithCheckGarbage(object):
raise
def test_wmi(self):
return windows.system.wmi
assert windows.system.wmi is not None
def test_handles(self):
return windows.system.handles
assert windows.system.handles
def test_bitness(self):
return windows.system.bitness
assert windows.system.bitness
def test_evtlog(self):
return windows.system.event_log
assert windows.system.event_log
def test_task_scheduler(self):
return windows.system.task_scheduler
assert windows.system.task_scheduler
def test_task_object_manager(self):
return windows.system.object_manager
assert windows.system.object_manager
def test_system_modules_ntosk(self):
# NtQuerySystemInformation(gdef.SystemModuleInformation) returns CHAR so not unicode
# Another Nt API that returns unicode ?
# assert is_unicode(windows.system.modules[0].name)
assert windows.system.modules[0].name.endswith(b"ntoskrnl.exe")
@check_for_gc_garbage
class TestSystemWithCheckGarbageAndHandleLeak(object):
def test_threads(self):
return windows.system.threads
assert windows.system.threads
def test_processes(self):
procs = windows.system.processes
assert windows.current_process.pid in [p.pid for p in procs]
assert is_unicode(windows.system.processes[0].name)
def test_system_modules(self):
return windows.system.modules
assert windows.system.modules
# Test environement dict
@@ -122,8 +130,5 @@ def test_unicode_environ_dict():
assert check_env_variable_exist(UNICODE_STRING_1)
def test_get_file_version():
assert windows.system.get_file_version(u"ntdll")
assert windows.system.get_file_version(u"kernel32")
res = windows.system.get_file_version(u"ntmarta")
assert res
assert isinstance(res, windows.pycompat.unicode_type)
assert is_unicode(windows.system.get_file_version(u"ntdll"))
assert is_unicode(windows.system.get_file_version(u"kernel32"))
+13 -13
View File
@@ -287,32 +287,32 @@ class System(object):
version = self.version
is_workstation = self.product_type == gdef.VER_NT_WORKSTATION
if version == (10, 0):
return ["Windows Server 2016", "Windows 10"][is_workstation]
return [u"Windows Server 2016", u"Windows 10"][is_workstation]
elif version == (6, 3):
return ["Windows Server 2012 R2", "Windows 8.1"][is_workstation]
return [u"Windows Server 2012 R2", u"Windows 8.1"][is_workstation]
elif version == (6, 2):
return ["Windows Server 2012", "Windows 8"][is_workstation]
return [u"Windows Server 2012", u"Windows 8"][is_workstation]
elif version == (6, 1):
return ["Windows Server 2008 R2", "Windows 7"][is_workstation]
return [u"Windows Server 2008 R2", u"Windows 7"][is_workstation]
elif version == (6, 0):
return ["Windows Server 2008", "Windows Vista"][is_workstation]
return [u"Windows Server 2008", u"Windows Vista"][is_workstation]
elif version == (5, 2):
metric = winproxy.GetSystemMetrics(gdef.SM_SERVERR2)
if is_workstation:
if self.bitness == 64:
return "Windows XP Professional x64 Edition"
return u"Windows XP Professional x64 Edition"
else:
return "TODO: version (5.2) + is_workstation + bitness == 32"
return u"TODO: version (5.2) + is_workstation + bitness == 32"
elif metric != 0:
return "Windows Server 2003 R2"
return u"Windows Server 2003 R2"
else:
return "Windows Server 2003"
return u"Windows Server 2003"
elif version == (5, 1):
return "Windows XP"
return u"Windows XP"
elif version == (5, 0):
return "Windows 2000"
return u"Windows 2000"
else:
return "Unknow Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
return u"Unknow Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
VERSION_MAPPER = gdef.FlagMapper(gdef.VER_NT_WORKSTATION, gdef.VER_NT_DOMAIN_CONTROLLER, gdef.VER_NT_SERVER)
@utils.fixedpropety
@@ -497,7 +497,7 @@ class System(object):
ubr = curver_key["UBR"].value
except WindowsError as e:
ubr = 0 # Not present on Win7
return "{0}.{1}.{2}.{3}".format(major, minor, build, ubr)
return u"{0}.{1}.{2}.{3}".format(major, minor, build, ubr)
except (WindowsError, ValueError):
return self.get_file_version("ntdll")