Parsing of hex bytes in Perl



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 02
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....

.



Relevant Pages

  • Does any one recognize this binary data storage format
    ... We are working on a data file reader and extraction tool for an old ... Hex On Disk: C0DBA8ECF441 ...
    (comp.lang.python)
  • Parsing of HEX bytes using PErl
    ... I am a student working on a project using Perl. ... I have few hex bytes as inputs for my program. ... I have to parse the input hex bytes using this data file and the output ... digits are same but the representations are different. ...
    (perl.beginners)
  • Re: Trying to pad a 40 digit number with zeros with no luck
    ... It  looks like you have this taking the 13th bit and turning it on, ... -a is to tell perl to split each line ... I split the input into 2 hex numbers: ... digits and followed by ". ...
    (comp.unix.shell)
  • Re: Replacing unicode characters
    ... > i artikel c0goke$l8b$2@wisteria.csv.warwick.ac.uk, skrev Ben Morrow... A 2-digit hex number, say 0x82, can also ... strings as sequences of 8-bit bytes. ... The fact that if you treat it as textual Perl ...
    (comp.lang.perl.misc)
  • Re: hexadecimal addition
    ... case you don't have a number, you have an unquoted string. ... You tell Perl a number written in your source file is hex by preceding ... Please read perldoc perldata. ...
    (comp.lang.perl.misc)