Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 20 additions & 43 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
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 \
hlmarkers.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)
2 changes: 1 addition & 1 deletion configfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions correlation.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;


Expand Down Expand Up @@ -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));

Expand Down
20 changes: 18 additions & 2 deletions datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DATATYPES_H
#include <ncurses.h>
#include "machine_type.h"
#include "config.h"

/* INPUT DATATYPES */
// this is for the special keys
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -59,6 +73,8 @@ typedef struct _tBuffer
tUInt8 nexthex;
tUInt64 changepos;
tInt64 baseaddr;
tHighlight markerhl[NUMHLMARKERS];
tUInt32 markerhlnum; // number of marker
} tBuffer;


Expand All @@ -68,7 +84,7 @@ typedef struct _tCorrelation
{
tBool correlated;
corr_algorithms algorithm;
tInt64 start_mindiff;
tUInt64 start_mindiff;
tInt64 mindiff;
tInt64 mindiffpos;
tInt64 bestmatch;
Expand Down
4 changes: 2 additions & 2 deletions hexcalc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions hlmark-elf.txt
Original file line number Diff line number Diff line change
@@ -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
114 changes: 114 additions & 0 deletions hlmarkers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>

#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;
}
41 changes: 41 additions & 0 deletions hlmarkers.h
Original file line number Diff line number Diff line change
@@ -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
Loading