home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / py2exe / resources / StringTables.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  2.6 KB  |  90 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. RT_STRING = 6
  5. _use_unicode = 0
  6.  
  7. try:
  8.     _use_unicode = unicode
  9. except NameError:
  10.     
  11.     try:
  12.         import pywintypes
  13.     except ImportError:
  14.         raise ImportError, 'Could not import StringTables, no unicode available'
  15.     except:
  16.         None<EXCEPTION MATCH>ImportError
  17.     
  18.  
  19.     None<EXCEPTION MATCH>ImportError
  20.  
  21. if _use_unicode:
  22.     
  23.     def w32_uc(text):
  24.         return unicode(text, 'unicode-escape').encode('utf-16-le')
  25.  
  26. else:
  27.     
  28.     def w32_uc(text):
  29.         return pywintypes.Unicode(text).raw
  30.  
  31.  
  32. class StringTable:
  33.     
  34.     def __init__(self):
  35.         self.strings = { }
  36.  
  37.     
  38.     def add_string(self, id, text):
  39.         self.strings[id] = text
  40.  
  41.     
  42.     def sections(self):
  43.         ids = self.strings.keys()
  44.         ids.sort()
  45.         sections = { }
  46.         for id in ids:
  47.             sectnum = id / 16 + 1
  48.             table = sections.get(sectnum)
  49.             if table is None:
  50.                 table = sections[sectnum] = { }
  51.             
  52.             table[id % 16] = self.strings[id]
  53.         
  54.         return sections
  55.  
  56.     
  57.     def binary(self):
  58.         import struct
  59.         sections = []
  60.         for key, sect in self.sections().items():
  61.             data = ''
  62.             for i in range(16):
  63.                 ustr = w32_uc(sect.get(i, ''))
  64.                 fmt = 'h%ds' % len(ustr)
  65.                 data = data + struct.pack(fmt, len(ustr) / 2, ustr)
  66.             
  67.             sections.append((key, data))
  68.         
  69.         return sections
  70.  
  71.  
  72. if __name__ == '__main__':
  73.     st = StringTable()
  74.     st.add_string(32, 'Hallo')
  75.     st.add_string(33, 'Hallo1')
  76.     st.add_string(34, 'Hallo2')
  77.     st.add_string(35, 'Hallo3')
  78.     st.add_string(1023, '__service__.VCULogService')
  79.     st.add_string(1024, '__service__.VCULogService')
  80.     st.add_string(1025, '__service__.VCULogService')
  81.     st.add_string(1026, '__service__.VCULogService')
  82.     import sys
  83.     sys.path.append('c:/tmp')
  84.     from hexdump import hexdump
  85.     for sectnum, data in st.binary():
  86.         print 'ID', sectnum
  87.         hexdump(data)
  88.     
  89.  
  90.