1

I have a "fixed-length" binary ASN.1 encoded file with a separate documentation for the mapping of data elements. For example the binary file is of the form:

0070 00A0 1700 35e7 0100 0010 0299 1a11
bc10 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0001 0001
0256 1c41 aa09 0000 0000 0000 0000 0000
.....

Here each record is 559 bytes long. The documentation gives the record structure as the length in bytes. This format is quite specific to this data, so I need to make a converter. For example

No.     Field Name     Data Length (Bytes)   Description
1         Field1             2                 Binary
2         Field2             4                 BCD
3         Field3             1                 BCD (Right Aligned)
.....

I don't have any information if this is a standard ASN.1 encoding. The description are a bit more detailed than shown here, as they say what the decoded numbers mean. Some are binary, some BCD and some BCD (right aligned).

I don't know much about ASN.1, so I'm trying to avoid re-inventing the wheel. Is there any tool (preferably in python) that I can tweak to convert this binary file into a text CSV file? I haven't been able to find something that serves my need except this. But it's a proprietary tool and is not an option for me.

sfactor
  • 12,592
  • 32
  • 102
  • 152

1 Answers1

2

There is a module for ASN.1: pyasn1.

Another possibility is to use the built-in struct module to separate the fields. And the answer to this question to read binary coded decimals.

Community
  • 1
  • 1
Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • Thanks! The pyasn1 module seems to have decoders for BER encoded files. It doesn't seem to have something that exactly suits my need. But I'll keep digging in. – sfactor Aug 17 '14 at 11:24
  • FYI, the BCD stuff is not a part of ASN.1. You will need a two step process - decode the ASN.1 data, then interpret the BCD. You may find some tool that combines these steps, but they are nonetheless conceptually distinct. We have tools at obj-sys.com for doing this sort of thing, but as you need a non-proprietary solution, they won't be of help to you. – Kevin Aug 18 '14 at 01:58