smsutil icon indicating copy to clipboard operation
smsutil copied to clipboard

I have a error: TypeError: decoding with 'gsm0338' codec failed (TypeError: an integer is required (got type NoneType))

Open bs111 opened this issue 5 years ago • 6 comments

I have a Modem Log from Phone. i Open it from Qcom tools. when i get the hex data to translate it. it has an error.

setp: 1.the TP_user_data is : "6376783E07C500" from the Qcom tools. 2. I used the following : C:\Users\borla>python Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

import smsutil hexcode="6376783E07C500" gsmcode=bytes.fromhex(hexcode) gsmcode b'cvx>\x07\xc5\x00' print(gsmcode.hex()) 6376783e07c500 smsutil.decode(gsmcode) Traceback (most recent call last): File "D:\Python37\lib\site-packages\smsutil\codecs.py", line 61, in decode return decode_gsm0338(input, decoding_map) File "D:\Python37\lib\site-packages\smsutil\codecs.py", line 52, in decode_gsm0338 decoded += chr(d) TypeError: an integer is required (got type NoneType)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "", line 1, in File "D:\Python37\lib\site-packages\smsutil_init_.py", line 45, in decode return bytestring.decode(encoding) TypeError: decoding with 'gsm0338' codec failed (TypeError: an integer is required (got type NoneType))

expact result "class 1" as the Qcom tools decode.

version: C:\Users\borla>pip install -U smsutil Looking in indexes: https://pypi.douban.com/simple Requirement already up-to-date: smsutil in d:\python37\lib\site-packages (1.1.1) Requirement already satisfied, skipping upgrade: future==0.16.0 in d:\python37\lib\site-packages (from smsutil) (0.16.0) win10 pro 1903 python 3.7

modem information 1.the hex information: [0x713A/009/001] OTA LOG 01:26:30.978 SMS/CP Data Direction : Network To MSLength: 42 0x10003b003b003a710008cedd4172bf00002a000000690127016f0891683110301405f0001a040ba15156813926f8001121801090625323076376783e07c500 2.the picture decode from QC tools:

bs111 avatar Oct 15 '19 12:10 bs111

66733773-2a5f4280-ee93-11e9-8d5c-83e27dc05ccb

bs111 avatar Oct 15 '19 12:10 bs111

Thank you for this, i will check and fix this as soon as I am available.

jezeniel avatar Oct 19 '19 04:10 jezeniel

I checked the issue, it seems that based on the right panel the right hex is 63 6c 61 73 73 20 31 which the library can decode, are you using other encodings?

jezeniel avatar Nov 14 '19 05:11 jezeniel

no ,Qcom tools says it was encoded by sm_tp_user_data_gsm7. gsm7 bit.

bs111 avatar Nov 14 '19 06:11 bs111

Apologies for this, this is indeed an issue of the library. Will find a way to fix this ASAP.

jezeniel avatar Dec 03 '19 11:12 jezeniel

Currently just an update, the hex format above is packed to 8 bits, currently there are no methods to unpack it. Most SMSC doesn't even need the packed bytes as per https://github.com/twitter/cloudhopper-commons/blob/master/ch-commons-charset/src/main/java/com/cloudhopper/commons/charset/GSMBitPacker.java#L44

The default unpacked gsm7 encoding would work. But will definitely develop a util to pack and unpack gsm7.

jezeniel avatar Feb 21 '20 03:02 jezeniel