Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to interact with some program remotely using socket ... but all I get are some packed data which I dont know how to unpack.

Any idea how can I find out ????

Replies are listed 'Best First'.
Re: Socket unpack
by ikegami (Patriarch) on Feb 16, 2010 at 07:31 UTC

    Read the spec. Google. Wikipedia. Not sure what you're expecting from us since you gave no info.

    You need to know things such as field size, byte order and whether it's signed or not. (e.g. 32-bit unsigned integer, big-endian). Then you can use unpack to convert the data into Perl values. (unpack 'N' for the example type).

      Thats my problem. The spec. is unknown for me and there`s no guide on it.

      I am trying to automate something that is not documented.

      Is it possible to find out the field size/byte order ...etc ?

        Yes and no. How can you tell what the following means?

        00 00 00 40 00 10 43 55 00 00 00 01 00 00 00 00

        Judging by the placement of the NULs, what are probably big-endian 4-byte numbers stand out.

        00 00 00 40 00 10 43 55 00 00 00 01 00 00 00 05 ----------- ----------- -----------

        If it was stored in little-endian byte order, it would look like

        40 00 00 00 55 43 10 00 01 00 00 00 05 00 00 00 ----------- ----------- -----------

        00 00 00 40 is likely a 32-bit field with value 64. Do you have an idea of what data you are getting? Are you expecting 64 for anything or 64 of something? If you change the input, do you see a corresponding change there?

        But maybe 00 00 00 40 is two 16-bit fields. Or two bytes and one 16-bit, or ...

        Do you see any repeating patterns? You could be looking at a list of records. For example,

        06 00 00 00 00 00 00 00 3C 00 00 00 7A 2D 01 01 ........<...z-.. EC 4E 14 DE FF FF FF FF FF FF FF FF 7A 2D 01 01 .N..........z-.. ED 4E 14 DE FF FF FF FF FF FF FF FF 39 5A 01 27 .N..........9Z.' E8 62 F4 EA FF FF FF FF FF FF FF FF 39 5A 01 27 .b..........9Z.' E7 62 F4 EA FF FF FF FF FF FF FF FF 39 5A 01 27 .b..........9Z.' 76 5D AE E5 FF FF FF FF FF FF FF FF 39 5A 01 27 v]..........9Z.' ...

        appears to contains 16 byte records (starting after 12 bytes). There are 60 such records, so the preceding 3C 00 00 00 must be the number of records that follow.

        You could study the sender's source code, disassembling a binary if necessary. If you have access to another receiver, you could also study it.

        If you need to send something back, you'll need to study an existing client, or at least the communication between an exiting client and server.

        Nothing simple ahead.

        I am trying to automate something that is not documented

        Are you sure? Perl is probably the most highly documented language around. So, I'd suggest reading perlipc for starters. Then post some code that you've tried.

Re: Socket unpack
by BrowserUk (Patriarch) on Feb 16, 2010 at 09:18 UTC
    1. What's on the other end of the socket?
    2. Do you have a few short samples of what it is sending you?
      1. There`s a server at the other end. which I have no access to except through a windows client I am trying to automate the process and make it possible to run on any other platform.
      2. Not much of anybody can understand. I might be missing something though.
        1. o&#8595;&#9604;&#1587;&#9787;&#8597;U&&#9644;-T&#1589;&#9500;&#1580; +v&#9616;&#9532;"w&#9532;o&#8616;&#9562;&#9608;i!&#1575;&#9559;4&#95 +58;&#9558;&#9572;&#9554;&#1589;&#1589;&#8962;&#9474;&#1617;&#9827; +&#9567;&#1581;&#9668;&#9787;&#9516;&#1571;&#9616;&#1612;I&#8730;&# +1573;2&#1610;&#9573;&#1610;&#1588;&#9559;&#9644;&#1611;g&#9532;&#1581 +;&#8616;&#8730;&#9612;^D,"&#8594;&#8595;]&#9559;&#9554; 2. ,&#8594;&#9566;.<t&#8252;&#9792;&#1617;&#1593;&#9568;>&#1590;&#9612;9 +^&#9578;hf;&#9572;j&#9580;&#9532;&#1600;&#9577;2&#9578;a &#1609;I& +#1582;\I&#8616;6&#8962;&#1571;N&#9829;&#1591;&#9787;&#9668;^,,&#96 +60;)&#1611;&#9472;g&#9619;),&#1572;&#9484;&#1586;&#9830;GI+&#9496;&#1 +604;&#1570;&#1600;f&#9516;[&#9562;&#9574;\N&#9792;R&#9570;&#1594;& +#9565;&#9557;&#1587;!
        There`s a server at the other end

        Yes. Client's usually connect to servers. What does the client do? What does it show you? Pictures, music, text, share prices, other?

        How did you capture that data? (From perl, cut&paste from the screen, other?)

        It might have been useful had you posted it as a hex dump.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Socket unpack
by zentara (Cardinal) on Feb 16, 2010 at 13:22 UTC
Re: Socket unpack
by Illuminatus (Curate) on Feb 16, 2010 at 15:13 UTC
    Assuming this mysterious server program is actually accessed by other existing clients, that might be the place to start. Assuming a network and not native socket, you should be able to capture all network traffic using wireshark or tcpdump. Try some sample commands on the working client, and look at the corresponding network traffic. That would probably get you basic functions. If you need to do something for which no client currently exists, then you are scr*wed. The request/response could be just about anything.