From 3f02b5541463c29ed5263b2e8278986d23b23be3 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 7 Aug 2026 13:08:50 +0200 Subject: [PATCH] Add r2plugin support --- r2plugin/README.md | 21 +++++++++++++++++++++ r2plugin/core/deps.h | 5 +++++ r2plugin/core/deps.mk | 7 +++++++ r2plugin/meson.build | 16 ++++++++++++++++ r2plugin/r2plugins.h | 5 +++++ r2plugin/static.cfg | 1 + src/core_r2yara.c | 8 ++++++-- 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 r2plugin/README.md create mode 100644 r2plugin/core/deps.h create mode 100644 r2plugin/core/deps.mk create mode 100644 r2plugin/meson.build create mode 100644 r2plugin/r2plugins.h create mode 100644 r2plugin/static.cfg diff --git a/r2plugin/README.md b/r2plugin/README.md new file mode 100644 index 0000000..7efa600 --- /dev/null +++ b/r2plugin/README.md @@ -0,0 +1,21 @@ +# r2plugin + +This directory contains the make and meson files required +to link r2yara statically inside radare2 (XPS). + +```console +cd radare2 +mkdir -p libr/xps/p +ln -s ../../../../r2yara libr/xps/p/r2yara +cp libr/xps/p/r2yara/r2plugin/config.mk libr/xps/config.mk +make -C libr/xps +``` + +Then build radare2 as usual (`./configure && make` or meson). +The build requires libyara to be available via pkg-config. + +Verify with: + +```console +r2 -q -c 'Lc~r2yara' -- +``` diff --git a/r2plugin/core/deps.h b/r2plugin/core/deps.h new file mode 100644 index 0000000..043da50 --- /dev/null +++ b/r2plugin/core/deps.h @@ -0,0 +1,5 @@ +/* r2yara - LGPLv3 - Copyright 2014-2026 - pancake */ + +#ifdef R2_CORE_H +extern RCorePlugin r_core_plugin_r2yara; +#endif diff --git a/r2plugin/core/deps.mk b/r2plugin/core/deps.mk new file mode 100644 index 0000000..acd2335 --- /dev/null +++ b/r2plugin/core/deps.mk @@ -0,0 +1,7 @@ +R2YARA_CORE_WD=$(LIBR)/xps/p/r2yara +R2YARA_YARA_CFLAGS=$(shell pkg-config --cflags yara 2>/dev/null) +R2YARA_YARA_LDFLAGS=$(shell pkg-config --libs yara 2>/dev/null || echo -lyara) +CFLAGS+=-I$(R2YARA_CORE_WD)/src $(R2YARA_YARA_CFLAGS) +LDFLAGS+=$(R2YARA_YARA_LDFLAGS) +R2YARA_CORE_OBJ=$(R2YARA_CORE_WD)/src/core_r2yara.o +EXTERNAL_STATIC_OBJS+=$(R2YARA_CORE_OBJ) diff --git a/r2plugin/meson.build b/r2plugin/meson.build new file mode 100644 index 0000000..2452426 --- /dev/null +++ b/r2plugin/meson.build @@ -0,0 +1,16 @@ +# r2yara XPS integration for radare2. +# Included from libr/xps/meson.build when r2yara sources live under +# libr/xps/p/r2yara/. Appends sources and include paths to the r_core +# aggregate so the static plugin is linked into libr_core. + +core_plugins += ['r2yara'] + +r_core_additional_inc += include_directories(join_paths('..', 'src')) + +r_core_additional_sources += files( + '../src/core_r2yara.c', +) + +# XPS has no per-plugin dependency hook; platform_deps is consumed by +# libr_core's dependency list, so libyara is appended there. +platform_deps += dependency('yara') diff --git a/r2plugin/r2plugins.h b/r2plugin/r2plugins.h new file mode 100644 index 0000000..ef4c7a5 --- /dev/null +++ b/r2plugin/r2plugins.h @@ -0,0 +1,5 @@ +/* r2yara - LGPLv3 - Copyright 2014-2026 - pancake */ + +#ifdef R2_CORE_H +#include "core/deps.h" +#endif diff --git a/r2plugin/static.cfg b/r2plugin/static.cfg new file mode 100644 index 0000000..486a7b4 --- /dev/null +++ b/r2plugin/static.cfg @@ -0,0 +1 @@ +core.r2yara diff --git a/src/core_r2yara.c b/src/core_r2yara.c index 1333ab3..cef209d 100644 --- a/src/core_r2yara.c +++ b/src/core_r2yara.c @@ -6,6 +6,10 @@ #define R_LIB_ABIVERSION R2_ABIVERSION #endif +#ifndef R2Y_VERSION +#define R2Y_VERSION "1.5.0" +#endif + #if R_LIB_ABIVERSION >= 125 #define r2yara_cmd_help(core, msg) r_cons_cmd_help ((core)->cons, msg) #define r2yara_cmd_help_match(core, msg, command) r_cons_cmd_help_match ((core)->cons, msg, command, 0, false) @@ -1232,7 +1236,7 @@ static bool cmd_yara_fini(RCorePluginSession *cps) { return true; } -RCorePlugin r_core_plugin_yara = { +RCorePlugin r_core_plugin_r2yara = { .meta = { .name = "yara", .desc = "YARA integration", @@ -1247,7 +1251,7 @@ RCorePlugin r_core_plugin_yara = { #ifndef CORELIB RLibStruct radare_plugin = { .type = R_LIB_TYPE_CORE, - .data = &r_core_plugin_yara, + .data = &r_core_plugin_r2yara, .abiversion = R2_ABIVERSION, .version = R2_VERSION };