Skip to content

Commit 3f02b55

Browse files
committed
Add r2plugin support
1 parent 794795e commit 3f02b55

7 files changed

Lines changed: 61 additions & 2 deletions

File tree

r2plugin/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# r2plugin
2+
3+
This directory contains the make and meson files required
4+
to link r2yara statically inside radare2 (XPS).
5+
6+
```console
7+
cd radare2
8+
mkdir -p libr/xps/p
9+
ln -s ../../../../r2yara libr/xps/p/r2yara
10+
cp libr/xps/p/r2yara/r2plugin/config.mk libr/xps/config.mk
11+
make -C libr/xps
12+
```
13+
14+
Then build radare2 as usual (`./configure && make` or meson).
15+
The build requires libyara to be available via pkg-config.
16+
17+
Verify with:
18+
19+
```console
20+
r2 -q -c 'Lc~r2yara' --
21+
```

r2plugin/core/deps.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* r2yara - LGPLv3 - Copyright 2014-2026 - pancake */
2+
3+
#ifdef R2_CORE_H
4+
extern RCorePlugin r_core_plugin_r2yara;
5+
#endif

r2plugin/core/deps.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
R2YARA_CORE_WD=$(LIBR)/xps/p/r2yara
2+
R2YARA_YARA_CFLAGS=$(shell pkg-config --cflags yara 2>/dev/null)
3+
R2YARA_YARA_LDFLAGS=$(shell pkg-config --libs yara 2>/dev/null || echo -lyara)
4+
CFLAGS+=-I$(R2YARA_CORE_WD)/src $(R2YARA_YARA_CFLAGS)
5+
LDFLAGS+=$(R2YARA_YARA_LDFLAGS)
6+
R2YARA_CORE_OBJ=$(R2YARA_CORE_WD)/src/core_r2yara.o
7+
EXTERNAL_STATIC_OBJS+=$(R2YARA_CORE_OBJ)

r2plugin/meson.build

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# r2yara XPS integration for radare2.
2+
# Included from libr/xps/meson.build when r2yara sources live under
3+
# libr/xps/p/r2yara/. Appends sources and include paths to the r_core
4+
# aggregate so the static plugin is linked into libr_core.
5+
6+
core_plugins += ['r2yara']
7+
8+
r_core_additional_inc += include_directories(join_paths('..', 'src'))
9+
10+
r_core_additional_sources += files(
11+
'../src/core_r2yara.c',
12+
)
13+
14+
# XPS has no per-plugin dependency hook; platform_deps is consumed by
15+
# libr_core's dependency list, so libyara is appended there.
16+
platform_deps += dependency('yara')

r2plugin/r2plugins.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* r2yara - LGPLv3 - Copyright 2014-2026 - pancake */
2+
3+
#ifdef R2_CORE_H
4+
#include "core/deps.h"
5+
#endif

r2plugin/static.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
core.r2yara

src/core_r2yara.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#define R_LIB_ABIVERSION R2_ABIVERSION
77
#endif
88

9+
#ifndef R2Y_VERSION
10+
#define R2Y_VERSION "1.5.0"
11+
#endif
12+
913
#if R_LIB_ABIVERSION >= 125
1014
#define r2yara_cmd_help(core, msg) r_cons_cmd_help ((core)->cons, msg)
1115
#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) {
12321236
return true;
12331237
}
12341238

1235-
RCorePlugin r_core_plugin_yara = {
1239+
RCorePlugin r_core_plugin_r2yara = {
12361240
.meta = {
12371241
.name = "yara",
12381242
.desc = "YARA integration",
@@ -1247,7 +1251,7 @@ RCorePlugin r_core_plugin_yara = {
12471251
#ifndef CORELIB
12481252
RLibStruct radare_plugin = {
12491253
.type = R_LIB_TYPE_CORE,
1250-
.data = &r_core_plugin_yara,
1254+
.data = &r_core_plugin_r2yara,
12511255
.abiversion = R2_ABIVERSION,
12521256
.version = R2_VERSION
12531257
};

0 commit comments

Comments
 (0)