Discussion:
[Bitpim-devel] Bug in unescape
Stu Grossman
2004-08-13 16:21:48 UTC
Permalink
It seems that under some circumstances, the phone will escape
characters other than 0x7e and 0x7d. I've run into a case where it
escapes 0x7f (which looks like 0x7d 0x5f in the raw). Unescape
doesn't handle this, so it gets passed through untouched, which then
causes bad crcs.

Since the escaping scheme looks something like byte-oriented PPP/HDLC,
I think it's probably reasonable to assume that 0x7d can escape
anything that follows it.

FYI, with this fixed, I can reliably do filesystem ops from my debian
system to a Samsung SCH-A650 using a simple USB cable.

def unescape(data):
esc=0
res=""
for d in data:
if d=="\x7d":
esc=0x20
else:
res+=chr(ord(d)^esc)
esc=0
return res
Roger Binns
2004-08-14 01:01:49 UTC
Permalink
Post by Stu Grossman
It seems that under some circumstances, the phone will escape
characters other than 0x7e and 0x7d.
That will explain some things :-) Yes, the CRC/escaping
scheme is the same as PPP.

This is my new code, which works correctly in all my tests. Please
eyeball it as well. For other people who want to test, do a CVS
update and include the tilde and open and close squiggly brackets
in data values.

def escape(data):
return data.replace("\x7d", "\x7d\x5d") \
.replace("\x7e", "\x7d\x5e")

def unescape(d):
if d.find("\x7d")<0: return d
res=list(d)
try:
start=0
while True:
p=res.index("\x7d", start)
res[p:p+2]=chr(ord(res[p+1])^0x20)
start=p+1
except ValueError:
return "".join(res)

Roger

Loading...