Jump to content
RyukShini

Is it possible to work with Mega.co.nz and AutoIT

Recommended Posts

RyukShini

I was wondering if its possible to make anything like this in AutoIT

 

function toArr(str)
{
    var ret = Array((str.length + 3) >> 2);

    // String to array of 32 bit ints
    for (var i = 0; i < str.length; i += 4)
    {
        // FYI:
        // NaN << x === 0
        // x | NaN === x
        ret[i >> 2] =
            (str.charCodeAt(i  ) << 24) |
            (str.charCodeAt(i+1) << 16) |
            (str.charCodeAt(i+2) <<  8) |
             str.charCodeAt(i+3);
    }
    return ret;
}

function megaKdf(pw)
{
    var pwkey = [0x93c467e3, 0x7db0c7a4, 0xd1be3f81, 0x0152cb56];
    var arrPw = toArr(pw);
    var aes   = Array((arrPw + 3) >> 2);

    // Init aes keys
    for (var i = 0; i < arrPw.length; i += 4)
    {
        aes[i >> 2] = new sjcl.cipher.aes([arrPw[i]|0, arrPw[i+1]|0, arrPw[i+2]|0, arrPw[i+3]|0]);
    }

    // Generate password key
    for (var i = 0; i < 65536; i++)
    {
        for (var j = 0; j < aes.length; j++)
        {
            pwkey = aes[j].encrypt(pwkey);
        }
    }

    return pwkey;
}

function loginHash(pwKey, email)
{
    var aes = new sjcl.cipher.aes(pwKey);
    var arrEmail = toArr(email);
    var hash = [0, 0, 0, 0];

    // Compress email with xor
    for (var i = 0; i < arrEmail.length; i++)
    {
        hash[i & 3] ^= arrEmail[i];
    }

    // Generate hash
    for (var i = 0; i < 16384; i++)
    {
        hash = aes.encrypt(hash);
    }

    return sjcl.codec.base64.fromBits([hash[0], hash[2]], true, true);
}

function badRand32()
{
    return Math.floor(0x100000000 * Math.random());
}

function generateMasterKey()
{
    return [badRand32(), badRand32(), badRand32(), badRand32()];
}

function confirmationLinkHash(pwKey)
{
    var aes = new sjcl.cipher.aes(pwKey);
    return aes.encrypt([badRand32(), 0, 0, badRand32()]);
}

function updateHashes(email, pw)
{
    var pwKey = megaKdf(pw);
    var masterKey = generateMasterKey();
    var clHash = confirmationLinkHash(pwKey, masterKey);
    var lHash = loginHash(pwKey, email);
    var aes = new sjcl.cipher.aes(pwKey);

    return lHash;
}

function htmlentities(str)
{
    return str.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#39;");
}

function analyzeLink(link, pw)
{
    var linkHex      = "N/A";
    var masterKey    = "N/A";
    var encMasterKey = "N/A";
    var pwHash       = "N/A";
    var unknown      = "N/A";
    var email        = "N/A";
    var spacer       = "N/A";
    var name         = "N/A";
    var unknown2     = "N/A";

    if (link.substr(0, 27) == "https://mega.co.nz/#confirm")
    {
        link = link.substr(27);
    }
    if (link.substr(0, 19) == "mega.co.nz/#confirm")
    {
        link = link.substr(19);
    }
    if (link.substr(0, 8) == "#confirm")
    {
        link = link.substr(8);
    }
    if (link.search(/^[0-9A-Za-z\-_]*$/) == 0)
    {
        link = sjcl.codec.hex.fromBits(sjcl.codec.base64.toBits(link, true));

        var pos;
        for (pos = 94; pos < link.length; pos += 2)
        {
            if (link.substr(pos, 2) == "09")
            {
                break;
            }
        }
        if (pos < link.length)
        {
            var pwKey = megaKdf(pw);
            var aes = new sjcl.cipher.aes(pwKey);
            var linkHash = aes.decrypt(sjcl.codec.hex.toBits(link.substr(32, 32)));
            if (linkHash[1] == 0 && linkHash[2] == 0)
            {
                masterKey = (new sjcl.cipher.aes(pwKey)).decrypt(sjcl.codec.hex.toBits(link.substr(0, 32)));
                masterKey = 'Base64: <span style="color:#f00; font-family:monospace;">' + sjcl.codec.base64.fromBits(masterKey, true, true) + '</span> (hex: <span style="color:#f00; font-family:monospace;">' + sjcl.codec.hex.fromBits(masterKey) + '</span>)';
            }
            else if (pw != "")
            {
                masterKey = "Wrong password";
            }
            encMasterKey = '<span style="color:#f00; font-family:monospace;">' + link.substr( 0, 32) + '</span>';
            pwHash       = '<span style="color:#080; font-family:monospace;">' + link.substr(32, 32) + '</span>';
            unknown      = '<span style="color:#00f; font-family:monospace;">' + link.substr(64, 30) + '</span>';
            email        = link.substr(94, pos - 94);
            spacer       = '<span style="color:#0cc; font-family:monospace;">09</span>';
            name         = link.substr(pos + 2, link.length - 16 - pos - 2);
            unknown2     = '<span style="color:#000; font-family:monospace;">' + link.substr(link.length - 16) + '</span>';
            linkHex = '<span style="font-family:monospace;">' + encMasterKey + " " + pwHash + " " + unknown +
                ' <span style="color:#888; font-family:monospace;">' + email + '</span> ' + spacer +
                ' <span style="color:#f0f; font-family:monospace;">' + name + '</span> ' + unknown2 + '</span>';
            email = htmlentities(sjcl.codec.utf8String.fromBits(sjcl.codec.hex.toBits(email))) + ' (<span style="color:#888; font-family:monospace;">' + email + '</span>)';
            name  = htmlentities(sjcl.codec.utf8String.fromBits(sjcl.codec.hex.toBits(name)))  + ' (<span style="color:#f0f; font-family:monospace;">' + name  + '</span>)';
        }
    }
    ge("linkHex").innerHTML          = linkHex;
    ge("linkMasterKey").innerHTML    = masterKey;
    ge("linkEncMasterKey").innerHTML = encMasterKey;
    ge("linkPwHash").innerHTML       = pwHash;
    ge("linkUnknown").innerHTML      = unknown;
    ge("linkEmail").innerHTML        = email;
    ge("linkSpacer").innerHTML       = spacer;
    ge("linkName").innerHTML         = name;
    ge("linkUnknown2").innerHTML     = unknown2;
}

 

Edited by RyukShini

Share this post


Link to post
Share on other sites
RyukShini

Anyone who has a clue??
Thanks in advance

Share this post


Link to post
Share on other sites
Danyfirex

Yes. or in any other programing lenguage.

 

Saludos

Share this post


Link to post
Share on other sites
spudw2k

Not being too familiar with the Javascript language reference, I don't know what some of the functions are doing (like how the comma separated values are handled/fed to the AES func...but it looks plausible.  As far as the HTML rendering, you'd have to embed some sort of browser/renderer unless you can afford to use other UI means/elements.

Share this post


Link to post
Share on other sites
orbs

@RyukShini,

it would be wiser not to try to translate the code, but to describe the task, and then try to implement it in AutoIt. then, if you need help with your AutoIt script, you can ask the forum.

but when you are asking AutoIt forum members to read and understand an enigmatic and lengthy piece of code written in another language, it is not surprising you have not yet got any help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • DynamicRookie
      By DynamicRookie
      Hey There!
       
      So, what i need to do is an app that can read text in a image (I.e. a png that has text saying "This is a png" and return the text to a variable)
      I'm pretty much a newbie on AutoIt, my purpose is doing that but i don't know any function that can

      Any help is much appreciated
    • santoshM
      By santoshM
      How can i exit from a procedure in auto
      Func test() if x=o then     return endif endFunc  
    • Valnurat
      By Valnurat
      Hi
      Small question.
      I trying to find all index in an array with value higher than 7.
      How can that be possible?
    • TrashBoat
      By TrashBoat
      Could someone help me create or give an idea of how to do a incrementing for loop that would do this: https://i.imgur.com/YFUt47H.gifv
      I'm having a hard time figuring it out :S
    • msd1994
      By msd1994
      I have a script that just adds some keyboard shortcuts for things like displaying the current song and artist, moving the window to the side so it won't pop up in my way, and play/pause, next song, previous song (these are the only 3 to still work since they don't need the window handle.)
      In some update recently, Spotify's window class swapped from "[CLASS:SpotifyMainWindow]" to "[CLASS:Chrome_WidgetWin_0]". Using the new class in my controls doesn't seem to work, I've tried getting the window handle from the process handle (_GetHwndFromPID($PID)) but that seems to fail as well.
      Does anybody have some idea of a way I could get this script working again?
       
      edit: seems like discord has the same window class name, so could be some issue with this? Still not sure of a way to solve the issue though, I added a function to get the handle of the active window and can just use that now, but it was able to find it on its own before on spotify startup or script startup which would be preferred.
       
      Thanks!
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.