Created
July 5, 2019 02:32
-
-
Save kion-dgl/779c6bff06edca42105db49ae79c1a06 to your computer and use it in GitHub Desktop.
A short script that looks through the high work memory for sega saturn to look for possible xp data structs
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 fp = fs.readFileSync("hwram.bin"); | |
const ptr_keys = [ | |
"vlist_offset", | |
"plist_offset", | |
"attr_offset", | |
"vntbl" | |
]; | |
let i = 0; | |
do { | |
let struct = { | |
offset : i, | |
vlist_offset : fp.readUInt32BE(i + 0), | |
vlist_count : fp.readUInt32BE(i + 4), | |
plist_offset : fp.readUInt32BE(i + 8), | |
plist_count : fp.readUInt32BE(i + 12), | |
attr_offset : fp.readUInt32BE(i + 16), | |
vntbl : fp.readUInt32BE(i + 20) | |
}; | |
let isStruct = true; | |
ptr_keys.forEach(function(key) { | |
if((struct[key] % 4) !== 0) { | |
isStruct = false; | |
} | |
if((struct[key] & 0x06000000) !== 0x06000000) { | |
isStruct = false; | |
} | |
}); | |
for(let key in struct) { | |
if(struct[key] === 0) { | |
isStruct = false; | |
} | |
} | |
if(struct.vlist_count > 0xffff) { | |
isStruct = false; | |
} | |
if(struct.plist_count > 0xffff) { | |
isStruct = false; | |
} | |
if(!isStruct) { | |
i += 4; | |
continue; | |
} | |
formatHex(struct); | |
console.log(struct); | |
i += 0x18; | |
} while(i < fp.length - 0x18); | |
function formatHex(obj) { | |
for(let key in obj) { | |
let num = obj[key].toString(16); | |
while(num.length < 6) { | |
num = "0" + num; | |
} | |
obj[key] = "0x" + num; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment