Skip to content

Instantly share code, notes, and snippets.

@qoh
Created March 28, 2016 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qoh/333f558f046354ac06d2 to your computer and use it in GitHub Desktop.
Save qoh/333f558f046354ac06d2 to your computer and use it in GitHub Desktop.
Key Inspector
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Key Inspector</title>
<style>
body {
margin: 64px;
}
</style>
</head>
<body>
<p id="text">This page requires JavaScript support</p>
<input type="file" id="file" />
<script>
(function() {
"use strict";
var text = document.getElementById("text");
text.textContent = "Loading...";
var processors = [
// {pad: "Intel (unknown, P", name: "Intel (unknown, Pentium family)"},
// {pad: "Intel Pentium III", name: "Intel Pentium III"},
// {pad: "Intel Pentium MIn", name: "Intel Pentium M"},
// {pad: "Intel CoreIntel C", name: "Intel Core"},
// {pad: "AMD (unknown)AMD ", name: "AMD (unknown)"},
// {pad: "AMD AthlonAMD Ath", name: "AMD Athlon"},
// {pad: "AuthenticAMDAuthe", name: "AuthenticAMD"},
// {pad: "GenuineIntelGenui", name: "GenuineIntel"},
// {pad: "Intel (unknown)In", name: "Intel (unknown)"},
// {pad: "Intel Core 2Intel", name: "Intel Core 2"},
// {pad: "Intel Itanium 2In", name: "Intel Itanium 2"},
// {pad: "Intel ItaniumInte", name: "Intel Itanium"},
// {pad: "Intel Pentium Cel", name: "Intel Pentium Celeron"},
// {pad: "Intel Pentium 4In", name: "Intel Pentium 4"},
// {pad: "Intel PentiumInte", name: "Intel Pentium"},
// {pad: "Unknown x86 Compa", name: "Unknown x86 Compatible"}
{pad: "Intel", name: "Intel"},
{pad: "AMD (", name: "AMD"},
{pad: "AMD A", name: "AMD Athlon"},
{pad: "Authe", name: "AuthenticAMD"},
{pad: "Genui", name: "GenuineIntel"},
{pad: "Unkno", name: "Unknown x86 Compatible"}
];
var valid_char_table = [
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,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,
0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,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,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,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,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,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,0,0,0,0,0
];
var key_chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
function codesToString(codes) {
return String.fromCharCode.apply(null, codes);
}
function keyToBLID(array) {
var blid = 0;
for (var byte of array) {
blid = blid * key_chars.length + key_chars.indexOf(String.fromCharCode(byte));
}
return blid;
}
function processKeyDat(view) {
if (view.byteLength !== 28 || codesToString(view.slice(0, 11)) !== "KEYDAT_V1\r\n") {
text.textContent = "This doesn't look like a valid key.dat file";
return;
}
var match = false;
var head_enc = view.slice(11, 16);
var head_dec = new Uint8Array(5);
for (var processor of processors) {
var i;
for (i = 0; i < 5; i++) {
head_dec[i] = head_enc[i] ^ (88 + processor.pad.charCodeAt(i));
if (valid_char_table[head_dec[i]] == 0) {
break;
}
}
if (i == 5) {
text.textContent = "BLID: " + keyToBLID(head_dec) + " | Processor: " + processor.name;
match = true;
break;
}
}
if (!match) {
text.textContent = "Could not decrypt key.dat file";
}
}
document.getElementById("file").addEventListener("change", function(event) {
text.textContent = "Processing...";
event.stopPropagation();
event.preventDefault();
if (event.target.files.length < 1) {
text.textContent = "Select a key.dat file to find the BLID and processor family";
return;
}
var reader = new FileReader();
reader.addEventListener("loadend", function() {
processKeyDat(new Uint8Array(reader.result));
});
reader.readAsArrayBuffer(event.target.files[0]);
});
text.textContent = "Select a key.dat file to find the BLID and processor family";
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment