Python Forum
How decode asn1 hex value using asn1tools
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How decode asn1 hex value using asn1tools
#1
I'm trying to decode the following ASN1 message using Python

b'\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x02\x89G\x11\x00\x1a\x01\x00\x10\x00\x80\x00\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x02\x98c\xc7h\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

This is my code:

import asn1tools
import socket
import sys

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_address = ('239.118.122.97', 8947)
#server_address = ('localhost', 8947)
#server_address = ('192.168.1.63', 8948)
#server_address = ('0.0.0.0', 8947)
print('starting up on {} port {}'.format(*server_address))
sock.bind(server_address)

while True:
    print('\nwaiting to receive message')
    data, address = sock.recvfrom(8947)

    print('\nreceived {} bytes from {}'.format(
        len(data), address))
    print(data)
    foo = asn1tools.compile_files(data,'uper')
I get the following error:

Error:
Traceback (most recent call last): File "udp.py", line 21, in <module> foo = asn1tools.compile_files(data,'uper') File "/usr/local/lib/python3.6/dist-packages/asn1tools/compiler.py", line 376, in compile_files return compile_dict(parse_files(filenames, encoding), File "/usr/local/lib/python3.6/dist-packages/asn1tools/parser.py", line 1877, in parse_files with open(filename, 'r', encoding=encoding, errors='replace') as fin: OSError: [Errno 9] Bad file descriptor
I've tried also f = asn1tools convert -i uper -o jer data unsuccessfully.

I expect a JSON format message.
buran write Dec-16-2020, 04:14 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
asn1tools.compile_files() is expecting a file descriptor. Why are you passing data?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Decode string ? JohnnyCoffee 1 813 Jan-11-2023, 12:29 AM
Last Post: bowlofred
  how to encode and decode same value absolut 2 2,328 Sep-08-2020, 09:46 AM
Last Post: TomToad
  struct.decode() and '\0' deanhystad 1 3,208 Apr-09-2020, 04:13 PM
Last Post: TomToad
  Parsing ASN1 CDR using Python library asn1 rash140 0 3,752 Mar-06-2020, 12:18 PM
Last Post: rash140
  Getting decode error. shankar 8 10,331 Sep-20-2019, 10:05 AM
Last Post: tinman
  how to decode UTF-8 in python 3 oco 3 37,402 Jun-05-2018, 11:05 AM
Last Post: wavic
  Ask help for utf-8 decode/encode forfan 12 10,843 Feb-25-2017, 02:04 AM
Last Post: forfan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020