Add Visual Studio "map" file parser script ##r2js

This commit is contained in:
pancake 2024-06-13 18:17:27 +02:00
parent 8b3314ac79
commit 0da877ec63

29
scripts/vsmap.r2.js Normal file
View File

@ -0,0 +1,29 @@
/* parser for the msvc map files */
const mapFileName = "Sqlite3Console.map";
function filterFlag(symName) {
return "sym." + symName.replace(/[^a-zA-Z0-9]/g, '_');
}
function loadFlagsFromVsMap(fileName) {
const script = [];
const lines = r2.cmd("cat " + fileName).split("\n");
let publics = false;
for (const line of lines) {
if (!publics) {
if (line.indexOf("Publics") !== -1) {
publics = true;
}
continue;
}
const [paddr, symName, symAddr, objName] = line.trim().split(/\s+/);
if (symName && symAddr) {
const flagName = filterFlag(symName);
script.push("'f " + flagName + " = 0x" + symAddr.replace(/^0+/g, ''));
}
}
return script;
}
loadFlagsFromVsMap(mapFileName).map(r2.cmd);