Advertisement
Guest User

Source

a guest
Nov 28th, 2024
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.72 KB | Source Code | 0 0
  1. void pane_hexview_select_byte(hexview_t* hv, uint64_t byte) {
  2.     int selected_row;
  3.     int selected_col;
  4.  
  5.     if(byte < hv->data_offset)
  6.         _throwerr("Trying to select byte outside of hexview. Byte: %llu, hexview data offset: %llu", byte, hv->data_offset);
  7.     if(byte > hv->last_byte)
  8.         _throwerr("Trying to select byte outside of hexview. Byte: %llu, hexview last byte: %llu", byte, hv->last_byte);
  9.  
  10.     cursor_move(hv->pane.row, hv->pane.col);
  11.     printc("0x%0*llX", SHADE, -1, hv->offset_display_digits, byte);
  12.  
  13.     if(hv->highlight) {
  14.         /* If different columns, repaint the column specifier */
  15.         if(hv->selected_byte % 0x10 != byte % 0x10) {
  16.             int col;
  17.  
  18.             /* Repaint the old column specifier */
  19.             col = hv->pane.col + hv->offset_display_width + ( ( hv->selected_byte - hv->offset_alignment ) % 0x10 ) * 4;
  20.             cursor_move(hv->pane.row, col);
  21.             printc("%02X", SHADE, -1, hv->offset_alignment + ( hv->selected_byte - hv->offset_alignment ) % 0x10);
  22.  
  23.             /* Paint the new column specifier */
  24.             col = hv->pane.col + hv->offset_display_width + ( ( byte - hv->offset_alignment ) % 0x10 ) * 4;
  25.             cursor_move(hv->pane.row, col);
  26.             printc("%02X", TINT, -1, hv->offset_alignment + ( byte - hv->offset_alignment ) % 0x10);
  27.         }
  28.  
  29.         /* If different rows, repaint the row specifier */
  30.         if( (hv->selected_byte - hv->offset_alignment) / 0x10 != (byte - hv->offset_alignment) / 0x10) {
  31.             int row;
  32.  
  33.             /* Repaint the old row specifier */
  34.             row = hv->pane.row + 2 + ( hv->selected_byte - hv->data_offset ) / 0x10;
  35.             cursor_move(row, hv->pane.col);
  36.             printc("0x%0*llX", SHADE, -1, hv->offset_display_digits, hv->data_offset + (( hv->selected_byte - hv->data_offset ) & ~0xF));
  37.  
  38.             /* Paint the new row specifier */
  39.             row = hv->pane.row + 2 + ( byte - hv->data_offset ) / 0x10;
  40.             cursor_move(row, hv->pane.col);
  41.             printc("0x%0*llX", TINT, -1, hv->offset_display_digits, hv->data_offset + (( byte - hv->data_offset ) & ~0xF));
  42.         }
  43.     }
  44.  
  45.  
  46.     /* Repaint the old selected byte */
  47.     int color = (hv->selected_byte - hv->offset_alignment) % 2 ? TINT : -1;
  48.     int byte_index = hv->selected_byte - hv->data_offset;
  49.     selected_row = hv->pane.row + 2 + byte_index / 16;
  50.     selected_col = hv->pane.col + hv->offset_display_width + (byte_index % 0x10) * 4;
  51.  
  52.     cursor_move(selected_row, selected_col);
  53.     printc("%02X", color, -1, hv->file->data[hv->selected_byte]);
  54.  
  55.  
  56.     /* Paint the new selected byte */
  57.     color = (byte - hv->offset_alignment) % 2 ? TINT : -1;
  58.     byte_index = byte - hv->data_offset;
  59.     selected_row = hv->pane.row + 2 + byte_index / 16;
  60.     selected_col = hv->pane.col + hv->offset_display_width + (byte_index % 0x10) * 4;
  61.  
  62.     cursor_move(selected_row, selected_col);
  63.     printc("%02X", color, HOVER_COLOR, hv->file->data[byte]);
  64.     hv->selected_byte = byte;
  65.  
  66. }
Tags: Code draw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement