#!/usr/bin/env python ## smsdecode.py, v0.1 ## Copyright (C) 2004 Gary Benson ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. """Decode *.sm[io] files as produced by the Siemens S55.""" def decode(msg): start = {0: 0x2C, 3: 0x27}[ord(msg[7])] p, l, s, d, out = start + 1, ord(msg[start]), 0, 0, [] while len(out) < l: c = ord(msg[p]) p += 1 out.append(((c & (0x7F >> s)) << s) | d) d = (c & (0x7F80 >> s)) >> (7 - s) s += 1 if s == 7: out.append(d) s = d = 0 return "".join(map(chr, out)) if __name__ == "__main__": import sys for path in sys.argv[1:]: print path + ":", decode(open(path, "r").read())