File: plugin.c

package info (click to toggle)
radare2 0.9.6-3.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 17,496 kB
  • ctags: 45,959
  • sloc: ansic: 240,999; sh: 3,645; makefile: 2,520; python: 1,212; asm: 312; ruby: 214; awk: 209; perl: 188; lisp: 169; java: 23; xml: 17; php: 6
file content (66 lines) | stat: -rw-r--r-- 1,799 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* radare - LGPL - Copyright 2009-2013 pancake<nopcode.org> */

#include <r_debug.h>
#include "../config.h"

static RDebugPlugin *debug_static_plugins[] = 
	{ R_DEBUG_STATIC_PLUGINS };

R_API int r_debug_plugin_init(RDebug *dbg) {
	RDebugPlugin *static_plugin;
	int i;

	INIT_LIST_HEAD (&dbg->plugins);
	for (i=0; debug_static_plugins[i]; i++) {
		static_plugin = R_NEW (RDebugPlugin);
		memcpy (static_plugin, debug_static_plugins[i], sizeof (RDebugPlugin));
		r_debug_plugin_add (dbg, static_plugin);
	}
	return R_TRUE;
}

R_API int r_debug_use(RDebug *dbg, const char *str) {
	struct list_head *pos;
	if (str)
	list_for_each_prev (pos, &dbg->plugins) {
		RDebugPlugin *h = list_entry (pos, RDebugPlugin, list);
		if (h->name && !strcmp (str, h->name)) {
			dbg->h = h;
			if (dbg->anal && dbg->anal->cur)
				r_debug_set_arch (dbg, dbg->anal->cur->arch, dbg->bits);
			dbg->bp->breakpoint = dbg->h->breakpoint;
			dbg->bp->user = dbg;
		}
	}
	if (dbg->h && dbg->h->reg_profile) {
		char *p = dbg->h->reg_profile (dbg);
		if (p == NULL) {
			eprintf ("Cannot retrieve reg profile from debug plugin (%s)\n", dbg->h->name);
		} else {
			r_reg_set_profile_string (dbg->reg, p);
			if (dbg->anal)
				dbg->anal->reg = dbg->reg;
			if (dbg->h->init)
				dbg->h->init (dbg);
			r_reg_set_profile_string (dbg->reg, p);
		}
	}
	return (dbg->h != NULL);
}

R_API int r_debug_plugin_list(RDebug *dbg) {
	int count = 0;
	struct list_head *pos;
	list_for_each_prev(pos, &dbg->plugins) {
		RDebugPlugin *h = list_entry(pos, RDebugPlugin, list);
		eprintf ("dbg %d %s %s\n", count, h->name, ((h==dbg->h)?"*":""));
		count++;
	}
	return R_FALSE;
}

R_API int r_debug_plugin_add(RDebug *dbg, RDebugPlugin *foo) {
	if (!foo->name) return R_FALSE;
	list_add_tail (&(foo->list), &(dbg->plugins));
	return R_TRUE;
}