Skip to content

Instantly share code, notes, and snippets.

@kion-dgl
Created July 5, 2019 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kion-dgl/dd3694cbad00d818391db055c03215df to your computer and use it in GitHub Desktop.
Save kion-dgl/dd3694cbad00d818391db055c03215df to your computer and use it in GitHub Desktop.
Using nodejs to compare two files, and logging the differences with more than 100 consequtive bytes
"use strict";
const fs = require("fs");
const src = fs.readFileSync("hwram.bin");
const dst = fs.readFileSync("hwram_sho.bin");
let key;
let chain = 0;
let changes = {};
for(let i = 0; i < src.length; i++) {
let a = src[i];
let b = dst[i];
if(a === b) {
chain = 0;
continue;
}
if(chain === 0) {
let num = i.toString(16);
while(num.length < 6) {
num = "0" + num;
}
key = "0x" + num;
}
changes[key] = changes[key] || 0;
changes[key]++;
chain++;
}
for(let key in changes) {
if(changes[key] > 100) {
continue;
}
delete changes[key];
}
console.log(changes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment