Skip to content

Commit

Permalink
Some fixes for r2 plugins tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka committed Nov 18, 2019
1 parent 2a45f24 commit 0929e01
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
10 changes: 5 additions & 5 deletions plugins/dev-anal.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ emulation - register profile, like in debugger, which is set within `set_reg_pro

```makefile
NAME=anal_snes
R2_PLUGIN_PATH=$(shell r2 -H|grep USER_PLUGINS|awk '{print $$2}')
R2_PLUGIN_PATH=$(shell r2 -H R2_USER_PLUGINS)
LIBEXT=$(shell r2 -H LIBEXT)
CFLAGS=-g -fPIC $(shell pkg-config --cflags r_anal)
LDFLAGS=-shared $(shell pkg-config --libs r_anal)
OBJS=$(NAME).o
SO_EXT=$(shell uname|grep -q Darwin && echo dylib || echo so)
LIB=$(NAME).$(SO_EXT)
LIB=$(NAME).$(LIBEXT)

all: $(LIB)

Expand Down Expand Up @@ -98,8 +98,8 @@ struct r_anal_plugin_t r_anal_plugin_snes = {
.diff_eval = NULL
};

#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_snes,
.version = R2_VERSION
Expand Down
10 changes: 5 additions & 5 deletions plugins/dev-asm.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
```makefile
NAME=asm_snes
R2_PLUGIN_PATH=$(shell r2 -H|grep USER_PLUGINS|awk '{print $$2}')
R2_PLUGIN_PATH=$(shell r2 -H R2_USER_PLUGINS)
LIBEXT=$(shell r2 -H LIBEXT)
CFLAGS=-g -fPIC $(shell pkg-config --cflags r_anal)
LDFLAGS=-shared $(shell pkg-config --libs r_anal)
OBJS=$(NAME).o
SO_EXT=$(shell uname|grep -q Darwin && echo dylib || echo so)
LIB=$(NAME).$(SO_EXT)
LIB=$(NAME).$(LIBEXT)
all: $(LIB)
Expand Down Expand Up @@ -85,8 +85,8 @@ RAsmPlugin r_asm_plugin_mycpu = {
.disassemble = &disassemble
};

#ifndef CORELIB
RLibStruct radare_plugin = {
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_mycpu,
.version = R2_VERSION
Expand Down
44 changes: 19 additions & 25 deletions plugins/dev-bin.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ In `info` add `et->has_va = 1;` and `ptr->srwx` with the `R_BIN_SCN_MAP;` attrib

```Makefile
NAME=bin_nes
R2_PLUGIN_PATH=$(shell r2 -hh|grep R2_LIBR_PLUGINS|awk '{print $$2}')
R2_PLUGIN_PATH=$(shell r2 -H R2_USER_PLUGINS)
LIBEXT=$(shell r2 -H LIBEXT)
CFLAGS=-g -fPIC $(shell pkg-config --cflags r_bin)
LDFLAGS=-shared $(shell pkg-config --libs r_bin)
OBJS=$(NAME).o
SO_EXT=$(shell uname|grep -q Darwin && echo dylib || echo so)
LIB=$(NAME).$(SO_EXT)
LIB=$(NAME).$(LIBEXT)

all: $(LIB)

Expand All @@ -36,29 +36,27 @@ uninstall:
**bin_nes.c:**

```c
#include <r_util.h>
#include <r_bin.h>

static int check(RBinFile *arch);
static int check_bytes(const ut8 *buf, ut64 length);

static void * load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){
check_bytes (buf, sz);
return R_NOTNULL;
static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, Sdb *sdb) {
ut64 size;
const ut8 *buf = r_buf_data (b, &size);
r_return_val_if_fail (buf, false);
*bin_obj = r_bin_internal_nes_load (buf, size);
return *bin_obj != NULL;
}


static int check(RBinFile *arch) {
const ut8 \*bytes = arch ? r_buf_buffer (arch->buf) : NULL;
ut64 sz = arch ? r_buf_size (arch->buf): 0;
return check_bytes (bytes, sz);
static void destroy(RBinFile *bf) {
r_bin_free_all_nes_obj (bf->o->bin_obj);
bf->o->bin_obj = NULL;
}

static int check_bytes(const ut8 *buf, ut64 length) {
static bool check_buffer(RBuffer *b) {
if (!buf || length < 4) return false;
return (!memcmp (buf, "\x4E\x45\x53\x1A", 4));
}


static RBinInfo* info(RBinFile *arch) {
RBinInfo \*ret = R_NEW0 (RBinInfo);
if (!ret) return NULL;
Expand All @@ -77,26 +75,22 @@ static RBinInfo* info(RBinFile *arch) {
return ret;
}


struct r_bin_plugin_t r_bin_plugin_nes = {
.name = "nes",
.desc = "NES",
.license = "BSD",
.init = NULL,
.fini = NULL,
.get_sdb = NULL,
.load = NULL,
.load_bytes = &load_bytes,
.check = &check,
.load_buffer = &load_buffer,
.destroy = &destroy,
.check_buffer = &check_buffer,
.baddr = NULL,
.check_bytes = &check_bytes,
.entries = NULL,
.sections = NULL,
.info = &info,
};

#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_nes,
.version = R2_VERSION
Expand Down
2 changes: 1 addition & 1 deletion plugins/r2pm.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
As you remember radare2 has its own [packaging manager](../tools/r2pm/intro.md) and we can easily
add newly written plugin for everyone to access.

All packages are located in [radare2-pm](https://github.com/radare/radare2-pm) repository, and have
All packages are located in [radare2-pm](https://github.com/radareorg/radare2-pm) repository, and have
very simple text format.

```
Expand Down

0 comments on commit 0929e01

Please sign in to comment.