root/hodgestar/PythonCode/PicturePocketRevEng/umontools.py

Revision 283, 0.9 kB (checked in by simon, 4 years ago)

Move Picture Pocket reverse engineering attempts into svn.

  • Property svn:mime-type set to text/python-source
  • Property svn:eol-style set to native
Line 
1"""Stringify data is usbmon logs.
2   """
3
4import sys
5
6def convert_data_to_ascii(oIter):
7    for sLine in oIter:
8        if not " = " in sLine:
9            yield sLine
10            continue
11
12        sLog, sData = sLine.split(" = ",1)
13
14        sHexByte, sNewData = "", ""
15        sData = sData.strip()
16
17        for c in sData:
18            if c.upper() in "ABCDEF0123456789":
19                sHexByte += c
20                if len(sHexByte) == 2:
21                    sNewData += chr(int(sHexByte,16))
22                    sHexByte = ""
23            elif c in " " and len(sHexByte) == 0:
24                sNewData += c
25            else:
26                raise RuntimeError("Bad character %s (ASCII: %s) found in data." % (c,ord(c)))
27
28        if len(sHexByte) != 0:
29            sNewData += " (trailing byte)"
30
31        yield sLog + " = " + sNewData + "\n"
32
33if __name__ == "__main__":
34    oIter = convert_data_to_ascii(sys.stdin)
35    for sLine in oIter:
36        sys.stdout.write(sLine)
Note: See TracBrowser for help on using the browser.