~ubuntu-branches/ubuntu/saucy/radare/saucy

« back to all changes in this revision

Viewing changes to src/flags.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Reichel
  • Date: 2009-05-22 19:01:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090522190100-qqp4aja112976t5v
Tags: 20090522-1
* new hg checkout
 - added 'cX' command to compare like 'cc' does but using two side hexdiff dump format
 - specify pointer & data size in pm with %<size>
 - add graph.weight
 - fix 'c' command (missing radare_read(0))
 - added /P search command that searchs for proximity in bytelevel distance
 - added more 'ag' and 'gu' commands to readline autocompletion.
 - fix build of debugger for non-linux systems
 - fixed code analysis at startup
 - more work in graphs (graph.split)
 - fixups in x86 code analysis

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2006, 2007, 2008
 
2
 * Copyright (C) 2006, 2007, 2008, 2009
3
3
 *       pancake <youterm.com>
4
4
 *
5
5
 * radare is free software; you can redistribute it and/or modify
69
69
        " fortune      ; show fortune message! :D\n"
70
70
        " ff [addr]    ; flag from this address\n"
71
71
        " fb [addr]    ; increment flag offset with new base address\n"
72
 
        " fd           ; print flag delta offset\n"
 
72
        " fd @ addr    ; print flag delta offset\n"
73
73
        " fc cmd       ; set command to be executed on flag at current seek\n"
74
74
        " fi pfx1 pfx2 ; flag interpolation between hit0_ and hit1_ for.example\n"
75
75
        " fg text[*]   ; grep for flag or all flags matching text* (like f | grep foo)\n"
449
449
        return nullstr;
450
450
}
451
451
 
452
 
/* TODO
 
452
/* 
 
453
 * idx = -2 : single ref with delta
453
454
 * idx = -1 : return all flags at given seek separated by comma
454
455
 * idx =  0 : just return the first one found
455
456
 * idx =  1 : continue searching for flag after the first one
456
457
 */
457
458
int string_flag_offset(char *buf, u64 seek, int idx)
458
459
{
459
 
        int delta = (int)config_get_i("cfg.delta");
 
460
        int delta;
460
461
        flag_t *ref = NULL;
461
462
        struct list_head *pos;
 
463
        int found = 0;
 
464
        char buf2[256];
462
465
 
 
466
#warning TODO: Implement delta
 
467
#if 0
 
468
                if ((flag->offset >= seek && flag->offset <= seek+128)) {
 
469
                //|| (flag->offset >= seek && flag->offset <= seek+config.vaddr)) {
 
470
                        if (idx == -1) {
 
471
                                if (buf[0])
 
472
                                        strcat(buf, ",");
 
473
                                strcat(buf, flag->name);
 
474
                                snprintf(buf2, 32, "+0x%llx", flag->offset-seek);
 
475
                                strcat(buf, buf2);
 
476
                        }
 
477
                } else
 
478
#endif
463
479
        buf[0]='\0';
464
480
 
465
481
        list_for_each(pos, &flags) {
466
482
                if (config.interrupted) break;
467
483
                flag_t *flag = (flag_t *)list_entry(pos, flag_t, list);
468
 
                if (flag->offset == seek) {
469
 
                        ref = flag;
470
 
                        if (idx==-1) {
 
484
                if (flag->offset == seek || flag->offset == seek+config.vaddr) {
 
485
                        found = 1;
 
486
                        if (idx<1) {
471
487
                                if (buf[0])
472
488
                                        strcat(buf, ",");
473
 
                                strcat(buf, ref->name);
474
 
                        } else break;
 
489
                                strcat(buf, flag->name);
 
490
                        } else {
 
491
                                ref = flag;
 
492
                                break;
 
493
                        }
475
494
                } else
476
 
                if (!flag->offset)
477
 
                        continue;
478
 
                else
479
 
                if (flag->offset <= seek && (!ref || flag->offset > ref->offset))
480
 
                        ref = flag;
 
495
                if (flag->offset <= seek+config.vaddr && (!ref || flag->offset > ref->offset)) {
 
496
                        if (!found)
 
497
                                ref = flag;
 
498
                }
481
499
        }
482
500
        if (idx==-1)
483
 
                return 1;
484
 
 
 
501
                return buf[0]!='\0';
 
502
        if (idx==-2) {
 
503
                if (buf[0]=='\0') {
 
504
                        if (ref) {
 
505
                                snprintf(buf2, 32, "%s+0x%llx", ref->name, (seek+config.vaddr)-ref->offset);
 
506
                                strcat(buf, buf2);
 
507
                        }
 
508
                }
 
509
                return buf[0]!='\0';
 
510
        }
 
511
        delta = (int)config_get_i("cfg.delta");
485
512
        if (ref) {
486
513
                long ul = (seek-ref->offset);
487
514
                if (ul == 0)
499
526
void print_flag_offset(u64 seek)
500
527
{
501
528
        char buf[256];
502
 
 
503
 
        if ( string_flag_offset(buf, seek, -1) )
 
529
        if ( string_flag_offset(buf, seek, -2) )
504
530
                cons_strcat(buf);
505
531
}
506
532
 
738
764
        case ' ':
739
765
        case '\n':
740
766
        case '\t':
 
767
        case '@':
 
768
        case '`':
 
769
        case '=':
 
770
        case '>':
 
771
        case '<':
 
772
//      case '(':
 
773
//      case ')':
741
774
        case '[':
742
 
        case '@':
 
775
        case ']':
 
776
        case ';':
 
777
        case '!':
 
778
        case '%':
743
779
                return 0;
744
780
        default:
745
781
                if (((ch >= '0') && (ch <= '9')))
763
799
                        break;
764
800
                }
765
801
                if (!flag_is_valid_char(*name)) {
766
 
                        strcpy(name, name+1);
 
802
                        strbcpy(name, name+1);
767
803
                        name = name -1;
768
804
                }
769
805
        }
1046
1082
                        if (cmd[0])
1047
1083
                                radare_cmd_raw(cmd, 0);
1048
1084
                }
1049
 
                cons_flush();
 
1085
                cons_flushit();
1050
1086
                ch = cons_readchar();
1051
1087
                ch = cons_get_arrow(ch); // get ESC+char, return 'hjkl' char
1052
1088
                switch(ch) {
1127
1163
                        cons_printf(" +/-   - increase/decrease block size\n");
1128
1164
                        cons_printf(" p/P   - rotate print format\n");
1129
1165
                        cons_printf(" :     - enter command\n");
1130
 
                        cons_flush();
 
1166
                        cons_flushit();
1131
1167
                        cons_any_key();
1132
1168
                        break;
1133
1169
                case ':':