Skip to content

Instantly share code, notes, and snippets.

@farooqkz
Last active December 13, 2017 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farooqkz/030aef60f469a5240a4b40504bef62d2 to your computer and use it in GitHub Desktop.
Save farooqkz/030aef60f469a5240a4b40504bef62d2 to your computer and use it in GitHub Desktop.
Simple file viewer in hex format. usage: hexview <filename>
// hexview.c
// Author: FarooqKZ
// It's free software under GPL3+ and comes WITHOUT ANY WARRENTY FROM MAIN AUTHOR
#include <stdio.h>
int main(int argc, char *argv[]){
if (argc == 1 || !strcmp(argv[1], "-h")){
printf("Usage: hexview file_path\n");
return 0;
}
FILE *fs = fopen(argv[1], "r");
long byte_number = 0;
while(1){
if ((++byte_number % 26) == 0) // goes to new line each 26 bytes
printf("\n"); // you may remove this part and then use fold to split it into lines
int t = getc(fs);
if (t == EOF)
break;
printf("%.2X ", t);
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment