Code Monkey home page Code Monkey logo

Comments (33)

eerimoq avatar eerimoq commented on July 29, 2024 2

Try the code below with release 0.55.0 of asn1tools. Then open cdr.xml to see the data in XML.

import asn1tools

ber = asn1tools.compile_files('huawei-cdr.asn', 'ber')
xer = asn1tools.compile_files('huawei-cdr.asn', 'xer')

with open('cdr.dat', 'rb') as fin:
    encoded_ber = fin.read()

decoded = ber.decode('CallEventDataFile', encoded_ber)
encoded_xer = xer.encode('CallEventDataFile', decoded)

with open('cdr.xml', 'w') as fout:
    fout.write(encoded_xer.decode('ascii'))

from asn1tools.

arsalan993 avatar arsalan993 commented on July 29, 2024 1

Worked like charm, Have a great day!!

from asn1tools.

edsase avatar edsase commented on July 29, 2024 1

It worked like a charm! Thank you so much @eerimoq!!!

from asn1tools.

Finndersen avatar Finndersen commented on July 29, 2024 1

hey @eerimoq @Immasarti I have reworked ber.MembersType.decode() to add support for SET members in any order, and also improved decode performance at the same time. See my fork: https://github.com/Finndersen/asn1tools There is also an open pull request

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

Fixed in 0.54.0 for BER and DER codecs.

from asn1tools.

arsalan993 avatar arsalan993 commented on July 29, 2024

kindly elaborate a bit.. i didnt get it what you mean by 0.54.0

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

Release 0.54.0. You can install it with pip install -U asn1tools.

from asn1tools.

arsalan993 avatar arsalan993 commented on July 29, 2024

I am getting this error now
asn1tools.codecs.ber.DecodeChoiceError

Sir, Is it possible if you can decode this since i need this data urgently for my project.
Here is the sample code which i am running
import asn1tools
foo = asn1tools.compile_files('huawei-cdr.asn')
f = open('cdr.dat','r')
sub = f.read()
print foo.decode('CallEventRecord', sub)

And here is dropbox link, folder contains two file "huawei-cdr.asn' this file is the asn mapper while "cdr.dat" file contain the encoded data.

ASN.1 data

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

Looks like you are trying to decode the wrong type. Replace CallEventRecord with CallEventDataFile and it should decode successfully.

from asn1tools.

arsalan993 avatar arsalan993 commented on July 29, 2024

I did that as well but same error

from asn1tools.

arsalan993 avatar arsalan993 commented on July 29, 2024

I have to include the code in my projectso than it can decode other similar dat files as well not just this one .
he is the output xml of the dat file which was generated using paid software
kindly open it in internet explorer not in sublimetext
https://www.dropbox.com/s/2p4c1tgh2d4kf8t/sample1.rar?dl=0

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

Ahh, and open the file with "rb".

from asn1tools.

arsalan993 avatar arsalan993 commented on July 29, 2024

Despite the fact that now it is working like charm one last issue that is left is .. now for the element value it is currently print byte array. he is a sample output at index 0 of the list

('mtSMSRecord', {'smsUserDataType': bytearray(b'\xff'), 'globalAreaID': bytearray(b'\x14\xf0\x10\x03\xf2\x015'), 'servedIMSI': bytearray(b'\x14\x00\x81U)Ud\xf2'), 'msClassmark': bytearray(b'WX\xa6'), 'recordType': 7, 'orgMSCId': bytearray(b'\x00[\x17'), 'deliveryTime': bytearray(b"\x18\x03\x07\x13W'+\x05\x00"), 'orgRNCorBSCId': bytearray(b'\x00\xff\xff'), 'systemType': 'unknown', 'origination': bytearray(b'\x91)\x03F\x16\x88\x19'), 'serviceCentre': bytearray(b'\x91)\x03\x00\x00@\xf2'), 'subscriberCategory': bytearray(b'\n'), 'firstmccmnc': bytearray(b'\x14\xf0\x10'), 'basicService': ('teleservice', bytearray(b'!')), 'recordingEntity': bytearray(b'\x91)\x03\x98\x08\x04\xf1'), 'servedMSISDN': bytearray(b'\x91)\x03I\x01\x00Y'), 'chargedParty': 'calledParty', 'callReference': bytearray(b'\x03\xfe;.\xa2\x0c'), 'additionalChgInfo': {'chargeIndicator': 2}, 'location': {'cellIdentifier': bytearray(b'\x015'), 'locationAreaCode': bytearray(b'\x03\xf2')}})

from asn1tools.

arsalan993 avatar arsalan993 commented on July 29, 2024

is it possible to convert byte array into its proper value. and how can i save an xml rather than list

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

Have a great day yourself!! :-)

from asn1tools.

edsase avatar edsase commented on July 29, 2024

Hi all,
Sorry to reopen this thread again.
Im doing a similar project like @arsalan993 and I dont get any errors when I extract the files using the script that @eerimoq posted above. However, the extracted cdr.xml does not have key parameters like "callDuration". I thought at first it had to do with my original cdr.dat files. But this is not the case as I still get the same result (without call duration) when I used the cdr.dat files of @arsalan993 . Grateful if you could point me in the correct direction to resolve this. Thanks!

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

Try decoding on this site: https://asn1.io/asn1playground/

If callDuration is still missing, your data does not contain callDuration.

from asn1tools.

edsase avatar edsase commented on July 29, 2024

Hi, thanks for the link to asn1playground. My data indeed has callDuration. I have tried the data of @arsalan993 which also has callDuration, but when I run it with the script you posted above, the callDuration does not show up. I also tried using the exact same version of asn1tools (0.54.0) as @arsalan993 and with his dataset. But still no callDuration.

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

Post the output from the playground here please.

from asn1tools.

edsase avatar edsase commented on July 29, 2024

Here's the encoded cdr_file and here is the decoded version from playground.

from asn1tools.

edsase avatar edsase commented on July 29, 2024

And below is an example record output from the playground and showing callDuration:

moCallRecord : {
recordType moCallRecord,
servedIMSI '16090501792314F6'H,
servedIMEI '53650102008666F0'H,
servedMSISDN '913282181872F0'H,
callingNumber '913282181872F0'H,
calledNumber '8161F0'H,
recordingEntity '913272170808F0'H,
mscIncomingROUTE rOUTEName : "BSC01B",
mscOutgoingROUTE rOUTEName : "IVR01B",
location {
locationAreaCode '024E'H,
cellIdentifier '2EF3'H
},
basicService teleservice : '11'H,
msClassmark '505881'H,
seizureTime '1902010004552B0000'H,
answerTime '1902010004562B0000'H,
releaseTime '1902010005012B0000'H,
callDuration 5,
radioChanRequested dualFullRatePreferred,
radioChanUsed fullRate,
causeForTerm normalRelease,
diagnostics gsm0408Cause : 144,
callReference '03EF035D93CC'H,
additionalChgInfo {
chargeIndicator charge
}

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

Should be fixed in version 0.146.1, available on PyPI!

However, the BER decoder is still not fully complient with the ASN.1 standard, but I think it works in practice. The ASN.1 standard allows SET members in any order, but asn1tools can only decode them if they are sorted.

from asn1tools.

lmasarati avatar lmasarati commented on July 29, 2024

The ASN.1 standard allows SET members in any order, but asn1tools can only decode them if they are sorted.

Hi @eerimoq , I'm having this problem with Huawei BER encoded CDRs that have non-sorted tag values in SET members.
I solved redefining the asn1tools.codecs.ber.MembersType.decode() method with a local version which has a 'while (offset < end_offset):' loop around the 'for member in self.root_members:' loop. It's not efficient, I know, but solved the problem with 2 additional cycles...

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

Sorry, I don't have time to help.

from asn1tools.

lmasarati avatar lmasarati commented on July 29, 2024

Sorry, I don't have time to help.

It was intended as a comment about your statement...
Actually, I was not asking for help, but offering a quick solution to anyone who's having the same problem.
Thanks.

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

Sorry, didn't read carefully. Almost everyone want help :P

from asn1tools.

lmasarati avatar lmasarati commented on July 29, 2024

Thanks @Finndersen, very appreciated.

from asn1tools.

Finndersen avatar Finndersen commented on July 29, 2024

Does it work as expected for your use case?

from asn1tools.

Finndersen avatar Finndersen commented on July 29, 2024

I have merged in changes

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

@Finndersen Pushing tags automatically publishes to PyPI. So it's easy to do.

from asn1tools.

lmasarati avatar lmasarati commented on July 29, 2024

Does it work as expected for your use case?

I confirm, yes.
Thanks.

from asn1tools.

Finndersen avatar Finndersen commented on July 29, 2024

@eerimoq I just manually created new release, will that also publish to PyPI?

from asn1tools.

eerimoq avatar eerimoq commented on July 29, 2024

@Finndersen You can find the logs from the tagged jobs here: https://github.com/eerimoq/asn1tools/actions/runs/591394281
A new release was published to PyPI. However, I forgot to tell you that the version in asn1tools/version.py should be bumped and committed before tagging with the same version. So please do that as well, otherwise asn1tools --version will show the older version. Just bump the version again to fix the issue.

from asn1tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.