Every line of 'scripthelpers' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
38 function getScriptFromEval(code){ 39 if (!scriptCache[code]){ 40 scriptCache[code] = VM.createScript(code); 41 } 42 return scriptCache[code]; 43 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
12 function hexlifyScript(script) { 13 function hexlify(ar) { 14 var result = ''; 15 for (var i = 0; i < ar.length; ++i) { 16 if (ar[i] < 16) { 17 result += '0'; 18 } 19 result += ar[i].toString(16); 20 } 21 return result; 22 } 23 24 // add header, pad to multiple of 16 bytes 25 data = new Uint8Array(4 + script.length + (16 - (4 + script.length) % 16)); 26 data[0] = 77; // 'M' 27 data[1] = 80; // 'P' 28 data[2] = script.length & 0xff; 29 data[3] = (script.length >> 8) & 0xff; 30 for (var i = 0; i < script.length; ++i) { 31 data[4 + i] = script.charCodeAt(i); 32 } 33 // TODO check data.length < 0x2000 34 35 // convert to .hex format 36 var addr = 0x3e000; // magic start address in flash 37 var chunk = new Uint8Array(5 + 16); 38 var output = []; 39 output.push(':020000040003F7') // extended linear address, 0x0003 40 for (var i = 0; i < data.length; i += 16, addr += 16) { 41 chunk[0] = 16; // length of data section 42 chunk[1] = (addr >> 8) & 0xff; // high byte of 16-bit addr 43 chunk[2] = addr & 0xff; // low byte of 16-bit addr 44 chunk[3] = 0; // type (data) 45 for (var j = 0; j < 16; ++j) { 46 chunk[4 + j] = data[i + j]; 47 } 48 var checksum = 0; 49 for (var j = 0; j < 4 + 16; ++j) { 50 checksum += chunk[j]; 51 } 52 chunk[4 + 16] = (-checksum) & 0xff; 53 output.push(':' + hexlify(chunk).toUpperCase()) 54 } 55 56 return output.join('\n'); 57 }