@@ -74,14 +74,17 @@ void gui_draw_title(char *format, ...) {
7474
7575}
7676
77- void gui_draw_hex (byte * file ) {
77+ void gui_draw_hex (byte * file , unsigned int file_current_offset ) {
7878
79+ file += file_current_offset ;
7980 unsigned int hex_per_line = getmaxx (hex ) / 3 ;
8081 unsigned int file_max_drawable = hex_per_line * getmaxy (hex );
8182 unsigned int file_size = strlen (file );
8283 unsigned int file_draw_size = (file_max_drawable < file_size ) ? file_max_drawable : file_size ;
8384 unsigned int line = 0 ;
8485 unsigned int i ;
86+ wmove (hex , 0 , 0 );
87+ wmove (text , 0 , 0 );
8588 for (i = 0 ; i < file_draw_size ; i += hex_per_line , ++ line ) {
8689 for (unsigned int j = 0 ; (j < hex_per_line ) && (i + j < file_draw_size ); ++ j ) {
8790 wprintw (hex , "%02x " , file [i + j ]);
@@ -96,10 +99,10 @@ void gui_draw_hex(byte *file) {
9699 wprintw (text , "%c" , file [i + j ]);
97100 }
98101 wprintw (text , "\n" );
99- mvwprintw (lines , line , 1 , "0x%08x:" , i );
102+ mvwprintw (lines , line , 1 , "0x%08x:" , i + file_current_offset );
100103
101104 }
102- mvwprintw (lines , line , 1 , "0x%08x:" , i );
105+ mvwprintw (lines , line , 1 , "0x%08x:" , i + file_current_offset );
103106
104107 box (lines , ' ' , 0 );
105108 REFRESH_WINDOW (hex )
@@ -108,29 +111,49 @@ void gui_draw_hex(byte *file) {
108111
109112}
110113
111- void draw_cursor_reset () {
114+ void draw_cursor_reset (unsigned int * file_current_offset ) {
112115
113116 wmove (hex , 0 , 0 );
114117 REFRESH_WINDOW (hex )
115118}
116119
117- void draw_cursor_up () {
120+ void draw_cursor_up (unsigned int * file_current_offset , byte * file ) {
118121
119- wmove (hex , getcury (hex ) - 1 , getcurx (hex ));
122+ unsigned int maxy = getmaxy (hex );
123+ unsigned int cur_y = getcury (hex );
124+ unsigned int cur_x = getcurx (hex );
125+ unsigned int hex_per_line = getmaxx (hex ) / 3 ;
126+ if (0 == cur_y && * file_current_offset > 0 ) {
127+ * file_current_offset -= hex_per_line ;
128+ gui_draw_hex (file , * file_current_offset );
129+ wmove (hex , cur_y + 1 , cur_x );
130+ } else {
131+ wmove (hex , cur_y - 1 , cur_x );
132+ }
120133 REFRESH_WINDOW (hex )
121134}
122135
123- void draw_cursor_down () {
136+ void draw_cursor_down (unsigned int * file_current_offset , byte * file ) {
124137
125- wmove (hex , getcury (hex ) + 1 , getcurx (hex ));
138+ unsigned int maxy = getmaxy (hex );
139+ unsigned int cur_y = getcury (hex );
140+ unsigned int cur_x = getcurx (hex );
141+ unsigned int hex_per_line = getmaxx (hex ) / 3 ;
142+ if (maxy - 1 == cur_y ) {
143+ * file_current_offset += hex_per_line ;
144+ gui_draw_hex (file , * file_current_offset );
145+ wmove (hex , cur_y - 1 , cur_x );
146+ } else {
147+ wmove (hex , cur_y + 1 , cur_x );
148+ }
126149 REFRESH_WINDOW (hex )
127150}
128- void draw_cursor_right () {
151+ void draw_cursor_right (unsigned int * file_current_offset , byte * file ) {
129152
130153 wmove (hex , getcury (hex ), getcurx (hex ) + 1 );
131154 REFRESH_WINDOW (hex )
132155}
133- void draw_cursor_left () {
156+ void draw_cursor_left (unsigned int * file_current_offset , byte * file ) {
134157
135158 wmove (hex , getcury (hex ), getcurx (hex )- 1 );
136159 REFRESH_WINDOW (hex )
0 commit comments