Advertisement
teknoraver

kernel hexdump

Apr 26th, 2016 (edited)
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #define COLS 16
  2.  
  3. static void hexdump(const char *buf, size_t length)
  4. {
  5.     bool star = false;
  6.     size_t i, j;
  7.  
  8.     for (i = 0; i < length; i += COLS, buf += COLS) {
  9.         if (i && !memcmp(buf, buf - COLS, COLS)) {
  10.             if (!star)
  11.                 printk(KERN_CONT "*\n");
  12.             star = true;
  13.             continue;
  14.         }
  15.         star = false;
  16.         printk("%px  ", buf + i);
  17.         for (j = 0; j < COLS; j++) {
  18.             printk(KERN_CONT "%02hhx ", buf[j]);
  19.             if ((j & (COLS / 2 - 1)) == COLS / 2 - 1)
  20.                 printk(KERN_CONT " ");
  21.         }
  22.         printk(KERN_CONT "|");
  23.         for (j = 0; j < COLS; j++) {
  24.             int c = buf[j];
  25.             printk(KERN_CONT "%c", c >= ' ' && c <= '~' ? c : '.');
  26.         }
  27.         printk(KERN_CONT "|\n");
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement