Skip to content

Synchronise modules (issue #46) #51

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

Merged
merged 11 commits into from
Jan 16, 2020
Merged

Conversation

TadeasKucera
Copy link
Contributor

@TadeasKucera TadeasKucera commented Jan 8, 2020

Synchronise symbols with yara downstream and enable use of symbols from yara upstream only:

  • We have compared current yaramod modules with modules in Avast yara downstream and we make it consistent in this PR.

  • We also change yaramod::ParserDriver to be able to avoid Avast-specific or VirusTotal-specific symbols when importing. Hence Add switch for turning on/off Avast and VirusTotal specific symbols #46 Is solved. This will be benefitial for people outside Avast that need only symbols present in yara upstream.

@TadeasKucera TadeasKucera force-pushed the update_modules_from_downstream branch from 9c4ed35 to 1f64914 Compare January 9, 2020 08:12
@TadeasKucera TadeasKucera changed the title Synchronise modules Synchronise modules (issue #46) Jan 13, 2020
@TadeasKucera TadeasKucera force-pushed the update_modules_from_downstream branch from 66de6d0 to ea31ce2 Compare January 13, 2020 15:34
@TadeasKucera TadeasKucera marked this pull request as ready for review January 13, 2020 16:58
@TadeasKucera TadeasKucera force-pushed the update_modules_from_downstream branch from 82ef8bc to ea31ce2 Compare January 15, 2020 08:27
ParserDriver(ParserMode parserMode);
explicit ParserDriver(const std::string& filePath, ParserMode parserMode = ParserMode::Regular);
explicit ParserDriver(std::istream& input, ParserMode parserMode = ParserMode::Regular);
ParserDriver(ParserMode parserMode, bool avastSpecific = true, bool vtSpecific = true);
Copy link
Member

Choose a reason for hiding this comment

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

It would be best to avoid just boolean parameters if it's unclear from the context of the function name of what they suppose to mean. Calls to such functions/methods then look like this ParserDriver(..., true, false). What exactly those true and false mean? The best way to do it would be through bitmasks because then you can do something like ParserDriver(..., Features::VirusTotal | Features::Avast).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I implemented this in the last commit.

{
if (!avastSpecific && (name == "androguard" || name == "phish")) // the androguard and phish modules are completely avast-specific
Copy link
Member

Choose a reason for hiding this comment

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

I would like this to be an attribute of the module itself, like which features you require in order to load? This feels like a hack because information about a module is taken out from it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood, instead of specifying here names of unsupported modules we get this information out of the module itself. Implemented here.

}
)");

Module::reset("androguard");
Copy link
Member

Choose a reason for hiding this comment

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

Will user need to call Module::reset() manually if they want to create more instances of yaramod? That doesn't sound very user friendly. This needs to happen all under the hood without user being aware of that. Please, change it so that user won't need to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The user does not need to call the reset method, we only need it in our tests where we construct more ParserDriver instances - all sharing the same modules, because modules are stored as global variables in module.cpp. These modules need to be reseted if we need ParserDriver with different Features. This is something that the user will never need, because they will use the same Features among their ParserDrivers. Maybe we could stop storing modules as global variables but store them either inside Yaramod or inside ParserDriver classes.

Copy link
Member

Choose a reason for hiding this comment

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

But what if I want to create Yaramod instance once with VirusTotal features and once with no additional features enabled? Would I need to do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, that would not require you calling the reset method. However, if you decided to use two different Yaramod instances, first one with ImportFeature::Avast and then second one with ImportFeature::Basic then yes, you would have to call the static method Module::reset(<module_name>). The problem is, that both ParserDriver instances share the same modules. In my opinien, it is a good thing that the modules are shared between the instances. The whole mean of issue #46 was to reduce the number of symbols stored and the complexity of modules. Therefore I propose a solution which would keep it:

Along with the globally stored modules we will store also global Feature instance named modules_state. Whenever new instance of Yaramod with parameter ImportFeature feature is created, we look at modules_state and update it:
modules_state |= feature
possibly enabling new modules/symbols. With this approach, when loading a module, we will only look at the global variable modules_state.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

However, if you decided to use two different Yaramod instances, first one with ImportFeature::Avast and then second one with ImportFeature::Basic then yes, you would have to call the static method Module::reset(<module_name>).

This is what I meant and I don't personally like it because it is so easy to misuse from user standpoint.

In my opinien, it is a good thing that the modules are shared between the instances.

Why do you think it is a good idea to keep the modules shared? I personally think that it was good idea when modules were immutable but I don't see any benefit when modules are possibly mutable.

Copy link
Member

Choose a reason for hiding this comment

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

I would propose to move from global modules to modules that are only local to certain ParserDriver instance. All the modules will have to be initialized multiple times when creating multiple Yaramod instances but I think that benefits of this solution outweigh benefits of having global modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it and I agree with you. We will get rid of global variables, we will get rid of the reset function or some hacks I proposed. It will be much cleaner and use just a liitle bit more memory to store the modules for each instance independently. I will implement it soon. Thank you for this discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: In commit we use new class ModulesPool which stores the modules. Each ParserDriver or YaraFileBuilder instance is assigned its own instance of ModulesPool class.

@TadeasKucera TadeasKucera force-pushed the update_modules_from_downstream branch from ef2a4f3 to 7afaecc Compare January 16, 2020 11:34
@metthal
Copy link
Member

metthal commented Jan 16, 2020

Thank you very much for the changes. Let's wait for the builds to finish and we'll merge it.

@TadeasKucera
Copy link
Contributor Author

Thank you for your suggestions! I believe we are ready for merge.

@metthal metthal merged commit 6c9ba54 into master Jan 16, 2020
@metthal metthal deleted the update_modules_from_downstream branch January 16, 2020 14:32
metthal added a commit that referenced this pull request Jan 17, 2020
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