2015-06-30 10:50:46 +02:00
|
|
|
/* radare - LGPL - Copyright 2015 - pancake, nibble */
|
|
|
|
|
|
|
|
#include <r_anal.h>
|
|
|
|
|
|
|
|
typedef void (*RAnalEsilPin)(RAnal *a);
|
|
|
|
|
2017-07-10 11:20:03 +02:00
|
|
|
#if 0
|
2015-06-30 10:50:46 +02:00
|
|
|
// TODO: those hardcoded functions should go
|
|
|
|
/* default pins from libc */
|
|
|
|
static void pin_strlen(RAnal *a) {
|
|
|
|
// get a0 register
|
|
|
|
// read memory and interpret it as a string
|
|
|
|
// set a0 to the result of strlen;
|
|
|
|
eprintf ("esilpin: strlen\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pin_write(RAnal *a) {
|
|
|
|
// get a0 register for fd
|
|
|
|
// get a1 register for data
|
|
|
|
// get a2 register for len
|
|
|
|
// read len bytes from data and print them to screen + fd
|
|
|
|
// set a0 to the result of write;
|
|
|
|
eprintf ("esilpin: write\n");
|
|
|
|
}
|
2017-07-10 11:20:03 +02:00
|
|
|
#endif
|
2015-06-30 10:50:46 +02:00
|
|
|
|
|
|
|
/* pin api */
|
|
|
|
|
|
|
|
#define DB a->sdb_pins
|
|
|
|
|
|
|
|
R_API void r_anal_pin_init(RAnal *a) {
|
|
|
|
sdb_free (DB);
|
|
|
|
DB = sdb_new0();
|
2017-06-09 02:50:28 -11:00
|
|
|
// sdb_ptr_set (DB, "strlen", pin_strlen, 0);
|
|
|
|
// sdb_ptr_set (DB, "write", pin_write, 0);
|
2015-06-30 10:50:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_anal_pin_fini(RAnal *a) {
|
2020-09-27 18:21:50 +08:00
|
|
|
if (sdb_free (DB)) {
|
|
|
|
DB = NULL;
|
|
|
|
}
|
2015-06-30 10:50:46 +02:00
|
|
|
}
|
|
|
|
|
2020-04-28 22:09:30 +02:00
|
|
|
R_API void r_anal_pin(RAnal *a, ut64 addr, const char *name) {
|
2015-06-30 10:50:46 +02:00
|
|
|
char buf[64];
|
|
|
|
const char *key = sdb_itoa (addr, buf, 16);
|
|
|
|
sdb_set (DB, key, name, 0);
|
|
|
|
}
|
|
|
|
|
2020-04-28 22:09:30 +02:00
|
|
|
R_API void r_anal_pin_unset(RAnal *a, ut64 addr) {
|
2015-06-30 10:50:46 +02:00
|
|
|
char buf[64];
|
|
|
|
const char *key = sdb_itoa (addr, buf, 16);
|
|
|
|
sdb_unset (DB, key, 0);
|
|
|
|
}
|
|
|
|
|
2017-06-09 02:50:28 -11:00
|
|
|
R_API const char *r_anal_pin_call(RAnal *a, ut64 addr) {
|
2015-06-30 10:50:46 +02:00
|
|
|
char buf[64];
|
2017-06-11 04:43:19 +04:30
|
|
|
const char *key = sdb_itoa (addr, buf, 16);
|
2015-09-14 02:08:31 +02:00
|
|
|
if (key) {
|
2017-06-09 02:50:28 -11:00
|
|
|
return sdb_const_get (DB, key, NULL);
|
|
|
|
#if 0
|
2017-06-11 04:43:19 +04:30
|
|
|
const char *name;
|
2015-09-14 02:08:31 +02:00
|
|
|
if (name) {
|
|
|
|
RAnalEsilPin fcnptr = (RAnalEsilPin)
|
|
|
|
sdb_ptr_get (DB, name, NULL);
|
|
|
|
if (fcnptr) {
|
|
|
|
fcnptr (a);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-06-09 02:50:28 -11:00
|
|
|
#endif
|
2015-06-30 10:50:46 +02:00
|
|
|
}
|
2017-06-09 02:50:28 -11:00
|
|
|
return NULL;
|
2015-06-30 10:50:46 +02:00
|
|
|
}
|
|
|
|
|
2020-06-12 10:26:55 +02:00
|
|
|
static bool cb_list(void *user, const char *k, const char *v) {
|
2015-06-30 10:50:46 +02:00
|
|
|
RAnal *a = (RAnal*)user;
|
2017-06-09 02:50:28 -11:00
|
|
|
if (*k == '0') {
|
2015-06-30 10:50:46 +02:00
|
|
|
// bind
|
2015-08-08 14:15:13 -04:00
|
|
|
a->cb_printf ("%s = %s\n", k, v);
|
2015-06-30 10:50:46 +02:00
|
|
|
} else {
|
|
|
|
// ptr
|
2015-08-08 14:15:13 -04:00
|
|
|
a->cb_printf ("PIN %s\n", k);
|
2015-06-30 10:50:46 +02:00
|
|
|
}
|
2015-09-14 02:08:31 +02:00
|
|
|
return true;
|
2015-06-30 10:50:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_anal_pin_list(RAnal *a) {
|
|
|
|
sdb_foreach (DB, cb_list, a);
|
|
|
|
}
|