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

    • JuanFelipe
      By JuanFelipe
      Cambiar a español Hello friends, I need help with a problem I have, I want to know if there is any way to update a GUI already running, that is I have a GUI of a certain size and with a button I would like to enlarge it:
      example: $ form1 = GUICreate ("", 200,100,0,0)   When you press the button, the gui increases its size, and actuates the new size.
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • santoshM
      By santoshM
      Dear friends i am facing a problem , i have created a window in autoit some time it is moving with the mouse curser even if iam not clicking the window 
    • sumanth1980
      By sumanth1980
      Here i am wrote a simple lines to install basic applications but when i clicked on one application/program to install it was working fine but when i cancel the program in the middle to install another program it was not working. I am not an expert in this but i want a solution for this ... Can any one help me on this....
      ORG-1.au3
    • PleaseHelpMEIWillLoveyou
      By PleaseHelpMEIWillLoveyou
      Is there a way to use a custom terminal or something from my pc and run a script on another pc.
      please let me know if its possible
      (not for anything bad just for a project im working on)
×