Skip to content

Commit f77bcf8

Browse files
committed
Added limit to highlighted different bytes
1 parent 78f01f5 commit f77bcf8

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/fhex.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ void Fhex::compare(QString filename) {
453453
unsigned long changes = res.size();
454454
unsigned long start_offset = 0;
455455
unsigned long offset = 0;
456+
int limit = MAX_DIFF_BYTES; //Show maximum 3000 different bytes
456457
QByteArray diff_bytes;
457458
for (pair<unsigned long, uint8_t> p : res) {
458459
if (offset == 0) {
@@ -461,16 +462,20 @@ void Fhex::compare(QString filename) {
461462
listOffsets->addItem("0x" + QString::number(start_offset, 16));
462463
}
463464
if (p.first - offset > 0) {
464-
addFloatingLabel(start_offset, static_cast<int>(diff_bytes.size()), "Compared file:\r\n" + diff_bytes.toHex(' ') + "\r\n-----------\r\n" + diff_bytes, DIFF_STYLE);
465+
if (limit > 0)
466+
addFloatingLabel(start_offset, static_cast<int>(diff_bytes.size()), "Compared file:\r\n" + diff_bytes.toHex(' ') + "\r\n-----------\r\n" + diff_bytes, DIFF_STYLE);
465467
diff_bytes.clear();
466468
offset = 0;
467469
} else {
468470
offset++;
469471
}
470472
diff_bytes.push_back(static_cast<char>(p.second));
473+
if (limit > 0)
474+
limit--;
471475
}
472476
if (diff_bytes.size() > 0) {
473-
addFloatingLabel(start_offset, static_cast<int>(diff_bytes.size()), "After:\r\n" + diff_bytes.toHex(' ') + "\r\n-----------\r\n" + diff_bytes, DIFF_STYLE);
477+
if (limit > 0)
478+
addFloatingLabel(start_offset, static_cast<int>(diff_bytes.size()), "After:\r\n" + diff_bytes.toHex(' ') + "\r\n-----------\r\n" + diff_bytes, DIFF_STYLE);
474479
diff_bytes.clear();
475480
}
476481

@@ -480,6 +485,17 @@ void Fhex::compare(QString filename) {
480485
this->statusBar.setText("Found " + QString::number(changes) + " different bytes");
481486
listOffsets->setVisible(true);
482487
}
488+
489+
if (limit == 0) {
490+
QMessageBox msgBox;
491+
msgBox.setText("The output displays only the first " + QString::number(MAX_DIFF_BYTES) + " different bytes for performance reasons.");
492+
msgBox.setStandardButtons(QMessageBox::Ok);
493+
msgBox.setDefaultButton(QMessageBox::Ok);
494+
msgBox.setIcon(QMessageBox::Icon::Warning);
495+
msgBox.setWindowTitle(this->windowTitle());
496+
msgBox.setWindowIcon(this->windowIcon());
497+
msgBox.exec();
498+
}
483499
}
484500

485501
void Fhex::on_menu_file_save_click() {

src/fhex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "qhexedit.h"
5151
#include "core/hexeditor.h"
5252

53+
#define MAX_DIFF_BYTES 3000
5354
#define DEFAULT_UNPRINTABLE_CHAR "."
5455
#define CHUNK_SIZE 1024
5556
#define CHART_DENSITY 1000 //A lower value implies a greater density

0 commit comments

Comments
 (0)