Search code examples
functionreverse-engineeringcracking

What is this function saying?


I would like to know what this function is saying... im an amateur.

function get_cached_balance() {
    var balance = "?";
    if (localStorage['rumola:balance'])
        balance = ""+localStorage['rumola:balance'];
    return balance;
}
function update_cached_balance(b) {
    localStorage['rumola:balance'] = b;
}
  1. I know "get_cached_balance" is the name of the function that can be called elsewhere.

    document.getElementById("purchase_a").innerHTML = chrome.i18n.getMessage("menu9").replace("?", w.get_cached_balance());
    
  2. I also know "?" is where the information is placed

     "menu9": { "message": "Purchase more credits (? remaining)"},
    
  3. but I don't know what's localstorage and rumola:balance and where to find it and modify the information. Just explain what the rest of the code is doing please. I have an idea but not 100% sure.


Solution

  • localStorage probably refers to window.localStorage, part of the JavaScript Storage API. You can find the documentations on this API here: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage

    Basically, the Storage API lets a JS application store some data on the browser in a structured way (like cookies, but easier to access from JavaScript). localStorage can be treated like a database mapping keys to values.

    rumola:balance is simply the name of a database key which is used to look up the current balance. If the key exists, then the function returns the stringized balance; otherwise, it returns '?'.