* Implement 'Cl' command to set sourceline comments
* Fix, implement and install rsc2 - Added rsc2 srcline script
This commit is contained in:
parent
f35152b547
commit
814d220ac6
|
@ -5,7 +5,7 @@ PWD=$(shell pwd)
|
|||
|
||||
PFX=${DESTDIR}${PREFIX}
|
||||
|
||||
BINS=rax2 rasm2 rabin2 rahash2 radiff2 radare2 rafind2 rarc2 ranal2 rasc2
|
||||
BINS=rax2 rasm2 rabin2 rahash2 radiff2 radare2 rafind2 rarc2 ranal2 rasc2 rsc2
|
||||
|
||||
all:
|
||||
@for a in ${BINS} ; do (cd $$a && ${MAKE} all) || exit 1; done
|
||||
|
@ -14,13 +14,19 @@ install:
|
|||
mkdir -p ${PFX}/bin
|
||||
for a in ${BINS} ; do ${INSTALL_PROGRAM} $$a/$$a ${PFX}/bin ; done
|
||||
# rarc2
|
||||
cp rarc2/rarc2 ${PFX}/bin
|
||||
cp rarc2/rarc2-tool ${PFX}/bin
|
||||
cp -f rarc2/rarc2 ${PFX}/bin
|
||||
cp -f rarc2/rarc2-tool ${PFX}/bin
|
||||
# shortcut
|
||||
-cd ${PFX}/bin && rm -f r2 ; ln -fs radare2 r2
|
||||
mkdir -p ${PFX}/lib/radare/bin
|
||||
cp -f rsc2/scripts/* ${PFX}/lib/radare/bin
|
||||
chmod +x ${PFX}/lib/radare/bin/*
|
||||
|
||||
install-symlink:
|
||||
symstall install-symlink:
|
||||
mkdir -p ${PFX}/bin
|
||||
mkdir -p ${PFX}/lib/radare/bin
|
||||
chmod +x rsc2/scripts/*
|
||||
cd rsc2/scripts ; for a in * ; do ln -fs ${PWD}/rsc2/scripts/$$a ${PFX}/lib/radare/bin/$$a ; done
|
||||
for a in ${BINS} ; do ln -fs ${PWD}/$$a/$$a ${PFX}/bin/$$a ; done
|
||||
ln -fs ${PWD}/rarc2/rarc2-tool ${PFX}/bin/rarc2-tool
|
||||
-ln -fs ${PFX}/bin/radare2 ${PFX}/bin/r2
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* radare - LGPL - Copyright 2009-2011 nibble<.ds@gmail.com> */
|
||||
|
||||
/* TODO:
|
||||
* -L [lib] dlopen library and show address
|
||||
* -L [lib] dlopen library and show addr
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -91,7 +91,7 @@ static int rabin_show_entrypoints() {
|
|||
if (rad) {
|
||||
printf ("f entry%i @ 0x%08"PFMT64x"\n", i, va?baddr+entry->rva:entry->offset);
|
||||
printf ("s entry%i\n", i);
|
||||
} else printf ("address=0x%08"PFMT64x" offset=0x%08"PFMT64x" baddr=0x%08"PFMT64x"\n",
|
||||
} else printf ("addr=0x%08"PFMT64x" off=0x%08"PFMT64x" baddr=0x%08"PFMT64x"\n",
|
||||
baddr+entry->rva, entry->offset, baddr);
|
||||
i++;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ static int rabin_show_main() {
|
|||
printf ("f main @ 0x%08"PFMT64x"\n", va?baddr+binmain->rva:binmain->offset);
|
||||
} else {
|
||||
eprintf ("[Main]\n");
|
||||
printf ("address=0x%08"PFMT64x" offset=0x%08"PFMT64x"\n",
|
||||
printf ("addr=0x%08"PFMT64x" off=0x%08"PFMT64x"\n",
|
||||
baddr+binmain->rva, binmain->offset);
|
||||
}
|
||||
return R_TRUE;
|
||||
|
@ -202,7 +202,7 @@ static int rabin_show_relocs() {
|
|||
|
||||
r_list_foreach (relocs, iter, reloc) {
|
||||
if (rad) printf ("f reloc.%s @ 0x%08"PFMT64x"\n", reloc->name, va?baddr+reloc->rva:reloc->offset);
|
||||
else printf ("sym=%02i address=0x%08"PFMT64x" offset=0x%08"PFMT64x" type=0x%08x %s\n",
|
||||
else printf ("sym=%02i addr=0x%08"PFMT64x" off=0x%08"PFMT64x" type=0x%08x %s\n",
|
||||
reloc->sym, baddr+reloc->rva, reloc->offset, reloc->type, reloc->name);
|
||||
i++;
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ static int rabin_show_imports() {
|
|||
va?baddr+import->rva:import->offset, import->size, import->name);
|
||||
printf ("f imp.%s @ 0x%08"PFMT64x"\n",
|
||||
import->name, va?baddr+import->rva:import->offset);
|
||||
} else printf ("address=0x%08"PFMT64x" offset=0x%08"PFMT64x" ordinal=%03"PFMT64d" "
|
||||
} else printf ("addr=0x%08"PFMT64x" off=0x%08"PFMT64x" ordinal=%03"PFMT64d" "
|
||||
"hint=%03"PFMT64d" bind=%s type=%s name=%s\n",
|
||||
baddr+import->rva, import->offset,
|
||||
import->ordinal, import->hint, import->bind,
|
||||
|
@ -297,8 +297,8 @@ static int rabin_show_symbols() {
|
|||
printf ("f sym.%s %"PFMT64d" 0x%08"PFMT64x"\n",
|
||||
symbol->name, symbol->size,
|
||||
va?baddr+symbol->rva:symbol->offset);
|
||||
} else printf ("address=0x%08"PFMT64x" offset=0x%08"PFMT64x" ordinal=%03"PFMT64d" "
|
||||
"forwarder=%s size=%"PFMT64d" bind=%s type=%s name=%s\n",
|
||||
} else printf ("addr=0x%08"PFMT64x" off=0x%08"PFMT64x" ordinal=%03"PFMT64d" "
|
||||
"forwarder=%s sz=%"PFMT64d" bind=%s type=%s name=%s\n",
|
||||
baddr+symbol->rva, symbol->offset,
|
||||
symbol->ordinal, symbol->forwarder,
|
||||
symbol->size, symbol->bind, symbol->type,
|
||||
|
@ -334,8 +334,8 @@ static int rabin_show_strings() {
|
|||
"Cs %"PFMT64d" @ 0x%08"PFMT64x"\n",
|
||||
string->string, string->size, va?baddr+string->rva:string->offset,
|
||||
string->size, va?baddr+string->rva:string->offset);
|
||||
} else printf ("address=0x%08"PFMT64x" offset=0x%08"PFMT64x" ordinal=%03"PFMT64d" "
|
||||
"size=%"PFMT64d" section=%s string=%s\n",
|
||||
} else printf ("addr=0x%08"PFMT64x" off=0x%08"PFMT64x" ordinal=%03"PFMT64d" "
|
||||
"sz=%"PFMT64d" section=%s string=%s\n",
|
||||
baddr+string->rva, string->offset,
|
||||
string->ordinal, string->size,
|
||||
section?section->name:"unknown", string->string);
|
||||
|
@ -389,8 +389,8 @@ static int rabin_show_sections() {
|
|||
R_BIN_SCN_WRITABLE (section->srwx)?'w':'-',
|
||||
R_BIN_SCN_EXECUTABLE (section->srwx)?'x':'-',
|
||||
section->name,va?baddr+section->rva:section->offset);
|
||||
} else printf ("idx=%02i address=0x%08"PFMT64x" offset=0x%08"PFMT64x" size=%"PFMT64d" vsize=%"PFMT64d" "
|
||||
"privileges=%c%c%c%c name=%s\n",
|
||||
} else printf ("idx=%02i addr=0x%08"PFMT64x" off=0x%08"PFMT64x" sz=%"PFMT64d" vsz=%"PFMT64d" "
|
||||
"perm=%c%c%c%c name=%s\n",
|
||||
i, baddr+section->rva, section->offset, section->size, section->vsize,
|
||||
R_BIN_SCN_SHAREABLE (section->srwx)?'s':'-',
|
||||
R_BIN_SCN_READABLE (section->srwx)?'r':'-',
|
||||
|
@ -480,9 +480,9 @@ static int rabin_show_fields() {
|
|||
r_name_filter (field->name, sizeof (field->name));
|
||||
printf ("f header.%s @ 0x%08"PFMT64x"\n",
|
||||
field->name, va?baddr+field->rva:field->offset);
|
||||
printf ("[%02i] address=0x%08"PFMT64x" offset=0x%08"PFMT64x" name=%s\n",
|
||||
printf ("[%02i] addr=0x%08"PFMT64x" off=0x%08"PFMT64x" name=%s\n",
|
||||
i, baddr+field->rva, field->offset, field->name);
|
||||
} else printf ("idx=%02i address=0x%08"PFMT64x" offset=0x%08"PFMT64x" name=%s\n",
|
||||
} else printf ("idx=%02i addr=0x%08"PFMT64x" off=0x%08"PFMT64x" name=%s\n",
|
||||
i, baddr+field->rva, field->offset, field->name);
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2006-2010
|
||||
* Copyright (C) 2006-2011
|
||||
* pancake <youterm.com>
|
||||
*
|
||||
* radare is free software; you can redistribute it and/or modify
|
||||
|
@ -31,6 +31,7 @@
|
|||
|
||||
static void rsc_help() {
|
||||
printf ("Usage: rsc [-l] [script] [-h]\n");
|
||||
printf ("RSCDATADIR="RSCDATADIR"\n");
|
||||
}
|
||||
|
||||
static void rsc_show_at(const char *dir) {
|
||||
|
@ -56,7 +57,7 @@ static const char *get_home_dir() {
|
|||
const char *home = getenv("HOME");
|
||||
gbuf[0]='\0';
|
||||
if (home != NULL)
|
||||
snprintf (gbuf, 1023, "%s/.radare/rsc", home);
|
||||
snprintf (gbuf, sizeof (gbuf), "%s/.radare/rsc", home);
|
||||
return gbuf;
|
||||
}
|
||||
|
||||
|
@ -68,26 +69,41 @@ static void rsc_show() {
|
|||
static const char *get_path_for(const char *name) {
|
||||
struct stat st;
|
||||
char path[1024];
|
||||
char lpath[1024];
|
||||
char pathfile[1024];
|
||||
|
||||
sprintf (path, "%s", get_home_dir ());
|
||||
sprintf (pathfile, "%s/%s", path, name);
|
||||
snprintf (path, sizeof (path), "%s", get_home_dir ());
|
||||
snprintf (pathfile, sizeof (pathfile), "%s/%s", path, name);
|
||||
if (!stat (pathfile, &st)) {
|
||||
strcpy (gbuf, path);
|
||||
strncpy (gbuf, path, sizeof (gbuf));
|
||||
return gbuf;
|
||||
}
|
||||
|
||||
sprintf(pathfile, RSCDATADIR"/%s", name);
|
||||
if (stat(pathfile, &st) == 0) {
|
||||
strcpy(gbuf, RSCDATADIR);
|
||||
snprintf (pathfile, sizeof (pathfile), RSCDATADIR"/%s", name);
|
||||
|
||||
if (readlink (pathfile, lpath, sizeof (lpath) == -1)) {
|
||||
strncpy (gbuf, lpath, sizeof (gbuf));
|
||||
return gbuf;
|
||||
} else {
|
||||
if (stat (pathfile, &st) == 0) {
|
||||
strcpy (gbuf, RSCDATADIR);
|
||||
return gbuf;
|
||||
}
|
||||
}
|
||||
// is file
|
||||
// is symlink
|
||||
if (lstat (pathfile, &st) == 0) {
|
||||
strcpy (gbuf, RSCDATADIR);
|
||||
printf ("FOUnd\n");
|
||||
return gbuf;
|
||||
}
|
||||
|
||||
printf ("jklsaf\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int rsc_run(int argc, const char **argv) {
|
||||
const char *path = get_path_for(argv[1]);
|
||||
const char *path = get_path_for (argv[1]);
|
||||
char buf[4096]; // TODO: use strfoo functions
|
||||
int i;
|
||||
|
||||
|
@ -99,9 +115,9 @@ static int rsc_run(int argc, const char **argv) {
|
|||
snprintf (buf, sizeof (buf), "\"%s/%s\" ", path, argv[1]);
|
||||
|
||||
for (i=2;i<argc;i++) {
|
||||
strcat (buf, "\"");
|
||||
strcat (buf, argv[i]);
|
||||
strcat (buf, "\" ");
|
||||
strncat (buf, "\"", sizeof (buf));
|
||||
strncat (buf, argv[i], sizeof (buf));
|
||||
strncat (buf, "\" ", sizeof (buf));
|
||||
}
|
||||
// printf("system('%s')\n", buf);
|
||||
return system (buf);
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/sh
|
||||
FILE=$1
|
||||
|
||||
if [ -z "${FILE}" ]; then
|
||||
echo "Usage: rsc2 srcline [file]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
START=$(rabin2 -rS ${FILE}| grep text|grep ^S| cut -d ' ' -f 3)
|
||||
SIZE=$(rabin2 -rS ${FILE} | grep text|grep ^S| cut -d ' ' -f 4)
|
||||
START=$(rax2 ${START})
|
||||
SIZE=$(rax2 ${SIZE})
|
||||
END=$((${START}+${SIZE}))
|
||||
|
||||
echo "Section text is: `rax2 ${START}` - `rax2 ${END}` (size=${SIZE})"
|
||||
|
||||
SEQ=$(jot ${SIZE} ${START} ${END})
|
||||
|
||||
OLINE=""
|
||||
for a in ${SEQ} ; do
|
||||
ADDR=$(rax2 $a)
|
||||
LINE=`addr2line -e ${FILE} $ADDR`
|
||||
if [ "${LINE}" = "??:0" ]; then
|
||||
continue
|
||||
fi
|
||||
if [ ! "${OLINE}" = "${LINE}" ]; then
|
||||
echo "Cl ${LINE} ${ADDR}"
|
||||
OLINE=${LINE}
|
||||
fi
|
||||
done
|
|
@ -3527,6 +3527,42 @@ static int cmd_meta(void *data, const char *input) {
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
{
|
||||
int num;
|
||||
char *f, *p, *line, buf[4096];
|
||||
f = strdup (input +2);
|
||||
p = strchr (f, ':');
|
||||
if (p) {
|
||||
*p=0;
|
||||
num = atoi (p+1);
|
||||
line = r_file_slurp_line (input+2, num, 0);
|
||||
if (!line) {
|
||||
const char *dirsrc = r_config_get (core->config, "dir.source");
|
||||
if (dirsrc && *dirsrc) {
|
||||
f = r_str_concat (strdup (dirsrc), f);
|
||||
line = r_file_slurp_line (f, num, 0);
|
||||
|
||||
}
|
||||
if (!line) {
|
||||
eprintf ("Cannot slurp file\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
}
|
||||
p = strchr (p+1, ' ');
|
||||
if (p) {
|
||||
snprintf (buf, sizeof (buf), "CC %s:%d %s @ %s",
|
||||
f, num, line, p+1);
|
||||
} else {
|
||||
snprintf (buf, sizeof (buf), "\"CC %s:%d %s\"",
|
||||
f, num, line);
|
||||
}
|
||||
r_core_cmd0 (core, buf);
|
||||
free (line);
|
||||
free (f);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'L': // debug information of current offset
|
||||
ret = r_bin_meta_get_line (core->bin, core->offset, file, 1023, &line);
|
||||
if (ret) {
|
||||
|
@ -3680,6 +3716,7 @@ static int cmd_meta(void *data, const char *input) {
|
|||
" C* # List meta info in r2 commands\n"
|
||||
" C- [len] [@][ addr] # delete metadata at given address range\n"
|
||||
" CL[-] [addr] # show 'code line' information (bininfo)\n"
|
||||
" Cl file:line [addr] # add comment with line information\n"
|
||||
" CC[-] [size] [string] # add/remove comment. Use CC! to edit with $EDITOR\n"
|
||||
" Cv[-] offset reg name # add var substitution\n"
|
||||
" Cs[-] [size] [[addr]] # add string\n"
|
||||
|
|
|
@ -351,6 +351,7 @@ R_API int r_core_config_init(RCore *core) {
|
|||
const char *p;
|
||||
cfg->printf = r_cons_printf;
|
||||
|
||||
r_config_set (cfg, "dir.source", "");
|
||||
r_config_set (cfg, "dir.plugins", LIBDIR"/radare2/"R2_VERSION"/");
|
||||
/* anal */
|
||||
r_config_set_i (cfg, "anal.depth", 50); // XXX: warn if depth is > 50 .. can be problematic
|
||||
|
|
|
@ -213,6 +213,7 @@ R_API int r_io_accept(RIO *io, int fd);
|
|||
R_API int r_io_shift(RIO *io, ut64 start, ut64 end, st64 move);
|
||||
|
||||
/* io/cache.c */
|
||||
R_API int r_io_cache_invalidate(RIO *io, ut64 from, ut64 to);
|
||||
R_API void r_io_cache_commit(RIO *io);
|
||||
R_API void r_io_cache_enable(RIO *io, int read, int write);
|
||||
R_API void r_io_cache_init(RIO *io);
|
||||
|
|
Loading…
Reference in New Issue