mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-09 20:04:49 +00:00
* Replace main for binsym in r_bin
* Added dummy commands for r_debug_fork/clone
This commit is contained in:
parent
a4f1627681
commit
421208a0c7
5
TODO
5
TODO
@ -18,6 +18,9 @@ Debugger
|
||||
|
||||
pancake
|
||||
-------
|
||||
* Implement software stepping (with code analysis+ breakpoints)
|
||||
* Implement dbg.bep
|
||||
- in r_core? in r_debug after attach? maybe only in r2 binr?
|
||||
* fork/clone child . inject code to create new threads or pids
|
||||
- dpn dptn
|
||||
* Functions in r_util to get lil/big ut8,16,32 from ut8*
|
||||
@ -45,7 +48,7 @@ pancake
|
||||
|
||||
nibble
|
||||
------
|
||||
* implement getsym() in r_bin , replace getmain()
|
||||
* Display getsym() stuff in rabin2, not only legit syms
|
||||
* Check if python plugin works from inside
|
||||
- write tuto, how to call py code from shell or r2
|
||||
* dmi command must read from memory if no file path provided
|
||||
|
@ -105,7 +105,7 @@ static int rabin_show_main() {
|
||||
RBinAddr *binmain;
|
||||
ut64 baddr = gbaddr?gbaddr:r_bin_get_baddr (bin);
|
||||
|
||||
if ((binmain = r_bin_get_main (bin)) == NULL)
|
||||
if ((binmain = r_bin_get_sym (bin, R_BIN_SYM_MAIN)) == NULL)
|
||||
return R_FALSE;
|
||||
if (rad) {
|
||||
printf ("fs symbols\n");
|
||||
|
@ -78,6 +78,7 @@ static RList* get_strings(RBinArch *arch, int min) {
|
||||
}
|
||||
|
||||
static int r_bin_init_items(RBin *bin, int dummy) {
|
||||
int i;
|
||||
struct list_head *pos;
|
||||
RBinArch *arch = &bin->curarch;
|
||||
|
||||
@ -95,8 +96,9 @@ static int r_bin_init_items(RBin *bin, int dummy) {
|
||||
return R_FALSE;
|
||||
if (arch->curplugin->baddr)
|
||||
arch->baddr = arch->curplugin->baddr (arch);
|
||||
if (arch->curplugin->main)
|
||||
arch->main = arch->curplugin->main (arch);
|
||||
if (arch->curplugin->binsym)
|
||||
for (i=0; i<R_BIN_SYM_LAST; i++)
|
||||
arch->binsym[i] = arch->curplugin->binsym (arch, i);
|
||||
if (arch->curplugin->entries)
|
||||
arch->entries = arch->curplugin->entries (arch);
|
||||
if (arch->curplugin->fields)
|
||||
@ -121,8 +123,8 @@ static int r_bin_init_items(RBin *bin, int dummy) {
|
||||
|
||||
/* TODO: Free plugins */
|
||||
static void r_bin_free_items(RBin *bin) {
|
||||
int i;
|
||||
RBinArch *arch = &bin->curarch;
|
||||
|
||||
if (arch->entries)
|
||||
r_list_free (arch->entries);
|
||||
if (arch->fields)
|
||||
@ -141,8 +143,9 @@ static void r_bin_free_items(RBin *bin) {
|
||||
r_list_free (arch->strings);
|
||||
if (arch->symbols)
|
||||
r_list_free (arch->symbols);
|
||||
if (arch->main)
|
||||
free (arch->main);
|
||||
if (arch->binsym)
|
||||
for (i=0; i<R_BIN_SYM_LAST; i++)
|
||||
free (arch->binsym[i]);
|
||||
if (arch->file)
|
||||
free (arch->file);
|
||||
if (arch->curplugin && arch->curplugin->destroy)
|
||||
@ -252,8 +255,10 @@ R_API ut64 r_bin_get_baddr(RBin *bin) {
|
||||
return bin->curarch.baddr;
|
||||
}
|
||||
|
||||
R_API RBinAddr* r_bin_get_main(RBin *bin) {
|
||||
return bin->curarch.main;
|
||||
R_API RBinAddr* r_bin_get_sym(RBin *bin, int sym) {
|
||||
if (sym<0 || sym>=R_BIN_SYM_LAST)
|
||||
return NULL;
|
||||
return bin->curarch.binsym[sym];
|
||||
}
|
||||
|
||||
R_API RList* r_bin_get_entries(RBin *bin) {
|
||||
@ -395,12 +400,14 @@ R_API void r_bin_set_user_ptr(RBin *bin, void *user) {
|
||||
}
|
||||
|
||||
R_API RBinObj *r_bin_get_object(RBin *bin, int flags) {
|
||||
int i;
|
||||
RBinObj *obj = R_NEW (RBinObj);
|
||||
if (obj) {
|
||||
obj->symbols = r_bin_get_symbols (bin);
|
||||
obj->imports = r_bin_get_imports (bin);
|
||||
obj->entries = r_bin_get_entries (bin);
|
||||
obj->main = r_bin_get_main (bin);
|
||||
for (i=0; i<R_BIN_SYM_LAST; i++)
|
||||
obj->binsym[i] = r_bin_get_sym (bin, i);
|
||||
obj->baddr = r_bin_get_baddr (bin);
|
||||
}
|
||||
return obj;
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
static inline int __strnlen(const char *str, int len) {
|
||||
int l = 0;
|
||||
|
||||
while (*str && --len) {
|
||||
str++;
|
||||
l++;
|
||||
|
@ -28,7 +28,7 @@ struct r_bin_plugin_t r_bin_plugin_dummy = {
|
||||
.destroy = &destroy,
|
||||
.check = NULL,
|
||||
.baddr = &baddr,
|
||||
.main = NULL,
|
||||
.binsym = NULL,
|
||||
.entries = NULL,
|
||||
.sections = NULL,
|
||||
.symbols = NULL,
|
||||
|
@ -21,13 +21,16 @@ static ut64 baddr(RBinArch *arch) {
|
||||
return Elf_(r_bin_elf_get_baddr) (arch->bin_obj);
|
||||
}
|
||||
|
||||
static RBinAddr* binmain(RBinArch *arch) {
|
||||
static RBinAddr* binsym(RBinArch *arch, int sym) {
|
||||
RBinAddr *ret = NULL;
|
||||
|
||||
if (!(ret = R_NEW (RBinAddr)))
|
||||
return NULL;
|
||||
memset (ret, '\0', sizeof (RBinAddr));
|
||||
ret->offset = ret->rva = Elf_(r_bin_elf_get_main_offset) (arch->bin_obj);
|
||||
switch (sym) {
|
||||
case R_BIN_SYM_MAIN:
|
||||
if (!(ret = R_NEW (RBinAddr)))
|
||||
return NULL;
|
||||
memset (ret, '\0', sizeof (RBinAddr));
|
||||
ret->offset = ret->rva = Elf_(r_bin_elf_get_main_offset) (arch->bin_obj);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -268,7 +271,7 @@ struct r_bin_plugin_t r_bin_plugin_elf = {
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
.main = &binmain,
|
||||
.binsym = &binsym,
|
||||
.entries = &entries,
|
||||
.sections = §ions,
|
||||
.symbols = &symbols,
|
||||
|
@ -21,7 +21,7 @@ struct r_bin_plugin_t r_bin_plugin_elf64 = {
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
.main = &binmain,
|
||||
.binsym = &binsym,
|
||||
.entries = &entries,
|
||||
.sections = §ions,
|
||||
.symbols = &symbols,
|
||||
|
@ -138,7 +138,7 @@ struct r_bin_plugin_t r_bin_plugin_java = {
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
.main = NULL,
|
||||
.binsym = NULL,
|
||||
.entries = &entries,
|
||||
.sections = NULL,
|
||||
.symbols = &symbols,
|
||||
|
@ -199,7 +199,7 @@ struct r_bin_plugin_t r_bin_plugin_mach0 = {
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
.main = NULL,
|
||||
.binsym = NULL,
|
||||
.entries = &entries,
|
||||
.sections = §ions,
|
||||
.symbols = &symbols,
|
||||
|
@ -19,7 +19,7 @@ struct r_bin_plugin_t r_bin_plugin_mach064 = {
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
.main = NULL,
|
||||
.binsym = NULL,
|
||||
.entries = &entries,
|
||||
.sections = §ions,
|
||||
.symbols = &symbols,
|
||||
|
@ -21,13 +21,16 @@ static ut64 baddr(RBinArch *arch) {
|
||||
return PE_(r_bin_pe_get_image_base) (arch->bin_obj);
|
||||
}
|
||||
|
||||
static RBinAddr* binmain(RBinArch *arch) {
|
||||
static RBinAddr* binsym(RBinArch *arch, int type) {
|
||||
RBinAddr *ret = NULL;
|
||||
|
||||
if (!(ret = R_NEW (RBinAddr)))
|
||||
return NULL;
|
||||
memset (ret, '\0', sizeof (RBinAddr));
|
||||
ret->offset = ret->rva = PE_(r_bin_pe_get_main_offset) (arch->bin_obj);
|
||||
switch (type) {
|
||||
case R_BIN_SYM_MAIN:
|
||||
if (!(ret = R_NEW (RBinAddr)))
|
||||
return NULL;
|
||||
memset (ret, '\0', sizeof (RBinAddr));
|
||||
ret->offset = ret->rva = PE_(r_bin_pe_get_main_offset) (arch->bin_obj);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -227,7 +230,7 @@ struct r_bin_plugin_t r_bin_plugin_pe = {
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
.main = &binmain,
|
||||
.binsym = &binsym,
|
||||
.entries = &entries,
|
||||
.sections = §ions,
|
||||
.symbols = &symbols,
|
||||
|
@ -4,9 +4,8 @@
|
||||
#include "bin_pe.c"
|
||||
|
||||
static int check(RBinArch *arch) {
|
||||
int idx, ret = R_FALSE;
|
||||
|
||||
idx = arch->buf->buf[0x3c]|(arch->buf->buf[0x3d]<<8);
|
||||
int ret = R_FALSE;
|
||||
int idx = arch->buf->buf[0x3c]|(arch->buf->buf[0x3d]<<8);
|
||||
if (arch->buf->length>=idx+0x20)
|
||||
if (!memcmp (arch->buf->buf, "\x4d\x5a", 2) &&
|
||||
!memcmp (arch->buf->buf+idx, "\x50\x45", 2) &&
|
||||
@ -24,7 +23,7 @@ struct r_bin_plugin_t r_bin_plugin_pe64 = {
|
||||
.destroy = &destroy,
|
||||
.check = &check,
|
||||
.baddr = &baddr,
|
||||
.main = &binmain,
|
||||
.binsym = &binsym,
|
||||
.entries = &entries,
|
||||
.sections = §ions,
|
||||
.symbols = &symbols,
|
||||
|
@ -7,10 +7,8 @@
|
||||
#include "mach0/dyldcache.h"
|
||||
|
||||
static int check(RBin *bin) {
|
||||
ut8 *filebuf;
|
||||
int size, ret = R_FALSE;
|
||||
|
||||
filebuf = (ut8*)r_file_slurp_range (bin->file, 0, 4, &size);
|
||||
ut8 *filebuf = (ut8*)r_file_slurp_range (bin->file, 0, 4, &size);
|
||||
if (filebuf && size == 4) {
|
||||
if (!memcmp (filebuf, "\x64\x79\x6c\x64", 4))
|
||||
ret = R_TRUE;
|
||||
@ -19,28 +17,26 @@ static int check(RBin *bin) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO: destroy must be void?
|
||||
static int destroy(RBin *bin) {
|
||||
r_bin_dyldcache_free ((struct r_bin_dyldcache_obj_t*)bin->bin_obj);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int load(RBin *bin) {
|
||||
if((bin->bin_obj = r_bin_dyldcache_new (bin->file)))
|
||||
return R_TRUE;
|
||||
return R_FALSE;
|
||||
return ((bin->bin_obj = r_bin_dyldcache_new (bin->file)))? R_TRUE: R_FALSE;
|
||||
}
|
||||
|
||||
static int extract(RBin *bin, int idx) {
|
||||
struct r_bin_dyldcache_lib_t *lib;
|
||||
int nlib;
|
||||
|
||||
lib = r_bin_dyldcache_extract ((struct r_bin_dyldcache_obj_t*)bin->bin_obj, idx, &nlib);
|
||||
if (!lib)
|
||||
return 0;
|
||||
bin->curarch.file = strdup (lib->path);
|
||||
bin->curarch.buf = lib->b;
|
||||
bin->curarch.size = lib->size;
|
||||
free (lib);
|
||||
int nlib = 0;
|
||||
struct r_bin_dyldcache_lib_t *lib = r_bin_dyldcache_extract (
|
||||
(struct r_bin_dyldcache_obj_t*)bin->bin_obj, idx, &nlib);
|
||||
if (lib) {
|
||||
bin->curarch.file = strdup (lib->path);
|
||||
bin->curarch.buf = lib->b;
|
||||
bin->curarch.size = lib->size;
|
||||
free (lib);
|
||||
}
|
||||
return nlib;
|
||||
}
|
||||
|
||||
|
@ -3745,7 +3745,13 @@ static void cmd_debug_pid(RCore *core, const char *input) {
|
||||
r_debug_kill (core->dbg, R_FALSE, sig);
|
||||
} else eprintf ("Invalid arguments\n");
|
||||
break;
|
||||
case 'n':
|
||||
eprintf ("TODO: debug_fork: %d\n", r_debug_fork (core->dbg));
|
||||
break;
|
||||
case 't':
|
||||
if (input[2] == 'n') {
|
||||
eprintf ("TODO: debug_clone: %d\n", r_debug_clone (core->dbg));
|
||||
} else
|
||||
if (input[2]=='=' || input[2]==' ')
|
||||
r_debug_select (core->dbg, core->dbg->pid,
|
||||
(int) r_num_math (core->num, input+3));
|
||||
@ -3758,6 +3764,8 @@ static void cmd_debug_pid(RCore *core, const char *input) {
|
||||
" dp* list all attachable pids\n"
|
||||
" dpa 377 attach and select this pid\n"
|
||||
" dp=748 select this pid\n"
|
||||
" dpn Create new process (fork)\n"
|
||||
" dpnt Create new thread (clone)\n"
|
||||
" dpt List threads of current pid\n"
|
||||
" dpt 74 List threads of given process\n"
|
||||
" dpt=64 Attach to thread\n"
|
||||
|
@ -69,7 +69,7 @@ R_API int r_core_bin_load(RCore *r, const char *file) {
|
||||
RBinAddr *binmain;
|
||||
|
||||
r_flag_space_set (r->flags, "symbols");
|
||||
if ((binmain = r_bin_get_main (r->bin)) != NULL)
|
||||
if ((binmain = r_bin_get_sym (r->bin, R_BIN_SYM_MAIN)) != NULL)
|
||||
r_flag_set (r->flags, "main", va?baddr+binmain->rva:binmain->offset,
|
||||
r->blocksize, 0);
|
||||
|
||||
|
@ -364,3 +364,16 @@ R_API RList *r_debug_frames (RDebug *dbg) {
|
||||
return dbg->h->frames (dbg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* TODO: Implement fork and clone */
|
||||
R_API int r_debug_fork (RDebug *dbg) {
|
||||
//if (dbg && dbg->h && dbg->h->frames)
|
||||
//return dbg->h->frames (dbg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
R_API int r_debug_clone (RDebug *dbg) {
|
||||
//if (dbg && dbg->h && dbg->h->frames)
|
||||
//return dbg->h->frames (dbg);
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,19 +22,19 @@
|
||||
#define R_BIN_SIZEOF_STRINGS 256
|
||||
#define R_BIN_MAX_ARCH 1024
|
||||
|
||||
// TODO: rename getmain() bin.getsym(RBin.SYM_ENTRY)
|
||||
enum {
|
||||
R_BIN_SYM_ENTRY,
|
||||
R_BIN_SYM_INIT,
|
||||
R_BIN_SYM_MAIN,
|
||||
R_BIN_SYM_FINI
|
||||
R_BIN_SYM_FINI,
|
||||
R_BIN_SYM_LAST
|
||||
};
|
||||
|
||||
typedef struct r_bin_arch_t {
|
||||
char *file;
|
||||
int size;
|
||||
ut64 baddr;
|
||||
struct r_bin_addr_t *main;
|
||||
struct r_bin_addr_t *binsym[R_BIN_SYM_LAST];
|
||||
struct r_bin_info_t *info;
|
||||
RList* entries;
|
||||
RList* sections;
|
||||
@ -81,7 +81,7 @@ typedef struct r_bin_plugin_t {
|
||||
int (*destroy)(RBinArch *arch);
|
||||
int (*check)(RBinArch *arch);
|
||||
ut64 (*baddr)(RBinArch *arch);
|
||||
struct r_bin_addr_t* (*main)(RBinArch *arch);
|
||||
struct r_bin_addr_t* (*binsym)(RBinArch *arch, int num);
|
||||
RList* (*entries)(RBinArch *arch);
|
||||
RList* (*sections)(RBinArch *arch);
|
||||
RList* (*symbols)(RBinArch *arch);
|
||||
@ -195,7 +195,7 @@ typedef struct r_bin_obj_t {
|
||||
RList/*<??>*/ *relocs;
|
||||
RList/*<??>*/ *strings;
|
||||
RBinInfo *info;
|
||||
RBinAddr *main;
|
||||
RBinAddr *binsym[R_BIN_SYM_LAST];
|
||||
// TODO: deprecate r_bin_is_big_endian
|
||||
// TODO: r_bin_is_stripped .. wrapped inside rbinobj?
|
||||
// TODO: has_dbg_syms... maybe flags?
|
||||
@ -210,7 +210,7 @@ R_API int r_bin_list(RBin *bin);
|
||||
R_API int r_bin_load(RBin *bin, const char *file, int dummy);
|
||||
R_API RBinObj *r_bin_get_object(RBin *bin, int flags);
|
||||
R_API ut64 r_bin_get_baddr(RBin *bin);
|
||||
R_API RBinAddr* r_bin_get_main(RBin *bin);
|
||||
R_API RBinAddr* r_bin_get_sym(RBin *bin, int sym);
|
||||
R_API RList* r_bin_get_entries(RBin *bin);
|
||||
R_API RList* r_bin_get_fields(RBin *bin);
|
||||
R_API RList* r_bin_get_imports(RBin *bin);
|
||||
|
@ -257,6 +257,8 @@ R_API RDebugTracepoint *r_debug_trace_add (RDebug *dbg, ut64 addr, int size);
|
||||
R_API RDebugTrace *r_debug_trace_new ();
|
||||
R_API void r_debug_trace_free (RDebug *dbg);
|
||||
R_API int r_debug_trace_tag (RDebug *dbg, int tag);
|
||||
R_API int r_debug_fork (RDebug *dbg);
|
||||
R_API int r_debug_clone (RDebug *dbg);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user