Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix offset type #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

raighne-datature
Copy link

@raighne-datature raighne-datature commented Jan 9, 2024

Hi,

It looks like the function does not work for offset signatures, I did some fixes but it does not support the 'any' type.

Copy link
Owner

@schlerp schlerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good! Only real question is about the "not implemented" error, I'm leaning towards just the continue like you have there since its probably a better experience for consumers of the library. What do you think?

PS. as you can probably tell i wrote this a very long time ago, it's probably time to revisit to API and look at how its used to polish it up to modern python standards and release a v1.0.

Do you mind sharing some snippets or your repo so i can see how you use this library?

if _byte != "nn":
test_hex.append(ord(bytes.fromhex(_byte)))
else:
test_hex.append(None)

for _loc, _byte in enumerate(test_hex):
if signature["offset"] == "any":
# any offset not supported yet
continue
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we raise a not implemented error?

@@ -1477,20 +1477,24 @@ def __init__(self, signature, *arg, **kw):
self.__dict__ = signature


def compare_sig(file_header, test_hex_string) -> bool:
def compare_sig(file_header, signature) -> bool:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fantastic

@@ -7,7 +7,7 @@ def readme():
return f.read()

setup(name='pyfsig',
version='0.6',
version='0.8.3',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

@schlerp
Copy link
Owner

schlerp commented Jan 10, 2024

we should probably update the offsets in the json dict to be integers rather than strings

@raighne-datature
Copy link
Author

I agree with you. Throwing a "not implemented" error will disrupt normal usage. I believe using continue is a good solution here, or we can list all the tested signatures first.

In my example, I only need to verify if the file is in ['jpg', 'mp4'], so it's very straightforward. However, I believe we can adhere to modern Python standards to refactor the code. Some developers prefer not to use python-magic due to its dependency on the additional libmagic library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants