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: Open json modules in read only mode #242

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace yaramod {

nlohmann::json readJsonFile(const std::string& filePath)
{
std::ifstream input{filePath, std::ios::out};
std::ifstream input{filePath};
if (!input.is_open())
throw YaramodError("Could not open '" + filePath);
std::stringstream buffer;
Expand Down
37 changes: 37 additions & 0 deletions tests/python/test_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import yaramod

def test_modules_that_are_readonly(tmp_path):
modules_directory = tmp_path
my_cuckoo_module = modules_directory / "my_cuckoo.json"
my_cuckoo_module.write_text('''{
"kind": "struct",
"name": "cuckoo",
"attributes": [
{
"kind": "function",
"name": "my_func",
"return_type": "i",
"overloads": [
{
"arguments": [
{
"type": "r",
"name": "data"
}
],
"documentation": "Test"
}
]
}
]
}
''')
my_cuckoo_module.chmod(0o444)
ymod = yaramod.Yaramod(modules_directory=str(modules_directory))
yfile = ymod.parse_string(r'''import "cuckoo"
rule test {
condition:
cuckoo.my_func(/.*/)
}
''')
assert yfile is not None