Replies: 2 comments 22 replies
-
If you're using a reasonable modern version you can use iterators, which are documented here: https://yara.readthedocs.io/en/stable/writingrules.html#iterators It also talks about iterating over dictionaries. Here's an example of using it to print the
|
Beta Was this translation helpful? Give feedback.
-
Ok so I have confirmed more of what you said. I wrote some functions to unpack the json in the module_load() function and here's what I learned: I learned that the definitions in module_definitions() are defined BEFORE the file is read in module_load(). One idea we talked about above was creating a structure like
Even though I could create val in the module_load() function, it's too late in the game. As you say, you need to pre-load the structure of the JSON for this to even stand a chance at working. Like a true catch-22. I'm abandoning this line of thought here. It sure would be nice if functions could return something iterable. But let's see how far I get without that.
At this point I have to agree. However, if the query resulted in something larger than a scalar type, I would return the JSON as a string. The reason I would do this is at minimum, it allows me to then stick that in a variable and then match a RE on that whole block of JSON. It's not ideal but it's functional. libjansson does not support any query into the JSON it loads. I'm going to look around for a more robust JSON lib. Even if I find something that returns some structure, I can "flatten" it, or rather cat it together back into a single string and return that as a string (a "sub-JSON" string, a smaller JSON block). If you have any suggestions of a decent C JSON lib, I'd like to know. With that, it should make yara quite minimally useful for my purpose (and perhaps others) with JSON formatted data. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to extend the yara-json module which parses json using libjansson.
It currently defines 3 functions:
Minimal, but a good base to start from. I'd like to return a dictionary of some subset of the json structure to iterate over in yara.
The docs don't seem to provide any example on how to do this though it says it's possible (https://yara.readthedocs.io/en/stable/writingrules.html?highlight=iterate#iterators). I looked at the pe module but it's not obvious to me what's going on.
Does anyone have a concise example how to make a dictionary in a module and how a function returns that or a pointer into that? It would be great to get an example into the docs for this because it's a great feature!
Beta Was this translation helpful? Give feedback.
All reactions