Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pako/1.0.6/pako.min.js"></script>
- <style>
- fieldset { margin: 20px; border: 1px solid; }
- p { margin: 10px; }
- </style>
- </head>
- <body>
- <fieldset>
- <legend>Create zRIF string from work.bin</legend>
- <p>
- 1. Select RIF file (work.bin): <input type="file" id="file" />
- </p>
- <p>
- 2. Press the button: <input type="button" id="convert" value="convert" />
- </p>
- <p>
- 3. Copy the zRIF string: <input type="text" id="zrif" size="100" />
- <div id="info1" style="display:none">
- <p>Content ID: <span id="id1"></span></p>
- <p>Raw key: <span id="raw1"></span></p>
- </div>
- </p>
- </fieldset>
- <fieldset>
- <legend>Create work.bin from zRIF string</legend>
- <p>
- 1. Provide zRIF string: <input type="text" id="zrif2" size="100" />
- </p>
- <p>
- 2. Convert to work.bin: <input type="button" id="convert2" value="convert" />
- </p>
- <p>
- 3. Click to download: <a href="" id="download"></a>
- </p>
- <div id="info2" style="display:none">
- <p>Content ID: <span id="id2"></span></p>
- <p>Raw key: <span id="raw2"></span></p>
- </div>
- </fieldset>
- <script>
- function base64ArrayBuffer(bytes) {
- var base64 = ''
- var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
- var byteLength = bytes.byteLength
- var byteRemainder = byteLength % 3
- var mainLength = byteLength - byteRemainder
- var a, b, c, d
- var chunk
- // Main loop deals with bytes in chunks of 3
- for (var i = 0; i < mainLength; i = i + 3) {
- // Combine the three bytes into a single integer
- chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]
- // Use bitmasks to extract 6-bit segments from the triplet
- a = (chunk & 16515072) >> 18 // 16515072 = (2^6 - 1) << 18
- b = (chunk & 258048) >> 12 // 258048 = (2^6 - 1) << 12
- c = (chunk & 4032) >> 6 // 4032 = (2^6 - 1) << 6
- d = chunk & 63 // 63 = 2^6 - 1
- // Convert the raw binary segments to the appropriate ASCII encoding
- base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]
- }
- // Deal with the remaining bytes and padding
- if (byteRemainder == 1) {
- chunk = bytes[mainLength]
- a = (chunk & 252) >> 2 // 252 = (2^6 - 1) << 2
- // Set the 4 least significant bits to zero
- b = (chunk & 3) << 4 // 3 = 2^2 - 1
- base64 += encodings[a] + encodings[b] + '=='
- } else if (byteRemainder == 2) {
- chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]
- a = (chunk & 64512) >> 10 // 64512 = (2^6 - 1) << 10
- b = (chunk & 1008) >> 4 // 1008 = (2^6 - 1) << 4
- // Set the 2 least significant bits to zero
- c = (chunk & 15) << 2 // 15 = 2^4 - 1
- base64 += encodings[a] + encodings[b] + encodings[c] + '='
- }
- return base64
- }
- function concatTypedArrays(a, b) { // a, b TypedArray of same type
- var c = new (a.constructor)(a.length + b.length);
- c.set(a, 0);
- c.set(b, a.length);
- return c;
- }
- var ddd = pako.inflate(atob("eNpjYBgFo2AU0AsYAIElGt8MRJiDCAsw3xhEmIAIU4N4AwNdRxcXZ3+/EJCAkW6Ac7C7ARwYgviuQAaIdoPSzlDaBUo7QmknIM3ACIZM78+u7kx3VWYEAGJ9HV0="));
- function encode(arr) {
- arr = pako.deflate(arr, {
- level: 9,
- windowBits: 10,
- memLevel: 8,
- dictionary: ddd
- });
- var dec = pako.inflate(arr, { dictionary: ddd });
- while (arr.length % 3 != 0) {
- arr = concatTypedArrays(arr, new Uint8Array([0]));
- }
- return base64ArrayBuffer(arr);
- }
- function updateInfo(bin, id) {
- var content = "";
- for (var i=0x10; i<0x40; i++) {
- if (bin[i] == 0) break;
- content += String.fromCharCode(bin[i]);
- }
- var key = "";
- for (var i=0x50; i<0x60; i++) {
- var hex = Number(bin[i]).toString(16);
- if (hex.length == 1) {
- hex = "0" + hex;
- }
- key += hex;
- }
- document.getElementById("id" + id).innerText = content;
- document.getElementById("raw" + id).innerText = key;
- document.getElementById("info" + id).style.display = "block";
- }
- function convert() {
- var files = document.getElementById('file').files;
- if (!files.length) {
- alert('Please select a file!');
- return;
- }
- var file = files[0];
- var start = 0;
- var reader = new FileReader();
- reader.onloadend = function(evt) {
- if (evt.target.readyState == FileReader.DONE) {
- var bin = new Uint8Array(evt.target.result);
- updateInfo(bin, "1");
- document.getElementById('zrif').value = encode(bin);
- }
- };
- reader.readAsArrayBuffer(file);
- }
- function decode(str) {
- var tmp = window.atob(str);
- var arr = new Uint8Array(tmp.length);
- for (var i=0; i<tmp.length; i++) {
- arr[i] = tmp.charCodeAt(i);
- }
- arr = pako.inflate(arr, {
- windowBits: 10,
- dictionary: ddd
- });
- return arr;
- }
- function convert2() {
- var rif = document.getElementById("zrif2").value;
- var bin;
- try {
- bin = decode(rif);
- } catch (e) {
- alert("Error converting: " + e);
- return;
- }
- if (bin.length != 512) {
- alert("wrong size of work.bin");
- return;
- }
- updateInfo(bin, "2");
- var a = document.getElementById("download");
- var blob = new Blob([bin], {type: "octet/stream"});
- var url = window.URL.createObjectURL(blob);
- a.href = url;
- a.download = a.innerText = "work.bin";
- }
- document.getElementById("convert").onclick = convert;
- document.getElementById("convert2").onclick = convert2;
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement