Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.54 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html>
  4.  
  5.   <head>
  6.     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pako/1.0.6/pako.min.js"></script>
  7.     <style>
  8. fieldset { margin: 20px; border: 1px solid; }
  9. p { margin: 10px; }
  10. </style>
  11.  
  12.   </head>
  13.   <body>
  14. <fieldset>
  15.     <legend>Create zRIF string from work.bin</legend>
  16.   <p>
  17.   1. Select RIF file (work.bin): <input type="file" id="file" />
  18.   </p>
  19.   <p>
  20.   2. Press the button: <input type="button" id="convert" value="convert" />
  21.   </p>
  22.   <p>
  23.   3. Copy the zRIF string: <input type="text" id="zrif" size="100" />
  24.   <div id="info1" style="display:none">
  25.     <p>Content ID: <span id="id1"></span></p>
  26.     <p>Raw key: <span id="raw1"></span></p>
  27.   </div>
  28.   </p>
  29. </fieldset>
  30.  
  31. <fieldset>
  32.     <legend>Create work.bin from zRIF string</legend>
  33.   <p>
  34.   1. Provide zRIF string: <input type="text" id="zrif2" size="100" />
  35.   </p>
  36.   <p>
  37.   2. Convert to work.bin: <input type="button" id="convert2" value="convert" />
  38.   </p>
  39.   <p>
  40.   3. Click to download: <a href="" id="download"></a>
  41.   </p>
  42.   <div id="info2" style="display:none">
  43.     <p>Content ID: <span id="id2"></span></p>
  44.     <p>Raw key: <span id="raw2"></span></p>
  45.   </div>
  46. </fieldset>
  47.  
  48. <script>
  49.  
  50. function base64ArrayBuffer(bytes) {
  51.   var base64    = ''
  52.   var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  53.  
  54.   var byteLength    = bytes.byteLength
  55.   var byteRemainder = byteLength % 3
  56.   var mainLength    = byteLength - byteRemainder
  57.  
  58.   var a, b, c, d
  59.   var chunk
  60.  
  61.   // Main loop deals with bytes in chunks of 3
  62.   for (var i = 0; i < mainLength; i = i + 3) {
  63.    // Combine the three bytes into a single integer
  64.    chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]
  65.  
  66.    // Use bitmasks to extract 6-bit segments from the triplet
  67.    a = (chunk & 16515072) >> 18 // 16515072 = (2^6 - 1) << 18
  68.    b = (chunk & 258048)   >> 12 // 258048   = (2^6 - 1) << 12
  69.    c = (chunk & 4032)     >>  6 // 4032     = (2^6 - 1) << 6
  70.    d = chunk & 63               // 63       = 2^6 - 1
  71.  
  72.    // Convert the raw binary segments to the appropriate ASCII encoding
  73.    base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]
  74.  }
  75.  
  76.  // Deal with the remaining bytes and padding
  77.  if (byteRemainder == 1) {
  78.    chunk = bytes[mainLength]
  79.  
  80.    a = (chunk & 252) >> 2 // 252 = (2^6 - 1) << 2
  81.  
  82.    // Set the 4 least significant bits to zero
  83.    b = (chunk & 3)   << 4 // 3   = 2^2 - 1
  84.  
  85.    base64 += encodings[a] + encodings[b] + '=='
  86.  } else if (byteRemainder == 2) {
  87.    chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]
  88.  
  89.    a = (chunk & 64512) >> 10 // 64512 = (2^6 - 1) << 10
  90.    b = (chunk & 1008)  >>  4 // 1008  = (2^6 - 1) << 4
  91.  
  92.    // Set the 2 least significant bits to zero
  93.    c = (chunk & 15)    <<  2 // 15    = 2^4 - 1
  94.  
  95.    base64 += encodings[a] + encodings[b] + encodings[c] + '='
  96.  }
  97.  
  98.  return base64
  99. }
  100.  
  101. function concatTypedArrays(a, b) { // a, b TypedArray of same type
  102.    var c = new (a.constructor)(a.length + b.length);
  103.    c.set(a, 0);
  104.    c.set(b, a.length);
  105.    return c;
  106. }
  107.  
  108. var ddd = pako.inflate(atob("eNpjYBgFo2AU0AsYAIElGt8MRJiDCAsw3xhEmIAIU4N4AwNdRxcXZ3+/EJCAkW6Ac7C7ARwYgviuQAaIdoPSzlDaBUo7QmknIM3ACIZM78+u7kx3VWYEAGJ9HV0="));
  109.  
  110. function encode(arr) {
  111.  arr = pako.deflate(arr, {
  112.     level: 9,
  113.    windowBits: 10,
  114.    memLevel: 8,
  115.       dictionary: ddd
  116.  });
  117.  var dec = pako.inflate(arr, { dictionary: ddd });
  118.  while (arr.length % 3 != 0) {
  119.    arr = concatTypedArrays(arr, new Uint8Array([0]));
  120.  }
  121.  return base64ArrayBuffer(arr);
  122. }
  123.  
  124. function updateInfo(bin, id) {
  125.  var content = "";
  126.  for (var i=0x10; i<0x40; i++) {
  127.     if (bin[i] == 0) break;
  128.     content += String.fromCharCode(bin[i]);
  129.  }
  130.  
  131.  var key = "";
  132.  for (var i=0x50; i<0x60; i++) {
  133.     var hex = Number(bin[i]).toString(16);
  134.     if (hex.length == 1) {
  135.       hex = "0" + hex;
  136.     }
  137.     key += hex;
  138.  }
  139.  
  140.  document.getElementById("id" + id).innerText = content;
  141.  document.getElementById("raw" + id).innerText = key;
  142.  document.getElementById("info" + id).style.display = "block";
  143. }
  144.  
  145. function convert() {
  146.  
  147.    var files = document.getElementById('file').files;
  148.    if (!files.length) {
  149.      alert('Please select a file!');
  150.      return;
  151.    }
  152.    var file = files[0];
  153.    var start = 0;
  154.  
  155.    var reader = new FileReader();
  156.    reader.onloadend = function(evt) {
  157.      if (evt.target.readyState == FileReader.DONE) {
  158.          var bin = new Uint8Array(evt.target.result);
  159.          updateInfo(bin, "1");
  160.          document.getElementById('zrif').value = encode(bin);
  161.      }
  162.    };
  163.    reader.readAsArrayBuffer(file);
  164. }
  165.  
  166. function decode(str) {
  167.  var tmp = window.atob(str);
  168.  var arr = new Uint8Array(tmp.length);
  169.  for (var i=0; i<tmp.length; i++) {
  170.    arr[i] = tmp.charCodeAt(i);
  171.  }
  172.  arr = pako.inflate(arr, {
  173.    windowBits: 10,
  174.       dictionary: ddd
  175.  });
  176.  return arr;
  177. }
  178.  
  179. function convert2() {
  180.   var rif = document.getElementById("zrif2").value;
  181.   var bin;
  182.   try {
  183.     bin = decode(rif);
  184.   } catch (e) {
  185.     alert("Error converting: " + e);
  186.     return;
  187.   }
  188.   if (bin.length != 512) {
  189.     alert("wrong size of work.bin");
  190.     return;
  191.   }
  192.   updateInfo(bin, "2");
  193.  
  194.   var a = document.getElementById("download");
  195.   var blob = new Blob([bin], {type: "octet/stream"});
  196.   var url = window.URL.createObjectURL(blob);
  197.   a.href = url;
  198.   a.download = a.innerText = "work.bin";
  199. }
  200.  
  201. document.getElementById("convert").onclick = convert;
  202. document.getElementById("convert2").onclick = convert2;
  203. </script>    
  204.  
  205. </body>
  206. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement