Instantly share code, notes, and snippets.

Embed
What would you like to do?
var decode_msi_name = (function() {
/*
NOTES:
- most entries start with 0x4840, which seems to be a marker
- corpus char code range 0x3864-0x4840
- range 0x3800-0x4840 exactly large enough to represent 1 or 2 char sequences
*/
var CMAP = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._";
var decode_msi_char = function(x) { return CMAP[x]||"_"; };
return function decode_msi_name(str) {
var i = 0, o = [], c = str.charCodeAt(0);
if(c == 0x4840) { ++i; o.push("*"); } /* technically '_' */
for(; i < str.length; ++i) {
c = str.charCodeAt(i);
if(c < 0x3800 || c > 0x4840) o.push(String.fromCharCode(c)); /* raw */
else if(c >= 0x4800) o.push(decode_msi_char(c-0x4800)); /* one char */
else { /* two chars */
o.push(decode_msi_char((c -= 0x3800) & 0x3f));
o.push(decode_msi_char((c>>6) & 0x3f));
}
}
return o.join("");
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment