Jump to content

Recommended Posts

I have the following javascript that I am trying to reverse engineer:

function set_sw(row) {
    var i;
    var ofs = ofs_sr + row * 6;
    var sel_var = document.forms[0].elements[ofs + 5];

    // Use the sw_id table to get the ID and the user-friendly name
    sel_var.options[0] = new Option("None", "None", false);
    for (i = 0; i < sw_id.length; i += 2) {
        sel_var.options[i/2+1]=new Option(sw_id[i+1], sw_id[i], false);
    }

    // Set the option
    if (sel[row * 2 + 1] == "") {
        sel_var.selectedIndex = 0;
        return;
    }
    for (i = 0; i < sw_id.length; i += 2) {
        if (sel[row * 2 + 1] == sw_id[i]) {
            sel_var.selectedIndex = i/2 + 1;
            return;
        }
    }
}

My question is how the array 'sel' is being used? That array appears to be used as pairs of values.

var sel = [0,"170000001A5EA905",0,"910000001A7F2A05"];
var sw_id = ["910000001A7F2A05","910000001A7F2A05","170000001A5EA905","Test"];

I am trying to understand where/how the first element of each pair is being used. It appears to me that it is not used but it seems strange then that it is there. I'm hoping some new eyes can help. Can someone tell me if and where it is being used in that script? TIA.

Link to comment
https://forums.phpfreaks.com/topic/311088-reverse-engineering-a-javascript/
Share on other sites

36 minutes ago, gw1500se said:

It appears to me that it is not used but it seems strange then that it is there.

It doesn't appear to be used.  It might just be there for consistency sake with the sw_id array.  If both array's are auto-generated somewhere than it might have just been easier to keep two lists of pairs and dump them to an array rather than one list of pairs and one list of values only.

 

I would have just written this to use either a 2d array or array of objects rather than this flattened array approach.  It's unnecessarily hard to understand as written.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.