Help making a BMS script from a javascript code

Programming related discussions related to game research
gamelandresearch
Posts: 13
Joined: Sun Feb 09, 2020 11:35 am

Help making a BMS script from a javascript code

Post by gamelandresearch »

Sorry this is kinda a noob question but the only code I could somewhat understand is QuickBMS so i'm trying make this one work on QuickBMS...

Code: Select all

let mRandom;

function getNextRandom() {
    mRandom ^= mRandom << 21;
    mRandom ^= mRandom >>> 35;
    mRandom ^= mRandom << 4;
   
    if (mRandom < 0)
        mRandom &= 2147483647;
   
    return mRandom / 2147483647;
}

function decryptPackage(bytes) {
    let view = new DataView(bytes);
   
    mRandom = 56895 & 25147 >> 1;
   
    for (let i = Math.min(view.byteLength, 65536) - 1; i >= 0; i -= 2)
        view.setInt8(i, view.getInt8(i) - Math.floor(getNextRandom() * 255));
   
    for (let i = view.byteLength - 1; i >= 0; i -= Math.floor(getNextRandom() * 255))
        view.setInt8(i, view.getInt8(i) - Math.floor(getNextRandom() * 255));
   
    for (let i = view.byteLength - 1; i >= Math.max(view.byteLength, 65536) - 65536; i -= 2)
        view.setInt8(i, view.getInt8(i) - Math.floor(getNextRandom() * 255));
   
    mRandom = 0;
    return bytes;
}


This code from Angry Birds Flash, I don't know how to convert
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Help making a BMS script from a javascript code

Post by aluigi »

The only way would be to implement it as a C function to call with calldll or with Encryption calldll.

The only doubt I have is about mRandom which is not clear if it's a 64bit or not, indeed I guess the script will not work correctly:

Code: Select all

set MEMORY_FILE10 string "

long long mRandom = 0;

int Math_min(int a, int b) {
    if(a < b) return a;
    return b;
}
int Math_max(int a, int b) {
    if(a > b) return a;
    return b;
}

int getNextRandom() {
    mRandom ^= mRandom << (long long)21;
    mRandom ^= (unsigned long long)mRandom >> (unsigned long long)35;
    mRandom ^= mRandom << (long long)4;
   
    if (mRandom < 0)
        mRandom &= 2147483647;
   
    return mRandom / 2147483647;
}

void decryptPackage(unsigned char *view, int view_byteLength) {
    //int view = new DataView(bytes);
    int i;
   
    mRandom = 56895 & 25147 >> 1;
   
    for (i = Math_min(view_byteLength, 65536) - 1; i >= 0; i -= 2)
        view[i] -= (getNextRandom() * 255);
   
    for (i = view_byteLength - 1; i >= 0; i -= (getNextRandom() * 255))
        view[i] -= (getNextRandom() * 255);
   
    for (i = view_byteLength - 1; i >= Math_max(view_byteLength, 65536) - 65536; i -= 2)
        view[i] -= (getNextRandom() * 255);
   
    mRandom = 0;
}
"

get SIZE asize
log MEMORY_FILE 0 SIZE
calldll MEMORY_FILE10 decryptPackage tcc RET MEMORY_FILE SIZE
log "dump.dat" 0 SIZE MEMORY_FILE
gamelandresearch
Posts: 13
Joined: Sun Feb 09, 2020 11:35 am

Re: Help making a BMS script from a javascript code

Post by gamelandresearch »

I tried to decrypt .pak but I got error, can you fix also don't forget to add both deflate and zlib compression after decrypting .pak
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Help making a BMS script from a javascript code

Post by aluigi »

Can't help. Replied here viewtopic.php?p=67777#p67777