/*
 
    Simple hex view, v1
 
     Anasazi
 
*/
 
 
 
#include <stdio.h>
 
#include <Windows.h>
 
#include <stdlib.h>
 
#include <conio.h>
 
 
 
#define COLOR_SEPERATOR  8
 
#define COLOR_EXTENDED   9
 
#define COLOR_ASCII      10
 
#define COLOR_SPECIAL    11
 
#define COLOR_ADDRESS    6
 
#define COLOR_TEXT       15
 
 
 
int CHECKASCII(unsigned char X) {
 
    if      (X >= 0x0  && X <= 0x1F) return COLOR_SPECIAL;
 
    else if (X >= 0x20 && X <= 0x7F) return COLOR_ASCII;
 
    else if (X >= 0x81 && X <= 0xFF) return COLOR_EXTENDED;
 
    else return 7;
 
};
 
 
 
int main(int argc, char * argv[])
 
{
 
    FILE * fInput; __int64 fileSize; unsigned char op[8];
 
    DWORD dwAddress = 0; short i = 8; HANDLE hConsole;
 
    if(argc < 1 || strlen(argv[1]) < 1) return 1;
 
 
 
    printf("File: %s\n", argv[1]);
 
    fInput = fopen(argv[1], "rb");
 
    if(!fInput) return 1;
 
 
 
    fseek(fInput, 0, SEEK_END);
 
    fileSize = ftell(fInput);
 
    rewind(fInput);
 
 
 
    printf("Filesize: %d\n\n", fileSize);
 
     
 
    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
 
    while(!feof(fInput)) {
 
        SetConsoleTextAttribute(hConsole, COLOR_ADDRESS);
 
        printf("%08X", dwAddress);
 
        SetConsoleTextAttribute(hConsole, COLOR_SEPERATOR);
 
        printf(" %c ", (unsigned char)179);
 
 
 
        while(i-->0) {
 
            op[i] = (unsigned char)fgetc(fInput);
 
            if(op[i] == EOF) break;
 
            SetConsoleTextAttribute(hConsole, CHECKASCII(op[i]));
 
            printf("%02X ", op[i]);
 
        }
 
        SetConsoleTextAttribute(hConsole, COLOR_SEPERATOR);
 
        printf("%c ", (unsigned char)179);
 
        SetConsoleTextAttribute(hConsole, COLOR_TEXT);
 
 
 
        while(i++<8) printf("%c", (isprint(op[7-i]) == 0) ? 0x20 : op[7-i]);
 
        dwAddress += 8; i = 8; printf("\n");
 
    }
 
 
 
    _getch();
 
    return 0;
 
}