Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
Added search-functionality for the "rpg_core(.js)"-File
Browse files Browse the repository at this point in the history
  • Loading branch information
Petschko committed Sep 23, 2018
1 parent 18fca5d commit f29e31d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ <h2>File-List</h2>
<script src="libs/lz-string.min.js"></script>
<script src="scripts/RPGFile.js?ver=1.1"></script>
<script src="scripts/ErrorException.js?ver=1.0"></script>
<script src="scripts/Decrypter.js?ver=1.2.1"></script>
<script src="scripts/Decrypter.js?ver=1.3.0"></script>
<script src="scripts/ZIP.js?ver=0.3"></script>
<script src="scripts/functions.js?ver=1.2.1"></script>
<script src="scripts/functions.js?ver=1.2.2"></script>
</body>
</html>
54 changes: 54 additions & 0 deletions scripts/Decrypter.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ Decrypter.detectEncryptionCode = function(rpgFile, callback) {
(window.addEventListener ? 'load' : 'onload', function() {
var key;
var fileContent;
var message = null;

This comment has been minimized.

Copy link
@Petschko

Petschko Sep 23, 2018

Author Owner

Ops, I have to revert this one


try {
fileContent = JSON.parse('[' + this.result + ']');
Expand All @@ -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)
*
Expand Down
6 changes: 5 additions & 1 deletion scripts/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)!'
);
});
}

Expand Down

0 comments on commit f29e31d

Please sign in to comment.