Files
flipperNfcToBin/index.html
Michael Micsen Johannessen Wehus 557ba42ea7 Simplified
2023-04-08 00:10:38 +01:00

94 lines
3.3 KiB
HTML

<!DOCTYPE html>
<html>
<body>
<h2>Mifare classic converter</h2>
<p>I take absolutely no liabilty for use please verify the files yourself before writing to a card you can end up
bricking your cards.</p>
<script src="./script.js"></script>
<script>
let cardSize = 1024 //1k card
let blocks = 64 // 1k card
let filename = Date.now()
document.addEventListener("DOMContentLoaded", function (event) {
const nfc = document.getElementById("nfc");
document.getElementById("file-selector").addEventListener("change", (event) => {
console.log(event.target.files[0])
if (event.target.files[0].name.endsWith(".bin")) {
getBinaryFromFile(event.target.files[0]).then((data) => {
filename = event.target.files[0].name.replace(".bin", "")
const hexStr = generateNfcFromBinary(data);
nfc.value = hexStr;
})
} else if (event.target.files[0].name.endsWith(".nfc")) {
getTextFromFile(event.target.files[0]).then((data) => {
filename = event.target.files[0].name.replace(".nfc", "")
nfc.value = data;
})
} else {
alert("Invalid file type");
return
}
});
});
function bin() {
let array = new Array(blocks)
const nfc = document.getElementById("nfc");
var text = nfc.value.split("\n");
const re = /Block (\d+): (([0-9a-fA-F]+ *)+)/gm
for (let i = 0; i < text.length; i++) {
const data = re.exec(text)
console.log(data)
if (data) {
const block = parseInt(data[1])
const bytes = data[2].replace(/ /g, '')
console.log(block, bytes)
if (block < blocks) {
console.log('block', block, bytes)
array[block] = bytes
}
}
}
let textHex = ""
console.log("number of blocks", blocks)
for (let i = 0; i < blocks; i++) {
console.log('block', i, array[i])
if (array[i] !== undefined && array[i]?.length == 32) {
textHex += array[i]
console.log("Writing block", i, array[i], "to text")
} else {
console.log('block', i, 'is empty')
//Filling with 0 if block is empty
textHex += '00000000000000000000000000000000'
}
}
downloadBinFile(textHex, filename + ".bin")
}
function nfc() {
downloadTextFile(document.getElementById("nfc").value, filename + ".nfc")
}
</script>
<button type="button" onclick="bin()">
Download .bin
</button>
<button type="button" onclick="nfc()">
Download .nfc
</button>
<p>.nfc file content here</p>
<br />
<input type="file" id="file-selector" accept=".bin,.nfc">
<br />
<textarea id="nfc" rows="20" cols="90"></textarea>
</body>
</html>