Parsing of hex bytes in Perl
- From: dharshana.ve@xxxxxxxxx
- Date: 26 Oct 2006 01:16:27 -0700
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....
.
- Prev by Date: How to read a hash from a file?
- Next by Date: Re: Parsing of HEX bytes using PErl
- Previous by thread: How to read a hash from a file?
- Next by thread: How to pass string in command line argument.
- Index(es):
Relevant Pages
|