From 3598bdc845fdf64ca0396f6845dae935400c7106 Mon Sep 17 00:00:00 2001 From: j-t-1 <120829237+j-t-1@users.noreply.github.com> Date: Sun, 24 Nov 2024 22:34:02 +0000 Subject: [PATCH 1/2] Small refactor of is_valid_function_name Slightly increases readability. --- pefile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pefile.py b/pefile.py index f804678..466551e 100644 --- a/pefile.py +++ b/pefile.py @@ -2318,11 +2318,11 @@ def is_valid_function_name( ) -> bool: allowed_extra = b"._?@$()<>" if relax_allowed_characters: - allowed_extra = b"!\"#$%&'()*+,-./:<>?[\\]^_`{|}~@" + allowed_extra += b"!\"#%&'*+,-/:[\\]^`{|}~" return ( s is not None and isinstance(s, (str, bytes, bytearray)) - and all((c in allowed_function_name or c in allowed_extra) for c in set(s)) + and all(c in (allowed_function_name + allowed_extra) for c in set(s)) ) From ea45151f1eb7fa2b210aedf0f265135f3c3c20c0 Mon Sep 17 00:00:00 2001 From: j-t-1 <120829237+j-t-1@users.noreply.github.com> Date: Mon, 16 Dec 2024 07:57:27 +0000 Subject: [PATCH 2/2] Small change of is_valid_function_name Slightly increases readability. --- pefile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pefile.py b/pefile.py index 466551e..fedd178 100644 --- a/pefile.py +++ b/pefile.py @@ -2306,7 +2306,7 @@ def is_valid_dos_filename(s): # charset we will assume the name is invalid. # The dot "." character comes from: https://github.com/erocarrera/pefile/pull/346 # All other symbols can be inserted by adding a name with that symbol to a .def file, -# and passing it to link.exe (See export_test.py) +# and passing it to link.exe, see export_test.py. allowed_function_name = ( string.ascii_lowercase + string.ascii_uppercase + string.digits ).encode() @@ -2316,9 +2316,9 @@ def is_valid_dos_filename(s): def is_valid_function_name( s: Union[str, bytes, bytearray], relax_allowed_characters: bool = False ) -> bool: - allowed_extra = b"._?@$()<>" + allowed_extra = b"$().<>?@_" if relax_allowed_characters: - allowed_extra += b"!\"#%&'*+,-/:[\\]^`{|}~" + allowed_extra = string.punctuation.encode() return ( s is not None and isinstance(s, (str, bytes, bytearray))