Created
July 5, 2019 02:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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