Skip to content

Commit

Permalink
Make module implementations self-contained
Browse files Browse the repository at this point in the history
Individual modules' YR_MODULE structs are now defined alongside the
rest of the module code.
  • Loading branch information
hillu committed Aug 26, 2022
1 parent d4a9324 commit a8be640
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 19 deletions.
13 changes: 13 additions & 0 deletions libyara/include/yara/modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,19 @@ struct YR_MODULE
YR_EXT_FINALIZE_FUNC finalize;
};

#define _yr_module_define_named(name) \
YR_MODULE name##__module = { \
#name, \
name##__declarations, \
name##__load, \
name##__unload, \
name##__initialize, \
name##__finalize}

#define yr_module_define_named(name) _yr_module_define_named(name)

#define yr_module_define() yr_module_define_named(MODULE_NAME)

struct YR_MODULE_IMPORT
{
const char* module_name;
Expand Down
19 changes: 1 addition & 18 deletions libyara/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <yara/libyara.h>
#include <yara/modules.h>

#define MODULE(name) \
int name##__declarations(YR_OBJECT* module); \
int name##__load( \
YR_SCAN_CONTEXT* context, \
YR_OBJECT* module, \
void* module_data, \
size_t module_data_size); \
int name##__unload(YR_OBJECT* main_structure); \
int name##__initialize(YR_MODULE* module); \
int name##__finalize(YR_MODULE* module); \
\
static YR_MODULE name##__module = { \
#name, \
name##__declarations, \
name##__load, \
name##__unload, \
name##__initialize, \
name##__finalize};
#define MODULE(name) extern YR_MODULE name##__module;

#include <modules/module_list>

Expand Down
2 changes: 2 additions & 0 deletions libyara/modules/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,5 @@ int module_unload(YR_OBJECT* module_object)
{
return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/cuckoo/cuckoo.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,5 @@ int module_unload(YR_OBJECT* module)

return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/demo/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ int module_unload(YR_OBJECT* module_object)
{
return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 1 addition & 1 deletion libyara/modules/dex/dex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1504,4 +1504,4 @@ int module_unload(YR_OBJECT* module_object)
return ERROR_SUCCESS;
}

#undef MODULE_NAME
yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/dotnet/dotnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -3536,3 +3536,5 @@ int module_unload(YR_OBJECT* module_object)

return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/elf/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1253,3 +1253,5 @@ int module_unload(YR_OBJECT* module_object)

return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,3 +867,5 @@ int module_unload(YR_OBJECT* module_object)

return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/macho/macho.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,3 +1373,5 @@ int module_unload(YR_OBJECT* module_object)
{
return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/magic/magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,5 @@ int module_unload(YR_OBJECT* module)

return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/math/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,3 +826,5 @@ int module_unload(YR_OBJECT* module_object)
{
return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/pb_tests/pb_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,5 @@ int module_load(

return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/pe/pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -4075,3 +4075,5 @@ int module_unload(YR_OBJECT* module_object)

return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,5 @@ int module_unload(YR_OBJECT* module_object)
module_object->data = (void*) 0xFABADA;
return ERROR_SUCCESS;
}

yr_module_define();
2 changes: 2 additions & 0 deletions libyara/modules/time/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ int module_unload(YR_OBJECT* module_object)
{
return ERROR_SUCCESS;
}

yr_module_define();

0 comments on commit a8be640

Please sign in to comment.