mirror of
https://github.com/radareorg/radare2.git
synced 2025-05-13 12:07:13 +00:00
* Added doc/oo: describes the object dis-orientation of libr
- Plugins should be singletons across object instances * Added hard/soft initializer for r_crypto - Needed for the as_new() - Added stupid vala example for r_crypto vapi * Implement r_debug->mmu methods
This commit is contained in:
parent
6d58b7bb7b
commit
df967c868b
41
doc/oo
Normal file
41
doc/oo
Normal file
@ -0,0 +1,41 @@
|
||||
Radare OO
|
||||
=========
|
||||
|
||||
I do realize that Object Orientation sucks, so I tried to do libr API
|
||||
following some sane and basic OO concepts.
|
||||
|
||||
- No inheritance
|
||||
- Instances are used to keep states
|
||||
- Enforces instance recycling
|
||||
- Reduce creation/destruction of objects
|
||||
- Easily interfaced with Vala thru the VAPIs
|
||||
|
||||
Global picture
|
||||
--------------
|
||||
[Class]
|
||||
|
|
||||
|-- [Plugins] // shared among instances
|
||||
| \
|
||||
| \
|
||||
`------> [Instance] ----> [Liberation]
|
||||
|
||||
* We need a construction/destruction API for plugins among instances
|
||||
- simplify code
|
||||
|
||||
A library implements a set of functionalities, those ones are mainly
|
||||
the lifecycle of the class containing the state of
|
||||
|
||||
Plugins are singletons. Or we will have to create factories for every class.
|
||||
|
||||
Lifecycle of the class
|
||||
----------------------
|
||||
Class
|
||||
- new
|
||||
- as_new
|
||||
- init
|
||||
- free
|
||||
|
||||
Library plugins
|
||||
---------------
|
||||
They are stored in the p/ directory of each library under the libr directory.
|
||||
|
@ -6,7 +6,7 @@
|
||||
static struct r_crypto_handle_t *crypto_static_plugins[] =
|
||||
{ R_CRYPTO_STATIC_PLUGINS };
|
||||
|
||||
R_API struct r_crypto_t *r_crypto_init(struct r_crypto_t *cry)
|
||||
R_API struct r_crypto_t *r_crypto_init(struct r_crypto_t *cry, int hard)
|
||||
{
|
||||
int i;
|
||||
if (cry) {
|
||||
@ -14,27 +14,44 @@ R_API struct r_crypto_t *r_crypto_init(struct r_crypto_t *cry)
|
||||
cry->iv = NULL;
|
||||
cry->key_len = 0;
|
||||
cry->user = NULL;
|
||||
// first call initializes the output_* variables
|
||||
r_crypto_get_output(cry);
|
||||
INIT_LIST_HEAD(&cry->handlers);
|
||||
for(i=0;crypto_static_plugins[i];i++)
|
||||
r_crypto_add(cry, crypto_static_plugins[i]);
|
||||
if (hard) {
|
||||
// first call initializes the output_* variables
|
||||
r_crypto_get_output(cry);
|
||||
INIT_LIST_HEAD(&cry->handlers);
|
||||
for(i=0;crypto_static_plugins[i];i++)
|
||||
r_crypto_add(cry, crypto_static_plugins[i]);
|
||||
}
|
||||
}
|
||||
return cry;
|
||||
}
|
||||
|
||||
R_API int r_crypto_add(struct r_crypto_t *cry, struct r_crypto_handle_t *h)
|
||||
{
|
||||
// add a check ?
|
||||
list_add_tail(&(h->list), &(cry->handlers));
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
// TODO: add _del
|
||||
R_API int r_crypto_del(struct r_crypto_t *cry, struct r_crypto_handle_t *h)
|
||||
{
|
||||
list_del(&(h->list));
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API struct r_crypto_t *r_crypto_new()
|
||||
{
|
||||
struct r_crypto_t *cry = MALLOC_STRUCT(struct r_crypto_t);
|
||||
return r_crypto_init(cry);
|
||||
return r_crypto_init(cry, R_TRUE);
|
||||
}
|
||||
|
||||
R_API struct r_crypto_t *r_crypto_as_new(struct r_crypto_t *cry)
|
||||
{
|
||||
struct r_crypto_t *c = MALLOC_STRUCT(struct r_crypto_t);
|
||||
if (c != NULL) {
|
||||
r_crypto_init(c, R_FALSE); // soft init
|
||||
memcpy(&c->handlers, &cry->handlers, sizeof(cry->handlers));
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
R_API struct r_crypto_t *r_crypto_free(struct r_crypto_t *cry)
|
||||
|
14
libr/crypto/t/racrypt.vala
Normal file
14
libr/crypto/t/racrypt.vala
Normal file
@ -0,0 +1,14 @@
|
||||
using Radare;
|
||||
|
||||
void main()
|
||||
{
|
||||
Crypto cto = new Crypto();
|
||||
|
||||
cto.set_algorithm("aes");
|
||||
int keysize = cto.get_key_size();
|
||||
//cto.set_key();
|
||||
//cto.set_iv();
|
||||
|
||||
/* dupplicate object */
|
||||
cry = cto.as_new();
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <r_debug.h>
|
||||
|
||||
R_API int r_debug_init(struct r_debug_t *dbg)
|
||||
R_API int r_debug_init(struct r_debug_t *dbg, int hard)
|
||||
{
|
||||
dbg->pid = -1;
|
||||
dbg->tid = -1;
|
||||
@ -11,9 +11,11 @@ R_API int r_debug_init(struct r_debug_t *dbg)
|
||||
dbg->regs = dbg->oregs = NULL;
|
||||
dbg->printf = printf;
|
||||
dbg->h = NULL;
|
||||
dbg->bp = r_bp_new();
|
||||
r_debug_handle_init(dbg);
|
||||
dbg->bp->iob.init = R_FALSE;
|
||||
if (hard) {
|
||||
dbg->bp = r_bp_new();
|
||||
r_debug_handle_init(dbg);
|
||||
dbg->bp->iob.init = R_FALSE;
|
||||
}
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
@ -176,12 +178,18 @@ R_API int r_debug_kill(struct r_debug_t *dbg, int pid, int sig)
|
||||
|
||||
// TODO move to mem.c
|
||||
/* mmu */
|
||||
R_API int r_debug_mmu_alloc(struct r_debug_t *dbg, ut64 size, ut64 *addr)
|
||||
R_API ut64 r_debug_mmu_alloc(struct r_debug_t *dbg, ut64 size, ut64 *addr)
|
||||
{
|
||||
return R_TRUE;
|
||||
ut64 ret = 0LL;
|
||||
if (dbg->h && dbg->h->mmu_alloc)
|
||||
ret = dbg->h->mmu_alloc(dbg, size, addr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_debug_mmu_free(struct r_debug_t *dbg, ut64 addr)
|
||||
{
|
||||
return R_TRUE;
|
||||
int ret = R_FALSE;
|
||||
if (dbg->h && dbg->h->mmu_free)
|
||||
ret = dbg->h->mmu_free(dbg, addr);
|
||||
return ret;
|
||||
}
|
||||
|
@ -36,10 +36,12 @@ struct r_crypto_handle_t {
|
||||
int (*update)(struct r_crypto_t* cry, const ut8 *buf, int len);
|
||||
int (*final)(struct r_crypto_t* cry, const ut8 *buf, int len);
|
||||
int (*use)(const char *algo);
|
||||
int (*fini)(struct r_crypto_t *cry);
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
R_API struct r_crypto_t *r_crypto_init(struct r_crypto_t *cry);
|
||||
R_API struct r_crypto_t *r_crypto_init(struct r_crypto_t *cry, int hard);
|
||||
R_API struct r_crypto_t *r_crypto_as_new(struct r_crypto_t *cry);
|
||||
R_API int r_crypto_add(struct r_crypto_t *cry, struct r_crypto_handle_t *h);
|
||||
R_API struct r_crypto_t *r_crypto_new();
|
||||
R_API struct r_crypto_t *r_crypto_free(struct r_crypto_t *cry);
|
||||
|
@ -13,20 +13,29 @@
|
||||
struct r_debug_handle_t {
|
||||
const char *name;
|
||||
const char **archs;
|
||||
int (*get_arch)();
|
||||
/* life */
|
||||
int (*startv)(int argc, char **argv);
|
||||
int (*attach)(int pid);
|
||||
int (*detach)(int pid);
|
||||
/* flow */
|
||||
int (*step)(int pid); // if step() is NULL; reimplement it with traps
|
||||
int (*cont)(int pid);
|
||||
int (*wait)(int pid);
|
||||
int (*get_arch)();
|
||||
int (*contsc)(int pid, int sc);
|
||||
//int (*bp_write)(int pid, ut64 addr, int hw, int type);
|
||||
int (*bp_write)(int pid, ut64 addr, int size, int hw, int rwx);
|
||||
/* registers */
|
||||
struct r_regset_t * (*reg_read)(int pid);
|
||||
int (*reg_write)(int pid, struct r_regset_t *regs);
|
||||
// XXX bad signature int (*bp_read)(int pid, ut64 addr, int hw, int type);
|
||||
/* memory */
|
||||
ut64 (*mmu_alloc)(void *user, ut64 size, ut64 addr);
|
||||
int (*mmu_free)(void *user, ut64 addr);
|
||||
|
||||
struct list_head list;
|
||||
|
||||
// DEPRECATED
|
||||
// XXX bad signature int (*bp_read)(int pid, ut64 addr, int hw, int type);
|
||||
//int (*bp_write)(int pid, ut64 addr, int hw, int type);
|
||||
//int (*bp_write)(int pid, ut64 addr, int size, int hw, int rwx);
|
||||
};
|
||||
|
||||
struct r_debug_t {
|
||||
@ -70,7 +79,7 @@ struct r_debug_pid_t {
|
||||
R_API int r_debug_handle_add(struct r_debug_t *dbg, struct r_debug_handle_t *foo);
|
||||
R_API int r_debug_handle_set(struct r_debug_t *dbg, const char *str);
|
||||
R_API int r_debug_handle_init(struct r_debug_t *dbg);
|
||||
R_API int r_debug_init(struct r_debug_t *dbg);
|
||||
R_API int r_debug_init(struct r_debug_t *dbg, int hard);
|
||||
R_API struct r_debug_t *r_debug_new();
|
||||
R_API struct r_debug_t *r_debug_free(struct r_debug_t *dbg);
|
||||
|
||||
|
@ -16,8 +16,12 @@ namespace Radare {
|
||||
public uint64 get_baddr();
|
||||
public Entrypoint* get_entry();
|
||||
public Section* get_sections();
|
||||
|
||||
public Radare.List<Bin.Symbol*> symbols;
|
||||
|
||||
public Symbol* get_symbols();
|
||||
public Import* get_imports();
|
||||
|
||||
public Info* get_info();
|
||||
public uint64 get_section_offset(string name);
|
||||
public uint64 get_section_rva(string name);
|
||||
|
@ -25,8 +25,8 @@ namespace Radare {
|
||||
public bool continue_until(uint64 addr);
|
||||
public bool continue_syscall(int syscall);
|
||||
|
||||
public bool mmu_alloc(uint64 size, out uint64 size);
|
||||
public bool mmu_free(uint64 addr);
|
||||
//public bool mmu_alloc(uint64 size, out uint64 size);
|
||||
//public bool mmu_free(uint64 addr);
|
||||
|
||||
/* registers */
|
||||
[Compact]
|
||||
@ -39,23 +39,24 @@ namespace Radare {
|
||||
bool reg_set(string name, uint64 val);
|
||||
bool reg_list(string name, uint64 val); // TODO must be deprecated
|
||||
|
||||
/* breakpoints */
|
||||
/* breakpoints
|
||||
public bool bp_enable(uint64 addr, bool set);
|
||||
public bool bp_add(uint64 addr, int sz, bool hw, int rwx);
|
||||
public bool bp_del(uint64 addr);
|
||||
public bool bp_restore(bool set);
|
||||
public bool bp_list(bool rad); // XXX to be deprecated
|
||||
*/
|
||||
/* processes */
|
||||
struct Process {
|
||||
int pid;
|
||||
int status;
|
||||
int runnable;
|
||||
public struct Process {
|
||||
public int pid;
|
||||
public int status;
|
||||
public int runnable;
|
||||
// list for childs
|
||||
// list for threads
|
||||
struct Process parent;
|
||||
//public struct Process *parent;
|
||||
}
|
||||
|
||||
enum ProcessStatus {
|
||||
public enum ProcessStatus {
|
||||
STOP,
|
||||
RUN,
|
||||
SLEEP,
|
||||
|
@ -50,7 +50,7 @@ namespace Radare {
|
||||
}
|
||||
|
||||
[Compact]
|
||||
[CCode (cprefix="ralist_", cheader_filename="list_c.h", cname="struct list_head")]
|
||||
[CCode (cprefix="ralist_", cheader_filename="list.h", cname="struct list_head")]
|
||||
public static class List<G> {
|
||||
[CCode (cname="ralist_next")]
|
||||
public bool next();
|
||||
@ -63,6 +63,7 @@ namespace Radare {
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: only required for list.vala (must be removed)
|
||||
// DEMO TEST DEMO TEST DEMO TEST DEMO TEST DEMO TEST //
|
||||
[Compact]
|
||||
[CCode (cname="struct foo", cheader_filename="list_c.h")]
|
||||
|
@ -64,7 +64,7 @@ asm:
|
||||
-g -o asm
|
||||
|
||||
bin:
|
||||
valac -C --vapidir=${PWD}/.. bin.vala --pkg r_bin
|
||||
valac -C --vapidir=${PWD}/.. bin.vala --pkg r_bin --pkg r_util
|
||||
gcc bin.c `pkg-config gobject-2.0 --libs --cflags` -I../../include/ \
|
||||
-lr_bin -Wl,-R../../bin -L../../bin \
|
||||
-lr_util -Wl,-R../../util -L../../util \
|
||||
|
@ -43,7 +43,13 @@ public class BinExample
|
||||
stdout.printf("idx=%02i name=%s\n", i, imp[i].name);
|
||||
}
|
||||
|
||||
/* TODO: make it possible */ /*
|
||||
stdout.printf("SYMBOLS\n");
|
||||
foreach (unowned Bin.Symbol* sym in bin.symbols) {
|
||||
stdout.printf(" => name=%s\n", sym->name);
|
||||
}
|
||||
*/
|
||||
|
||||
var sym = bin.get_symbols();
|
||||
for (i=0; !sym[i].last; i++) {
|
||||
stdout.printf("idx=%02i name=%s\n", i, sym[i].name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user