225 lines
3.8 KiB
C++
225 lines
3.8 KiB
C++
#include <curses.h>
|
|
#include <stdio.h>
|
|
|
|
struct data
|
|
{
|
|
struct data* plast;
|
|
struct data* pnext;
|
|
char vals[16][16];
|
|
};
|
|
|
|
WINDOW *stdscr,*woffs,*whex, *wascii, *wtop, *wbot;
|
|
const char *topline= " Offset Hex ASCII";
|
|
char xoffs[] = "12345678",*soffs;
|
|
char xhex[] = " 14 15 16 32 32 34 20 54 61 67 65 73 61 6D 74 0D ",*shex;
|
|
char xascii[] = "1234567890123456",*sascii;
|
|
int result;
|
|
char *ptv="12345678";
|
|
FILE *fp;
|
|
int ipoint;
|
|
data daten,*pfirst;
|
|
|
|
void initvar()
|
|
{
|
|
pfirst=&daten;
|
|
soffs=xoffs;
|
|
shex=xhex;
|
|
sascii=xascii;
|
|
}
|
|
|
|
int screeninit()
|
|
{
|
|
int retval=0;
|
|
|
|
stdscr= initscr();
|
|
if(start_color()) retval=1;
|
|
nonl();
|
|
intrflush(stdscr, FALSE);
|
|
keypad(stdscr, TRUE);
|
|
|
|
// Zwei Fenster
|
|
woffs =newwin(18,10,3 ,0 );
|
|
whex =newwin(18,52,3 ,10);
|
|
wascii=newwin(18,18,3 ,62);
|
|
wtop =newwin(3 ,80,0 ,0 );
|
|
wbot =newwin(4 ,80,21,0 );
|
|
|
|
// Scrollen erlauben
|
|
scrollok(woffs,1);
|
|
scrollok(whex,1);
|
|
scrollok(wascii,1);
|
|
|
|
// Color-Pairs anlegen (Farbkombinationen)
|
|
if(init_pair(1,COLOR_BLUE,COLOR_BLACK)) retval=1;
|
|
if(init_pair(2,COLOR_CYAN,COLOR_BLACK)) retval=1;
|
|
|
|
wattrset(woffs,COLOR_PAIR(1));
|
|
wattrset(whex,COLOR_PAIR(1));
|
|
wattrset(wascii,COLOR_PAIR(1));
|
|
wattrset(wbot,COLOR_PAIR(1));
|
|
wattrset(wtop,COLOR_PAIR(1));
|
|
|
|
box(woffs,0,0);
|
|
box(whex,0,0);
|
|
box(wascii,0,0);
|
|
box(wtop,0,0);
|
|
box(wbot,0,0);
|
|
|
|
wattrset(woffs,COLOR_PAIR(2));
|
|
wattrset(whex,COLOR_PAIR(2));
|
|
wattrset(wascii,COLOR_PAIR(2));
|
|
wattrset(wtop,COLOR_PAIR(2));
|
|
wattrset(wbot,COLOR_PAIR(2));
|
|
|
|
return(retval);
|
|
}
|
|
|
|
char* tohex(int base10)
|
|
{
|
|
int newbase=16;
|
|
int erg;
|
|
int rest=0;
|
|
int pos=0;
|
|
int i;
|
|
static char swap[9];
|
|
char c[9];
|
|
|
|
swap="********";
|
|
c[pos]='0'+rest;
|
|
while (base10 > 0)
|
|
{
|
|
erg=base10/newbase;
|
|
rest=base10%newbase;
|
|
if (rest <= 9)
|
|
c[pos]='0'+rest;
|
|
else
|
|
c[pos]='A'+(rest-10);
|
|
|
|
base10=erg;
|
|
pos++;
|
|
c[pos]='\0';
|
|
}
|
|
while(pos < 8)
|
|
{
|
|
c[pos]='0';
|
|
pos++;
|
|
}
|
|
pos--;
|
|
for (i=0;i<=pos;i++)
|
|
{
|
|
swap[i]=c[pos-i];
|
|
}
|
|
|
|
return(swap);
|
|
|
|
|
|
}
|
|
|
|
int loadcontents()
|
|
{
|
|
int retval=0;
|
|
int x,y;
|
|
for(x=0;x<16;x++)
|
|
for(y=0;y<16;y++)
|
|
{
|
|
daten.vals[y][x]=fgetc(fp);
|
|
if (daten.vals[y][x]==EOF) daten.vals[y][x]=0;
|
|
}
|
|
for(x=0;x<16;x++)
|
|
for(y=0;y<16;y++)
|
|
printf("%c",daten.vals[y][x]);
|
|
|
|
return (retval);
|
|
}
|
|
|
|
void endscr()
|
|
{
|
|
delwin(woffs);
|
|
delwin(whex);
|
|
delwin(wascii);
|
|
delwin(wtop);
|
|
delwin(wbot);
|
|
endwin();
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
//Variablen
|
|
unsigned int i,z;
|
|
|
|
printf("%s\n",tohex(0));
|
|
printf("%s\n",tohex(10));
|
|
printf("%s\n",tohex(20));
|
|
printf("%s\n",tohex(30));
|
|
printf("%s\n",tohex(40));
|
|
printf("%s\n",tohex(50));
|
|
|
|
//Vorbereitung
|
|
//Parameter angegeben?
|
|
if(argc < 2)
|
|
{
|
|
fprintf(stderr,"THX-MESSAGE:\n\nUSAGE: %s <filename> \n",argv[0]);
|
|
exit(1);
|
|
}
|
|
//Datei öffnen
|
|
fp=fopen(argv[1],"r");
|
|
if (fp == NULL)
|
|
{
|
|
fprintf(stderr,"THX-MESSAGE:\n\nERROR opening file: %s \n",argv[1]);
|
|
exit(2);
|
|
}
|
|
//Datei -> Speicher
|
|
if(loadcontents())
|
|
{
|
|
fprintf(stderr,"THX-MESSAGE:\n\nERROR reading %s (too less RAM?)\n",argv[1]);
|
|
exit(3);
|
|
}
|
|
// pointer setzen
|
|
initvar();
|
|
// Terminal initialisieren
|
|
if(screeninit())
|
|
{
|
|
endscr();
|
|
fprintf(stderr,"!!!Terminal not supported!!! -> Abort \n");
|
|
exit(5);
|
|
}
|
|
mvwaddstr(wtop,1,1,topline);
|
|
mvwaddstr(wbot,1,1,argv[1]);
|
|
|
|
|
|
//Hauptprogramm
|
|
|
|
for (i=1;i<17;i++)
|
|
{
|
|
ptv = tohex(i-1);
|
|
for(z=0;z<9;z++)
|
|
{
|
|
xoffs[z] = *(ptv+z);
|
|
}
|
|
mvwaddstr(woffs,i,1,soffs);
|
|
for (z=0;z<16;z++)
|
|
{
|
|
ptv = tohex(daten.vals[z][i-1]);
|
|
xhex[z*3+1] = *(ptv+6);
|
|
xhex[z*3+2] = *(ptv+7);
|
|
}
|
|
mvwaddstr(whex,i,1,shex);
|
|
for (z=0;z<16;z++)
|
|
{
|
|
xascii[z] = ((daten.vals[z][i-1]) > 33)?(daten.vals[z][i-1]):254;
|
|
}
|
|
mvwaddstr(wascii,i,1,sascii);
|
|
}
|
|
|
|
wrefresh(woffs);
|
|
wrefresh(whex);
|
|
wrefresh(wascii);
|
|
wrefresh(wtop);
|
|
wrefresh(wbot);
|
|
|
|
|
|
sleep(1);
|
|
endscr();
|
|
return (fclose(fp));
|
|
}
|