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

« back to all changes in this revision

Viewing changes to src/visual.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:
120
120
        COMMAND('x', 0, "show xrefs of the current offset", xrefs_here),
121
121
        COMMAND('i', 0, "insert mode (tab to change hex,asm,ascii, q to back)", insert),
122
122
        COMMAND('I', 0, "invert current block", invert),
123
 
        COMMAND('_', 0, "set block size", setblocksize),
 
123
        //COMMAND('_', 0, "set block size", setblocksize),
124
124
        COMMAND('z', 0, "zoom full/block with pO", zoom),
125
125
        COMMAND('Z', 0, "resets zoom preferences", zoom_reset),
126
126
        COMMAND('w', 1, "write hex string", insert_hexa_string),
136
136
 
137
137
void visual_show_help()
138
138
{
 
139
        int fus = cons_flushable;
 
140
        cons_flushable = 0;
139
141
        cons_strcat("\x1b[2J\x1b[0;0H\n");
140
142
        TITLE
141
143
        cons_printf("Visual keybindings:\n");
142
144
        TITLE_END
143
145
        cons_printf(
144
 
        ":<cmd>     radare command (vi like)\n"
145
 
        ";          edit or add comment\n"
146
 
        "\"         change metadata of current cursor seek\n"
147
 
        ",.         ',' marks an offset, '.' seeks to mark or eip if no mark\n"
148
 
        "m'         m1 -> mark current position as char '1'. '1 will jump to mark 1\n"
149
 
        "g,G        seek to beggining or end of file\n"
150
 
        "+-*/       +1, -1, +width, -width -> block size\n"
151
 
        "<>         seek block aligned (cursor mode = folder code)\n"
152
 
        "[]         adjust screen width\n"
153
 
        "a,A,=      insert patch assembly, rsc asm or !hack\n"
154
 
        "i          insert mode (tab to switch btw hex,asm,ascii, 'q' to normal)\n"
155
 
        "f,F        seek between flag list (f = forward, F = backward)\n"
156
 
        "n,N        seek between hits of the hit0 search\n"
157
 
        "t          visual track/browse flagspaces and flags\n"
158
 
        "e          visual eval configuration variables\n"
159
 
        "C          toggle scr.color\n"
160
 
        "d          convert cursor selected bytes to ascii, code or hex\n"
161
 
//      "b[k][cmd]  binds key 'k' to the specified command\n"
162
 
        "m          applies rfile magic on this block\n" // ???
163
 
        "I          invert block (same as pIx or so)\n"
164
 
        "y,Y        yank and Yankee aliases for copy and paste\n"
165
 
        "f,F        go next, previous flag (cursor mode to add/remove)\n"
166
 
        "h,j,k,l    scroll view to left, down, up, right.\n"
167
 
        "J,K        up down scroll one block.\n"
168
 
        "H,L        scroll left, right by 2 bytes (16 bits).\n"
169
 
        "p,P        switch between hex, bin and string formats\n"
170
 
        "x          show xrefs of the current offset\n"
171
 
        "w          write hexpair bytes in cursor\n"
172
 
        "q          exits visual mode\n");
 
146
        " :<cmd>     radare command (vi like)\n"
 
147
        " ;          edit or add comment\n"
 
148
        " \"         change metadata of current cursor seek\n"
 
149
        " ,.         ',' marks an offset, '.' seeks to mark or eip if no mark\n"
 
150
        " m'         m1 -> mark current position as char '1'. '1 will jump to mark 1\n"
 
151
        " g,G        seek to beggining or end of file\n"
 
152
        " +-*/       +1, -1, +width, -width -> block size\n"
 
153
        " <>         seek block aligned (cursor mode = folder code)\n"
 
154
        " []{}()     adjust screen width, move horitzontally and vertically\n"
 
155
        " a,A,=      insert patch assembly, rsc asm or !hack\n"
 
156
        " i          insert mode (tab to switch btw hex,asm,ascii, 'q' to normal)\n"
 
157
        " f,F        seek between flag list (f = forward, F = backward)\n"
 
158
        " n,N        seek between hits of the hit0 search\n"
 
159
        " t          visual track/browse flagspaces and flags\n"
 
160
        " e          visual eval configuration variables\n"
 
161
        " C          toggle scr.color\n"
 
162
        " d          convert cursor selected bytes to ascii, code or hex\n"
 
163
//      " b[k][cmd]  binds key 'k' to the specified command\n"
 
164
        " m,'        ma, 'a, will mark current seek as 'a' and 'a will jump there\n"
 
165
        " I          invert block (same as pIx or so)\n"
 
166
        " y,Y        yank and Yankee aliases for copy and paste\n"
 
167
        " f,F        go next, previous flag (cursor mode to add/remove)\n"
 
168
        " h,j,k,l    scroll view to left, down, up, right.\n"
 
169
        " J,K        up down scroll one block.\n"
 
170
        " H,L        scroll left, right by 2 bytes (16 bits).\n"
 
171
        " p,P        switch between hex, bin and string formats\n"
 
172
        " x          show xrefs of the current offset\n"
 
173
        " w          write hexpair bytes in cursor\n"
 
174
        " q          exits visual mode\n");
173
175
        TITLE
174
176
        cons_printf("\nCursor mode:\n");
175
177
        TITLE_END
176
178
        cons_printf(
177
 
        "c          toggle cursor mode\n"
178
 
        "hjkl       move cursor (also arrows)\n"
179
 
        "HJKL       select bytes (shift+arrows)\n"
180
 
        "f/F        set/unset flag at cursor\n");
 
179
        " c          toggle cursor mode\n"
 
180
        " hjkl       move cursor (also arrows)\n"
 
181
        " HJKL       select bytes (shift+arrows)\n"
 
182
        " f/F        set/unset flag at cursor\n");
181
183
        if (config.debug) {
182
184
        TITLE
183
185
        cons_printf("\nDebugger keybindings:\n");
184
186
        TITLE_END
185
187
        cons_printf(
186
 
        "!          show debugger commands help\n"
187
 
        "F1         commands help\n"
188
 
        "F2         set breakpoint (execute)\n"
189
 
        "F3         set watchpoint (read)\n"
190
 
        "F4         continue until cursor or here (for loops)\n"
191
 
        "F6         continue until syscall (!contsc)\n"
192
 
        "F7         step in debugger user code (!step)\n"
193
 
        "F8         step over in debugger (!stepo)\n"
194
 
        "F9         continue execution (!cont)\n"
195
 
        "F10        continue until user code (!contu)\n"
 
188
        " !          show debugger commands help\n"
 
189
        " F1         commands help\n"
 
190
        " F2         set breakpoint (execute)\n"
 
191
        " F3         set watchpoint (read)\n"
 
192
        " F4         continue until cursor or here (for loops)\n"
 
193
        " F6         continue until syscall (!contsc)\n"
 
194
        " F7 F8      !step and !stepover\n"
 
195
        " F9         continue execution (!cont)\n"
 
196
        " F10        continue until user code (!contu)\n"
196
197
        );
197
198
        }
198
199
        cons_flush();
 
200
cons_flushable = fus;
 
201
        //cons_flushit();
199
202
}
200
203
 
201
204
CMD_DECL(visual_bind_run)
253
256
                config.insert_mode = 1;
254
257
                config.cursor_mode = 1;
255
258
                config.ocursor = -1;
256
 
                cons_flush();
 
259
                cons_flushit();
257
260
        } else {
258
261
                cons_printf("Not in write mode.\n");
259
262
                cons_any_key();
294
297
                        "m - memory format (pm)\n"
295
298
                        "< - close folder\n"
296
299
                        "> - open folder\n");
297
 
                        cons_flush();
 
300
        //              cons_flush();
 
301
        cons_flushit();
298
302
                        c = cons_readchar();
299
303
                }
300
304
                if (c == 'u') {
414
418
 
415
419
CMD_DECL(yank)
416
420
{
417
 
        int off = 0;
 
421
        int i, off = 0;
418
422
        char *ptr = strchr(input, ' ');
419
423
        if (ptr == NULL)
420
424
                ptr = input;
422
426
        case 'y':
423
427
                cmd_yank_paste(input);
424
428
                return 0;
 
429
        case 'f':
 
430
                free(yank_buffer);
 
431
                yank_buffer = slurp(input+2, &yank_buffer_size);
 
432
                eprintf("Yanking %d bytes into the clipboard from '%s'\n",
 
433
                        yank_buffer_size, input+2);
 
434
                //radare_cmd("yi", 0);
 
435
                return 0;
 
436
        case 'F':
 
437
                eprintf("TODO\n");
 
438
                return 0;
425
439
        case 't':
426
 
                radare_move(input+1);
 
440
                switch(input[1]) {
 
441
                case 'f':
 
442
                        /* ytf -> yank to file */
 
443
                        if (input[2]!= ' ') {
 
444
                                eprintf("Usage: ytf [file]\n");
 
445
                        } else file_dump(input+3, yank_buffer, yank_buffer_size);
 
446
                        break;
 
447
                case 'F':
 
448
                        /* ytf -> yank to file */
 
449
                        eprintf("TODO\n");
 
450
                        break;
 
451
                case ' ':
 
452
                        radare_move(input+1);
 
453
                        break;
 
454
                default:
 
455
                        eprintf("Unknown yt subcommand. try y?\n");
 
456
                }
 
457
                return 0;
 
458
        case 'i':
 
459
                cons_printf("buffer=");
 
460
                for(i=0;i<yank_buffer_size;i++) {
 
461
                        cons_printf("%02x", yank_buffer[i]);
 
462
                }
 
463
                cons_printf("\nsize=%d\n", yank_buffer_size);
427
464
                return 0;
428
465
        }
429
466
        if (ptr[0]=='?') {
430
 
                eprintf("Usage: y[ft] [length]\n");
431
 
                eprintf(" > y 10 @ eip     ; yanks 10 bytes from eip\n");
432
 
                eprintf(" > yy @ edi       ; write these bytes where edi points\n");
433
 
                eprintf(" > yt [len] dst   ; copy N bytes from here to dst\n");
 
467
                eprintf("Usage: y[ft] [length]\n"
 
468
                " > y 10 @ eip     ; yanks 10 bytes from eip\n"
 
469
                " > yi             ; show information about the yanked data\n"
 
470
                " > yy @ edi       ; write these bytes where edi points\n"
 
471
                " > yt [len] dst   ; copy N bytes from here to dst\n"
 
472
                " > yf file        ; yank file into clipboard\n"
 
473
                " > ytf file       ; paste clipboard buffer to file\n");
 
474
                //" > yF/ytF file    ; yank file hexpairs into clipboard (TODO)\n");
434
475
                return 0;
435
476
        }
436
 
 
437
477
        free(yank_buffer);
438
478
        yank_buffer_size = get_math(ptr);
439
479
        if (yank_buffer_size > config.block_size || yank_buffer_size == 0)
486
526
                                off = config.cursor;
487
527
                        radare_seek(old+off, SEEK_SET);
488
528
                        io_write(config.fd, yank_buffer, sz);
489
 
                        eprintf("%d bytes yanked.\n", (int) sz);
 
529
                        eprintf("%d bytes written.\n", (int) sz);
490
530
                        radare_seek(old, SEEK_SET);
491
531
                        radare_read(0);
492
532
                } else {
508
548
        cons_printf("Select XREF from list:\n");
509
549
        data_xrefs_here(config.seek);
510
550
        cons_printf("==> ");
511
 
        cons_flush();
 
551
        //cons_flush();
 
552
        cons_flushit();
512
553
        foo = cons_readchar() - '0';
513
554
        if (foo<10) {
514
555
                addr = data_seek_to(config.seek, -1, foo);
824
865
        cons_printf("\nradare command: ");
825
866
        fflush(stdin);
826
867
        fflush(stdout);
827
 
        cons_flush();
 
868
        cons_flushit();
828
869
        cons_set_raw(0);
829
870
        buf[0]='\0';
830
871
 
860
901
                bds[n].key = key;
861
902
                bds[n].cmd = strdup(buf);
862
903
        } 
863
 
        cons_flush();
 
904
        cons_flushit();
864
905
}
865
906
 
866
907
void visual_draw_screen()
893
934
                strcpy(buf, "<insert assembly> ('tab')");
894
935
                break;
895
936
        default:
896
 
                string_flag_offset(buf, config.seek, -1);
 
937
                string_flag_offset(buf, config.seek, -2);
897
938
                if (config.cursor!=-1)
898
939
                        string_flag_offset(buf2, config.seek+config.cursor, -1);
899
940
        }
956
997
        radare_print("", last_print_format);
957
998
 
958
999
        fflush(stdout);
959
 
        cons_flush();
 
1000
        //cons_flush();
 
1001
        cons_flushit();
960
1002
}
961
1003
 
962
1004
// autoadjust height of screen
1196
1238
 
1197
1239
        cons_clear();
1198
1240
        cons_set_raw(1);
 
1241
        cons_flushable = 1;
 
1242
        cons_skipxy(0,0);
1199
1243
        while(1) {
1200
1244
                const char *scrseek = config_get("scr.seek");
1201
1245
                if (inc<1) inc = 1;
1208
1252
                        radare_cmd(".!regs*", 0);
1209
1253
                radare_prompt_command();
1210
1254
                visual_draw_screen();
 
1255
        cons_flushit();
1211
1256
 
1212
1257
                        // XXX 
1213
1258
                if (config.debug&&last_print_format == FMT_VISUAL&&scrseek&&scrseek[0]) {
1564
1609
                        cons_set_raw(0);
1565
1610
                        lpf = last_print_format;
1566
1611
                        config.visual=0;
 
1612
                cons_flushable = 0;
1567
1613
#if HAVE_LIB_READLINE
1568
1614
                        ptr = readline(VISUAL_PROMPT);
1569
1615
                        line[0]='\0';
1602
1648
                        //line[strlen(line)-1]='\0';
1603
1649
                        radare_cmd(line, 1);
1604
1650
#endif
 
1651
                cons_flushable = 1;
 
1652
                cons_flush();
1605
1653
                        config.visual=1;
1606
1654
                        last_print_format = lpf;
1607
1655
                        cons_set_raw(1);
1918
1966
                        } else
1919
1967
                                config.seek++;
1920
1968
                        break;
 
1969
                case '(': cons_skipxy(0,-1); break;
 
1970
                case ')': cons_skipxy(0,1); break;
 
1971
                case '{': cons_skipxy(-1,0); break;
 
1972
                case '}': cons_skipxy(1,0); break;
 
1973
#if 0
 
1974
                case '-': config.height--; break;
 
1975
                case '_': config.height++; break;
 
1976
#endif
1921
1977
                case '*':
1922
1978
                        radare_set_block_size_i(config.block_size+inc);
1923
1979
                        break;
1932
1988
                                if (config.cursor>=0 && config.cursor< config.block_size) {
1933
1989
                                        c = config.cursor;
1934
1990
                                        ch = config.block[config.cursor];
1935
 
                                        sprintf(buf, "wx %02x @ 0x%llx", (unsigned char)(++ch), config.seek); //+config.cursor);
 
1991
                                        sprintf(buf, "wx %02x @ 0x%llx",
 
1992
                                                (u8)(++ch), config.seek); //+config.cursor);
1936
1993
                                        radare_cmd(buf, 0);
1937
1994
                                        config.cursor = c;
1938
1995
                                        config.ocursor = -1;
1948
2005
                                if (config.cursor>=0 && config.cursor< config.block_size) {
1949
2006
                                        c = config.cursor;
1950
2007
                                        ch = config.block[config.cursor];
1951
 
                                        eprintf("cursor %d\n", config.cursor);
1952
2008
                                        sprintf(buf, "wx %02x @ 0x%llx", (unsigned char)(--ch), config.seek); //+config.cursor);
1953
2009
                                        radare_cmd(buf, 0);
1954
2010
                                        config.cursor = c;
1996
2052
        config.visual = 0;
1997
2053
        config.cursor_mode = 0;
1998
2054
        cons_set_raw(0);
 
2055
        cons_flushable = 0;
1999
2056
}