Skip to content

Commit

Permalink
Some random code cleanup and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Nov 23, 2015
1 parent cab871f commit d42ecbf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 47 deletions.
20 changes: 14 additions & 6 deletions configure
Expand Up @@ -160,7 +160,8 @@ System types:
--target=TARGET configure for building compilers for TARGET [HOST]
EOF2

printf "\nOptional Features:
printf "
Optional Features:
--disable-debugger disable native debugger features
--with-sysmagic force to use system's magic
--disable-loadlibs disable loading plugins
Expand All @@ -176,17 +177,21 @@ printf "\nOptional Features:
--with-ostype Choose OS type ( gnulinux windows darwin haiku ) (USEROSTYPE=auto)
--without-pic do not build libr as a program independent location
--with-nonpic build the library archives .a
--with-libversion specify different libversion (LIBVERSION=xxx)\n"
printf "\nSome influential environment variables:
--with-libversion specify different libversion (LIBVERSION=xxx)
"
printf "
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
CPPFLAGS C preprocessor flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
CPPFLAGS C/C++ preprocessor flags, e.g. -I<include dir> if you have
headers in a nonstandard directory <include dir>
CPP C preprocessor\n"
printf "\nReport bugs to: pancake <pancake@nopcode.org>"
CPP C preprocessor
"
printf "
Report bugs to: pancake <pancake@nopcode.org>"
echo ""
exit 0
}
Expand Down Expand Up @@ -448,6 +453,9 @@ if [ "$HAVE_BIGEND" = "1" ]; then
LIL_ENDIAN="0"; fi
check_library HAVE_LIB_LUA5_1 lua5.1 0
if [ "$USEROSTYPE" = "auto" ]; then
if [ "$HOST_OS" = "mingw32_nt-6.2" ]; then
USEROSTYPE="mingw32"
else
if [ "$HOST_OS" = "mingw32_nt" ]; then
USEROSTYPE="mingw32"
else
Expand All @@ -472,7 +480,7 @@ if [ "$HOST_OS" = "openbsd" ]; then
USEROSTYPE="bsd"
else
if [ "$HOST_OS" = "darwin" ]; then
USEROSTYPE="darwin"; fi; fi; fi; fi; fi; fi; fi; fi; fi
USEROSTYPE="darwin"; fi; fi; fi; fi; fi; fi; fi; fi; fi; fi
if [ "$LIBVERSION" = "xxx" ]; then
LIBVERSION="$VERSION"; fi
SEDFLAGS=" -e '"
Expand Down
5 changes: 4 additions & 1 deletion configure.acr
Expand Up @@ -95,6 +95,9 @@ ARG_WITH USEROSTYPE=auto ostype Choose OS type ( gnulinux windows darwin haiku )
(( TODO: throw error if unknown ostype ))
(( TODO: handle BSD os as different ostype? ))
IFEQ USEROSTYPE auto ; {
IFEQ HOST_OS mingw32_nt-6.2 ; {
USEROSTYPE = mingw32 ;
}{
IFEQ HOST_OS mingw32_nt ; {
USEROSTYPE = mingw32 ;
}{
Expand All @@ -121,7 +124,7 @@ IFEQ USEROSTYPE auto ; {
}{
IFEQ HOST_OS darwin ; {
USEROSTYPE = darwin ;
} } } } } } } }
} } } } } } } } }
}

ARG_WITHOUT WITHPIC pic do not build libr as a program independent location ;
Expand Down
61 changes: 25 additions & 36 deletions libr/core/asm.c
Expand Up @@ -14,26 +14,22 @@ static void add_hit_to_sorted_hits(RList* hits, ut64 addr, int len, ut8 is_valid
static int prune_hits_in_addr_range(RList *hits, ut64 addr, ut64 len, ut8 is_valid);

static int rcoreasm_address_comparator(RCoreAsmHit *a, RCoreAsmHit *b){
if (a->addr == b->addr)
return 0;
else if (a->addr < b->addr)
return -1;
// a->addr > b->addr
return 1;
if (a->addr == b->addr) return 0;
if (a->addr < b->addr) return -1;
return 1; /* a->addr > b->addr */
}

R_API RCoreAsmHit *r_core_asm_hit_new() {
RCoreAsmHit *hit = R_NEW (RCoreAsmHit);
RCoreAsmHit *hit = R_NEW0 (RCoreAsmHit);
if (!hit) return NULL;
hit->code = NULL;
hit->len = 0;
hit->addr = -1;
hit->valid = false;
return hit;
}

R_API RList *r_core_asm_hit_list_new() {
RList *list = r_list_new ();
if (!list) return NULL;
list->free = &r_core_asm_hit_free;
return list;
}
Expand Down Expand Up @@ -129,7 +125,7 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6
r_regex_free (rx);
}
}
if (align) {
if (align && align>1) {
if (addr % align) {
matches = false;
}
Expand Down Expand Up @@ -187,7 +183,6 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6
return hits;
}


static void add_hit_to_sorted_hits(RList* hits, ut64 addr, int len, ut8 is_valid) {
RCoreAsmHit *hit = r_core_asm_hit_new();
if (hit) {
Expand Down Expand Up @@ -216,15 +211,13 @@ static void add_hit_to_hits(RList* hits, ut64 addr, int len, ut8 is_valid) {
}

static int prune_hits_in_addr_range(RList *hits, ut64 addr, ut64 len, ut8 is_valid) {
RCoreAsmHit hit;
RCoreAsmHit hit = {0};
hit.addr = addr;
hit.len = len;
hit.code = NULL;
hit.valid = is_valid;
return prune_hits_in_hit_range(hits, &hit);
}


static int prune_hits_in_hit_range(RList *hits, RCoreAsmHit *hit){
RListIter *iter, *iter_tmp;
RCoreAsmHit *to_check_hit;
Expand Down Expand Up @@ -259,34 +252,31 @@ static RCoreAsmHit * find_addr(RList *hits, ut64 addr) {
return r_list_iter_get_data(addr_iter);
}


static int handle_forward_disassemble(RCore* core, RList *hits, ut8* buf, ut64 len, ut64 current_buf_pos, ut64 current_instr_addr, ut64 end_addr){
RCoreAsmHit *hit = NULL, *found_addr = NULL;
// forward disassemble from the current instruction up to the end address
ut64 temp_instr_len = 0,
temp_instr_addr = current_instr_addr,
tmp_current_buf_pos = current_buf_pos,
start = 0, end = 0,
start_range = current_instr_addr,
end_range = end_addr;

RAsmOp op;
RCoreAsmHit *hit = NULL, *found_addr = NULL;
ut8 is_valid = false;
ut64 temp_instr_addr = current_instr_addr;
ut64 tmp_current_buf_pos = current_buf_pos;
ut64 start_range = current_instr_addr;
ut64 end_range = end_addr;
ut64 temp_instr_len = 0;
ut64 start = 0, end = 0;
ut8 is_valid = false;
RAsmOp op;

if (end_addr < current_instr_addr)
return end_addr;

r_asm_set_pc (core->assembler, current_instr_addr);
while ( tmp_current_buf_pos < len && temp_instr_addr < end_addr) {
while (tmp_current_buf_pos < len && temp_instr_addr < end_addr) {
temp_instr_len = len - tmp_current_buf_pos;
IFDBG eprintf("Current position: %"PFMT64d" instr_addr: 0x%"PFMT64x"\n", tmp_current_buf_pos, temp_instr_addr);
temp_instr_len = r_asm_disassemble (core->assembler, &op, buf+tmp_current_buf_pos, temp_instr_len);

if (temp_instr_len == 0){
is_valid = false;
temp_instr_len = 1;
} else
is_valid = true;
} else is_valid = true;

// check to see if addr exits
found_addr = find_addr(hits, temp_instr_addr);
Expand All @@ -299,8 +289,7 @@ static int handle_forward_disassemble(RCore* core, RList *hits, ut8* buf, ut64 l
ut32 prune_results = 0;
prune_results = prune_hits_in_addr_range(hits, temp_instr_addr, temp_instr_len, is_valid);
add_hit_to_sorted_hits(hits, temp_instr_addr, temp_instr_len, is_valid);

if (prune_results ) {
if (prune_results) {
r_list_add_sorted (hits, hit, ((RListComparator)rcoreasm_address_comparator));
IFDBG eprintf("Pruned %u hits from list in fwd sweep.\n", prune_results);
} else {
Expand Down Expand Up @@ -474,7 +463,7 @@ static RList * r_core_asm_back_disassemble_all(RCore *core, ut64 addr, ut64 len,
return NULL;
}

if (len == 0){
if (len == 0) {
return hits;
}

Expand Down Expand Up @@ -587,11 +576,11 @@ static RList *r_core_asm_back_disassemble (RCore *core, ut64 addr, int len, ut64
last_num_invalid ++;
// disassembly perfect
} else if (current_buf_pos + current_instr_len == next_buf_pos) {
// i think this may be the only case where an invalid instruction will be
// added because handle_forward_disassemble and handle_disassembly_overlap
// are only called in cases where a valid instruction has been found.
// and they are lazy, since they purge the hit list
ut32 purge_results = 0;
// i think this may be the only case where an invalid instruction will be
// added because handle_forward_disassemble and handle_disassembly_overlap
// are only called in cases where a valid instruction has been found.
// and they are lazy, since they purge the hit list
ut32 purge_results = 0;
ut8 is_valid = true;
IFDBG eprintf(" handling underlap case: current_instr_addr: 0x%"PFMT64x".\n", current_instr_addr);
purge_results = prune_hits_in_addr_range(hits, current_instr_addr, current_instr_len, /* is_valid */ true);
Expand Down
5 changes: 1 addition & 4 deletions libr/socket/run.c
Expand Up @@ -629,10 +629,7 @@ R_API int r_run_start(RRunProfile *p) {
#if __APPLE__
posix_spawnattr_t attr = {0};
pid_t pid = -1;
#endif
int ret;

#if __APPLE__
posix_spawnattr_init (&attr);
if (p->_args[0]) {
char **envp = r_sys_get_environ();
Expand Down Expand Up @@ -698,7 +695,7 @@ R_API int r_run_start(RRunProfile *p) {
{ int i; for (i=3; i<10; i++) close (i); }
// TODO: use posix_spawn
if (p->_setgid) {
ret = setgid (atoi (p->_setgid));
int ret = setgid (atoi (p->_setgid));
if (ret < 0)
return 1;
}
Expand Down

0 comments on commit d42ecbf

Please sign in to comment.