diff --git a/index.html b/index.html index 48b1c9d..a7b197f 100644 --- a/index.html +++ b/index.html @@ -310,8 +310,8 @@

File-List

- + - + diff --git a/scripts/Decrypter.js b/scripts/Decrypter.js index 441ecda..3a1f032 100644 --- a/scripts/Decrypter.js +++ b/scripts/Decrypter.js @@ -277,6 +277,7 @@ Decrypter.detectEncryptionCode = function(rpgFile, callback) { (window.addEventListener ? 'load' : 'onload', function() { var key; var fileContent; + var message = null; try { fileContent = JSON.parse('[' + this.result + ']'); @@ -294,12 +295,65 @@ Decrypter.detectEncryptionCode = function(rpgFile, callback) { } } + // Try a search + if(key === null) + key = Decrypter.searchEncryptionCode(this.result, 'rpg_core', false); + callback(key); }, false); reader.readAsText(rpgFile.file); }; +/** + * Searches for the encryption-key in other places + * + * @param {string} fileContent - Content of the File, where to search + * @param {string} searchParam - What method should be used to search + * @param {boolean} lzString - Decompress LZ-String + * @returns {null|string} - null if the key was not found else the key + */ +Decrypter.searchEncryptionCode = function(fileContent, searchParam, lzString) { + var result = null; + fileContent = (lzString) ? LZString.decompressFromBase64(fileContent) : fileContent; + + // Exit on empty File-Content (Usually caused if LZ-String-Decompress was not an LZ-String) + if(fileContent === null) + return null; + + switch(searchParam) { + case 'rpg_core': + var innerFunctionCodeMatches = null; + var lines = fileContent.split('\n'); + for(var line = 0; line < lines.length; line++) { + var l = lines[line]; + // Clean the line + l = l.trim(); + l = l.replace(/[\r\n\t]/g, ''); + + innerFunctionCodeMatches = l.match(/^(.*)this\._encryptionKey ?= ?"(.*)"(.*);(.*)?$/); + + if(innerFunctionCodeMatches !== null) + break; + } + + if(innerFunctionCodeMatches && innerFunctionCodeMatches.length > 2) + result = innerFunctionCodeMatches[2]; + + // Verify result + if(! result || typeof result === 'undefined') + result = null; + + // Also try a LZ-String search + if(result === null && ! lzString) + result = Decrypter.searchEncryptionCode(fileContent, searchParam, true); + + return result; + default: + return null; + } +}; + /** * Check if the string only has HEX-Chars (0-9 & A-F) * diff --git a/scripts/functions.js b/scripts/functions.js index 56e93b9..9662244 100644 --- a/scripts/functions.js +++ b/scripts/functions.js @@ -35,7 +35,11 @@ function getCode(systemFileElId, codeTextElId) { codeTextEl.className = addCssClass(codeTextEl.className, 'valid'); alert('Key found^^! (' + key + ')'); } else - alert('Error: Encryption-Key not found - Make sure that you select the correct file!'); + alert( + 'Error: Encryption-Key not found - Make sure that you select the correct file!\n\n' + + 'In rare cases the Key is hidden in this File: ./www/js/rpg_core(.js)\n\n' + + 'Please try to select the rpg_core(.js) file and try again (if not already done)!' + ); }); }