Hello to all,

Maybe you can help me with this, I would like to know if it is possible with Perl
read from binary and get a string pattern given by a regex?

If possible, may you show me an example please.

Thanks for any help.

It would have been wonderful if you give an example of what you are trying to achieve. However, you could check if this link can help.Using regexp with binary data

Hello 2teez,

Thanks for answer and share the link. I hope you can help me in how to do this, I actually don't know Perl, but I've seen that can read binary files.

I want to get 2 related patterns and print them in the same line if belong to the same block, the 2nd pattern sometimes exists sometimes doesn't. So, if pattern1 is found twice consecutive, means that the previous pattern1 doesnt have a pattern2 related. The input below is the content of binary file.

If the content was in text file, whithout spaces nor end of lines, the following regexs work and would extract the numbers wthout f's:

(ff32)(.{6,8})(991145[^f]*)(.734[^f]*) --> For pattern1
(03)(8[0-9].*?)(840e.{28}) --> For pattern2

The output with these 2 patterns:

ff32001b01991145278934550f73494549232fffff
ff32000071991145278934551f73494554768fffff 03800f0102000000307349526905ffffff00810f01020000013a73495269559fffff008310010c0000009f7349526905ffffff0101840e0001000001000100ffff00000101

I think that regexs for binary data would be something like below:

0xff 0x32( 0x..){3,4}( 0x99 0x11 0x45)( 0x..){5}( 0x73 0x4.)( 0x..){6} -->For Pattern1
0x03 0x8.( 0x..).*( 0x84 0x0e)( 0x..){14} --> For Pattern2

Then, may you help with in how to do this with Perl, maybe after match the patterns, each one should be stored in a variable to be able to separated or apply some format to matched strins before printing.

Thanks in advance for any help.

38 30 37 31 33 34 34 06 99 11 45 27 89 34 55 ff
32 00 1b 01 99 11 45 27 89 34 55 0f 73 49 45 49
23 2f ff ff 00 15 00 0a 48 00 01 5a 00 02 42 00
01 60 00 01 33 00 01 36 00 01 37 00 01 5b 00 01
7e 00 01 69 00 00 6a 00 00 79 00 00 93 00 01 22
00 00 21 00 01 09 00 01 0a 00 01 26 00 01 02 00
01 04 00 01 05 00 01 06 00 01 10 00 01 08 00 01
2b 00 00 2c 00 01 2d 00 01 2e 00 01 55 00 01 56
00 07 2a 00 00 2f 00 00 30 00 00 31 00 00 ff 34
00 80 09 32 c9 06 88 88 80 00 a0 00 80 09 35 c9
06 00 00 80 00 00 00 80 09 3c c9 06 88 88 80 00
80 00 80 09 43 c9 06 88 88 80 00 80 00 05 82 00
37 06 01 00 00 01 00 65 00 00 00 02 00 00 02 00
18 00 00 00 03 00 00 03 00 17 00 00 00 04 00 00
04 00 01 00 00 00 05 00 00 05 00 15 00 00 00 0a
00 ff ff 00 65 00 00 00 07 80 2e c9 18 05 91 73
49 52 69 53 1f ff ff ff 00 91 73 49 52 69 53 1f
ff ff 00 01 03 ca 03 08 08 fe cb 0a 00 00 00 00
00 00 00 00 00 00 cc 01 01 81 1b c9 0b 00 91 73
49 52 69 56 7f ff ff ff ca 06 00 00 00 00 00 00
cb 01 03 cc 01 01 ff 32 00 00 71 99 11 45 27 89
34 55 1f 73 49 45 54 76 8f ff ff 00 15 00 0a 48
00 01 5a 00 02 42 00 01 60 00 01 33 00 01 36 00
01 37 00 01 5b 00 01 66 00 01 65 00 01 77 00 01
78 00 01 7e 00 01 69 00 00 6a 00 00 79 00 00 93
00 01 22 00 00 21 00 01 09 00 01 0a 00 01 26 00
01 02 00 01 04 00 01 05 00 01 06 00 01 10 00 01
08 00 01 2b 00 00 2c 00 01 2d 00 01 2e 00 01 55
00 01 56 00 07 2a 00 00 2f 00 00 30 00 00 31 00
00 ff 34 00 80 09 32 c9 06 88 88 80 00 a0 00 80
09 35 c9 06 00 00 80 00 00 00 80 09 3c c9 06 88
88 80 00 80 00 80 09 43 c9 06 88 88 80 00 80 00
03 80 0f 01 02 00 00 00 30 73 49 52 69 05 ff ff
ff 00 81 0f 01 02 00 00 01 3a 73 49 52 69 55 9f
ff ff 00 83 10 01 0c 00 00 00 9f 73 49 52 69 05
ff ff ff 01 01 84 0e 00 01 00 00 01 00 01 00 ff
ff 00 00 01 01
85 06 00 03 79 00 01 ea 05 00 01
82 00 37 06 01 00 00 01 00 65 00 00 00 02 00 00
02 00 18 00 00 00 03 00 00 03 00 17 00 00 00 04
00 00 04 00 01 00 00 00 05 00 00 05 00 15 00 00
00 0a 00 ff ff 00 65 00 00 00 07 80 2e c9 18 00
91 73 49 52 69 53 9f ff ff ff 00 91 73 49 52 69
53 9f ff ff 00 01 03 ca 03 08 08 fe cb 0a 00 00
00 00 00 00 00 00 00 00 cc 01 01 81 1b c9 0b 00
91 73 49 52 69 56 7f ff ff ff ca 06 00 00 00 00
00 00 cb 01 03 cc 01 01 ff 33 31 33 30 38 30 37
31 33 34 34 30 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.