Update indentation in some more random files

This commit is contained in:
pancake 2015-12-14 14:32:18 +01:00
parent 98578e2452
commit 965d789c4a
7 changed files with 451 additions and 327 deletions

View File

@ -4,8 +4,7 @@
#include <r_list.h>
#include <r_types.h>
R_API RAnalCycleFrame *r_anal_cycle_frame_new () {
R_API RAnalCycleFrame *r_anal_cycle_frame_new() {
RAnalCycleFrame *cf = R_NEW0 (RAnalCycleFrame);
if (cf) {
if (!(cf->hooks = r_list_new ())) {
@ -16,7 +15,7 @@ R_API RAnalCycleFrame *r_anal_cycle_frame_new () {
return cf;
}
R_API void r_anal_cycle_frame_free (RAnalCycleFrame *cf) {
R_API void r_anal_cycle_frame_free(RAnalCycleFrame *cf) {
if (!cf) return;
r_list_free (cf->hooks);
free (cf);

View File

@ -3,10 +3,10 @@
#include <r_anal.h>
#define MINLEN 1
static int is_string (const ut8 *buf, int size, int *len) {
static int is_string(const ut8 *buf, int size, int *len) {
int i;
if (size < 1) return 0;
if (size>3 && buf[0] && !buf[1] && buf[2] && !buf[3]) {
if (size > 3 && buf[0] && !buf[1] && buf[2] && !buf[3]) {
*len = 1; // XXX: TODO: Measure wide string length
return 2; // is wide
}
@ -15,10 +15,10 @@ static int is_string (const ut8 *buf, int size, int *len) {
*len = i;
return 1;
}
if (buf[i] == 10|| buf[i] == 13|| buf[i] == 9) {
if (buf[i] == 10 || buf[i] == 13 || buf[i] == 9) {
continue;
}
if (buf[i]<32 || buf[i]>127) {
if (buf[i] < 32 || buf[i] > 127) {
// not ascii text
return 0;
}
@ -31,19 +31,19 @@ static int is_string (const ut8 *buf, int size, int *len) {
return 1;
}
static int is_number (const ut8 *buf, int endian, int size) {
static int is_number(const ut8 *buf, int endian, int size) {
ut64 n = r_mem_get_num (buf, size, endian);
return (n<UT32_MAX)? (int)n: 0;
return (n < UT32_MAX)? (int)n: 0;
}
static int is_null (const ut8 *buf, int size) {
const char zero[8] = {0,0,0,0,0,0,0,0};
static int is_null(const ut8 *buf, int size) {
const char zero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
return (!memcmp (buf, &zero, size))? 1: 0;
}
static int is_invalid (const ut8 *buf, int size) {
if (size<1) return 1;
if (size>8) size = 8;
static int is_invalid(const ut8 *buf, int size) {
if (size < 1) return 1;
if (size > 8) size = 8;
return (!memcmp (buf, "\xff\xff\xff\xff\xff\xff\xff\xff", size))? 1: 0;
}
@ -63,8 +63,8 @@ static ut64 is_pointer(RIOBind *iob, const ut8 *buf, int endian, int size) {
// this makes disasm 5x faster, but can result in some false positives
// we should compare with current offset, to avoid
// short/long references. and discard invalid ones
if (n<0x1000) return 0; // probably wrong
if (n>0xffffffffffffLL) return 0; // probably wrong
if (n < 0x1000) return 0; // probably wrong
if (n > 0xffffffffffffLL) return 0; // probably wrong
if (iob->read_at (iob->io, n, buf2, size) != size) return 0;
return is_invalid (buf2, size)? 0: n;
@ -73,17 +73,18 @@ static ut64 is_pointer(RIOBind *iob, const ut8 *buf, int endian, int size) {
static int is_bin(const ut8 *buf, int size) {
// TODO: add more
if((size >= 4 && !memcmp (buf, "\xcf\xfa\xed\xfe", 4))
|| (size >= 4 && !memcmp (buf, "\x7e""ELF", 4))
|| (size >= 2 && !memcmp (buf, "MZ", 2)))
if ((size >= 4 && !memcmp (buf, "\xcf\xfa\xed\xfe", 4)) || (size >= 4 && !memcmp (buf, "\x7e"
"ELF",
4)) ||
(size >= 2 && !memcmp (buf, "MZ", 2)))
return 1;
return 0;
}
// TODO : add is_flag, is comment?
// TODO: add is_flag, is comment?
// XXX: optimize by removing all strlens here
R_API char *r_anal_data_to_string (RAnalData *d) {
R_API char *r_anal_data_to_string(RAnalData *d) {
int i, len, idx, mallocsz = 1024;
ut32 n32;
char *line;
@ -91,19 +92,19 @@ R_API char *r_anal_data_to_string (RAnalData *d) {
if (!d) return NULL;
line = malloc (mallocsz);
snprintf (line, mallocsz, "0x%08"PFMT64x" ", d->addr);
snprintf (line, mallocsz, "0x%08" PFMT64x " ", d->addr);
n32 = (ut32)d->ptr;
len = R_MIN (d->len, 8);
for (i=0, idx = strlen (line); i<len; i++) {
int msz = mallocsz-idx;
if (msz>1) {
snprintf (line+idx, msz, "%02x", d->buf[i]);
for (i = 0, idx = strlen (line); i < len; i++) {
int msz = mallocsz - idx;
if (msz > 1) {
snprintf (line + idx, msz, "%02x", d->buf[i]);
idx += 2;
}
}
if (i>0 && d->len> len) {
int msz = mallocsz-idx;
snprintf (line+idx, msz, "..");
if (i > 0 && d->len > len) {
int msz = mallocsz - idx;
snprintf (line + idx, msz, "..");
idx += 2;
msz -= 2;
}
@ -112,7 +113,7 @@ R_API char *r_anal_data_to_string (RAnalData *d) {
if (mallocsz - idx > 12) {
switch (d->type) {
case R_ANAL_DATA_TYPE_STRING:
snprintf (line+idx, mallocsz-idx, "string \"%s\"", d->str);
snprintf (line + idx, mallocsz - idx, "string \"%s\"", d->str);
idx = strlen (line);
break;
case R_ANAL_DATA_TYPE_WIDE_STRING:
@ -120,17 +121,17 @@ R_API char *r_anal_data_to_string (RAnalData *d) {
break;
case R_ANAL_DATA_TYPE_NUMBER:
if (n32 == d->ptr) {
snprintf (line+idx, mallocsz-idx,
snprintf (line + idx, mallocsz - idx,
"number %d 0x%x", n32, n32);
} else {
snprintf (line+idx, mallocsz-idx,
"number %"PFMT64d" 0x%"PFMT64x,
snprintf (line + idx, mallocsz - idx,
"number %" PFMT64d " 0x%" PFMT64x,
d->ptr, d->ptr);
}
break;
case R_ANAL_DATA_TYPE_POINTER:
strcat (line, "pointer ");
sprintf (line+strlen (line), " 0x%08"PFMT64x, d->ptr);
sprintf (line + strlen (line), " 0x%08" PFMT64x, d->ptr);
break;
case R_ANAL_DATA_TYPE_INVALID:
strcat (line, "invalid");
@ -155,7 +156,7 @@ R_API char *r_anal_data_to_string (RAnalData *d) {
return line;
}
R_API RAnalData *r_anal_data_new_string (ut64 addr, const char *p, int len, int type) {
R_API RAnalData *r_anal_data_new_string(ut64 addr, const char *p, int len, int type) {
RAnalData *ad = R_NEW0 (RAnalData);
if (!ad) return NULL;
ad->str = NULL;
@ -168,30 +169,30 @@ R_API RAnalData *r_anal_data_new_string (ut64 addr, const char *p, int len, int
if (type == R_ANAL_DATA_TYPE_WIDE_STRING) {
/* TODO: add support for wide strings */
} else {
ad->str = malloc (len+1);
ad->str = malloc (len + 1);
if (!ad->str) {
free (ad);
return NULL;
}
memcpy (ad->str, p, len);
ad->str[len] = 0;
ad->buf = malloc (len+1);
memcpy (ad->buf, ad->str, len+1);
ad->len = len+1; // string length + \x00
ad->buf = malloc (len + 1);
memcpy (ad->buf, ad->str, len + 1);
ad->len = len + 1; // string length + \x00
}
ad->ptr = 0L;
return ad;
}
R_API RAnalData *r_anal_data_new (ut64 addr, int type, ut64 n, const ut8 *buf, int len) {
R_API RAnalData *r_anal_data_new(ut64 addr, int type, ut64 n, const ut8 *buf, int len) {
RAnalData *ad = R_NEW0 (RAnalData);
int l = R_MIN (len, 8);
if (!ad) {
return NULL;
}
ad->buf = (ut8*) &(ad->sbuf);
ad->buf = (ut8 *)&(ad->sbuf);
memset (ad->buf, 0, 8);
if (l<1) {
if (l < 1) {
r_anal_data_free (ad);
return NULL;
}
@ -202,101 +203,101 @@ R_API RAnalData *r_anal_data_new (ut64 addr, int type, ut64 n, const ut8 *buf, i
ad->type = type;
ad->str = NULL;
switch (type) {
case R_ANAL_DATA_TYPE_PATTERN:
case R_ANAL_DATA_TYPE_SEQUENCE:
ad->len = len;
break;
default:
ad->len = l;
case R_ANAL_DATA_TYPE_PATTERN:
case R_ANAL_DATA_TYPE_SEQUENCE:
ad->len = len;
break;
default:
ad->len = l;
}
ad->ptr = n;
return ad;
}
R_API void r_anal_data_free (RAnalData *d) {
R_API void r_anal_data_free(RAnalData *d) {
if (d) {
if (d->buf != (ut8*)&(d->sbuf)) free (d->buf);
if (d->buf != (ut8 *)&(d->sbuf)) free (d->buf);
if (d->str != NULL) free (d->str);
free (d);
}
}
R_API RAnalData *r_anal_data (RAnal *anal, ut64 addr, const ut8 *buf, int size) {
R_API RAnalData *r_anal_data(RAnal *anal, ut64 addr, const ut8 *buf, int size) {
ut64 dst = 0;
int n, nsize = 0;
int bits = anal->bits;
int endi = !anal->big_endian;
int word = R_MIN (8, bits/8);
int word = R_MIN (8, bits / 8);
if (size<4)
if (size < 4)
return NULL;
if (size >= word && is_invalid (buf, word))
return r_anal_data_new (addr, R_ANAL_DATA_TYPE_INVALID,
-1, buf, word);
-1, buf, word);
{
int i, len = R_MIN (size, 64);
int is_pattern = 0;
int is_sequence = 0;
char ch = buf[0];
char ch2 = ch+1;
for (i=1; i<len; i++) {
char ch2 = ch + 1;
for (i = 1; i < len; i++) {
if (ch2 == buf[i]) {
ch2++;
is_sequence++;
} else is_sequence = 0;
if (ch==buf[i]) {
if (ch == buf[i]) {
is_pattern++;
}
}
if (is_sequence>len-2) {
if (is_sequence > len - 2) {
return r_anal_data_new (addr, R_ANAL_DATA_TYPE_SEQUENCE, -1,
buf, is_sequence);
buf, is_sequence);
}
if (is_pattern>len-2) {
if (is_pattern > len - 2) {
return r_anal_data_new (addr, R_ANAL_DATA_TYPE_PATTERN, -1,
buf, is_pattern);
buf, is_pattern);
}
}
if (size >= word && is_null (buf, word))
return r_anal_data_new (addr, R_ANAL_DATA_TYPE_NULL,
-1, buf, word);
-1, buf, word);
if (is_bin (buf, size))
return r_anal_data_new (addr, R_ANAL_DATA_TYPE_HEADER, -1,
buf, word);
buf, word);
if (size >= word) {
dst = is_pointer (&anal->iob, buf, endi, word);
if (dst) return r_anal_data_new (addr,
R_ANAL_DATA_TYPE_POINTER, dst, buf, word);
R_ANAL_DATA_TYPE_POINTER, dst, buf, word);
}
switch (is_string (buf, size, &nsize)) {
case 1: return r_anal_data_new_string (addr, (const char *)buf,
nsize, R_ANAL_DATA_TYPE_STRING);
nsize, R_ANAL_DATA_TYPE_STRING);
case 2: return r_anal_data_new_string (addr, (const char *)buf,
nsize, R_ANAL_DATA_TYPE_WIDE_STRING);
nsize, R_ANAL_DATA_TYPE_WIDE_STRING);
}
if (size >= word) {
n = is_number (buf, endi, word);
if (n) return r_anal_data_new (addr, R_ANAL_DATA_TYPE_NUMBER,
n, buf, word);
n, buf, word);
}
return r_anal_data_new (addr, R_ANAL_DATA_TYPE_UNKNOWN, dst,
buf, R_MIN(word, size));
buf, R_MIN (word, size));
}
R_API const char *r_anal_data_kind (RAnal *a, ut64 addr, const ut8 *buf, int len) {
R_API const char *r_anal_data_kind(RAnal *a, ut64 addr, const ut8 *buf, int len) {
int inv = 0;
int unk = 0;
int str = 0;
int num = 0;
int i, j;
RAnalData *data;
int word = a->bits /8;
for (i = j = 0; i<len; j++) {
int word = a->bits / 8;
for (i = j = 0; i < len; j++) {
if (str && !buf[i])
str ++;
data = r_anal_data (a, addr+i, buf+i, len-i);
str++;
data = r_anal_data (a, addr + i, buf + i, len - i);
if (data == NULL) {
i+= word;
i += word;
continue;
}
switch (data->type) {
@ -305,7 +306,7 @@ R_API const char *r_anal_data_kind (RAnal *a, ut64 addr, const ut8 *buf, int len
i += word;
break;
case R_ANAL_DATA_TYPE_NUMBER:
if (data->ptr> 1000) num++;
if (data->ptr > 1000) num++;
i += word;
break;
case R_ANAL_DATA_TYPE_UNKNOWN:
@ -313,9 +314,9 @@ R_API const char *r_anal_data_kind (RAnal *a, ut64 addr, const ut8 *buf, int len
i += word;
break;
case R_ANAL_DATA_TYPE_STRING:
if (data->len>0) {
if (data->len > 0) {
i += data->len;
} else i+=word;
} else i += word;
str++;
break;
default:
@ -323,10 +324,10 @@ R_API const char *r_anal_data_kind (RAnal *a, ut64 addr, const ut8 *buf, int len
}
r_anal_data_free (data);
}
if (j<1) return "unknown";
if ((inv*100/j)>60) return "invalid";
if ((unk*100/j)>60) return "code";
if ((num*100/j)>60) return "code";
if ((str*100/j)>40) return "text";
if (j < 1) return "unknown";
if ((inv * 100 / j) > 60) return "invalid";
if ((unk * 100 / j) > 60) return "code";
if ((num * 100 / j) > 60) return "code";
if ((str * 100 / j) > 40) return "text";
return "data";
}

File diff suppressed because it is too large Load Diff

View File

@ -31,13 +31,13 @@ struct MACH0_(SClassRoT) {
#ifdef R_BIN_MACH064
ut32 reserved;
#endif
mach0_ut ivarLayout; /* const uint8_t* (32/64-bit pointer) */
mach0_ut ivarLayout; /* const uint8_t* (32/64-bit pointer) */
mach0_ut name; /* const char* (32/64-bit pointer) */
mach0_ut baseMethods; /* const SMEthodList* (32/64-bit pointer) */
mach0_ut baseProtocols; /* const SProtocolList* (32/64-bit pointer) */
mach0_ut baseMethods; /* const SMEthodList* (32/64-bit pointer) */
mach0_ut baseProtocols; /* const SProtocolList* (32/64-bit pointer) */
mach0_ut ivars; /* const SIVarList* (32/64-bit pointer) */
mach0_ut weakIvarLayout;/* const uint8_t * (32/64-bit pointer) */
mach0_ut baseProperties;/* const SObjcPropertyList* (32/64-bit pointer) */
mach0_ut weakIvarLayout; /* const uint8_t * (32/64-bit pointer) */
mach0_ut baseProperties; /* const SObjcPropertyList* (32/64-bit pointer) */
};
struct MACH0_(SProtocolList) {
@ -614,7 +614,7 @@ static void get_protocol_list_t(mach0_ut p, RBinFile *arch, RBinClass *klass) {
///////////////////////////////////////////////////////////////////////////////
static void get_class_ro_t(mach0_ut p, RBinFile *arch, ut32 *is_meta_class, RBinClass *klass) {
struct MACH0_(obj_t) *bin;
struct MACH0_(obj_t) * bin;
struct MACH0_(SClassRoT) cro = { 0 };
ut32 offset, left;
ut64 r, s;
@ -760,7 +760,7 @@ static void __r_bin_class_free(RBinClass *p) {
r_bin_class_free (p);
}
RList *MACH0_(parse_classes) (RBinFile *arch) {
RList *MACH0_(parse_classes)(RBinFile *arch) {
RList /*<RBinClass>*/ *ret = NULL;
ut64 num_of_unnamed_class = 0;
RBinClass *klass = NULL;
@ -840,7 +840,7 @@ RList *MACH0_(parse_classes) (RBinFile *arch) {
goto get_classes_error;
}
// TODO: unnecessary slow sequential read? use fread for endianness
// TODO: unnecessary slow sequential read? use fread for endianness
#ifdef R_BIN_MACH064
len = r_buf_fread_at (arch->buf, s->paddr + i, (ut8 *)&p, "l", 1);
#else
@ -852,7 +852,7 @@ RList *MACH0_(parse_classes) (RBinFile *arch) {
if (!klass->name) {
klass->name = r_str_newf ("UnnamedClass%" PFMT64d,
num_of_unnamed_class);
num_of_unnamed_class);
if (!klass->name) {
goto get_classes_error;
}

View File

@ -189,7 +189,7 @@ R_API RConfigNode *r_config_set(RConfig *cfg, const char *name, const char *valu
}
if (node->flags & CN_BOOL) {
int b = (!strcmp (value, "true") || !strcmp (value, "1"));
node->i_value = (ut64) (b == 0)? 0: 1;
node->i_value = (ut64)(b == 0)? 0: 1;
free (node->value);
node->value = strdup (b? "true": "false");
} else {

View File

@ -12,7 +12,7 @@ extern "C" {
#ifndef _INCLUDE_R_LIST_HEAD_H_
#define _INCLUDE_R_LIST_HEAD_H_
typedef void (*RListFree) (void *ptr);
typedef void (*RListFree)(void *ptr);
typedef struct r_list_iter_t {
void *data;
@ -25,7 +25,7 @@ typedef struct r_list_t {
RListFree free;
} RList;
typedef int (*RListComparator) (const void *a, const void *b);
typedef int (*RListComparator)(const void *a, const void *b);
#define ROFList_Parent RList
typedef struct r_oflist_t {
@ -117,8 +117,7 @@ R_API RListIter *r_list_find(const RList *list, const void *p, RListComparator c
int idx = 0;\
void *ptr;\
RListIter *iter;\
r_list_foreach (x, iter, ptr)\
r_flist_set (x->array, idx++, ptr);\
r_list_foreach (x, iter, ptr) r_flist_set (x->array, idx++, ptr);\
}\
x->array;
#endif

View File

@ -2,6 +2,9 @@
FILES="
libr/include/r_list.h
libr/include/r_reg.h
libr/anal/cycles.c
libr/anal/esil.c
libr/anal/data.c
libr/config/config.c
libr/config/callback.c
libr/config/t/test.c