Nп/п : 23 из 100
 От   : Janis Papanagnou                    2:5075/128        31 авг 23 18:47:12
 К    : All                                                   31 авг 23 19:49:01
 Тема : Musings about inspecting and processing binary data with shell
----------------------------------------------------------------------------------
                                                                                 
@MSGID: 1@dont-email.me> 8a85e45b
@REPLYADDR Janis Papanagnou
<janis_papanagnou+ng@hotmail.com>
@REPLYTO 2:5075/128 Janis Papanagnou
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: 1@dont-email.me>
@TZUTC: 0200
@PID: Mozilla/5.0 (X11; Linux x86_64; rv:45.0)
Gecko/20100101 Thunderbird/45.8.0
@TID: FIDOGATE-5.12-ge4e8b94
When I saw a recent post where data got extracted from a binary file
it made me think about what would be the "right way" to do such jobs.

Shells (as other Unix tools) have problems at least with binary `\0`.
Kornshell supports binary data with `typeset -b`; it stores the data
in a MIME format. I couldn`t see, though, how to _process_ the binary
raw data within Kornshell easily. (If anyone has experiences here I`d
certainly like to hear!)
The `od` tool allows displaying binary data in various formats, but
it works on a whole data stream (not on individual fields).
Are there any tools that support a more flexible inspection of binary
data?

I was thinking of some data specification and a tool to work with that
specification and binary data files. My current experimental hack has
a data specification of a form as shown in this example

4 X magic (41424300)
4 S version (31323334)
2 - skip (55ee)
2 D reserved (0004)
0 X variable data (11223344)
8 D start of header (0000000000000100)
8 D end of header (00000000000002ff)
4 D auth size (00000020)
0 B auth data (...)
4 X marker (ffffffff)
4 X label (deadbeef)
4 - skip (00000000)
3 S EOT (454f54)
1 Z illegal format

basically defining the number of octets ("bytes") of a field, a type
that indicates the desired interpretation and output format, and an
informal text that describes the field (the numeric data in brackets
here is only for my tests).
Skipping of fields is possible (with type = `-`), and variable length
data could be processed (with length = 0) depending on a previous len
data element. Endian`ness could be supported for numeric data fields.
(An extension might support null-terminated data fields and distantly
located length fields.) It would create something like

          0x41424300magic (41424300)
              `1234`version (31323334)
                   4reserved (0004)
          0x11223344variable data (11223344)
                 256start of header (0000000000000100)
                 767end of header (00000000000002ff)
                  32auth size (00000020)
<0102040811121418212224284142444881828488000000000101010180808080>auth
data (...)
          0xffffffffmarker (ffffffff)
          0xdeadbeeflabel (deadbeef)
               `EOT`EOT (454f54)
*** Error: unsupported format `Z`! (Use X, D, B, S, or -)

Before I continue working on my hacked sample script I`d be interested
to know whether such a tool with similar functionality already exists
[in the free Linux world]; I would think this is a common task so that
some usable tool certainly should exists but my own cursory search did
not lead anywhere. So any hints are welcome.

Janis
--- Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
 * Origin: A noiseless patient Spider (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх