Bring back the interest on sys/indent.sh

This commit is contained in:
pancake 2017-02-10 02:05:58 +01:00
parent 7d0aa11196
commit 70930f4496
15 changed files with 231 additions and 207 deletions

View File

@ -1,6 +1,7 @@
/* copyright 2015-2016 radare2 by pancake */
/* copyright 2015-2017 radare2 by pancake */
#include <r_userconf.h>
#include <r_util.h>
#ifndef R2_GITTAP
#define R2_GITTAP ""

View File

@ -1,14 +1,14 @@
/* radare - LGPL - Copyright 2009-2016 - pancake, nibble, maijin */
#include "../blob/version.c"
#include <getopt.c> /* getopt.h is not portable :D */
#include <r_anal.h>
#include <r_asm.h>
#include <r_lib.h>
#include <r_types.h>
#include <r_util.h>
#include <stdio.h>
#include <string.h>
#include <getopt.c> /* getopt.h is not portable :D */
#include <r_types.h>
#include <r_asm.h>
#include <r_anal.h>
#include <r_util.h>
#include <r_lib.h>
#include "../blob/version.c"
static RLib *l = NULL;
static RAsm *a = NULL;
@ -28,7 +28,7 @@ static int show_analinfo(const char *arg, ut64 offset) {
if (json) {
printf ("[");
}
for (ret = 0; ret < len; ) {
for (ret = 0; ret < len;) {
aop.size = 0;
if (r_anal_op (anal, &aop, offset, buf + ret, len - ret) > 0) {
//printf ("%s\n", R_STRBUF_SAFEGET (&aop.esil));
@ -105,11 +105,11 @@ static void rasm2_list(RAsm *la, const char *arch) {
const char *str_bits = "32, 64";
const char *license = "GPL";
printf ("\"%s\":{\"bits\":[%s],\"license\":\"%s\",\"description\":\"%s\",\"features\":\"%s\"}%s",
h->name, str_bits, license, h->desc, feat, iter->n? ",": "");
h->name, str_bits, license, h->desc, feat, iter->n? ",": "");
} else {
printf ("%s%s %-9s %-11s %-7s %s\n",
feat, feat2, bits, h->name,
h->license? h->license: "unknown", h->desc);
feat, feat2, bits, h->name,
h->license? h->license: "unknown", h->desc);
}
}
}
@ -212,14 +212,12 @@ static int rasm_show_help(int v) {
" If '-l' value is greater than output length, output is padded with nops\n"
" If the last argument is '-' reads from stdin\n");
printf ("Environment:\n"
" RASM2_NOPLUGINS do not load shared plugins (speedup loading)\n"
" R_DEBUG if defined, show error messages and crash signal\n"
"");
" RASM2_NOPLUGINS do not load shared plugins (speedup loading)\n"
" R_DEBUG if defined, show error messages and crash signal\n"
"");
}
if (v == 2) {
printf (
"Supported Assembler directives:\n"
);
printf ("Supported Assembler directives:\n");
r_asm_list_directives ();
}
return 0;
@ -458,7 +456,7 @@ int main (int argc, char *argv[]) {
filters = optarg;
break;
case 'h':
help ++;
help++;
case 'i':
skip = r_num_math (NULL, optarg);
break;

View File

@ -1,11 +1,14 @@
/* radare - LGPL - Copyright 2007-2016 - pancake */
/* radare - LGPL - Copyright 2007-2017 - pancake */
#include <r_util.h>
#include <r_print.h>
#include "../blob/version.c"
#include <r_print.h>
#define STDIN_BUFFER_SIZE 354096
#define R_STATIC_ASSERT(x) switch (0) {case 0: case (x):;}
#define R_STATIC_ASSERT(x)\
switch (0) { \
case 0:\
case (x):;\
}
static RNum *num;
static int help();
@ -14,7 +17,7 @@ static int use_stdin();
static int force_mode = 0;
static int rax(char *str, int len, int last);
static int format_output (char mode, const char *s) {
static int format_output(char mode, const char *s) {
ut64 n = r_num_math (num, s);
char strbits[65];
if (force_mode) {
@ -22,27 +25,27 @@ static int format_output (char mode, const char *s) {
}
if (flags & 2) {
ut64 n2 = n;
r_mem_swapendian ((ut8*)&n, (ut8*)&n2, (n >> 32) ? 8 : 4);
r_mem_swapendian ((ut8 *)&n, (ut8 *)&n2, (n >> 32)? 8: 4);
}
switch (mode) {
case 'I': printf ("%"PFMT64d"\n", n); break;
case 'I': printf ("%" PFMT64d "\n", n); break;
case '0': {
int len = strlen (s);
if (len > 0 && s[len - 1] == 'f') {
R_STATIC_ASSERT(sizeof (float) == 4)
R_STATIC_ASSERT (sizeof (float) == 4)
float f = (float)num->fvalue;
ut8 *p = (ut8*)&f;
ut8 *p = (ut8 *)&f;
printf ("Fx%02x%02x%02x%02x\n", p[3], p[2], p[1], p[0]);
} else {
printf ("0x%"PFMT64x"\n", n);
printf ("0x%" PFMT64x "\n", n);
}
} break;
} break;
case 'F': {
float *f = (float*)&n;
float *f = (float *)&n;
printf ("%ff\n", *f);
} break;
} break;
case 'f': printf ("%.01lf\n", num->fvalue); break;
case 'O': printf ("0%"PFMT64o"\n", n); break;
case 'O': printf ("0%" PFMT64o "\n", n); break;
case 'B':
if (n) {
r_num_to_bits (strbits, n);
@ -53,7 +56,7 @@ static int format_output (char mode, const char *s) {
if (n) {
r_num_to_trits (strbits, n);
printf ("%st\n", strbits);
} else printf ("0t\n");
} else printf ("0t\n");
break;
default:
eprintf ("Unknown output mode %d\n", mode);
@ -62,7 +65,7 @@ static int format_output (char mode, const char *s) {
return true;
}
static int help () {
static int help() {
printf (
" =[base] ; rax2 =10 0x46 -> output in base 10\n"
" int -> hex ; rax2 10\n"
@ -100,15 +103,14 @@ static int help () {
" -x hash string ; rax2 -x linux osx\n"
" -u units ; rax2 -u 389289238 # 317.0M\n"
" -w signed word ; rax2 -w 16 0xffff\n"
" -v version ; rax2 -v\n"
);
" -v version ; rax2 -v\n");
return true;
}
static int rax (char *str, int len, int last) {
static int rax(char *str, int len, int last) {
float f;
ut8 *buf;
char *p, out_mode = (flags & 128) ? 'I' : '0';
char *p, out_mode = (flags & 128)? 'I': '0';
int i;
if (!(flags & 4) || !len)
len = strlen (str);
@ -150,7 +152,7 @@ static int rax (char *str, int len, int last) {
case 'v': blob_version ("rax2"); return 0;
case '\0': return !use_stdin ();
default:
out_mode = (flags ^ 32) ? '0' : 'I';
out_mode = (flags ^ 32)? '0': 'I';
if (str[1] >= '0' && str[1] <= '9') {
if (str[2] == 'x') out_mode = 'I';
return format_output (out_mode, str);
@ -173,14 +175,14 @@ static int rax (char *str, int len, int last) {
return false;
}
}
dotherax:
dotherax:
if (flags & 1) { // -s
int n = ((strlen (str)) >> 1) + 1;
buf = malloc (n);
if (buf) {
memset (buf, '\0', n);
n = r_hex_str2bin (str, (ut8*)buf);
n = r_hex_str2bin (str, (ut8 *)buf);
if (n > 0) fwrite (buf, n, 1, stdout);
#if __EMSCRIPTEN__
puts ("");
@ -216,20 +218,20 @@ static int rax (char *str, int len, int last) {
int n = ((strlen (str)) >> 1) + 1;
char *s = NULL;
ut32 *m;
buf = (ut8*) malloc (n);
buf = (ut8 *)malloc (n);
if (!buf) {
return false;
}
m = (ut32 *) buf;
m = (ut32 *)buf;
memset (buf, '\0', n);
n = r_hex_str2bin (str, (ut8*)buf);
n = r_hex_str2bin (str, (ut8 *)buf);
if (n < 1 || !memcmp (str, "0x", 2)) {
ut64 q = r_num_math (num, str);
s = r_print_randomart ((ut8*)&q, sizeof (q), q);
s = r_print_randomart ((ut8 *)&q, sizeof (q), q);
printf ("%s\n", s);
free (s);
} else {
s = r_print_randomart ((ut8*)buf, n, *m);
s = r_print_randomart ((ut8 *)buf, n, *m);
printf ("%s\n", s);
free (s);
}
@ -239,16 +241,19 @@ static int rax (char *str, int len, int last) {
ut64 n = r_num_math (num, str);
if (n >> 32) {
/* is 64 bit value */
ut8 *np = (ut8*)&n;
if (flags & 1) fwrite (&n, sizeof (n), 1, stdout);
else printf ("%02x%02x%02x%02x" "%02x%02x%02x%02x\n",
np[0], np[1], np[2], np[3],
np[4], np[5], np[6], np[7]);
ut8 *np = (ut8 *)&n;
if (flags & 1)
fwrite (&n, sizeof (n), 1, stdout);
else printf ("%02x%02x%02x%02x"
"%02x%02x%02x%02x\n",
np[0], np[1], np[2], np[3],
np[4], np[5], np[6], np[7]);
} else {
/* is 32 bit value */
ut32 n32 = (ut32)(n & UT32_MAX);
ut8 *np = (ut8*)&n32;
if (flags & 1) fwrite (&n32, sizeof (n32), 1, stdout);
ut32 n32 = (ut32) (n & UT32_MAX);
ut8 *np = (ut8 *)&n32;
if (flags & 1)
fwrite (&n32, sizeof (n32), 1, stdout);
else printf ("%02x%02x%02x%02x\n",
np[0], np[1], np[2], np[3]);
}
@ -259,53 +264,53 @@ static int rax (char *str, int len, int last) {
// TODO: move to r_util
for (i = 0; i < strlen (str); i++) {
ut8 ch = str[i];
printf ("%d%d%d%d" "%d%d%d%d",
ch & 128? 1:0,
ch & 64? 1:0,
ch & 32? 1:0,
ch & 16? 1:0,
ch & 8? 1:0,
ch & 4? 1:0,
ch & 2? 1:0,
ch & 1? 1:0
);
printf ("%d%d%d%d"
"%d%d%d%d",
ch & 128? 1: 0,
ch & 64? 1: 0,
ch & 32? 1: 0,
ch & 16? 1: 0,
ch & 8? 1: 0,
ch & 4? 1: 0,
ch & 2? 1: 0,
ch & 1? 1: 0);
}
return true;
} else if (flags & (1 << 16)) { // -w
ut64 n = r_num_math (num, str);
if (n >> 31) {
// is >32bit
n = (st64)(st32)n;
n = (st64) (st32)n;
} else if (n >> 14) {
n = (st64)(st16)n;
n = (st64) (st16)n;
} else if (n >> 7) {
n = (st64)(st8)n;
n = (st64) (st8)n;
}
printf ("%"PFMT64d"\n", n);
printf ("%" PFMT64d "\n", n);
fflush (stdout);
return true;
} else if (flags & (1 << 15)) { // -N
ut64 n = r_num_math (num, str);
if (n >> 32) {
/* is 64 bit value */
ut8 *np = (ut8*)&n;
ut8 *np = (ut8 *)&n;
if (flags & 1) {
fwrite (&n, sizeof (n), 1, stdout);
} else {
printf ("\\x%02x\\x%02x\\x%02x\\x%02x"
"\\x%02x\\x%02x\\x%02x\\x%02x\n",
np[0], np[1], np[2], np[3],
np[4], np[5], np[6], np[7]);
"\\x%02x\\x%02x\\x%02x\\x%02x\n",
np[0], np[1], np[2], np[3],
np[4], np[5], np[6], np[7]);
}
} else {
/* is 32 bit value */
ut32 n32 = (ut32)(n & UT32_MAX);
ut8 *np = (ut8*) & n32;
ut32 n32 = (ut32) (n & UT32_MAX);
ut8 *np = (ut8 *)&n32;
if (flags & 1) {
fwrite (&n32, sizeof (n32), 1, stdout);
} else {
printf ("\\x%02x\\x%02x\\x%02x\\x%02x\n",
np[0], np[1], np[2], np[3]);
np[0], np[1], np[2], np[3]);
}
}
fflush (stdout);
@ -318,14 +323,14 @@ static int rax (char *str, int len, int last) {
} else if (flags & (1 << 11)) { // -t
ut32 n = r_num_math (num, str);
RPrint *p = r_print_new ();
r_print_date_unix (p, (const ut8*)&n, sizeof (ut32));
r_print_date_unix (p, (const ut8 *)&n, sizeof (ut32));
r_print_free (p);
return true;
} else if (flags & (1 << 12)) { // -E
const int len = strlen (str);
char * out = calloc (sizeof (char), ((len + 1) * 4) / 3);
char *out = calloc (sizeof (char), ((len + 1) * 4) / 3);
if (out) {
r_base64_encode (out, (const ut8*)str, len);
r_base64_encode (out, (const ut8 *)str, len);
printf ("%s\n", out);
fflush (stdout);
free (out);
@ -334,7 +339,7 @@ static int rax (char *str, int len, int last) {
} else if (flags & (1 << 13)) { // -D
const int len = strlen (str);
/* http://stackoverflow.com/questions/4715415/base64-what-is-the-worst-possible-increase-in-space-usage */
ut8* out = calloc (sizeof (ut8), ((len + 2) / 3) * 4);
ut8 *out = calloc (sizeof (ut8), ((len + 2) / 3) * 4);
if (out) {
r_base64_decode (out, str, len);
printf ("%s\n", out);
@ -368,8 +373,8 @@ static int rax (char *str, int len, int last) {
eprintf ("RNum ERROR: Division by Zero\n");
return false;
}
n32 = (ut32)(n & UT32_MAX);
asnum = r_num_as_string (NULL, n, false);
n32 = (ut32) (n & UT32_MAX);
asnum = r_num_as_string (NULL, n, false);
memcpy (&f, &n32, sizeof (f));
memcpy (&d, &n, sizeof (d));
@ -377,12 +382,12 @@ static int rax (char *str, int len, int last) {
s = n >> 16 << 12;
a = n & 0x0fff;
r_num_units (unit, n);
eprintf ("%"PFMT64d" 0x%"PFMT64x" 0%"PFMT64o
eprintf ("%" PFMT64d " 0x%" PFMT64x " 0%" PFMT64o
" %s %04x:%04x ",
n, n, n, unit, s, a);
if (n >> 32) {
eprintf ("%"PFMT64d" ", (st64)n);
eprintf ("%" PFMT64d " ", (st64)n);
} else {
eprintf ("%d ", (st32)n);
}
@ -391,7 +396,7 @@ static int rax (char *str, int len, int last) {
free (asnum);
}
/* binary and floating point */
r_str_bits (out, (const ut8*)&n, sizeof (n), NULL);
r_str_bits (out, (const ut8 *)&n, sizeof (n), NULL);
eprintf ("%s %.01lf %ff %lf\n",
out, num->fvalue, f, d);
@ -399,7 +404,7 @@ static int rax (char *str, int len, int last) {
}
if (str[0] == '0' && str[1] == 'x') {
out_mode = (flags & 32) ? '0' : 'I';
out_mode = (flags & 32)? '0': 'I';
} else if (str[0] == 'b') {
out_mode = 'B';
str++;
@ -418,12 +423,12 @@ static int rax (char *str, int len, int last) {
} else if (str[0] == 'O' && str[1] == 'x') {
out_mode = 'O';
*str = '0';
} else if (str[strlen (str)-1] == 'd') {
} else if (str[strlen (str) - 1] == 'd') {
out_mode = 'I';
str[strlen (str)-1] = 'b';
//TODO: Move print into format_output
} else if (str[strlen (str)-1] == 'f') {
ut8 *p = (ut8*)&f;
str[strlen (str) - 1] = 'b';
//TODO: Move print into format_output
} else if (str[strlen (str) - 1] == 'f') {
ut8 *p = (ut8 *)&f;
sscanf (str, "%f", &f);
printf ("Fx%02x%02x%02x%02x\n", p[3], p[2], p[1], p[0]);
return true;
@ -439,8 +444,8 @@ static int rax (char *str, int len, int last) {
return true;
}
static int use_stdin () {
char * buf = calloc (1, STDIN_BUFFER_SIZE + 1);
static int use_stdin() {
char *buf = calloc (1, STDIN_BUFFER_SIZE + 1);
int l; //, sflag = (flags & 5);
if (!buf) {
return 0;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2012-2016 - pancake */
/* radare - LGPL - Copyright 2012-2017 - pancake */
#include <r_anal.h>
@ -72,14 +72,17 @@ static ut64 is_pointer(RAnal *anal, const ut8 *buf, int size) {
#endif
}
static int is_bin(const ut8 *buf, int size) {
// TODO: add more
if ((size >= 4 && !memcmp (buf, "\xcf\xfa\xed\xfe", 4)))
static bool is_bin(const ut8 *buf, int size) {
// TODO: add more magic signatures heres
if ((size >= 4 && !memcmp (buf, "\xcf\xfa\xed\xfe", 4))) {
return true;
if ((size >= 4 && !memcmp (buf, "\x7e" "ELF", 4)))
}
if ((size >= 4 && !memcmp (buf, "\x7eELF", 4))) {
return true;
if ((size >= 2 && !memcmp (buf, "MZ", 2)))
}
if ((size >= 2 && !memcmp (buf, "MZ", 2))) {
return true;
}
return false;
}

View File

@ -31,7 +31,7 @@ static int bbExist(AbbState *abb, ut64 addr) {
RAnalBlock *bb;
RListIter *iter;
if (abb->bbdb) {
return (int)sdb_num_get (abb->bbdb, sdb_fmt (0, "0x%08"PFMT64x, addr), NULL);
return (int)sdb_num_get (abb->bbdb, sdb_fmt (0, "0x%08" PFMT64x, addr), NULL);
}
r_list_foreach (abb->bbs, iter, bb) {
if (bb->addr == addr) {
@ -41,7 +41,7 @@ static int bbExist(AbbState *abb, ut64 addr) {
return 0;
}
static AbbState *abbstate_new (ut64 len) {
static AbbState *abbstate_new(ut64 len) {
ut8 *buf = malloc (len);
if (!buf) {
return NULL;
@ -148,31 +148,31 @@ static RAnalBlock *parseOpcode(AbbState *abb, RAnalOp *aop) {
// find functions
#define F(x,...) sdb_fmt(0,x,...)
#define F(x, ...) sdb_fmt (0, x, ...)
static RAnalBlock *getBlock(AbbState *abb, ut64 addr) {
return sdb_ptr_get (abb->bbdb, sdb_fmt (0, "ptr.0x%08"PFMT64x, addr), NULL);
return sdb_ptr_get (abb->bbdb, sdb_fmt (0, "ptr.0x%08" PFMT64x, addr), NULL);
}
static void printBasicBlocks(AbbState *abb, ut64 fcnaddr, ut64 addr) {
RAnalBlock *bb = getBlock (abb, addr);
if (!bb) {
eprintf ("Missing basic block for 0x%08"PFMT64x"\n", addr);
eprintf ("Missing basic block for 0x%08" PFMT64x "\n", addr);
return;
}
if (sdb_bool_get (abb->bbdb, sdb_fmt(0, "bb.0x%08"PFMT64x".0x%08"PFMT64x, fcnaddr, addr), NULL)) {
if (sdb_bool_get (abb->bbdb, sdb_fmt (0, "bb.0x%08" PFMT64x ".0x%08" PFMT64x, fcnaddr, addr), NULL)) {
return;
}
sdb_bool_set (abb->bbdb, sdb_fmt (0, "used.0x%08"PFMT64x, addr), true, 0);
sdb_bool_set (abb->bbdb, sdb_fmt (0, "bb.0x%08"PFMT64x".0x%08"PFMT64x, fcnaddr, addr), true, 0);
r_cons_printf ("afb+ 0x%08"PFMT64x" 0x%08"PFMT64x" %d", fcnaddr, bb->addr, bb->size);
sdb_bool_set (abb->bbdb, sdb_fmt (0, "used.0x%08" PFMT64x, addr), true, 0);
sdb_bool_set (abb->bbdb, sdb_fmt (0, "bb.0x%08" PFMT64x ".0x%08" PFMT64x, fcnaddr, addr), true, 0);
r_cons_printf ("afb+ 0x%08" PFMT64x " 0x%08" PFMT64x " %d", fcnaddr, bb->addr, bb->size);
if (bb->jump != UT64_MAX) {
r_cons_printf (" 0x%08"PFMT64x, bb->jump);
r_cons_printf (" 0x%08" PFMT64x, bb->jump);
}
if (bb->fail != UT64_MAX) {
r_cons_printf (" 0x%08"PFMT64x, bb->fail);
r_cons_printf (" 0x%08" PFMT64x, bb->fail);
}
r_cons_newline();
r_cons_newline ();
if (bb->jump != UT64_MAX) {
printBasicBlocks (abb, fcnaddr, bb->jump);
}
@ -182,8 +182,8 @@ static void printBasicBlocks(AbbState *abb, ut64 fcnaddr, ut64 addr) {
}
static void printFunction(ut64 addr, const char *name) {
char *_name = name ? (char *)name : r_str_newf ("fcn.%"PFMT64x, addr);
r_cons_printf ("af+ 0x%08"PFMT64x" %s\n", addr, _name);
char *_name = name? (char *)name: r_str_newf ("fcn.%" PFMT64x, addr);
r_cons_printf ("af+ 0x%08" PFMT64x " %s\n", addr, _name);
if (!name) {
free (_name);
}
@ -230,13 +230,13 @@ R_API bool core_anal_bbs(RCore *core, ut64 len) {
int ti = -1;
abb->last = at;
r_cons_break_push (NULL, NULL);
eprintf ("Analyzing basic blocks from 0x%08"PFMT64x" to 0x%08"PFMT64x"\n", abb->addr, abb->addr + len);
for (i = 0; i < len ; i++) {
eprintf ("Analyzing basic blocks from 0x%08" PFMT64x " to 0x%08" PFMT64x "\n", abb->addr, abb->addr + len);
for (i = 0; i < len; i++) {
if (r_cons_is_breaked ()) {
break;
}
mountain:
if (!r_anal_op (core->anal, &aop, abb->addr + i, abb->buf + i, R_MIN (len -i, 16))) {
if (!r_anal_op (core->anal, &aop, abb->addr + i, abb->buf + i, R_MIN (len - i, 16))) {
continue;
}
int next = bbExist (abb, at + i);
@ -262,8 +262,8 @@ R_API bool core_anal_bbs(RCore *core, ut64 len) {
r_list_append (abb->fcnents, n);
}
/* register basic block */
sdb_num_set (abb->bbdb, sdb_fmt (0, "0x%08"PFMT64x, bb->addr), bb->size, 0);
sdb_ptr_set (abb->bbdb, sdb_fmt (0, "ptr.0x%08"PFMT64x, bb->addr), bb, 0);
sdb_num_set (abb->bbdb, sdb_fmt (0, "0x%08" PFMT64x, bb->addr), bb->size, 0);
sdb_ptr_set (abb->bbdb, sdb_fmt (0, "ptr.0x%08" PFMT64x, bb->addr), bb, 0);
r_list_append (abb->bbs, bb);
/* walk child blocks */
if (!r_list_empty (abb->nextbbs)) {
@ -280,13 +280,13 @@ R_API bool core_anal_bbs(RCore *core, ut64 len) {
i = nat->addr - at;
abb->bb_addr = nat->addr;
if (nat->type == 'c') {
// r_list_append (abb->fcnents, nat);
// r_list_append (abb->fcnents, nat);
} else {
free (nat);
}
goto mountain;
} else {
eprintf ("Out of bounds basic block for 0x%08"PFMT64x"\n", nat->addr);
eprintf ("Out of bounds basic block for 0x%08" PFMT64x "\n", nat->addr);
}
}
free (nat);
@ -301,7 +301,7 @@ R_API bool core_anal_bbs(RCore *core, ut64 len) {
r_anal_op_fini (&aop);
}
r_cons_break_pop ();
eprintf ("Found %d basic blocks\n", r_list_length (abb->bbs));
findFunctions (core, abb);

View File

@ -4,13 +4,6 @@
#include "r_print.h"
#include "r_io.h"
#ifdef IFDBG
#undef IFDBG
#endif
#define DO_THE_DBG 0
#define IFDBG if (DO_THE_DBG)
/*
* perform_mapped_file_yank will map in a file and yank from offset the number of len bytes from
* filename. if the len is -1, the all the bytes are mapped into the yank buffer.
@ -21,8 +14,12 @@ static ut32 consume_chars(const char *input, char b);
static ut32 find_next_char(const char *input, char b) {
ut32 i = 0;
if (!input) return i;
for (; *input != b; i++, input++) {}
if (!input) {
return i;
}
for (; *input != b; i++, input++) {
/* nothing */
}
return i;
}
@ -31,7 +28,9 @@ static ut32 consume_chars(const char *input, char b) {
if (!input) {
return i;
}
for (; *input == b; i++, input++) ;
for (; *input == b; i++, input++) {
/* nothing */
}
return i;
}
@ -50,8 +49,7 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch
// map the file in for IO operations.
if (yankfd && load_align) {
yank_file_sz = r_io_size (core->io);
map = r_io_map_add_next_available (core->io, yankfd->fd, R_IO_READ,
0, 0, yank_file_sz, load_align);
map = r_io_map_add_next_available (core->io, yankfd->fd, R_IO_READ, 0, 0, yank_file_sz, load_align);
loadaddr = map ? map->from : -1;
if (yankfd && map && loadaddr != -1) {
// ***NOTE*** this is important, we need to
@ -72,31 +70,16 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch
len = yank_file_sz;
}
IFDBG eprintf ("yankfd: %p, yank->fd = %d, fd=%d\n", yankfd,
(int)(yankfd ? yankfd->fd : -1), (int)fd);
// this wont happen if the file failed to open or the file failed to
// map into the IO layer
if (yankfd) {
ut64 res = r_io_seek (core->io, addr, R_IO_SEEK_SET),
actual_len = len <= yank_file_sz ? len : 0;
ut64 res = r_io_seek (core->io, addr, R_IO_SEEK_SET);
ut64 actual_len = len <= yank_file_sz ? len : 0;
ut8 *buf = NULL;
IFDBG eprintf (
"Addr (%"PFMT64d
") file_sz (%"PFMT64d
") actual_len (%"PFMT64d
") len (%"PFMT64d
") bytes from file: %s\n", addr, yank_file_sz,
actual_len, len, filename);
if (actual_len > 0 && res == addr) {
IFDBG eprintf (
"Creating buffer and reading %"PFMT64d
" bytes from file: %s\n", actual_len, filename);
buf = malloc (actual_len);
actual_len = r_io_read_at (core->io, addr, buf,
actual_len);
IFDBG eprintf (
"Reading %"PFMT64d " bytes from file: %s\n",
actual_len, filename);
r_core_yank_set (core, R_CORE_FOREIGN_ADDR, buf, len);
res = true;
} else if (res != addr) {
@ -156,12 +139,11 @@ R_API int r_core_yank(struct r_core_t *core, ut64 addr, int len) {
if (!buf) {
return false;
}
if (addr != core->offset)
if (addr != core->offset) {
r_core_seek (core, addr, 1);
}
r_core_read_at (core, addr, buf, len);
r_core_yank_set (core, addr, buf, len);
if (curseek != addr) {
r_core_seek (core, curseek, 1);
}
@ -177,30 +159,37 @@ R_API int r_core_yank_string(RCore *core, ut64 addr, int maxlen) {
eprintf ("r_core_yank_string: cannot yank negative bytes\n");
return false;
}
if (addr != core->offset)
if (addr != core->offset) {
r_core_seek (core, addr, 1);
}
/* Ensure space and safe termination for largest possible string allowed */
buf = malloc (core->blocksize + 1);
if (!buf)
buf = calloc (1, core->blocksize + 1);
if (!buf) {
return false;
}
buf[core->blocksize] = 0;
r_core_read_at (core, addr, buf, core->blocksize);
if (maxlen == 0) {
maxlen = r_str_nlen ((const char*)buf, core->blocksize); //Don't use strnlen, see: http://sourceforge.net/p/mingw/bugs/1912/
// Don't use strnlen, see: http://sourceforge.net/p/mingw/bugs/1912/
maxlen = r_str_nlen ((const char*)buf, core->blocksize);
} else if (maxlen > core->blocksize) {
maxlen = core->blocksize;
}
r_core_yank_set (core, addr, buf, maxlen);
if (curseek != addr)
if (curseek != addr) {
r_core_seek (core, curseek, 1);
}
free (buf);
return true;
}
R_API int r_core_yank_paste(RCore *core, ut64 addr, int len) {
if (len<0) return false;
if (len == 0 || len >= core->yank_buf->length) len =
core->yank_buf->length;
if (len < 0) {
return false;
}
if (len == 0 || len >= core->yank_buf->length) {
len = core->yank_buf->length;
}
r_core_write_at (core, addr, core->yank_buf->buf, len);
return true;
}
@ -211,7 +200,9 @@ R_API int r_core_yank_to(RCore *core, const char *_arg) {
char *str, *arg;
int res = false;
while (*_arg==' ') _arg++;
while (*_arg==' ') {
_arg++;
}
arg = strdup (_arg);
str = strchr (arg, ' ');
if (str) {
@ -229,10 +220,9 @@ R_API int r_core_yank_to(RCore *core, const char *_arg) {
free (arg);
return res;
}
if (r_core_yank (core, core->offset, len) == true)
if (r_core_yank (core, core->offset, len) == true) {
res = r_core_yank_paste (core, pos, len);
}
free (arg);
return res;
}
@ -240,45 +230,57 @@ R_API int r_core_yank_to(RCore *core, const char *_arg) {
R_API int r_core_yank_dump(RCore *core, ut64 pos) {
int res = false, i = 0;
int ybl = core->yank_buf->length;
if (ybl>0) {
if (ybl > 0) {
if (pos<ybl) {
r_cons_printf ("0x%08"PFMT64x " %d ",
core->yank_buf->base+pos,
core->yank_buf->length-pos);
for (i = pos; i < core->yank_buf->length; i++)
for (i = pos; i < core->yank_buf->length; i++) {
r_cons_printf ("%02x",
core->yank_buf->buf[i]);
}
r_cons_newline ();
res = true;
} else eprintf ("Position exceeds buffer length.\n");
} else eprintf ("No buffer yanked already\n");
} else {
eprintf ("Position exceeds buffer length.\n");
}
} else {
eprintf ("No buffer yanked already\n");
}
return res;
}
R_API int r_core_yank_hexdump(RCore *core, ut64 pos) {
int res = false;
int ybl = core->yank_buf->length;
if (ybl>0) {
if (ybl > 0) {
if (pos < ybl) {
r_print_hexdump (core->print, pos,
core->yank_buf->buf + pos,
ybl - pos, 16, 1);
res = true;
} else eprintf ("Position exceeds buffer length.\n");
} else eprintf ("No buffer yanked already\n");
} else {
eprintf ("Position exceeds buffer length.\n");
}
} else {
eprintf ("No buffer yanked already\n");
}
return res;
}
R_API int r_core_yank_cat(RCore *core, ut64 pos) {
int ybl = core->yank_buf->length;
if (ybl>0) {
if (ybl > 0) {
if (pos < ybl) {
r_cons_memcat ((const char*)core->yank_buf->buf + pos,
core->yank_buf->length - pos);
r_cons_newline ();
return true;
} else eprintf ("Position exceeds buffer length.\n");
} else r_cons_newline ();
}
eprintf ("Position exceeds buffer length.\n");
} else {
r_cons_newline ();
}
return false;
}
@ -290,7 +292,8 @@ R_API int r_core_yank_cat_string(RCore *core, ut64 pos) {
r_cons_memcat ((const char*)core->yank_buf->buf + pos, len);
r_cons_newline ();
return true;
} else eprintf ("Position exceeds buffer length.\n");
}
eprintf ("Position exceeds buffer length.\n");
} else {
r_cons_newline ();
}
@ -301,8 +304,12 @@ R_API int r_core_yank_hud_file(RCore *core, const char *input) {
char *buf = NULL;
bool res = false;
ut32 len = 0;
if (!input || !*input) return false;
for (input++; *input==' '; input++) ;
if (!input || !*input) {
return false;
}
for (input++; *input == ' '; input++) {
/* nothing */
}
buf = r_cons_hud_file (input, r_config_get_i (core->config, "scr.color"));
len = buf ? strlen ((const char*)buf) + 1 : 0;
res = r_core_yank_set_str (core, R_CORE_FOREIGN_ADDR, buf, len);
@ -314,7 +321,9 @@ R_API int r_core_yank_hud_path(RCore *core, const char *input, int dir) {
char *buf = NULL;
ut32 len = 0;
int res;
for (input++; *input==' '; input++) ;
for (input++; *input==' '; input++) {
/* nothing */
}
buf = r_cons_hud_path (input, dir, r_config_get_i (core->config, "scr.color"));
len = buf ? strlen ((const char*)buf) + 1 : 0;
res = r_core_yank_set_str (core, R_CORE_FOREIGN_ADDR, buf, len);
@ -322,12 +331,13 @@ R_API int r_core_yank_hud_path(RCore *core, const char *input, int dir) {
return res;
}
R_API int r_core_yank_file_ex(RCore *core, const char *input) {
R_API bool r_core_yank_file_ex(RCore *core, const char *input) {
ut64 len = 0, adv = 0, addr = 0;
int res = false;
if (!input) return res;
bool res = false;
if (!input) {
return res;
}
// get the number of bytes to yank
adv = consume_chars (input, ' ');
len = r_num_math (core->num, input+adv);
@ -343,7 +353,6 @@ R_API int r_core_yank_file_ex(RCore *core, const char *input) {
}
adv++;
IFDBG eprintf ("Handling the input: %s\n", input+adv);
// XXX - bug, will fail if address needs to be computed and has spaces
addr = r_num_math (core->num, input+adv);
@ -354,7 +363,6 @@ R_API int r_core_yank_file_ex(RCore *core, const char *input) {
}
adv++;
IFDBG eprintf ("Filename: %s\n", input+adv);
// grab the current file descriptor, so we can reset core and io state
// after our io op is done
return perform_mapped_file_yank (core, addr, len, input+adv);
@ -366,6 +374,5 @@ R_API int r_core_yank_file_all(RCore *core, const char *input) {
return false;
}
adv = consume_chars (input, ' ');
IFDBG eprintf ("Filename: %s\n", input+adv);
return perform_mapped_file_yank (core, 0, -1, input+adv);
}

View File

@ -309,7 +309,7 @@ R_API int r_core_yank_cat (RCore *core, ut64 pos);
R_API int r_core_yank_cat_string (RCore *core, ut64 pos);
R_API int r_core_yank_hud_file (RCore *core, const char *input);
R_API int r_core_yank_hud_path (RCore *core, const char *input, int dir);
R_API int r_core_yank_file_ex (RCore *core, const char *input);
R_API bool r_core_yank_file_ex (RCore *core, const char *input);
R_API int r_core_yank_file_all (RCore *core, const char *input);
#define R_CORE_LOADLIBS_ENV 1

View File

@ -82,8 +82,8 @@ typedef enum {
typedef struct r_reg_item_t {
char *name;
int /*RRegisterType*/ type;
int size; /* 8,16,32,64 ... 128/256 ??? */
int offset; /* offset in data structure */
int size; /* 8,16,32,64 ... 128/256 ??? */
int offset; /* offset in data structure */
int packed_size; /* 0 means no packed register, 1byte pack, 2b pack... */
bool is_float;
char *flags;
@ -98,8 +98,8 @@ typedef struct r_reg_arena_t {
typedef struct r_reg_set_t {
RRegArena *arena;
RList *pool; /* RRegArena */
RList *regs; /* RRegItem */
RList *pool; /* RRegArena */
RList *regs; /* RRegItem */
int maskregstype; /* which type of regs have this reg set (logic mask with RRegisterType R_REG_TYPE_XXX) */
} RRegSet;
@ -138,7 +138,7 @@ R_API int r_reg_set_profile(RReg *reg, const char *profile);
R_API RRegSet *r_reg_regset_get(RReg *r, int type);
R_API ut64 r_reg_getv(RReg *reg, const char *name);
R_API ut64 r_reg_setv(RReg *reg, const char *name, ut64 val);
R_API const char *r_reg_32_to_64(RReg* reg, const char* rreg32);
R_API const char *r_reg_32_to_64(RReg *reg, const char *rreg32);
R_API const char *r_reg_get_type(int idx);
R_API const char *r_reg_get_name(RReg *reg, int kind);
R_API const char *r_reg_get_role(int role);
@ -192,7 +192,7 @@ R_API ut64 r_reg_get_pack(RReg *reg, RRegItem *item, int packidx, int packbits);
R_API ut8 *r_reg_get_bytes(RReg *reg, int type, int *size);
R_API bool r_reg_set_bytes(RReg *reg, int type, const ut8 *buf, const int len);
R_API bool r_reg_read_regs(RReg *reg, ut8 *buf, const int len);
R_API int r_reg_arena_set_bytes(RReg *reg, const char* str);
R_API int r_reg_arena_set_bytes(RReg *reg, const char *str);
R_API RRegArena *r_reg_arena_new(int size);
R_API void r_reg_arena_free(RRegArena *ra);
R_API int r_reg_fit_arena(RReg *reg);

View File

@ -1,9 +1,12 @@
/* radare - LGPL - Copyright 2013 - pancake */
/* sliced list */
/* radare - LGPL - Copyright 2013-2017 - pancake */
/* sliced list implementation */
#ifndef R2_SLIST_H
#define R2_SLIST_H
#include <r_util.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -47,7 +47,7 @@ R_API ut8 *r_reg_get_bytes(RReg *reg, int type, int *size) {
}
/* deserialize ALL register types into buffer */
/* XXX does the same as r_reg_get_bytes ? */
/* XXX does the same as r_reg_get_bytes? */
R_API bool r_reg_read_regs(RReg *reg, ut8 *buf, const int len) {
int i, off = 0;
RRegArena *arena;
@ -72,9 +72,11 @@ R_API bool r_reg_read_regs(RReg *reg, ut8 *buf, const int len) {
}
memset (arena->bytes, 0, arena->size);
memcpy (arena->bytes, buf + off,
R_MIN (len - off, arena->size));
R_MIN (len - off, arena->size));
off += arena->size;
if (off > len) return false;
if (off > len) {
return false;
}
}
return true;
}
@ -204,8 +206,9 @@ R_API void r_reg_arena_pop(RReg *reg) {
RRegArena *a;
int i;
for (i = 0; i < R_REG_TYPE_LAST; i++) {
if (r_list_length (reg->regset[i].pool) < 2)
if (r_list_length (reg->regset[i].pool) < 2) {
continue;
}
a = r_list_pop (reg->regset[i].pool);
r_reg_arena_free (a);
a = reg->regset[i].pool->tail->data;
@ -276,7 +279,7 @@ R_API ut8 *r_reg_arena_dup(RReg *reg, const ut8 *source) {
return ret;
}
R_API int r_reg_arena_set_bytes(RReg *reg, const char* str) {
R_API int r_reg_arena_set_bytes(RReg *reg, const char *str) {
while (IS_WHITESPACE (*str)) {
str++;
}
@ -286,7 +289,7 @@ R_API int r_reg_arena_set_bytes(RReg *reg, const char* str) {
return -1;
}
int bin_str_len = (len + 1) / 2; //2 hex chrs for 1 byte
ut8* bin_str = malloc (bin_str_len);
ut8 *bin_str = malloc (bin_str_len);
if (!bin_str) {
eprintf ("Failed to decode hex str.\n");
return -1;

View File

@ -11,8 +11,9 @@ R_API double r_reg_get_double(RReg *reg, RRegItem *item) {
double vld = 0.0f;
int off;
double ret = 0.0f;
if (!reg || !item)
if (!reg || !item) {
return 0LL;
}
off = BITS2BYTES (item->offset);
regset = &reg->regset[item->arena];
switch (item->size) {
@ -61,8 +62,9 @@ R_API long double r_reg_get_longdouble(RReg *reg, RRegItem *item) {
long double vld = 0.0f;
int off;
long double ret = 0.0f;
if (!reg || !item)
if (!reg || !item) {
return 0LL;
}
off = BITS2BYTES (item->offset);
regset = &reg->regset[item->arena];
switch (item->size) {
@ -82,7 +84,7 @@ R_API long double r_reg_get_longdouble(RReg *reg, RRegItem *item) {
}
R_API bool r_reg_set_longdouble(RReg *reg, RRegItem *item, long double value) {
ut8 *src;
ut8 *src = NULL;
if (!item) {
eprintf ("r_reg_set_value: item is NULL\n");

View File

@ -11,7 +11,7 @@ OBJS+=sandbox.o calc.o thread.o thread_lock.o thread_msg.o
OBJS+=strpool.o bitmap.o strht.o p_date.o p_format.o print.o
OBJS+=p_seven.o slist.o randomart.o log.o zip.o debruijn.o
OBJS+=utf8.o strbuf.o lib.o name.o spaces.o signal.o syscmd.o
OBJS+=diff.o bdiff.o stack.o queue.o tree.o des.o id_storage.o
OBJS+=diff.o bdiff.o stack.o queue.o tree.o des.o idpool.o
OBJS+=punycode.o
# DO NOT BUILD r_big api (not yet used and its buggy)

View File

@ -57,7 +57,7 @@ R_API bool r_id_pool_kick_id(RIDPool *pool, ut32 kick) {
if (!pool->freed_ids) {
pool->freed_ids = r_queue_new (2);
}
r_queue_enqueue (pool->freed_ids, (void *)kick);
r_queue_enqueue (pool->freed_ids, (void *)(size_t)kick);
return true;
}

View File

@ -1,7 +1,6 @@
/* radare - LGPL - Copyright 2013 - pancake */
// -- work in progress -- //
#include "r_util.h"
#include "r_slist.h"
R_API RSList *r_slist_new() {

View File

@ -34,7 +34,10 @@ libr/util/slist.c
libr/util/log.c
libr/util/cache.c
libr/core/file.c
libr/core/yank.c
libr/core/blaze.c
binr/rasm2/rasm2.c
binr/rax2/rax2.c
"
case "$1" in
"help"|-h)