From 5a82f04f9edda312fe792ac55279f8a9737b9c40 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Thu, 1 Aug 2024 00:22:59 -0700 Subject: [PATCH] flatten and simplify some code --- mem_edit/utils.py | 2 +- mem_edit/windows.py | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/mem_edit/utils.py b/mem_edit/utils.py index fac9f3c..96d0180 100644 --- a/mem_edit/utils.py +++ b/mem_edit/utils.py @@ -96,7 +96,7 @@ def ctypes_equal( if isinstance(a, (ctypes.Array, ctypes.Structure, ctypes.Union, ctypes._SimpleCData)): if not ctypes_equal(a_attr, b_attr): return False - elif not a_attr == b_attr: + elif a_attr != b_attr: return False return True diff --git a/mem_edit/windows.py b/mem_edit/windows.py index c165f99..50246ec 100644 --- a/mem_edit/windows.py +++ b/mem_edit/windows.py @@ -192,10 +192,9 @@ class Process(AbstractProcess): max_path_len, ) - if rval > 0: - return name_buffer.value.decode() - else: + if rval <= 0: return None + return name_buffer.value.decode() @staticmethod def list_available_pids() -> list[int]: @@ -218,11 +217,9 @@ class Process(AbstractProcess): num_returned = floor(returned_size.value / ctypes.sizeof(ctypes.wintypes.DWORD)) - if nn == num_returned: - nn *= 2 - continue - else: + if nn != num_returned: break + nn *= 2 return pids[:num_returned]