-
Notifications
You must be signed in to change notification settings - Fork 17
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
Native library detection plugin #267
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, mostly a few changes related to where the database of patterns is stored.
Let's add this helper function to the ConfigManager class (in surfactant/configmanager.py
):
"""Determines the path to the data directory, for storing things such as databases.
Returns:
Path: The path to the data directory.
"""
if platform.system() == "Windows":
data_dir = Path(os.getenv("LOCALAPPDATA", os.path.expanduser("~\\AppData\\Local")))
else:
data_dir = Path(os.getenv("XDG_DATA_HOME", os.path.expanduser("~/.local/share")))
data_dir = data_dir / self.app_name
return data_dir
(There are also ~3 things flagged by the pre-commit CI check to change).
86155bb
to
c3f7960
Compare
f1fda19
to
61092f3
Compare
606e2ca
to
8b74a71
Compare
Interesting, I came across two patterns that don't compile and cause an error:
Will need to test whatever they are using for matching with the regular expressions, but it is possible the first doesn't have the behavior they intended (and the 2nd is just ambiguous). |
I think they are using |
@@ -96,7 +96,7 @@ def match_by_attribute(attribute: str, content: str, patterns_database: Dict) -> | |||
if attribute == "filename": | |||
if name == content: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if name == content: | |
if name.lower() == content.lower(): |
For the filename, let's make it a case-insensitive comparison.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
c57f26a
to
ef0919f
Compare
Summary
If merged this pull request will detect native libraries from files. It will find matches either through file name or file content using regex patterns. Statically linked libraries will also be detected.
First, run
get_emba_db.py
to generate the EMBA database.Then, just run surfactant and in the output file there will be a
nativeLibraries: []
for each file that states all the libraries that it was able to detect. The output will have eitherisLibrary: []
meaning the file is the library, orcontainsLibrary: []
which means the libraries were statically linked within the file.