#include "HexFile.h" #include "BinaryFile.h" #include "FileComparator.h" #include "HexView.h" #include #include #include #include int main(int argc, char* argv[]) { if (argc != 3) { std::cout << "Usage: HexCompare " << std::endl; std::cout << "Supported formats: .hex, .s19, .s28, .s37, .srec, .bin" << std::endl; return 1; } //show the abslute path of the execute file std::cout << "Current path is " << argv[0] << std::endl; //获取命令行的当前目录 char buffer[MAX_PATH]; GetModuleFileName(NULL, buffer, MAX_PATH); std::cout << "Current path is " << buffer << std::endl; std::string file1 = argv[1]; std::string file2 = argv[2]; // Load files HexFile hexLoader; BinaryFile binLoader; std::vector data1, data2; // Try to load as hex file first, then as binary if (!hexLoader.load(file1)) { if (!binLoader.load(file1)) { std::cerr << "Failed to load file: " << file1 << std::endl; return 1; } data1 = binLoader.getData(); } else { data1 = hexLoader.getData(); } if (!hexLoader.load(file2)) { if (!binLoader.load(file2)) { std::cerr << "Failed to load file: " << file2 << std::endl; return 1; } data2 = binLoader.getData(); } else { data2 = hexLoader.getData(); } std::cout << "File 1 size: " << data1.size() << " bytes" << std::endl; std::cout << "File 2 size: " << data2.size() << " bytes" << std::endl; // Compare files FileComparator comparator; auto diffs = comparator.compare(data1, data2); std::cout << "Differences found: " << diffs.size() << std::endl; if (!diffs.empty()) { std::cout << "\nFirst 10 differences:" << std::endl; for (size_t i = 0; i < std::min(diffs.size(), size_t(10)); i++) { const auto& diff = diffs[i]; std::cout << "Offset: 0x" << std::hex << diff.offset << " File1: 0x" << std::hex << std::setw(2) << std::setfill('0') << static_cast(diff.byte1) << " File2: 0x" << std::hex << std::setw(2) << std::setfill('0') << static_cast(diff.byte2) << std::endl; } } // Display hex view with differences highlighted HexView hexView; // Set up highlight callback for differences hexView.setHighlightCallback([&diffs](size_t offset) { for (const auto& diff : diffs) { if (diff.offset == offset) { return true; } } return false; }); std::cout << "\nHex View Comparison (differences in red):" << std::endl; hexView.displayCompare(data1, data2, 0, 20); return 0; }