Created
December 10, 2017 10:49
-
-
Save hikalium/ea228e12a9e295d26fdb5acb8edf8539 to your computer and use it in GitHub Desktop.
seccon 2017 online CTF writeup (Remote debugging of a micro computer)
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
var fs = require('fs'); | |
var regNames = { | |
0: "PC", | |
1: "SP", | |
}; | |
var prevRegs = [ | |
0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, | |
]; | |
fs.readFile(process.argv[2], 'utf8', function (err, text) { | |
var splitted = text.split("\n").join("").split("+"); | |
var filtered = splitted | |
.filter((s) => {return !s.startsWith("$g");}) | |
.filter((s) => {return !s.startsWith("$T");}) | |
.filter((s) => {return !s.startsWith("$s");}) | |
.filter((s) => {return !s.startsWith("$OK");}) | |
.filter((s) => {return s.length;}); | |
for(var s of filtered){ | |
var currentRegs = []; | |
var bytes = s | |
.substr(1) | |
.match(/.{1,2}/g) | |
.slice(0, 64) | |
.map((e) => {return parseInt(e, 16);}); | |
for(var i = 0; i < 16; i++){ | |
var val = | |
bytes[i * 4] + | |
(bytes[i * 4 + 1] << 8) + | |
(bytes[i * 4 + 2] << 16) + | |
(bytes[i * 4 + 3] << 24) ; | |
var name = "R" + i; | |
if(regNames[i]) name = regNames[i]; | |
currentRegs.push(val); | |
if(i == 0){ | |
console.log(name + ": 0x" + val.toString(16)) | |
} else if(prevRegs[i] != val){ | |
console.log("\t" + name + | |
": 0x" + prevRegs[i].toString(16) + | |
" -> 0x" + val.toString(16)); | |
} | |
} | |
prevRegs = currentRegs; | |
console.log("----"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment