Last active
December 13, 2017 15:55
-
-
Save farooqkz/030aef60f469a5240a4b40504bef62d2 to your computer and use it in GitHub Desktop.
Simple file viewer in hex format. usage: hexview <filename>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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