From ebfaff7586bda50f5901d32d1d39dfe72d344d12 Mon Sep 17 00:00:00 2001 From: Timo Engel Date: Fri, 13 Mar 2026 21:20:37 +0100 Subject: [PATCH 1/4] replace Makefile --- Makefile | 62 +++++++++++++++++--------------------------------------- 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/Makefile b/Makefile index 7415929..16e06c9 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,21 @@ -CC= gcc -LDFLAGS= -L/usr/lib -L/usr/local/lib -L/usr/lib/ncurses -L/usr/local/lib/ncurses -CPPFLAGS= -I/usr/include -I/usr/local/include -I/usr/include/ncurses -I/usr/local/include/ncurses -CFLAGS= -O3 -Wall -std=c99 -#CFLAGS+= -ffunction-sections -fdata-sections -#LDFLAGS+= --gc-sections -LIBS= -lncurses -DESTDIR= /usr/local/ - -OFILES=buffers.o \ - configfile.o \ - correlation.o \ - gpl.o \ - hexcalc.o \ - input.o \ - machine_type.o \ - main.o \ - markers.o \ - menu.o \ - output.o \ - search.o \ - ui.o - -all: dhex - -dhex: $(OFILES) - $(CC) $(LDFLAGS) -o $@ $(OFILES) $(LIBS) - -install:all - strip dhex - cp dhex $(DESTDIR)/bin - cp dhex.1 $(DESTDIR)/man/man1 - cp dhexrc.5 $(DESTDIR)/man/man5 - cp dhex_markers.5 $(DESTDIR)/man/man5 - cp dhex_searchlog.5 $(DESTDIR)/man/man5 - - - -.c.o: - $(CC) $< -c -I. $(CPPFLAGS) $(CFLAGS) $(OPTIONS) - +SRC:=buffers.c configfile.c correlation.c gpl.c hexcalc.c input.c \ + machine_type.c main.c markers.c menu.c output.c search.c ui.c +OBJ:=$(patsubst %.c,%.o,$(SRC)) +DEP:=$(patsubst %.c,%.d,$(SRC)) +CFLAGS:=-Wall -MMD $(shell pkgconf --cflags ncurses) +LDFLAGS:=$(shell pkgconf --libs ncurses) +TARGET=dhex + +$(TARGET): $(OBJ) + @echo linking $(TARGET) + @gcc $(OBJ) $(LDFLAGS) -o $(TARGET) + +%.o: %.c + @echo compiling $< + @gcc $(CFLAGS) -c $< -o $@ + +.PHONY: clean clean: - rm -f dhex $(OFILES) - + @rm -f $(OBJ) $(DEP) $(TARGET) +-include $(DEP) From 228c745c315b7f7d6773600d81a6e2c36947d816 Mon Sep 17 00:00:00 2001 From: Timo Engel Date: Sat, 14 Mar 2026 08:50:38 +0100 Subject: [PATCH 2/4] fix compiler warnings --- configfile.c | 2 +- correlation.c | 6 ++---- datatypes.h | 2 +- hexcalc.c | 4 ++-- main.c | 2 -- markers.c | 4 ++-- markers.h | 2 +- menu.c | 4 +--- output.c | 28 ++++++++++++---------------- search.c | 5 +---- search.h | 2 +- ui.c | 2 +- ui.h | 2 +- 13 files changed, 26 insertions(+), 39 deletions(-) diff --git a/configfile.c b/configfile.c index 47cd6ac..07c93f9 100644 --- a/configfile.c +++ b/configfile.c @@ -171,7 +171,7 @@ int getcolors(tOutput* output,char* line) int readconfigfile(tOutput* output,char* filename) { tFptr f=fopen(filename,"rb"); - unsigned char line[512]; + char line[512]; unsigned char c; int lineidx=0; int keyboardcnt; diff --git a/correlation.c b/correlation.c index ef49608..79b40f2 100644 --- a/correlation.c +++ b/correlation.c @@ -27,7 +27,7 @@ void find_longestmatch(tOutput* output,tCorrelation* correlation,tBuffer* buf1,t mvwprintw(output->win,offsy+1,offsx+1,"pos1:"); mvwprintw(output->win,offsy+4,offsx+1,"longest match:"); mvwprintw(output->win,offsy+5,offsx+1,"at"); - if (smallwin) mvwprintw(smallwin,4,1,"%18lli",0); + if (smallwin) mvwprintw(smallwin,4,1,"%18i",0); wrefresh(output->win); } @@ -115,7 +115,7 @@ void find_bestmatch(tOutput* output,tCorrelation* correlation,tBuffer* buf1,tBuf mvwprintw(output->win,offsy+1,offsx+1,"pos1:"); mvwprintw(output->win,offsy+4,offsx+1,"best match:"); mvwprintw(output->win,offsy+5,offsx+1,"at"); - if (smallwin) mvwprintw(smallwin,4,1,"%18lli",0); + if (smallwin) mvwprintw(smallwin,4,1,"%18i",0); wrefresh(output->win); } @@ -178,7 +178,6 @@ void find_mindiff(tOutput* output,tCorrelation* correlation,tBuffer* buf1,tBuffe WINDOW* smallwin=NULL; tBuffer* smallbuf; tBuffer* bigbuf; - tInt64 match; tBool found=0; @@ -207,7 +206,6 @@ void find_mindiff(tOutput* output,tCorrelation* correlation,tBuffer* buf1,tBuffe for (pos1=-(tInt64)smallbuf->bufsize;pos1<(tInt64)bigbuf->bufsize && correlation->mindiff;pos1++) { diff=0; - match=0; if (smallwin) mvwprintw(smallwin,1,3,"%16lli",((tInt64)bigbuf->bufsize-pos1)); else fprintf(stderr,"%16lli\r",((tInt64)buf1->bufsize-pos1)); diff --git a/datatypes.h b/datatypes.h index 2f18d6e..ed9aa6e 100644 --- a/datatypes.h +++ b/datatypes.h @@ -68,7 +68,7 @@ typedef struct _tCorrelation { tBool correlated; corr_algorithms algorithm; - tInt64 start_mindiff; + tUInt64 start_mindiff; tInt64 mindiff; tInt64 mindiffpos; tInt64 bestmatch; diff --git a/hexcalc.c b/hexcalc.c index 18bd2fd..c10d721 100644 --- a/hexcalc.c +++ b/hexcalc.c @@ -82,7 +82,7 @@ void hexcalc(tOutput* output,thHexCalc* hHexCalc) setcolor(output,(field==FIELDBIN && cursorline==i)?COLOR_INPUT:COLOR_TEXT); for (j=0;j<32;j++) { - if (x || !j) mvwprintw(output->win,offsy+18-i,offsx+76-j,"%i",(x&1)); + if (x || !j) mvwprintw(output->win,offsy+18-i,offsx+76-j,"%lli",(x&1)); else mvwprintw(output->win,offsy+18-i,offsx+76-j," "); x>>=1; } @@ -96,7 +96,7 @@ void hexcalc(tOutput* output,thHexCalc* hHexCalc) setcolor(output,(field==FIELDBIN && cursorline==-1)?COLOR_INPUT:COLOR_TEXT); for (j=0;j<32;j++) { - if (x || !j) mvwprintw(output->win,offsy+19,offsx+76-j,"%i",(x&1)); + if (x || !j) mvwprintw(output->win,offsy+19,offsx+76-j,"%lli",(x&1)); else mvwprintw(output->win,offsy+19,offsx+76-j," "); x>>=1; } diff --git a/main.c b/main.c index a271723..2460467 100644 --- a/main.c +++ b/main.c @@ -214,7 +214,6 @@ int parsecommandlineoptions(int argc,char** argv,tInt64* baseaddr1,tInt64* basea case 's': { tInt8 stringtype=0; // 0=unknown, 1=ascii, 2=hex - tBool forward=1; tSearch* search; tBool* gosearch; int j; @@ -225,7 +224,6 @@ int parsecommandlineoptions(int argc,char** argv,tInt64* baseaddr1,tInt64* basea { if (lastopt[j]=='a' || lastopt[j]=='A') stringtype=1; if (lastopt[j]=='h' || lastopt[j]=='H') stringtype=2; - if (lastopt[j]=='b' || lastopt[j]=='B') forward=0; if (lastopt[j]=='1') { search=search1; diff --git a/markers.c b/markers.c index 925f890..2281982 100644 --- a/markers.c +++ b/markers.c @@ -95,7 +95,7 @@ int writemarkerfile(tMarkers* markers,char* filename) fclose(f); return RETOK; } -tInt8 gotomask(tOutput* output,tMarkers* markers,tUInt64* cursorpos,tInt64 baseaddr) +tInt8 gotomask(tOutput* output,tMarkers* markers,tInt64* cursorpos,tInt64 baseaddr) { tUInt64 actcursorpos=*cursorpos+baseaddr; tUInt64 newcursorpos=*cursorpos+baseaddr; @@ -168,7 +168,7 @@ tInt8 gotomask(tOutput* output,tMarkers* markers,tUInt64* cursorpos,tInt64 basea snprintf(buf,17,"%c%llx",markers->relative[i],markers->cursorpos[i]); mvwprintw(output->win,offsy+5+i,offsx+32-strlen(buf),"%s",buf); - mvwprintw(output->win,offsy+5+i,offsx+42,"%16llx",abs(markers->cursorpos[i]-actcursorpos)); + mvwprintw(output->win,offsy+5+i,offsx+42,"%16x",abs(markers->cursorpos[i]-actcursorpos)); } setcolor(output,COLOR_TEXT); mvwprintw(output->win,offsy+3,offsx+9,"%17llx",newcursorpos); diff --git a/markers.h b/markers.h index 210d3cb..d25766f 100644 --- a/markers.h +++ b/markers.h @@ -6,7 +6,7 @@ void* initmarkers(); int parsemarkerfile(tMarkers* markers,char* filename); -tInt8 gotomask(tOutput* output,tMarkers* markers,tUInt64* cursorpos,tInt64 baseaddr); +tInt8 gotomask(tOutput* output,tMarkers* markers,tInt64* cursorpos,tInt64 baseaddr); #endif diff --git a/menu.c b/menu.c index 6369d57..226cf63 100644 --- a/menu.c +++ b/menu.c @@ -219,8 +219,6 @@ tInt8 MenuInteract(tOutput* output,tMenu* Menu,tInt16 offsy,tInt16 offsx) { tInt16 ch; int i; - tInt8 retval; - ch=0; printMenu(output,Menu,offsy,offsx); while (ch!=KEYENTER) @@ -233,7 +231,7 @@ tInt8 MenuInteract(tOutput* output,tMenu* Menu,tInt16 offsy,tInt16 offsx) case KEYUP: MenuMoveUp(Menu); break; case KEYDOWN: MenuMoveDown(Menu); break; case KEYTAB: Menu->menuitemactive=(Menu->menuitemactive+1)%Menu->menuitemnum;break; - case KEYENTER: retval=Menu->menuitemactive; break; + case KEYENTER: break; default: if (ch>=' ' && ch<127) { diff --git a/output.c b/output.c index 327fd61..c9d1036 100644 --- a/output.c +++ b/output.c @@ -87,7 +87,6 @@ void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 int addrwidth; int bytesperline; tInt32 intpos1; - tInt32 charcnt; @@ -120,13 +119,12 @@ void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 intpos1=getbufferidx(hBuf1,firstpos1); if (intpos1>=0) { - charcnt=0; for (i=0;iwin,i+1,0, "% 8X ",(tUInt32)(firstpos1+hBuf1->baseaddr)); - else mvwprintw(output->win,i+1,0,"% 16llX ",firstpos1+hBuf1->baseaddr); + if (addrwidth==8) mvwprintw(output->win,i+1,0, "%8X ",(tUInt32)(firstpos1+hBuf1->baseaddr)); + else mvwprintw(output->win,i+1,0,"%16llX ",firstpos1+hBuf1->baseaddr); mvwprintw(output->win,i+1,COLS-bytesperline-5," "); wmove(output->win,i+1,addrwidth+3); @@ -206,7 +204,6 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor tInt32 intpos1b; tInt32 intpos2; tInt32 intpos2b; - tInt32 charcnt; uicolors oldcolor; @@ -243,10 +240,10 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor mvwprintw(output->win,0,1,"[ / ]"); mvwprintw(output->win,LINES/2,1,"[ / ]"); setcolor(output,COLOR_TEXT); - mvwprintw(output->win,0,2,"%8X",(tUInt32)cursorpos1+hBuf1->baseaddr); - mvwprintw(output->win,0,11,"%8X",(tUInt32)hBuf1->bufsize+hBuf1->baseaddr); - mvwprintw(output->win,LINES/2,2,"%8X",(tUInt32)cursorpos2+hBuf2->baseaddr); - mvwprintw(output->win,LINES/2,11,"%8X",(tUInt32)hBuf2->bufsize+hBuf2->baseaddr); + mvwprintw(output->win,0,2,"%8llX",(tUInt32)cursorpos1+hBuf1->baseaddr); + mvwprintw(output->win,0,11,"%8llX",(tUInt32)hBuf1->bufsize+hBuf1->baseaddr); + mvwprintw(output->win,LINES/2,2,"%8llX",(tUInt32)cursorpos2+hBuf2->baseaddr); + mvwprintw(output->win,LINES/2,11,"%8llX",(tUInt32)hBuf2->bufsize+hBuf2->baseaddr); } setcolor(output,COLOR_HEADER); mvwprintw(output->win,0,COLS-2-strlen(hBuf1->filename),"%s",hBuf1->filename); @@ -267,15 +264,14 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor } if (intpos1>=0 || intpos2>=0) { - charcnt=0; intpos1b=intpos1; intpos2b=intpos2; for (i=0;i<(LINES+1)/2-2;i++) { setcolor(output,COLOR_HEXFIELD); - if (addrwidth==8) mvwprintw(output->win,i+1,0, "% 8X ",(tUInt32)(cursorpos1+hBuf1->baseaddr)); - else mvwprintw(output->win,i+1,0,"% 16llX ",cursorpos1+hBuf1->baseaddr); + if (addrwidth==8) mvwprintw(output->win,i+1,0, "%8X ",(tUInt32)(cursorpos1+hBuf1->baseaddr)); + else mvwprintw(output->win,i+1,0,"%16llX ",cursorpos1+hBuf1->baseaddr); mvwprintw(output->win,i+1,COLS-bytesperline-5," "); oldcolor=COLOR_HEXFIELD; @@ -346,8 +342,8 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor for (i=0;i<(LINES+1)/2-2;i++) { setcolor(output,COLOR_HEXFIELD); - if (addrwidth==8) mvwprintw(output->win,i+1+LINES/2,0, "% 8X ",(tUInt32)(cursorpos2+hBuf2->baseaddr)); - else mvwprintw(output->win,i+1+LINES/2,0,"% 16llX ",cursorpos2+hBuf2->baseaddr); + if (addrwidth==8) mvwprintw(output->win,i+1+LINES/2,0, "%8X ",(tUInt32)(cursorpos2+hBuf2->baseaddr)); + else mvwprintw(output->win,i+1+LINES/2,0,"%16llX ",cursorpos2+hBuf2->baseaddr); mvwprintw(output->win,i+1+LINES/2,COLS-bytesperline-5," "); oldcolor=COLOR_HEXFIELD; @@ -411,7 +407,7 @@ void printmainmenu(tOutput* output,tBool diffmode) { int i; int x; - unsigned char* menutextsnodiff[]={ + char* menutextsnodiff[]={ "Goto ", // F1 "Search", // F2 "Next ", // F3 @@ -423,7 +419,7 @@ void printmainmenu(tOutput* output,tBool diffmode) "Undo ", // F9 "Quit "}; // F10 - unsigned char* menutextsdiff[]={ + char* menutextsdiff[]={ " ", // F1 " ", // F2 "Next ", // F3 diff --git a/search.c b/search.c index 9adc1e7..22c7833 100644 --- a/search.c +++ b/search.c @@ -11,7 +11,7 @@ void clearsearch(tSearch* search) memset(search,0,sizeof(tSearch)); search->forwardnotbackward=1; } -tInt8 searchfor(tSearch* search,tBuffer* buf,tUInt64* cursorpos,tBool nextnotprev) +tInt8 searchfor(tSearch* search,tBuffer* buf,tInt64* cursorpos,tBool nextnotprev) { tInt64 actcursorpos=*cursorpos; tInt64 oldcursorpos=*cursorpos; @@ -77,10 +77,7 @@ tInt8 searchfor(tSearch* search,tBuffer* buf,tUInt64* cursorpos,tBool nextnotpre // state 2: read until the end of the line tUInt64 x=0; tBool havenum; - tInt64 firstsearchlogpos; - firstsearchlogpos=search->lastsearchlogpos; - setfilepos(frlog,search->lastsearchlogpos); havenum=0; while (!done && !havenum) diff --git a/search.h b/search.h index 1928596..414066c 100644 --- a/search.h +++ b/search.h @@ -5,6 +5,6 @@ #include "datatypes.h" void clearsearch(tSearch* search); -tInt8 searchfor(tSearch* search,tBuffer* buf,tUInt64* cursorpos,tBool nextnotprev); +tInt8 searchfor(tSearch* search,tBuffer* buf,tInt64* cursorpos,tBool nextnotprev); #endif diff --git a/ui.c b/ui.c index fd12a0b..7937450 100644 --- a/ui.c +++ b/ui.c @@ -10,7 +10,7 @@ #include "search.h" #include "correlation.h" -void searchmask(tOutput* output,tSearch* search,tBuffer* buf,tUInt64* cursorpos) +void searchmask(tOutput* output,tSearch* search,tBuffer* buf,tInt64* cursorpos) { tInt8 itemnums[10]; tMenu Menu1; diff --git a/ui.h b/ui.h index e1dc415..a63bc19 100644 --- a/ui.h +++ b/ui.h @@ -5,7 +5,7 @@ #include "search.h" #include "output.h" #include "correlation.h" -void searchmask(tOutput* output,tSearch* search,tBuffer* buf,tUInt64* cursorpos); +void searchmask(tOutput* output,tSearch* search,tBuffer* buf,tInt64* cursorpos); tInt8 savedialog(tOutput* output,tBuffer* buf); tInt8 correlationmask(tOutput* output,tCorrelation* correlation); #endif From 829af5fa425a8d9762bb297f37b5574db7419fde Mon Sep 17 00:00:00 2001 From: Timo Engel Date: Sat, 14 Mar 2026 09:34:37 +0100 Subject: [PATCH 3/4] new option to output fixed number of bytes per line --- main.c | 27 +++++++++++++++++++-------- output.c | 12 ++++++------ output.h | 6 +++--- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index a271723..8d068b0 100644 --- a/main.c +++ b/main.c @@ -54,6 +54,7 @@ void helpscreen(char* argv0,int exitval) fprintf(stderr," -g, -G show the license\n"); fprintf(stderr," -f, -F [configfile] read the config from [configfile]\n"); fprintf(stderr," -m, -M [markerfile] read the bookmarks from [markerfile]\n"); + fprintf(stderr," -b, -B [bytes] output [bytes] bytes per output line\n"); fprintf(stderr,"\n"); fprintf(stderr,"%s [Parameters] [Filename]: Edit a single file\n",argv0); fprintf(stderr," -ab, -AB [x] set the base address to [x] (binary)\n"); @@ -130,7 +131,7 @@ int parsecursorpos(tInt64* cursorpos1,tInt64* cursorpos2,char* lastopt,char* arg return RETOK; } -int parsecommandlineoptions(int argc,char** argv,tInt64* baseaddr1,tInt64* baseaddr2,tInt64* cursorpos1,tInt64* cursorpos2,tBool* diffmode,int* filename1,int* filename2,tBool* keyboardsetupreq,char* markerfilename,char* configfile,tSearch* search1,tBool* gosearch1,tSearch* search2,tBool* gosearch2,tCorrelation* correlation,tBool* gocorr) +int parsecommandlineoptions(int argc,char** argv,tInt64* baseaddr1,tInt64* baseaddr2,tInt64* cursorpos1,tInt64* cursorpos2,tBool* diffmode,int* filename1,int* filename2,tBool* keyboardsetupreq,char* markerfilename,char* configfile,tSearch* search1,tBool* gosearch1,tSearch* search2,tBool* gosearch2,tCorrelation* correlation,tBool* gocorr,int* dispWidth) { int filenamecnt=0; int i; @@ -341,6 +342,15 @@ int parsecommandlineoptions(int argc,char** argv,tInt64* baseaddr1,tInt64* basea case 'M': if (markerfilename) memcpy(markerfilename,argv[i],64); break; + case 'b': + case 'B': + *dispWidth = atoi(argv[i]); + if (*dispWidth < 1) + { + fprintf(stderr,"invalid bytes per output line\n"); + retval=RETNOK; + } + break; default: retval=RETNOK; break; @@ -374,6 +384,7 @@ int main(int argc,char** argv) tOutput* output=NULL; tInt64 baseaddr1=0; tInt64 cursorpos1; + int dispWidth=0; tInt64 firstpos1; tInt64 baseaddr2=0; tInt64 cursorpos2; @@ -416,7 +427,7 @@ int main(int argc,char** argv) clearsearch(&search1); clearsearch(&search2); clear_correlation(&correlation); - if (parsecommandlineoptions(argc,argv,&baseaddr1,&baseaddr2,&cursorpos1,&cursorpos2,&diffmode,&filename1,&filename2,&keyboardsetupreq,markerfilename,configfile,&search1,&gosearch1,&search2,&gosearch2,&correlation,&gocorr)!=RETOK) + if (parsecommandlineoptions(argc,argv,&baseaddr1,&baseaddr2,&cursorpos1,&cursorpos2,&diffmode,&filename1,&filename2,&keyboardsetupreq,markerfilename,configfile,&search1,&gosearch1,&search2,&gosearch2,&correlation,&gocorr,&dispWidth)!=RETOK) { if (output) { @@ -535,9 +546,9 @@ int main(int argc,char** argv) { printmainmenu(output,diffmode); if (diffmode) - printbufferdiff(output,buf1,buf2,cursorpos1,cursorpos2); + printbufferdiff(output,buf1,buf2,cursorpos1,cursorpos2,dispWidth); else - printbuffersingle(output,buf1,cursorpos1,firstpos1,windowfield); + printbuffersingle(output,buf1,cursorpos1,firstpos1,windowfield,dispWidth); ch=getkey((tKeyTab*)output->pKeyTab,1); #define MOVEMENTDEFINE(KEY,VIKEY,mvchar,mvline,mvpage) \ @@ -549,11 +560,11 @@ int main(int argc,char** argv) oldfirstpos2=firstpos2; \ oldcursorpos2=cursorpos2; \ \ - err=movepositions(&cursorpos1,&firstpos1,buf1->bufsize,mvchar,mvline,mvpage,diffmode); \ + err=movepositions(&cursorpos1,&firstpos1,buf1->bufsize,mvchar,mvline,mvpage,diffmode,dispWidth); \ \ if (diffmode) \ { \ - movepositions(&cursorpos2,&firstpos2,buf2->bufsize,mvchar,mvline,mvpage,diffmode); \ + movepositions(&cursorpos2,&firstpos2,buf2->bufsize,mvchar,mvline,mvpage,diffmode,dispWidth); \ err=((cursorpos1<0 && cursorpos2<0) || (cursorpos1>buf1->bufsize && cursorpos2>buf2->bufsize)); \ } \ if (err) \ @@ -718,7 +729,7 @@ int main(int argc,char** argv) buf1->changes[buf1->changesnum].pos=cursorpos1; buf1->changes[buf1->changesnum].after=buf1->nexthex; buf1->changesnum++; - movepositions(&cursorpos1,&firstpos1,buf1->bufsize,1,0,0,diffmode); + movepositions(&cursorpos1,&firstpos1,buf1->bufsize,1,0,0,diffmode,dispWidth); } buf1->nibble=!buf1->nibble; buf1->changepos=cursorpos1; @@ -729,7 +740,7 @@ int main(int argc,char** argv) buf1->changes[buf1->changesnum].pos=cursorpos1; buf1->changes[buf1->changesnum].after=ch; buf1->changesnum++; - movepositions(&cursorpos1,&firstpos1,buf1->bufsize,1,0,0,diffmode); + movepositions(&cursorpos1,&firstpos1,buf1->bufsize,1,0,0,diffmode,dispWidth); } } if (ch==KEYF10) diff --git a/output.c b/output.c index 327fd61..241bd36 100644 --- a/output.c +++ b/output.c @@ -79,7 +79,7 @@ void drawcenterframe(tOutput* output,tInt8 h,tInt8 w,char* header) { drawframe(output,LINES/2-h/2,COLS/2-w/2,h,w,header); } -void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 firstpos1,tUInt8 windowfield) +void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 firstpos1,tUInt8 windowfield,int dispWidth) { int i; int j; @@ -92,7 +92,7 @@ void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 addrwidth=((hBuf1->bufsize+hBuf1->baseaddr)>0xffffffffull)?16:8; - bytesperline=(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. + bytesperline=dispWidth?dispWidth:(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. setcolor(output,COLOR_HEADLINE); wmove(output->win,0,0); @@ -196,7 +196,7 @@ void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 } } } -void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursorpos1,tInt64 cursorpos2) +void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursorpos1,tInt64 cursorpos2,int dispWidth) { int i; int j; @@ -211,7 +211,7 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor addrwidth=((hBuf1->bufsize+hBuf1->baseaddr)>0xffffffffull || (hBuf2->bufsize+hBuf2->baseaddr)>0xffffffffull)?16:8; - bytesperline=(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. + bytesperline=dispWidth?dispWidth:(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. setcolor(output,COLOR_HEADLINE); wmove(output->win,0,0); @@ -452,7 +452,7 @@ void printmainmenu(tOutput* output,tBool diffmode) } } -tInt32 movepositions(tInt64* cursorpos,tInt64* firstpos,tInt64 maxbufsize,tInt32 chars,tInt32 lines,tInt32 pages,tBool diffmode) +tInt32 movepositions(tInt64* cursorpos,tInt64* firstpos,tInt64 maxbufsize,tInt32 chars,tInt32 lines,tInt32 pages,tBool diffmode,int dispWidth) { tInt32 bytesperline; tInt32 bytesperhalfpage; @@ -464,7 +464,7 @@ tInt32 movepositions(tInt64* cursorpos,tInt64* firstpos,tInt64 maxbufsize,tInt32 addrwidth=(maxbufsize>0xffffffffull)?16:8; - bytesperline=(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. + bytesperline=dispWidth?dispWidth:(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. bytesperhalfpage=bytesperline*(LINES/2-2); bytesperpage=bytesperline*(LINES-2); diff --git a/output.h b/output.h index cef29e9..52694c4 100644 --- a/output.h +++ b/output.h @@ -11,11 +11,11 @@ void initcolors(); void colorpair(tOutput* output,uicolors uicol,short fg,short bg,int attr); void pairsinit(tOutput* output); void setcolor(tOutput* output,uicolors col); -void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 firstpos1,tUInt8 windowfield); -void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursorpos1,tInt64 cursorpos2); +void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 firstpos1,tUInt8 windowfield,int dispWidth); +void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursorpos1,tInt64 cursorpos2,int dispWidth); void printmainmenu(tOutput* output,tBool diffmode); void drawframe(tOutput* output,tInt16 y,tInt16 x,tInt8 h,tInt8 w,char* header); void drawcenterframe(tOutput* output,tInt8 h,tInt8 w,char* header); -tInt32 movepositions(tInt64* cursorpos,tInt64* firstpos,tInt64 maxbufsize,tInt32 chars,tInt32 lines,tInt32 pages,tBool diffmode); +tInt32 movepositions(tInt64* cursorpos,tInt64* firstpos,tInt64 maxbufsize,tInt32 chars,tInt32 lines,tInt32 pages,tBool diffmode,int dispWidth); #endif From 56bc49e801f1da05ba8e812c2cf3f75e8f46931b Mon Sep 17 00:00:00 2001 From: Timo Engel Date: Sat, 21 Mar 2026 17:28:45 +0100 Subject: [PATCH 4/4] Add option to highlight regions by address or by byte value. Use -l, -L [highlightfile] on the command line to specify a highlight marker file. --- Makefile | 3 +- datatypes.h | 18 +++++- hlmark-elf.txt | 24 +++++++ hlmarkers.c | 114 +++++++++++++++++++++++++++++++++ hlmarkers.h | 41 ++++++++++++ main.c | 17 ++++- output.c | 167 ++++++++++++++++++++++++++----------------------- 7 files changed, 302 insertions(+), 82 deletions(-) create mode 100644 hlmark-elf.txt create mode 100644 hlmarkers.c create mode 100644 hlmarkers.h diff --git a/Makefile b/Makefile index 16e06c9..3890400 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ SRC:=buffers.c configfile.c correlation.c gpl.c hexcalc.c input.c \ - machine_type.c main.c markers.c menu.c output.c search.c ui.c + machine_type.c main.c markers.c menu.c output.c search.c ui.c \ + hlmarkers.c OBJ:=$(patsubst %.c,%.o,$(SRC)) DEP:=$(patsubst %.c,%.d,$(SRC)) CFLAGS:=-Wall -MMD $(shell pkgconf --cflags ncurses) diff --git a/datatypes.h b/datatypes.h index ed9aa6e..2414562 100644 --- a/datatypes.h +++ b/datatypes.h @@ -2,6 +2,7 @@ #define DATATYPES_H #include #include "machine_type.h" +#include "config.h" /* INPUT DATATYPES */ // this is for the special keys @@ -19,7 +20,8 @@ typedef struct _tKeyTab /* OUTPUT DATATYPES */ -typedef enum {COLOR_NONE,COLOR_BRACKETS,COLOR_INPUT,COLOR_CURSOR,COLOR_TEXT,COLOR_HEXFIELD,COLOR_DIFF,COLOR_HEADLINE,COLOR_HEADER,COLOR_MENUHOTKEY,COLOR_MENUNORMAL,COLOR_FRAME,COLOR_MENUACTIVE,COLOR_MENUHOTKEYACTIVE,COLOR_CURSORDIFF,UICOLORNUM} uicolors; +typedef enum {COLOR_NONE,COLOR_BRACKETS,COLOR_INPUT,COLOR_CURSOR,COLOR_TEXT,COLOR_HEXFIELD,COLOR_DIFF,COLOR_HEADLINE,COLOR_HEADER,COLOR_MENUHOTKEY,COLOR_MENUNORMAL,COLOR_FRAME,COLOR_MENUACTIVE,COLOR_MENUHOTKEYACTIVE,COLOR_CURSORDIFF,COLOR_HL_RED,COLOR_HL_REDD,COLOR_HL_GREEN,COLOR_HL_GREEND,COLOR_HL_BLUE,COLOR_HL_BLUED,COLOR_HL_CYAN,COLOR_HL_CYAND,COLOR_HL_YELLOW,COLOR_HL_YELLOWD,COLOR_HL_MAGENTA,COLOR_HL_MAGENTAD,COLOR_HL_WHITE,COLOR_HL_WHITED,COLOR_HL_BLACK,COLOR_HL_BLACKD,UICOLORNUM} uicolors; + typedef struct _tColors { short fg; @@ -43,6 +45,18 @@ typedef struct _tChange tUInt8 after; } tChange; +#define NUMHLMARKERS 20 +typedef enum {HLMARKER_POS, HLMARKER_VALUE} hlmarkertype; + +typedef struct _tHighlight +{ + tUInt64 numA; + tUInt64 numB; + hlmarkertype type; + uicolors color; + uicolors colord; +} tHighlight; + typedef struct _tBuffer { tBool valid; @@ -59,6 +73,8 @@ typedef struct _tBuffer tUInt8 nexthex; tUInt64 changepos; tInt64 baseaddr; + tHighlight markerhl[NUMHLMARKERS]; + tUInt32 markerhlnum; // number of marker } tBuffer; diff --git a/hlmark-elf.txt b/hlmark-elf.txt new file mode 100644 index 0000000..7ffe121 --- /dev/null +++ b/hlmark-elf.txt @@ -0,0 +1,24 @@ +# ELF header (64 bit) +# +# https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#ELF_header + +red @ 0x0000-0x0003 # e_ident[EI_MAG0] - e_ident[EI_MAG3] +green @ 0x0004 # e_ident[EI_CLASS] +blue @ 0x0005 # e_ident[EI_DATA] +cyan @ 0x0006 # e_ident[EI_VERSION] +yellow @ 0x0007 # e_ident[EI_OSABI] +magenta @ 0x0008 # e_ident[EI_ABIVERSION] +white @ 0x0009-0x000f # e_ident[EI_PAD] +black @ 0x0010-0x0011 # e_type +red @ 0x0012-0x0013 # e_machine +green @ 0x0014-0x0017 # e_version +blue @ 0x0018-0x001f # e_entry +cyan @ 0x0020-0x0027 # e_phoff +yellow @ 0x0028-0x002f # e_shoff +magenta @ 0x0030-0x0033 # e_flags +white @ 0x0034-0x0035 # e_ehsize +black @ 0x0036-0x0037 # e_phentsize +red @ 0x0038-0x0039 # e_phnum +green @ 0x003a-0x003b # e_shentsize +blue @ 0x003c-0x003d # e_shnum +cyan @ 0x003e-0x003f # e_shstrndx diff --git a/hlmarkers.c b/hlmarkers.c new file mode 100644 index 0000000..8edbc1a --- /dev/null +++ b/hlmarkers.c @@ -0,0 +1,114 @@ +#include +#include +#include +#include +#include +#include + +#include "datatypes.h" + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +const char* COLORS_STR[] = { + "black", "red", "green", "yellow", "blue","magenta", "cyan", "white" +}; + +const uicolors COLORS_UI[] = { + COLOR_HL_BLACK, + COLOR_HL_RED, + COLOR_HL_GREEN, + COLOR_HL_YELLOW, + COLOR_HL_BLUE, + COLOR_HL_MAGENTA, + COLOR_HL_CYAN, + COLOR_HL_WHITE}; + +const uicolors COLORS_UIDIFF[] = { + COLOR_HL_BLACKD, + COLOR_HL_REDD, + COLOR_HL_GREEND, + COLOR_HL_YELLOWD, + COLOR_HL_BLUED, + COLOR_HL_MAGENTAD, + COLOR_HL_CYAND, + COLOR_HL_WHITED}; + + +static int parseLine(tHighlight* marker, const char* line) +{ + for (int cIdx = 0; cIdx < ARRAY_SIZE(COLORS_STR); ++cIdx) + { + if (strncasecmp(line, COLORS_STR[cIdx], strlen(COLORS_STR[cIdx])) != 0) + { + continue; + } + const char* typeStr = line + strlen(COLORS_STR[cIdx]); + typeStr += strspn(typeStr, "\t "); ; + if (*typeStr == '@') + { + marker->type = HLMARKER_POS; + } + else if (*typeStr == ':') + { + marker->type = HLMARKER_VALUE; + } + else + { + return RETNOK; + } + const char* numAstr = typeStr + 1; + char* numBstr = NULL; + marker->numA = -1; + marker->numB = -1; + errno = 0; + marker->numA = strtoull(numAstr, &numBstr, 0); + marker->numB = marker->numA; + if (errno != 0 || numBstr == numAstr) + { + return RETNOK; + } + if (*typeStr == '@' && *numBstr == '-') + { + numBstr += 1; + char* endPtr = NULL; + marker->numB = strtoull(numBstr, &endPtr, 0); + if (errno != 0 || endPtr == numBstr) + { + return RETNOK; + } + } + // printf("hlmarkers: color=%-10s type=%c numA=%-8lld numB=%-8lld \n", + // COLORS_STR[cIdx], *typeStr, marker->numA, marker->numB); + marker->color = COLORS_UI[cIdx]; + marker->colord = COLORS_UIDIFF[cIdx]; + return RETOK; + } + return RETNOK; +} + +int parsehlmarkerfile(tHighlight* marker, uint32_t* num, const char* filename) +{ + FILE* f = fopen(filename, "r"); + char line[0xff]; + *num = 0; + while (!feof(f) && + fgets(line, sizeof(line), f) > 0 && + *num < NUMHLMARKERS) + { + const char* cfgLine = line + strspn(line, "\f\n\r\t\v "); + if (cfgLine[0] == '#' || !isalpha(cfgLine[0])) + { + continue; + } + if (parseLine(&marker[*num], cfgLine) != RETOK) + { + fprintf(stderr, "error reading hl marker file '%s'\n" + "invalid entry: %s", filename, line); + return RETNOK; + } + *num += 1; + } + fclose(f); + // getchar(); + return RETOK; +} diff --git a/hlmarkers.h b/hlmarkers.h new file mode 100644 index 0000000..763719c --- /dev/null +++ b/hlmarkers.h @@ -0,0 +1,41 @@ +#ifndef HLMARKERS_H +#define HLMARKERS_H + +/** + * Use -l, -L [highlightfile] on the command line to specify a highlight marker + * file. The syntax for highlight markers is: + * + * COLOR:VALUE + * COLOR@OFFSET_START[-OFFSET_END] + * + * COLOR + * One of the colors black, red, green, yellow, blue, magenta, cyan, white. + * :VALUE + * The byte value to highlight. + * @OFFSET_START[-OFFSET_END] + * The byte offset or offset range to highlight. + * + * Comments start with '#'. Whitespace are ignored. All strings are + * case-insensitive. Numerical values are parsed with strtoull(3) and can be + * decimal (no prefix), hexadecimal (prefix 0x) or octal (prefix 0). If multiple + * entries apply, only the last entry will be visible. + * + * Examples: + * + * magenta : 0x70 # byte value hexadecimal + * white : 32 # byte value decimal + * red:010 # byte value octal + * red @ 2 # offset decimal + * GREEN @ 8-11 # offset range decimal + * blue@0x120-0x12f # offset range hexadecimal + * red@010 # offset octal + * + */ + +#include "machine_type.h" +#include "output.h" +#include "datatypes.h" + +int parsehlmarkerfile(tHighlight* hlmarkers,uint32_t* num,char* filename); + +#endif diff --git a/main.c b/main.c index c92df11..6338ed9 100644 --- a/main.c +++ b/main.c @@ -17,6 +17,7 @@ #include "search.h" #include "gpl.h" #include "markers.h" +#include "hlmarkers.h" #include "correlation.h" void welcomescreen(char* argv0) @@ -55,6 +56,7 @@ void helpscreen(char* argv0,int exitval) fprintf(stderr," -f, -F [configfile] read the config from [configfile]\n"); fprintf(stderr," -m, -M [markerfile] read the bookmarks from [markerfile]\n"); fprintf(stderr," -b, -B [bytes] output [bytes] bytes per output line\n"); + fprintf(stderr," -l, -L [highlightfile] read the highlight markers from [highlightfile]\n"); fprintf(stderr,"\n"); fprintf(stderr,"%s [Parameters] [Filename]: Edit a single file\n",argv0); fprintf(stderr," -ab, -AB [x] set the base address to [x] (binary)\n"); @@ -131,7 +133,7 @@ int parsecursorpos(tInt64* cursorpos1,tInt64* cursorpos2,char* lastopt,char* arg return RETOK; } -int parsecommandlineoptions(int argc,char** argv,tInt64* baseaddr1,tInt64* baseaddr2,tInt64* cursorpos1,tInt64* cursorpos2,tBool* diffmode,int* filename1,int* filename2,tBool* keyboardsetupreq,char* markerfilename,char* configfile,tSearch* search1,tBool* gosearch1,tSearch* search2,tBool* gosearch2,tCorrelation* correlation,tBool* gocorr,int* dispWidth) +int parsecommandlineoptions(int argc,char** argv,tInt64* baseaddr1,tInt64* baseaddr2,tInt64* cursorpos1,tInt64* cursorpos2,tBool* diffmode,int* filename1,int* filename2,tBool* keyboardsetupreq,char* markerfilename,char* configfile,tSearch* search1,tBool* gosearch1,tSearch* search2,tBool* gosearch2,tCorrelation* correlation,tBool* gocorr,int* dispWidth,char* hlmarkerfilename) { int filenamecnt=0; int i; @@ -349,6 +351,10 @@ int parsecommandlineoptions(int argc,char** argv,tInt64* baseaddr1,tInt64* basea retval=RETNOK; } break; + case 'l': + case 'L': + if (hlmarkerfilename) memcpy(hlmarkerfilename,argv[i],64); + break; default: retval=RETNOK; break; @@ -398,6 +404,7 @@ int main(int argc,char** argv) tBool gosearch2=0; tCorrelation correlation; char markerfilename[64]; + char hlmarkerfilename[64]; tUInt8 windowfield=0; // 0=hex field buffer 1, 1=ascii field buffer 1, 2=hex field buffer 2, 3=ascii field buffer 2 tBool diffmode=0; @@ -413,6 +420,7 @@ int main(int argc,char** argv) memset(configfile,0,512); memset(markerfilename,0,64); + memset(hlmarkerfilename,0,64); markers=initmarkers(); output=malloc(sizeof(tOutput)); memset(output,0,sizeof(tOutput)); @@ -425,7 +433,7 @@ int main(int argc,char** argv) clearsearch(&search1); clearsearch(&search2); clear_correlation(&correlation); - if (parsecommandlineoptions(argc,argv,&baseaddr1,&baseaddr2,&cursorpos1,&cursorpos2,&diffmode,&filename1,&filename2,&keyboardsetupreq,markerfilename,configfile,&search1,&gosearch1,&search2,&gosearch2,&correlation,&gocorr,&dispWidth)!=RETOK) + if (parsecommandlineoptions(argc,argv,&baseaddr1,&baseaddr2,&cursorpos1,&cursorpos2,&diffmode,&filename1,&filename2,&keyboardsetupreq,markerfilename,configfile,&search1,&gosearch1,&search2,&gosearch2,&correlation,&gocorr,&dispWidth,hlmarkerfilename)!=RETOK) { if (output) { @@ -522,6 +530,11 @@ int main(int argc,char** argv) fprintf(stderr,"error opening second inputfile %s\n",argv[filename2]); exit(1); } + if (hlmarkerfilename[0] && + parsehlmarkerfile(buf1->markerhl,&buf1->markerhlnum,hlmarkerfilename)!=RETOK) + { + exit(1); + } if (gosearch1) searchfor(&search1,buf1,&cursorpos1,1); if (gosearch2 && diffmode) searchfor(&search2,buf2,&cursorpos2,1); if (gocorr && diffmode) diff --git a/output.c b/output.c index e9b8f2e..ace5e97 100644 --- a/output.c +++ b/output.c @@ -23,6 +23,22 @@ void initcolors(tOutput* output) output->colors[COLOR_HEADLINE].fg =COLOR_BLUE; output->colors[COLOR_HEADLINE].bg =COLOR_BLACK; output->colors[COLOR_HEADLINE].attrs =0; // output->colors[COLOR_INFO].fg =COLOR_WHITE; output->colors[COLOR_INFO].bg =COLOR_BLACK; output->colors[COLOR_INFO].attrs =A_BOLD; output->colors[COLOR_HEADER].fg =COLOR_BLACK; output->colors[COLOR_HEADER].bg =COLOR_CYAN; output->colors[COLOR_HEADER].attrs =0; + output->colors[COLOR_HL_RED].fg =COLOR_BLACK; output->colors[COLOR_HL_RED].bg =COLOR_RED; output->colors[COLOR_HL_RED].attrs =0; + output->colors[COLOR_HL_REDD].fg =COLOR_YELLOW; output->colors[COLOR_HL_REDD].bg =COLOR_RED; output->colors[COLOR_HL_REDD].attrs =A_BOLD; + output->colors[COLOR_HL_GREEN].fg =COLOR_BLACK; output->colors[COLOR_HL_GREEN].bg =COLOR_GREEN; output->colors[COLOR_HL_GREEN].attrs =0; + output->colors[COLOR_HL_GREEND].fg =COLOR_YELLOW; output->colors[COLOR_HL_GREEND].bg =COLOR_GREEN; output->colors[COLOR_HL_GREEND].attrs =A_BOLD; + output->colors[COLOR_HL_BLUE].fg =COLOR_WHITE; output->colors[COLOR_HL_BLUE].bg =COLOR_BLUE; output->colors[COLOR_HL_BLUE].attrs =0; + output->colors[COLOR_HL_BLUED].fg =COLOR_YELLOW; output->colors[COLOR_HL_BLUED].bg =COLOR_BLUE; output->colors[COLOR_HL_BLUED].attrs =A_BOLD; + output->colors[COLOR_HL_CYAN].fg =COLOR_BLACK; output->colors[COLOR_HL_CYAN].bg =COLOR_CYAN; output->colors[COLOR_HL_CYAN].attrs =0; + output->colors[COLOR_HL_CYAND].fg =COLOR_YELLOW; output->colors[COLOR_HL_CYAND].bg =COLOR_CYAN; output->colors[COLOR_HL_CYAND].attrs =A_BOLD; + output->colors[COLOR_HL_YELLOW].fg =COLOR_BLACK; output->colors[COLOR_HL_YELLOW].bg =COLOR_YELLOW; output->colors[COLOR_HL_YELLOW].attrs =0; + output->colors[COLOR_HL_YELLOWD].fg =COLOR_MAGENTA; output->colors[COLOR_HL_YELLOWD].bg =COLOR_YELLOW; output->colors[COLOR_HL_YELLOWD].attrs =A_BOLD; + output->colors[COLOR_HL_MAGENTA].fg =COLOR_BLACK; output->colors[COLOR_HL_MAGENTA].bg =COLOR_MAGENTA; output->colors[COLOR_HL_MAGENTA].attrs =0; + output->colors[COLOR_HL_MAGENTAD].fg =COLOR_YELLOW; output->colors[COLOR_HL_MAGENTAD].bg =COLOR_MAGENTA; output->colors[COLOR_HL_MAGENTAD].attrs =A_BOLD; + output->colors[COLOR_HL_WHITE].fg =COLOR_BLACK; output->colors[COLOR_HL_WHITE].bg =COLOR_WHITE; output->colors[COLOR_HL_WHITE].attrs =0; + output->colors[COLOR_HL_WHITED].fg =COLOR_MAGENTA; output->colors[COLOR_HL_WHITED].bg =COLOR_WHITE; output->colors[COLOR_HL_WHITED].attrs =A_BOLD; + output->colors[COLOR_HL_BLACK].fg =COLOR_WHITE; output->colors[COLOR_HL_BLACK].bg =COLOR_BLACK; output->colors[COLOR_HL_BLACK].attrs =0; + output->colors[COLOR_HL_BLACKD].fg =COLOR_YELLOW; output->colors[COLOR_HL_BLACKD].bg =COLOR_BLACK; output->colors[COLOR_HL_BLACKD].attrs =A_BOLD; } void colorpair(tOutput* output,uicolors uicol,short fg,short bg,int attr) { @@ -79,11 +95,62 @@ void drawcenterframe(tOutput* output,tInt8 h,tInt8 w,char* header) { drawframe(output,LINES/2-h/2,COLS/2-w/2,h,w,header); } + +uicolors findcolor(unsigned char* c1, unsigned char* c2, bool diffmode, + const tBuffer* hBuf, bool hexwindow, tUInt8 windowfield, + tInt64 cursorpos, tUInt64 pos) +{ + bool isdiff = false; + int k; + uicolors color; + color = COLOR_HEXFIELD; + if (diffmode) + { + if (*c1 != *c2) + { + color = COLOR_DIFF; + isdiff = true; + } + } + else + { + for (k = 0; k < hBuf->changesnum; k++) + { + if (hBuf->changes[k].pos == pos) + { + isdiff = true; + *c1 = hBuf->changes[k].after; + color = COLOR_DIFF; + } + } + } + for (k = 0; k < hBuf->markerhlnum; k++) + { + if (hBuf->markerhl[k].type == HLMARKER_POS && + hBuf->markerhl[k].numA <= pos && hBuf->markerhl[k].numB >= pos) + { + if (isdiff) color = hBuf->markerhl[k].colord; + else color = hBuf->markerhl[k].color; + } + if (hBuf->markerhl[k].type == HLMARKER_VALUE && + hBuf->markerhl[k].numA == *c1) + { + if (isdiff) color = hBuf->markerhl[k].colord; + else color = hBuf->markerhl[k].color; + } + } + if (diffmode == false && cursorpos == pos) + { + if (hexwindow == true && windowfield == 0) color = COLOR_INPUT; + if (hexwindow == false && windowfield == 1) color = COLOR_INPUT; + } + return color; +} + void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 firstpos1,tUInt8 windowfield,int dispWidth) { int i; int j; - int k; int addrwidth; int bytesperline; tInt32 intpos1; @@ -119,37 +186,24 @@ void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 intpos1=getbufferidx(hBuf1,firstpos1); if (intpos1>=0) { - for (i=0;iwin,i+1,0, "%8X ",(tUInt32)(firstpos1+hBuf1->baseaddr)); else mvwprintw(output->win,i+1,0,"%16llX ",firstpos1+hBuf1->baseaddr); mvwprintw(output->win,i+1,COLS-bytesperline-5," "); wmove(output->win,i+1,addrwidth+3); - colhex=1; for (j=0;jfilesize) c=hBuf1->data[intpos1+j]; else c=-1; if (!(j&7)) wprintw(output->win," "); wprintw(output->win," "); - for (k=0;kchangesnum;k++) - { - if (hBuf1->changes[k].pos==(firstpos1+j)) - { - setcolor(output,COLOR_DIFF); - c=hBuf1->changes[k].after; - colhex=0; - } - } - if (cursorpos1==(firstpos1+j) && windowfield==0) - { - setcolor(output,COLOR_INPUT); - colhex=0; - } + setcolor(output, findcolor(&c, &c, false, hBuf1, true, windowfield, + cursorpos1, firstpos1+j)); // TODO: setcolor(hBuf1->data[intpos1]!=buf2->data[intpos2]?COLOR_DIFF:COLOR_HEXFIELD); if (c>=0) { @@ -162,8 +216,6 @@ void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 else wprintw(output->win," "); - if (!colhex) setcolor(output,COLOR_HEXFIELD); - colhex=1; // mvwprintw(output->win,i+1,addrwidth+5+j*3+j/8," "); } for (j=0;jfilesize) c=hBuf1->data[intpos1]; else c=' '; - for (k=0;kchangesnum;k++) - { - if (hBuf1->changes[k].pos==(firstpos1)) - { - setcolor(output,COLOR_DIFF); - c=hBuf1->changes[k].after; - } - } - - if (cursorpos1 == firstpos1 && (windowfield == 0 || windowfield == 1)) { - setcolor(output, COLOR_INPUT); - } - + setcolor(output, findcolor(&c, &c, false, hBuf1, false, windowfield, + cursorpos1, firstpos1)); // TODO: setcolor(buf1->data[intpos1]!=buf2->data[intpos2]?COLOR_DIFF:COLOR_HEXFIELD); mvwprintw(output->win,i+1,COLS-bytesperline+j,"%c",(c>=32 && c<127)?c:'.'); intpos1++; firstpos1++; - setcolor(output, COLOR_HEXFIELD); } } } @@ -204,7 +244,6 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor tInt32 intpos1b; tInt32 intpos2; tInt32 intpos2b; - uicolors oldcolor; addrwidth=((hBuf1->bufsize+hBuf1->baseaddr)>0xffffffffull || (hBuf2->bufsize+hBuf2->baseaddr)>0xffffffffull)?16:8; @@ -267,30 +306,22 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor intpos1b=intpos1; intpos2b=intpos2; - for (i=0;i<(LINES+1)/2-2;i++) + for (i=0;i<(LINES+1)/2-2;i++) // diff 1 { setcolor(output,COLOR_HEXFIELD); if (addrwidth==8) mvwprintw(output->win,i+1,0, "%8X ",(tUInt32)(cursorpos1+hBuf1->baseaddr)); else mvwprintw(output->win,i+1,0,"%16llX ",cursorpos1+hBuf1->baseaddr); mvwprintw(output->win,i+1,COLS-bytesperline-5," "); - oldcolor=COLOR_HEXFIELD; wmove(output->win,i+1,addrwidth+3); for (j=0;j=0 && (intpos1+j)filesize) c1=hBuf1->data[intpos1+j]; else c1=-1; if ((intpos2+j)>=0 && (intpos2+j)filesize) c2=hBuf2->data[intpos2+j]; else c2=-1; - if (c1!=c2 && oldcolor==COLOR_HEXFIELD) - { - setcolor(output,COLOR_DIFF); - oldcolor=COLOR_DIFF; - } else if (c1==c2) { - setcolor(output,COLOR_HEXFIELD); - oldcolor=COLOR_HEXFIELD; - } wprintw(output->win," "); if (j!=(bytesperline-1)) { @@ -298,6 +329,8 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor } if (c1>=0) { + setcolor(output, findcolor(&c1, &c2, true, hBuf1, true, false, + cursorpos1, intpos1+j)); wprintw(output->win,"%02x",(c1&0xff)); } else @@ -314,23 +347,14 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor if (intpos2>=0 && intpos2filesize) c2=hBuf2->data[intpos2]; else c2=' '; - - if (c1!=c2 && oldcolor==COLOR_HEXFIELD) - { - setcolor(output,COLOR_DIFF); - oldcolor=COLOR_DIFF; - } else if (c1==c2) { - setcolor(output,COLOR_HEXFIELD); - oldcolor=COLOR_HEXFIELD; - } + setcolor(output, findcolor(&c1, &c2, true, hBuf1, false, false, + cursorpos1, intpos1)); wprintw(output->win,"%c",(c1>=32 && c1<127)?c1:'.'); intpos1++; cursorpos1++; intpos2++; } } - oldcolor=COLOR_HEXFIELD; - setcolor(output,COLOR_HEXFIELD); if (!(LINES&1)) { wmove(output->win,LINES/2-1,0); @@ -339,30 +363,22 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor intpos1=intpos1b; intpos2=intpos2b; - for (i=0;i<(LINES+1)/2-2;i++) + for (i=0;i<(LINES+1)/2-2;i++) // diff 2 { setcolor(output,COLOR_HEXFIELD); if (addrwidth==8) mvwprintw(output->win,i+1+LINES/2,0, "%8X ",(tUInt32)(cursorpos2+hBuf2->baseaddr)); else mvwprintw(output->win,i+1+LINES/2,0,"%16llX ",cursorpos2+hBuf2->baseaddr); mvwprintw(output->win,i+1+LINES/2,COLS-bytesperline-5," "); - oldcolor=COLOR_HEXFIELD; wmove(output->win,i+1+LINES/2,addrwidth+3); for (j=0;j=0 && (intpos1+j)filesize) c1=hBuf1->data[intpos1+j]; else c1=-1; if ((intpos2+j)>=0 && (intpos2+j)filesize) c2=hBuf2->data[intpos2+j]; else c2=-1; - if (c1!=c2 && oldcolor==COLOR_HEXFIELD) - { - setcolor(output,COLOR_DIFF); - oldcolor=COLOR_DIFF; - } else if (c1==c2) { - setcolor(output,COLOR_HEXFIELD); - oldcolor=COLOR_HEXFIELD; - } wprintw(output->win," "); if (j!=(bytesperline-1)) { @@ -370,6 +386,8 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor } if (c2>=0) { + setcolor(output, findcolor(&c1, &c2, true, hBuf1, true, false, + cursorpos1, intpos1+j)); wprintw(output->win,"%02x",(c2&0xff)); } else @@ -386,15 +404,8 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor if (intpos2>=0 && intpos2filesize) c2=hBuf2->data[intpos2]; else c2=' '; - - if (c1!=c2 && oldcolor==COLOR_HEXFIELD) - { - setcolor(output,COLOR_DIFF); - oldcolor=COLOR_DIFF; - } else if (c1==c2) { - setcolor(output,COLOR_HEXFIELD); - oldcolor=COLOR_HEXFIELD; - } + setcolor(output, findcolor(&c1, &c2, true, hBuf1, false, false, + cursorpos1, intpos1)); wprintw(output->win,"%c",(c2>=32 && c2<127)?c2:'.'); intpos1++; intpos2++;