Hi all,

I am a student working on a project using Perl.

My work is...

I have few hex bytes as inputs for my program. Its a series of hex bytes. for eg: 01 0a ab 2a 1c etc...

Here each byte stands for some representation. I also have a data file in which all the representations are stored. For eg:

01 => "abcd" 02 => "ertg" 1c => "srfrf" etc...

I have to parse the input hex bytes using this data file and the output should show the parsed input series.

The problem i face in linear search id, there are few hex bytes in which the digits are same but the representations are different. For eg: 01 stands for "abcd" and also in some other place it stands for "cdfv" also.

My program follows ASN.1 format. I mean The bytes come in a fashion like TYPE and then LENGTH and then VALUE..

So i have to parse in teh above mentioned manner.

I am unable to come up with an algorithm for the same as i am very new to Perl programming.

Also, the data files are very huge and input also is very huge file in which there are several hex bytes.

So plz can anyone help me in this?

The raw files(Given as input) looks like the following:

0d a1 0b 02 01 02 02 01 0e 30 03 04 01 93 7f 01 00 8b 2a 1c 0d a2 0b 0 +2 01 03 30 06 02 01 0e 80 01 04

The data files in which all possible hex combinations stored look like this

....... 02 OpCode Tag 01 OpCode Length 26 Foron 0A Reg1 0B Era1 0C Act1 0D De1 0E Int1 11 Reg4 12 Get5 13 Pro6 3B Pro7 3C Uns7 3D Uns 10 Not8 ......

The above is just a small block of the data file... Here The byte 02 stand for a TYPE

the byte 01 stands for its LENGTH

the the following bytes after that stands for the possible occurences of the VALUES.

But in the input string, according to the LENGTH, the value part occurs. For eg: if LENGTH is 01, only one possible VALUE follows it... else if LENGTH is 02, then 2 VALUES etc...

The output according to the input shown here shud look like the following:

0d -> De1 a1 -> Comp1 0b -> Era1 02 -> Opcode tag 01 -> Opcode length* 02 -> cdff etc.....

here since the length is 01(where it is starred), one of the possible values only can occur once... i mean each time...

So like this there are many TYPE LENGTH VALUES in the data files... so hex value in one TLV can have one description and the same hex value in another can have another description..

If i get some logic to search in each TLVs also, its good...

I hope this will explain you better....

20061026 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

2006-10-27 Retitled by Corion, as per Monastery guidelines
Original title: 'Please help needed badly.....'


In reply to help needed badly parsing ASN.1 data by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.