From bae093a549a64d6638e8a250dff582b60c6bb5e2 Mon Sep 17 00:00:00 2001 From: Sammy Date: Wed, 12 Mar 2025 13:14:36 +0100 Subject: [PATCH 1/3] added suggested solution for the bug taking into account the version of windows --- htpclient/initialize.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/htpclient/initialize.py b/htpclient/initialize.py index 8e1431c..8025618 100644 --- a/htpclient/initialize.py +++ b/htpclient/initialize.py @@ -104,13 +104,27 @@ def __update_information(self): devices.append(line[1].strip()) elif Initialize.get_os() == 1: # windows - output = subprocess.check_output("wmic cpu get name", shell=True) - output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") - for line in output: - line = line.rstrip("\r\n ") - if line == "Name" or not line: - continue - devices.append(line) + platform_release = platform.uname().release + if int(platform_release) >= 10: + processor_information = subprocess.check_output( + 'powershell -Command "Get-CimInstance Win32_Processor | Select-Object -ExpandProperty Name"', + shell=True) + processor_information = processor_information.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + for line in processor_information: + line = line.rstrip("\r\n ") + if line == "Name" or not line: + continue + devices.append(line) + else: + processor_information = subprocess.check_output( + 'powershell -Command "Get-WmiObject Win32_Processor | Select-Object -ExpandProperty Name"', + shell=True) + processor_information = processor_information.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + for line in processor_information: + line = line.rstrip("\r\n ") + if line == "Name" or not line: + continue + devices.append(line) output = subprocess.check_output("wmic path win32_VideoController get name", shell=True) output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") for line in output: From a54adb611277b2b8c8af43701f3291a47189b4a0 Mon Sep 17 00:00:00 2001 From: Sammy Date: Thu, 13 Mar 2025 13:56:16 +0100 Subject: [PATCH 2/3] Added more fallbacks, deduplicated some code --- htpclient/initialize.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/htpclient/initialize.py b/htpclient/initialize.py index 8025618..3566592 100644 --- a/htpclient/initialize.py +++ b/htpclient/initialize.py @@ -105,33 +105,28 @@ def __update_information(self): elif Initialize.get_os() == 1: # windows platform_release = platform.uname().release - if int(platform_release) >= 10: + if platform_release == "" or int(platform_release) >= 10: processor_information = subprocess.check_output( 'powershell -Command "Get-CimInstance Win32_Processor | Select-Object -ExpandProperty Name"', shell=True) processor_information = processor_information.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") - for line in processor_information: - line = line.rstrip("\r\n ") - if line == "Name" or not line: - continue - devices.append(line) + video_controller = subprocess.check_output( + 'powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name"', + shell=True) + video_controller = video_controller.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") else: processor_information = subprocess.check_output( - 'powershell -Command "Get-WmiObject Win32_Processor | Select-Object -ExpandProperty Name"', + 'wmic cpu get name', shell=True) processor_information = processor_information.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") - for line in processor_information: + video_controller = subprocess.check_output('wmic path win32_VideoController get name', shell=True) + video_controller = video_controller.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + + for source in (processor_information, video_controller): + for line in source: line = line.rstrip("\r\n ") - if line == "Name" or not line: - continue - devices.append(line) - output = subprocess.check_output("wmic path win32_VideoController get name", shell=True) - output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") - for line in output: - line = line.rstrip("\r\n ") - if line == "Name" or not line: - continue - devices.append(line) + if line and line != "Name": + devices.append(line) else: # OS X output = subprocess.check_output("system_profiler SPDisplaysDataType -detaillevel mini", shell=True) From 34d64761ee2227841f72712a668c2a8974f75424 Mon Sep 17 00:00:00 2001 From: Sammy Date: Mon, 17 Mar 2025 08:45:32 +0100 Subject: [PATCH 3/3] moved the decoding out to a function to then be called --- htpclient/initialize.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/htpclient/initialize.py b/htpclient/initialize.py index 3566592..7fdcd8f 100644 --- a/htpclient/initialize.py +++ b/htpclient/initialize.py @@ -63,6 +63,9 @@ def __login(self): if not os.path.isdir("multicast"): os.mkdir("multicast") + def decode_output(self, output): + return output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + def __update_information(self): if not self.config.get_value('uuid'): self.config.set_value('uuid', str(uuid.uuid4())) @@ -72,7 +75,7 @@ def __update_information(self): devices = [] if Initialize.get_os() == 0: # linux output = subprocess.check_output("cat /proc/cpuinfo", shell=True) - output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + output = self.decode_output(output) tmp = [] for line in output: line = line.strip() @@ -96,7 +99,7 @@ def __update_information(self): except subprocess.CalledProcessError: # we silently ignore this case on machines where lspci is not present or architecture has no pci bus output = b"" - output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + output = self.decode_output(output) for line in output: if not line: continue @@ -109,18 +112,18 @@ def __update_information(self): processor_information = subprocess.check_output( 'powershell -Command "Get-CimInstance Win32_Processor | Select-Object -ExpandProperty Name"', shell=True) - processor_information = processor_information.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + processor_information = self.decode_output(processor_information) video_controller = subprocess.check_output( 'powershell -Command "Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name"', shell=True) - video_controller = video_controller.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + video_controller = self.decode_output(video_controller) else: processor_information = subprocess.check_output( 'wmic cpu get name', shell=True) - processor_information = processor_information.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + processor_information = self.decode_output(processor_information) video_controller = subprocess.check_output('wmic path win32_VideoController get name', shell=True) - video_controller = video_controller.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + video_controller = self.decode_output(video_controller) for source in (processor_information, video_controller): for line in source: @@ -130,7 +133,7 @@ def __update_information(self): else: # OS X output = subprocess.check_output("system_profiler SPDisplaysDataType -detaillevel mini", shell=True) - output = output.decode(encoding='utf-8').replace("\r\n", "\n").split("\n") + output = self.decode_output(output) for line in output: line = line.rstrip("\r\n ") if "Chipset Model" not in line: