Fix rafind2 help, honor rasm2 -l and fix objc demangle
Fix overflow in objc method name demangling
This commit is contained in:
parent
d5c68d9766
commit
53b7f83749
6 changed files with 39 additions and 28 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2009-2012 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2013 - pancake */
|
||||
|
||||
#define USE_THREADS 1
|
||||
|
||||
|
|
@ -20,8 +20,8 @@ static int main_help(int line) {
|
|||
printf ("Usage: r2 [-dDwntLqv] [-P patch] [-p prj] [-a arch] [-b bits] [-i file]\n"
|
||||
" [-s addr] [-B blocksize] [-c cmd] [-e k=v] [file]\n");
|
||||
if (line != 1) printf (
|
||||
" -a [arch] set asm.arch eval var\n"
|
||||
" -b [bits] set asm.bits eval var\n"
|
||||
" -a [arch] set asm.arch\n"
|
||||
" -b [bits] set asm.bits\n"
|
||||
" -B [size] initial block size\n"
|
||||
" -c 'cmd..' execute radare command\n"
|
||||
" -d use 'file' as a program to debug\n"
|
||||
|
|
|
|||
|
|
@ -51,19 +51,23 @@ static int show_help(char *argv0, int line) {
|
|||
printf ("Usage: %s [-Xnzhv] [-b size] [-f from] [-t to] [-[m|s|e] str] [-x hex] file ...\n", argv0);
|
||||
if (line) return 0;
|
||||
printf (
|
||||
" -z search for zero-terminated strings\n"
|
||||
" -s [str] search for a specific string (can be used multiple times)\n"
|
||||
" -e [regex] search for regular expression string matches\n"
|
||||
" -x [hex] search for hexpair string (909090) (can be used multiple times)\n"
|
||||
" -m [str] set a binary mask to be applied on keywords\n"
|
||||
" -f [from] start searching from address 'from'\n"
|
||||
" -t [to] stop search at address 'to'\n"
|
||||
" -X show hexdump of search results\n"
|
||||
" -n do not stop on read errors\n"
|
||||
" -r print using radare commands\n"
|
||||
" -b [size] set block size\n"
|
||||
" -h show this help\n"
|
||||
" -v print version and exit\n"
|
||||
" -b [size] set block size\n"
|
||||
|
||||
" -f [from] start searching from address 'from'\n"
|
||||
" -t [to] stop search at address 'to'\n"
|
||||
" -n do not stop on read errors\n"
|
||||
|
||||
" -s [str] search for a specific string (can be used multiple times)\n"
|
||||
" -x [hex] search for hexpair string (909090) (can be used multiple times)\n"
|
||||
" -e [regex] search for regular expression string matches\n"
|
||||
" -m [str] set a binary mask to be applied on keywords\n"
|
||||
" -z search for zero-terminated strings\n"
|
||||
|
||||
" -r print using radare commands\n"
|
||||
" -X show hexdump of search results\n"
|
||||
" -Z show zero-terminated strings of search results\n"
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -260,6 +260,8 @@ int main(int argc, char *argv[]) {
|
|||
} else {
|
||||
content = r_file_slurp (file, &length);
|
||||
if (content) {
|
||||
if (len && len>0 && len<length)
|
||||
length = len;
|
||||
content[length] = '\0';
|
||||
if (dis) ret = rasm_disasm (content, offset,
|
||||
length, a->bits, ascii, bin, dis-1);
|
||||
|
|
@ -269,21 +271,24 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
} else if (argv[optind]) {
|
||||
if (!strcmp (argv[optind], "-")) {
|
||||
int length;
|
||||
do {
|
||||
len = read (0, buf, sizeof (buf)-1);
|
||||
length = read (0, buf, sizeof (buf)-1);
|
||||
if (len>0 && len < length)
|
||||
length = len;
|
||||
if ((!bin || !dis) && feof (stdin))
|
||||
break;
|
||||
if (!bin || !dis) buf[strlen (buf)-1]='\0';
|
||||
if (dis) ret = rasm_disasm (buf, offset,
|
||||
len, a->bits, ascii, bin, dis-1);
|
||||
else ret = rasm_asm (buf, offset, len, a->bits, bin);
|
||||
length, a->bits, ascii, bin, dis-1);
|
||||
else ret = rasm_asm (buf, offset, length, a->bits, bin);
|
||||
idx += ret;
|
||||
offset += ret;
|
||||
if (!ret) {
|
||||
//eprintf ("invalid\n");
|
||||
return 0;
|
||||
}
|
||||
} while (!len || idx<len);
|
||||
} while (!len || idx<length);
|
||||
return idx;
|
||||
}
|
||||
if (dis) ret = rasm_disasm (argv[optind], offset, len,
|
||||
|
|
|
|||
|
|
@ -552,7 +552,8 @@ R_API int r_bin_class_add_method (RBin *bin, const char *classname, const char *
|
|||
}
|
||||
|
||||
R_API void r_bin_class_add_field (RBin *bin, const char *classname, const char *name) {
|
||||
eprintf ("TODO add field: %s \n", name);
|
||||
#warning TODO: add_field into class
|
||||
//eprintf ("TODO add field: %s \n", name);
|
||||
}
|
||||
|
||||
R_API ut64 r_bin_get_offset (RBin *bin) {
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
/* radare - LGPL - Copyright 2011-2012 - pancake */
|
||||
/* radare - LGPL - Copyright 2011-2013 - pancake */
|
||||
|
||||
#include <r_bin.h>
|
||||
#include <cxx/demangle.h>
|
||||
|
||||
// http://code.google.com/p/smali/wiki/TypesMethodsAndFields
|
||||
R_API char *r_bin_demangle_java(const char *str) {
|
||||
RBuffer *buf;
|
||||
const char *w = NULL;
|
||||
int n = 0;
|
||||
char *ret;
|
||||
const char *ptr;
|
||||
int is_array = 0;
|
||||
const char *ptr;
|
||||
int is_ret = 0;
|
||||
int wlen = 0;
|
||||
RBuffer *buf;
|
||||
int n = 0;
|
||||
char *ret;
|
||||
|
||||
ptr = strchr (str, '(');
|
||||
if (!ptr)
|
||||
|
|
@ -119,7 +119,7 @@ R_API char *r_bin_demangle_objc(RBin *bin, const char *sym) {
|
|||
clas = strdup (sym+2);
|
||||
name = strchr (clas, ' ');
|
||||
if (name) *name++ = 0;
|
||||
for (i=0;name[i];i++) {
|
||||
for (i=0; name[i]; i++) {
|
||||
if (name[i]==']') {
|
||||
name[i] = 0;
|
||||
} else
|
||||
|
|
@ -138,7 +138,7 @@ R_API char *r_bin_demangle_objc(RBin *bin, const char *sym) {
|
|||
return NULL;
|
||||
}
|
||||
*args = 0;
|
||||
name = strdup (args+2);
|
||||
name = strdup (args+2); // memleak :D
|
||||
args = NULL;
|
||||
for (i=0; name[i]; i++) {
|
||||
if (name[i]=='_') {
|
||||
|
|
@ -154,7 +154,7 @@ R_API char *r_bin_demangle_objc(RBin *bin, const char *sym) {
|
|||
}
|
||||
if (type) {
|
||||
if (!strcmp (type, "field")) {
|
||||
ret = malloc (strlen (type)+strlen (name)+32);
|
||||
ret = malloc (strlen (clas)+strlen (name)+32);
|
||||
sprintf (ret, "field int %s::%s", clas, name);
|
||||
} else {
|
||||
if (nargs) {
|
||||
|
|
@ -174,6 +174,7 @@ R_API char *r_bin_demangle_objc(RBin *bin, const char *sym) {
|
|||
r_bin_class_add_method (bin, clas, name, nargs);
|
||||
}
|
||||
}
|
||||
name = NULL;
|
||||
}
|
||||
free (clas);
|
||||
free (args);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
.Dd Mar 11, 2012
|
||||
.Dd Feb 15, 2013
|
||||
.Dt RASM2 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
|
|
|||
Loading…
Reference in a new issue