george-hopkins / codeplug

codeplug decoder and builder for Motorola radios
MIT License
53 stars 16 forks source link

CPS R16 CP V14 structure not decodable #3

Open dk5ras opened 6 years ago

dk5ras commented 6 years ago

When I am trying to decode a new R16 / V14 EMEA CP I get these errors:

Traceback (most recent call last): File "codeplug.py", line 166, in File "codeplug.py", line 162, in main File "codeplug.py", line 121, in _decode_cmd File "src\lxml\etree.pyx", line 3230, in lxml.etree.fromstring (src\lxml\etree.c:81056) File "src\lxml\parser.pxi", line 1871, in lxml.etree._parseMemoryDocument (src\lxml\etree.c:121236) File "src\lxml\parser.pxi", line 1759, in lxml.etree._parseDoc (src\lxml\etree.c:119912) File "src\lxml\parser.pxi", line 1125, in lxml.etree._BaseParser._parseDoc (src\lxml\etree.c:114159) File "src\lxml\parser.pxi", line 598, in lxml.etree._ParserContext._handleParseResultDoc (src\lxml\etree.c:107724) File "src\lxml\parser.pxi", line 709, in lxml.etree._handleParseResult (src\lxml\etree.c:109433) File "src\lxml\parser.pxi", line 638, in lxml.etree._raiseParseError (src\lxml\etree.c:108287) File "", line 1 lxml.etree.XMLSyntaxError: xmlParseCharRef: invalid xmlChar value 65535, line 1, column 101402 [11032] Failed to execute script codeplug

The decryption key appears to be the same, possible just some structure changes...

KR0SIV commented 5 years ago

I seem to be having the same issue (both branches). The archive was saved as GEMSTONE on CPS 16 build 823

PS C:\users\harold\Google Drive\codeplug-prepare> codeplug decode .\900.ctb Traceback (most recent call last): File "C:\Users\Harold\AppData\Local\Programs\Python\Python37-32\Scripts\codeplug-script.py", line 11, in <module> load_entry_point('codeplug==0.2.0', 'console_scripts', 'codeplug')() File "C:\Users\Harold\AppData\Local\Programs\Python\Python37-32\lib\site-packages\codeplug.py", line 162, in main return args.func(args) File "C:\Users\Harold\AppData\Local\Programs\Python\Python37-32\lib\site-packages\codeplug.py", line 121, in _decode_c md xml = etree.fromstring(result) File "src\lxml\etree.pyx", line 3213, in lxml.etree.fromstring File "src\lxml\parser.pxi", line 1877, in lxml.etree._parseMemoryDocument File "src\lxml\parser.pxi", line 1765, in lxml.etree._parseDoc File "src\lxml\parser.pxi", line 1127, in lxml.etree._BaseParser._parseDoc File "src\lxml\parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc File "src\lxml\parser.pxi", line 711, in lxml.etree._handleParseResult File "src\lxml\parser.pxi", line 640, in lxml.etree._raiseParseError File "<string>", line 3 lxml.etree.XMLSyntaxError: xmlParseCharRef: invalid xmlChar value 65535, line 3, column 95496

BogdanDIA commented 5 years ago

I have the same problem on a codeplug for EMEA. Investigating the problem seems it is caused by a construct inside the XML that cannot be parsed by etree:

￿

This &#xFFFF is not valid utf-8 character and that is why etree gives the error in etree.fromstring()

dk5ras commented 5 years ago

Again we have such an issues. What is VA_RESERVED, what CPS setting has an influence on this? So maybe it is possible to avoid it?

BogdanDIA commented 5 years ago

VA - is voice announcement. Seems someone at Motorola put a &#xFFFF as default value but this is not valid character.

I remember I got past of this error by with the following changes in codeplug.py:

--- a/codeplug.py +++ b/codeplug.py @@ -118,10 +118,11 @@ def _decode_cmd(args):

 result = decode(data, base64.b64decode(config['key']), base64.b64decode(config['iv']))

- xml = etree.fromstring(result) + #xml = etree.fromstring(result)

 with open(args.output or args.file + '.xml', 'wb') as f:

- f.write(etree.tostring(xml, pretty_print=True)) + f.write(result)

Then to create back the encrypted ctb, search the xml for VA_RESERVED and replace the &#xFFFF with xFFFFFF or other valid utf-8 character. Then use the same codeplug.py

KR0SIV commented 5 years ago

@BogdanDIA is this how your changes should look?

`def _decode_cmd(args): config = _read_config(args.config)

with open(args.file, 'rb') as f:
    data = f.read()

archive_type, result = decode(data, base64.b64decode(config['key']), base64.b64decode(config['iv']))

#xml = etree.fromstring(result)

output_path = args.output or args.file + '.xml'
with open(output_path, 'wb') as f:
    f.write(result)
    #f.write(etree.tostring(xml, pretty_print=True))

print('Decoded {} archive to {}'.format(archive_type, output_path))`

This fails with the following result for me.

Traceback (most recent call last): File "codeplug.py", line 313, in main() File "codeplug.py", line 309, in main return args.func(args) File "codeplug.py", line 249, in _decode_cmd config = _read_config(args.config) File "codeplug.py", line 243, in _read_config raise Exception('Invalid configuration') Exception: Invalid configuration

KR0SIV commented 5 years ago

I may have actually stumbled on a different codeplug archive format.

C:\Users\Windows7-VM\Desktop\codeplug-matrix>python codeplug.py decode Untitled .ctb Traceback (most recent call last): File "codeplug.py", line 312, in <module> main() File "codeplug.py", line 308, in main return args.func(args) File "codeplug.py", line 254, in _decode_cmd archive_type, result = decode(data, base64.b64decode(config['key']), base64 b64decode(config['iv'])) File "codeplug.py", line 171, in decode raise Exception('Unsupported archive type: {}'.format(archive_type)) Exception: Unsupported archive type: PHOENIX

This was the error when I read the same radio using an older version of the CPS.

mitchrk commented 4 years ago

Has there been any update to this, I have a V14 Codeplug that is failing to read with similar errors above, I have patched the file with the relevant parts from @BogdanDIA However no luck, Still getting the invalid xmlChar value errors

AlSayedAlMohdar commented 3 years ago

I still have the same issue and the same error code ,But for the new CPS2 that have the .ctb2 extension . The CPS2 doesn't have the cpservices.dll.

scottm12x commented 3 years ago

There appears to be a problem with CPS 2.0 ID's going into RM 2.0. Was hoping could isolate with this but no luck so far. This was a great tool, hoping someone can update it.