* Add 0xeb (short jmp) in modify asm x86 plugin

* Add help for 'fs' command
* Added 'fS' command to sort by offset (fSo) or name (fSn)
  - Current r_flag_sort breaks the linkedlist
This commit is contained in:
pancake 2010-04-09 11:32:17 +02:00
parent f5bf177c60
commit db3aa272b0
6 changed files with 60 additions and 11 deletions

View File

@ -31,8 +31,14 @@ static int modify(RAsm *a, ut8 *buf, int field, ut64 val) {
memcpy (buf+1, &val32, sizeof (val32));
}
return 5;
case 0xeb: // jmp short
case 0x73: // jnz
buf[1] = (char)(val-a->pc);
if (field == R_ASM_MOD_RAWVALUE) {
buf[1] = (char)val;
} else
if (field == R_ASM_MOD_VALUE) {
buf[1] = (char)(val-a->pc);
}
return 2;
}
return ret;

View File

@ -1149,6 +1149,9 @@ static int cmd_flag(void *data, const char *input) {
case '-':
r_flag_unset (&core->flags, input+1);
break;
case 'S':
r_flag_sort (&core->flags, (input[1]=='n'));
break;
case 's':
if (input[1]==' ') r_flag_space_set (&core->flags, input+2);
else r_flag_space_list (&core->flags);
@ -1175,7 +1178,11 @@ static int cmd_flag(void *data, const char *input) {
" f+name 12 @ 33 ; like above but creates new one if doesnt exist\n"
" f-name ; remove flag 'name'\n"
" f ; list flags\n"
" f* ; list flags in r commands\n");
" f* ; list flags in r commands\n"
" fs functions ; set flagspace\n"
" fs * ; set no flagspace\n"
" fs ; display flagspaces\n"
" fS[on] ; sort flags by offset or name\n");
break;
}
return 0;

View File

@ -137,6 +137,12 @@ R_API int r_core_visual_trackflags(RCore *core) {
case 'J':
option+=10;
break;
case 'o':
r_flag_sort (&core->flags, 0);
break;
case 'n':
r_flag_sort (&core->flags, 1);
break;
case 'j':
option++;
break;

View File

@ -5,7 +5,6 @@
#include <r_cons.h>
#include <stdio.h>
#if USE_BTREE
/* compare names */
static int ncmp(const void *a, const void *b) {
RFlagItem *fa = (RFlagItem *)a;
@ -27,25 +26,54 @@ static int cmp(const void *a, const void *b) {
else if (fa->offset < fb->offset) ret = -1;
return ret;
}
#endif
R_API int r_flag_init(RFlag *f) {
int i;
INIT_LIST_HEAD(&f->flags);
INIT_LIST_HEAD (&f->flags);
f->space_idx = -1;
f->space_idx2 = -1;
#if USE_BTREE
btree_init(&f->tree);
btree_init(&f->ntree);
btree_init (&f->tree);
btree_init (&f->ntree);
#endif
for (i=0;i<R_FLAG_SPACES_MAX;i++)
f->space[i] = NULL;
return 0;
}
R_API void r_flag_sort(RFlag *flag) {
// TODO: Implement sorted linked list
eprintf ("TODO: r_flag_sort\n");
R_API int r_flag_sort(RFlag *f, int namesort) {
int ret = R_FALSE;
int changes;
RFlagItem *fi = NULL;
struct list_head *pos;
INIT_LIST_HEAD (&f->flags_tmp);
// get bigger one
list_for_each (pos, &f->flags) {
RFlagItem *flag = list_entry (pos, RFlagItem, list);
if (fi == NULL)
fi = flag;
else if (((namesort)? ncmp (fi, flag): cmp (fi, flag)) > 0)
fi = flag;
}
list_move (&fi->list, &f->flags_tmp);
// find bigger ones after this
do {
changes = 0;
list_for_each (pos, &f->flags) {
RFlagItem *flag = list_entry (pos, RFlagItem, list);
if (((namesort)? ncmp (fi, flag): cmp (fi, flag)) > 0) {
fi = flag;
changes = 1;
}
}
if (fi && changes) {
ret = R_TRUE;
list_move (&fi->list, &f->flags_tmp);
}
} while (changes);
f->flags = f->flags_tmp;
return ret;
}
R_API RFlag * r_flag_new() {

View File

@ -35,6 +35,7 @@ typedef struct r_flag_t {
struct btree_node *ntree; /* index by name */
#endif
struct list_head flags;
struct list_head flags_tmp;
} RFlag;
#ifdef R_API
@ -45,6 +46,7 @@ R_API struct r_flag_item_t *r_flag_get(struct r_flag_t *f, const char *name);
R_API struct r_flag_item_t *r_flag_get_i(struct r_flag_t *f, ut64 off);
R_API int r_flag_unset(struct r_flag_t *f, const char *name);
R_API int r_flag_set(struct r_flag_t *fo, const char *name, ut64 addr, ut32 size, int dup);
R_API int r_flag_sort(RFlag *f, int namesort);
R_API int r_flag_name_check(const char *name);
R_API int r_flag_name_filter(char *name);

View File

@ -54,7 +54,7 @@ int main(int argc, char **argv) {
break;
default:
/* generate signature file */
r_sign_generate (&sig, argv[optind], stdout);
//r_sign_generate (&sig, argv[optind], stdout);
break;
}
return 0;