[RPGM] decompressor script for SRD_DataCompressor.js

Discussion in 'Tools & Tutorials' started by the66, May 8, 2018.

  1. the66

    the66 beware, the germans are cuming Modder Donor

    1,892
    2,728
    Jan 27, 2017
    i just created a little script to decompress the .json files created with the SRD_DataCompressor.js plugin for RPG Maker MV
    it's pretty raw and checks for no errors at all
    so back up any files, that might get destroyed

    usage:
    extract the archive and copy decompress.py to the www/data folder of the game with said plugin
    you should have a folder called compressed within it
    run the script (you need a working python 2.7 installation) and enjoy your uncompressed .json's
    it's only tested with

    Please Log in / Register to view this link

    ,

    Please Log in / Register to view this link

    and inserts there also the encryption key for the encrypted audio and image files to the right position

    edit: script updated, wrong file name for enc_key was displayed
     

    Attached Files:

    XdnaX, gue5t, N7 and 2 others like this.
  2. Tdius

    Tdius Active Member

    142
    7
    Feb 20, 2018
    not work clothes shop close
     
  3. the66

    the66 beware, the germans are cuming Modder Donor

    1,892
    2,728
    Jan 27, 2017
    the script doesn't fix errors, it just enables you to access the formerly compressed data files :rolleyes:
     
  4. Maim Lain

    Maim Lain Active Member Modder

    366
    593
    Apr 4, 2018
    Thanks for making this! I'm trying to get it to work with

    Please Log in / Register to view this link

    but I'm getting an error:
    TypeError: cannot use a string pattern on a bytes-like object

    Here's a link of just the data files if you'd like to take a look at it. :)

    Please Log in / Register to view this link



    Edit:

    Please Log in / Register to view this link

    worked for me. But I still can't get an encyrption key from the

    Please Log in / Register to view this link

    :/

    rpg_core.js says this. very confusing that there is no key.
    Code:
    Decrypter.hasEncryptedImages = false;
    Decrypter.hasEncryptedAudio = false;
    Decrypter._requestImgFile = [];
    Decrypter._headerlength = 16;
    Decrypter._xhrOk = 400;
    Decrypter._encryptionKey = "";
     
  5. the66

    the66 beware, the germans are cuming Modder Donor

    1,892
    2,728
    Jan 27, 2017
    my script worked absolutely fine here
    Code:
    Searching encryption key
    Key 3a76fa9709ca6c0f6d4c9847df430287 found in rpg_core.js
    Injecting encryption key into system.json
    Done
    
     
  6. Maim Lain

    Maim Lain Active Member Modder

    366
    593
    Apr 4, 2018
    Maybe I'm an idiot. How exactly did you run/execute your script? I think that's what I'm doing wrong.
     
  7. the66

    the66 beware, the germans are cuming Modder Donor

    1,892
    2,728
    Jan 27, 2017
    1. have a working python 2.7 environment (i assume, you have)
    2. drop the script to the folder that contains the compressed folder (should be game root/www/data)
    3. run the script decompress.py or like you did with the .bat
    now the compressed *.json from the folder compressed are beeing decompressed and copied to the the script folder
    in step 2 system.json is scanned for the encryption key and if it's not found, the content of the js folder is scanned
    if we have the key now, it's injected into system.json and you can use your preferred image/audio decryption tool
    (if no key has been found, it's hidden somewhere else and i have to update my script :))
     
  8. Maim Lain

    Maim Lain Active Member Modder

    366
    593
    Apr 4, 2018
    Oops. :coldsweat: I just assumed it was python 3. I swear more people use python 2 than 3 even though it's >current year. Thanks for the rest of the explanation though.

    Could you tell me what you think of

    Please Log in / Register to view this link

    The javascript files in School of Lust are all like this, and with my limited knowledge I don't think it's actual encryption with a missing key, but just functions/loops/variables that are used to obfuscate the code (I could be wrong). You know of any simple way to make these readable?
     
  9. the66

    the66 beware, the germans are cuming Modder Donor

    1,892
    2,728
    Jan 27, 2017
    i would reverse-engineer this function
    Code:
    function fyf(t)
        {
        var d=2633285;
        var w=t.length;
        var n=[];
        for(var v=0;v<w;v++)
            {
            n[v]=t.charAt(v)
            };
        for(var v=0;v<w;v++)
            {
            var y=d*(v+288)+(d%31111);
            var g=d*(v+229)+(d%52938);
            var s=y%w;
            var i=g%w;
            var u=n[s];
            n[s]=n[i];
            n[i]=u;
            d=(y+g)%2746409;
            };
        return n.join('')
        }
    looks for me like rearranging a string
     
  10. Maim Lain

    Maim Lain Active Member Modder

    366
    593
    Apr 4, 2018
    Yeah that's what I thought, that the JS code is just held in variables and passed into functions that un-obfuscate it, but it looks like there's unique functions for each file.

    Here's another one for example. It's pretty similar.
    Code:
    function()
    {
    var ycG='',mvz=11;
    function xLp(r)
    {
    var y=2442126;
    var h=r.length;
    var p=[];
    for(var j=0;j<h;j++)
    {
    p[j]=r.charAt(j)};
    for(var j=0;j<h;j++)
    {
    var f=y*(j+252)+(y%17122);
    var t=y*(j+196)+(y%53127);
    var a=f%h;
    var u=t%h;
    var o=p[a];
    p[a]=p[u];
    p[u]=o;y=(f+t)%2489181;
    };
    return p.join('')
    }
    So I don't think there's a fast or easy way to 'decrypt' all the JS files. :/
     
  11. the66

    the66 beware, the germans are cuming Modder Donor

    1,892
    2,728
    Jan 27, 2017
    you might look for the code that creates these functions, it's probably in the plugin that isn't encrypted
    but do you really have that strong need, to view the code of the js plugins? :)
     
  12. Maim Lain

    Maim Lain Active Member Modder

    366
    593
    Apr 4, 2018
    I think the game dev wrote or used the code that creates the functions to obfuscate his plugins and I don't think it would have been included in the game.

    And I need the code of the JS plugins because I can't create the incest patch for the game without changing a couple things in a few of the plugins. I've figured out how to do everything else needed to make the patch but this is the last thing that is preventing me from doing so. =/
     
  13. the66

    the66 beware, the germans are cuming Modder Donor

    1,892
    2,728
    Jan 27, 2017
    well, then write a script that..
    1. scans for *.js containing the crypt function
    2. open that file one by one
    1. scan for the different var values within the crypt function
    2. feed your own decrypter function with these and decrypt the data
    3. write the decrypted .js, crop the crypt function, exchange the encrypted data with your generated ones
     
  14. Maim Lain

    Maim Lain Active Member Modder

    366
    593
    Apr 4, 2018
    I'm not sure if I know enough to be able to do all of that. I could probably write that script in pseudo-code but if I tried to do it for real it would probably take me forever lol.

    I was messing around with the JS function and printed variables near the bottom and found you can print the decrypted code, but if you try substituting that code for the encrypted plugin it won't work. I think the game or one of the plugins relys on the code in the plugins being encrypted. Oh well, thanks for your help.

    Please Log in / Register to view this link


    Please Log in / Register to view this link

    (click preview to run)
     
  15. gue5t

    gue5t Well-Known Member Uploader

    545
    631
    Sep 11, 2016
    Clicking on preview doesn't decrypt the code correctly resulting in damaged plugins.js file.

    [EDIT]
    I'm attaching a manually fixed version that should work (with SRD_DataCompressor disabled)
     

    Attached Files:

    Maim Lain likes this.
  16. Maim Lain

    Maim Lain Active Member Modder

    366
    593
    Apr 4, 2018
    I just saw this now, this works with my patch changes, so I think you figured everything out. Thanks! What did you do differently to decrypt plugins.js? I knew something had to be wrong with mine because:

    #1. Printing RJm(8512); did nothing, I only printed RJm
    #2. Everything in my link was wrapped in a function which returned 6807, but that was weird and I didn't include that because I can't see how you would use that function for anything.
     
  17. gue5t

    gue5t Well-Known Member Uploader

    545
    631
    Sep 11, 2016
    I didn't do anything to RE that - my java knowledge isn't good enough unfortunately :(
    You had almost the whole thing except it had some characters escaped (like \u2500 instead of ) and some variables like <Ellye Title Text> missing (basically every text string between <> was missing) so I converted the characters and added the missing variables. I hope I haven't missed something.

    P.S. If someone can find a way to decode his scripts it'll be better because it's a problem if we have to do this manually for each version.
     
  18. Maim Lain

    Maim Lain Active Member Modder

    366
    593
    Apr 4, 2018
    Ah, in one of my previous comments to you in the SoL thread (I deleted it once I found out you had already fixed plugins.js) I mentioned that I found some UTF characters weren't translated, but I only caught ones that began with '\x' and didn't know there were others beginning '\u' that you found, and I didn't catch missing '<>' text either.

    I think I understand the <> thing now. Since that specific online compiler is wrapping the output in an html doc, it thinks <> are html tags so whenever <> appears in the output if you inspect element on the output it treats it as a new element and omits the text in it. This link will include the <> text now.

    Please Log in / Register to view this link



    I've tried looking online for a site that will convert any UTF codes inside a block of text to the normal characters but surprisingly can't find anything that works.. Also I think that it contains both UTF-8 characters and UTF-16 characters but I'm not 100% sure.

    Thanks again btw for figuring that out.
     
  19. the66

    the66 beware, the germans are cuming Modder Donor

    1,892
    2,728
    Jan 27, 2017

    Please Log in / Register to view this link

    for your en/decoding, whatever needs
     
  20. gue5t

    gue5t Well-Known Member Uploader

    545
    631
    Sep 11, 2016
    @Maim Lain, It seems I missed a few spaces on two lines, here's the fixed version.
    @the66, I can't find a tool that converts \x0D to \r directly so I'm guessing it'll be a combination + it's much faster to do it by hand for so smaller a sample.
     

    Attached Files: