Comments (33)
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.
Worked like charm, Have a great day!!
from asn1tools.
It worked like a charm! Thank you so much @eerimoq!!!
from asn1tools.
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.
Fixed in 0.54.0 for BER and DER codecs.
from asn1tools.
kindly elaborate a bit.. i didnt get it what you mean by 0.54.0
from asn1tools.
Release 0.54.0. You can install it with pip install -U asn1tools
.
from asn1tools.
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.
from asn1tools.
Looks like you are trying to decode the wrong type. Replace CallEventRecord
with CallEventDataFile
and it should decode successfully.
from asn1tools.
I did that as well but same error
from asn1tools.
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.
Ahh, and open the file with "rb"
.
from asn1tools.
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.
is it possible to convert byte array into its proper value. and how can i save an xml rather than list
from asn1tools.
Have a great day yourself!! :-)
from asn1tools.
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.
Try decoding on this site: https://asn1.io/asn1playground/
If callDuration is still missing, your data does not contain callDuration.
from asn1tools.
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.
Post the output from the playground here please.
from asn1tools.
Here's the encoded cdr_file and here is the decoded version from playground.
from asn1tools.
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.
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.
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.
Sorry, I don't have time to help.
from asn1tools.
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.
Sorry, didn't read carefully. Almost everyone want help :P
from asn1tools.
Thanks @Finndersen, very appreciated.
from asn1tools.
Does it work as expected for your use case?
from asn1tools.
I have merged in changes
from asn1tools.
@Finndersen Pushing tags automatically publishes to PyPI. So it's easy to do.
from asn1tools.
Does it work as expected for your use case?
I confirm, yes.
Thanks.
from asn1tools.
@eerimoq I just manually created new release, will that also publish to PyPI?
from asn1tools.
@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)
- Generated C OER decoder fails to decode fixed-length sequences with lengths of more than 255
- Decode successfully ignores extra bytes HOT 2
- encode_message() fails to validate ASN.1 BIT STRING SIZE constraints
- how to parse the "CONTAING SEQUENCE" msg immediately HOT 1
- Compile nrppa using PER fail
- How to view encoded values
- Test failures with pyparsing 3.1.1 HOT 4
- oer c code generation fails when addition contains a sequence with enums (type error) HOT 2
- decoding erros HOT 9
- SEQUENCE OF has no maximum length HOT 1
- parser claims "syntax error" for `SEQUENCE (SIZE (32)) OF OCTET STRING (SIZE (6))` with `DEFAULT` HOT 4
- How to encode a complex json object ?
- ParseError when compile the ASN1 schema file
- OpenType does not exist for xer
- Changing `numeric_enums` parameter has no effect when `cache_dir` is set and cache previously created
- Example for ETSI CAM-ASN1 to Json Command
- Decode hangs when decoding the output of encode if ASN.1 contains a SEQUENCE of CHOICE of SEQUENCE
- Hello eerimoq
- Error Decoding Indefinite Length ASN.1 Elements Containing Extension Marker HOT 1
- Type 'SetupRelease' not found in module 'EUTRA-RRC-Definitions'.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asn1tools.