Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend size of address when file is larger than 4GB #72

Merged
merged 2 commits into from
Jul 31, 2024
Merged
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
14 changes: 11 additions & 3 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int computeLineSize(void) { return computeCursorXPos(lineLength - 1, 0) + 1; }
int computeCursorXCurrentPos(void) { return computeCursorXPos(cursor, hexOrAscii); }
int computeCursorXPos(int cursor, int hexOrAscii)
{
int r = 11;
int r = nAddrDigits + 3;
int x = cursor % lineLength;
int h = (hexOrAscii ? x : lineLength - 1);

Expand Down Expand Up @@ -162,6 +162,13 @@ void exitCurses(void)
endwin();
}

static void printaddr(uint64_t addr)
{
char templ[7]; // maximum string is "%016lX", which is 6 chars + 1 null byte
sprintf(templ,"%%0%dlX", nAddrDigits);
PRINTW((templ, addr));
}

void display(void)
{
long long fsize;
Expand All @@ -176,7 +183,7 @@ void display(void)
move(i / lineLength, 0);
for (j = 0; j < colsUsed; j++) printw(" "); /* cleanup the line */
move(i / lineLength, 0);
PRINTW(("%08lX", (int) (base + i)));
printaddr(base+i);
}

attrset(NORMAL);
Expand All @@ -201,7 +208,8 @@ void displayLine(int offset, int max)
#ifdef HAVE_COLORS
mark_color = COLOR_PAIR(4) | A_BOLD;
#endif
PRINTW(("%08lX ", (int) (base + offset)));
printaddr(base + offset);
PRINTW((" "));
for (i = offset; i < offset + lineLength; i++) {
if (i > offset) MAXATTRPRINTW(bufferAttr[i] & MARKED, (((i - offset) % blocSize) ? " " : " "));
if (i < max) {
Expand Down
27 changes: 27 additions & 0 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
#include "hexedit.h"


// Compute number of hex-digits needed to display an address.
// We only increase this by full bytes (2 digits).
// Because the input is uint64_t, the maximum result is 16 (64bit = 16*4bit).
int compute_nDigits(uint64_t maxAddr)
{
int digits = 0;
while (maxAddr) {
digits+=2;
maxAddr >>= 8;
}

if (digits==0) {
return 2;
}

return digits;
}


void openFile(void)
{
struct stat st;
Expand Down Expand Up @@ -53,6 +73,13 @@ void openFile(void)
fileSize = 0;
}
biggestLoc = fileSize;

nAddrDigits = compute_nDigits(biggestLoc);

// use at least 8 digits (4 byte addresses)
if (nAddrDigits < 8) {
nAddrDigits = 8;
}
}

void readFile(void)
Expand Down
1 change: 1 addition & 0 deletions hexedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ INT base, oldbase;
int normalSpaces, cursor, cursorOffset, hexOrAscii;
int cursor, blocSize, lineLength, colsUsed, page;
int fd, nbBytes, oldcursor, oldattr, oldcursorOffset;
int nAddrDigits;
int sizeCopyBuffer, *bufferAttr;
char *progName, *fileName, *baseName;
unsigned char *buffer, *copyBuffer;
Expand Down
1 change: 1 addition & 0 deletions hexedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ extern INT base, oldbase;
extern int normalSpaces, cursor, cursorOffset, hexOrAscii;
extern int cursor, blocSize, lineLength, colsUsed, page;
extern int isReadOnly, fd, nbBytes, oldcursor, oldattr, oldcursorOffset;
extern int nAddrDigits;
extern int sizeCopyBuffer, *bufferAttr;
extern char *progName, *fileName, *baseName;
extern unsigned char *buffer, *copyBuffer;
Expand Down
Loading