Advertisement
iful99

opmin louncer

Dec 30th, 2014
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. ED.py
  3. opmin 7.1.32444
  4. ibnu wahyudi
  5. 11/03/2014
  6. """
  7.  
  8. import appuifw2
  9. import e32
  10. import os
  11.  
  12. exe_name = 'OperaMini.exe'
  13. h0 = 817569
  14. h1 = 405144
  15. h2 = 405120
  16. h3 = 817925
  17. p0 = 95
  18. p1 = 15
  19. p2 = 22
  20. p3 = 216
  21.  
  22. class ExeRead:
  23.     def __init__(s):
  24.         s.exe = 'C:\\sys\\bin\\' + exe_name
  25.         s.server = {}
  26.         if not os.path.exists(s.exe):
  27.             s.exe = 'E' + s.exe[1:]
  28.         #s.cek()
  29.        
  30.     def cek(s):
  31.         if s.server == {}:
  32.             a = open(s.exe)
  33.             b = a.read()
  34.             a.close()
  35.             s.server.update({
  36.                 '01. http': b[h0:h0+p0].replace('\x00', ''),
  37.                 '02. header': b[h1:h1+p1].replace('\x00', ''),
  38.                 '03. header_value': b[h2:h2+p2].replace('\x00', ''),
  39.                 '04. server_key': b[h3:h3+p3].replace('\x00', '')})
  40.             del b
  41.         else:
  42.             pass
  43.  
  44.  
  45. def write(path, pos, input, max):
  46.     bin = open(path, 'a+')
  47.     bin.seek(pos)
  48.     bin.write(input + ((max - len(input))*'\x00'))
  49.     bin.close()
  50.  
  51. class Editor(ExeRead):
  52.     def __init__(s):
  53.         s.t, s.k, s.cf, s.tmp = [], [], [], {}
  54.         ExeRead.__init__(s)
  55.         s.cek()
  56.         s.app = appuifw2.app
  57.         s.box = appuifw2.Listbox2(double=1)
  58.         s.tx = appuifw2.Text(skinned=1, edit_callback=s.count)
  59.         s.item = appuifw2.Item
  60.         for i in s.server.keys():
  61.             s.t.append(i.upper().replace('_', ' '))
  62.             s.k.append(i)
  63.             s.tmp.update({i : s.server.get(i)})
  64.             e32.ao_yield()
  65.         s.t.sort()
  66.         s.k.sort()
  67.         s.path = os.path.join(os.getcwd(), 'config')
  68.         if not os.path.exists(s.path):
  69.             os.makedirs(s.path)
  70.  
  71.     def main(s):
  72.         del s.box[:]
  73.         s.app.title = u'EDITOR'
  74.         s.app.body = s.box
  75.         for i in range(len(s.t)):
  76.             s.box.append(s.item(title=u''+s.t[i], subtitle=u''+s.tmp.get(s.k[i])))
  77.             e32.ao_yield()
  78.         s.softkey('main')
  79.         s.app.menu = [
  80.             (u'Config [green]', s.config),
  81.             (u'Exit', s.exit)]
  82.         s.app.exit_key_handler = s.launch
  83.         s.box.bind(63557, s.to_edit)
  84.         s.box.bind(63586, s.config)
  85.         s.box.bind(8, lambda: None)
  86.    
  87.     def exit(s):
  88.         lock.signal()
  89.         s.softkey()
  90.         os.abort()
  91.    
  92.     def to_edit(s):
  93.         s.tx.clear()
  94.         pos = s.box.current()
  95.         max = eval('p%s' % (s.box.current()))
  96.         s.app.title = u'Max = %s chars' % (max)
  97.         s.app.body = s.tx
  98.         s.app.menu = [(u'Save', s.save), (u'Back', s.main)]
  99.         s.app.exit_key_handler = s.save
  100.         s.softkey('text')
  101.         s.tx.add(unicode(s.box[pos].subtitle))
  102.         s.tx.select_all()
  103.         s.tx.set_limit(max)
  104.    
  105.     def count(s, pos=None, anchor=None):
  106.         max = eval('p%s' % (s.box.current()))
  107.         cur = max - len(s.tx.get())
  108.         if cur == 0:
  109.             ind = u'Less'
  110.         elif cur == 1:
  111.             ind = u'1 Chr'
  112.         else:
  113.             ind = u'%s Chrs' % (cur)
  114.         s.tx.indicator_text = ind
  115.    
  116.     def save(s):
  117.         pos = s.box.current()
  118.         old = s.tmp.get(s.k[pos])
  119.         new = s.tx.get()
  120.         if new != old and new != '':
  121.             if appuifw2.query(u'Save changes?', 'query'):
  122.                 s.tmp.update({s.k[pos] : new})
  123.                 e32.ao_sleep(0.1)
  124.                 #print 'temp updated'
  125.             pass
  126.         pass
  127.         del (old, new, pos)
  128.         s.main()
  129.    
  130.     def preLaunch(s):
  131.         s.app.title = u'Launch...'
  132.         for i in range(len(s.k)):
  133.             #s.app.title = u'Writing ' + ('.'*(i+1))
  134.             #print s.server.get(s.k[i])
  135.             #print s.tmp.get(s.k[i])
  136.             if s.server.get(s.k[i]) != s.tmp.get(s.k[i]):
  137.                 #print i
  138.                 write(s.exe, eval('h%s' % (i)), s.tmp.get(s.k[i]), eval('p%s' % (i)))
  139.             else:
  140.                 pass
  141.             e32.ao_yield()
  142.    
  143.     def launch(s):
  144.         s.preLaunch()
  145.         e32.ao_sleep(0.5)
  146.         #s.app.title = u'Launch...'
  147.         e32.start_exe(s.exe, '', 0)
  148.         s.exit()
  149.    
  150.     def softkey(s, x=None):
  151.         if x == None:
  152.             l = u'Option'
  153.             r = u'Exit'
  154.         elif x == 'main':
  155.             l = u'Option'
  156.             r = u'Launch'
  157.         elif x == 'text':
  158.             l = u'Option'
  159.             r = u'Save'
  160.         elif x == 'config':
  161.             l = u'Option'
  162.             r = u'Apply'
  163.         elif x == 'back':
  164.             l = u'Option'
  165.             r = u'Back'
  166.         s.app.menu_key_text = l
  167.         s.app.exit_key_text = r
  168.  
  169.     def config(s):
  170.         del s.box[:]
  171.         del s.cf[:]
  172.         s.cf = [os.path.join(s.path, i) for i in os.listdir(s.path)]
  173.         s.app.title = u'CONFIG'
  174.         s.app.body = s.box
  175.         #print s.cf
  176.         if s.cf != []:
  177.             for i in range(len(s.cf)):
  178.                 s.box.append(s.item(title=u''+os.path.basename(s.cf[i]), subtitle=u'' + eval(open(s.cf[i]).read()).get('01. http') ))
  179.                 e32.ao_yield()
  180.             s.box.sort()
  181.             s.cf.sort()
  182.         if s.cf == []:
  183.             s.softkey('back')
  184.             s.app.exit_key_handler = s.main
  185.             s.box.bind(8, lambda: None)
  186.         else:
  187.             s.softkey('config')
  188.             s.app.exit_key_handler = s.apply
  189.             s.box.bind(8, s.delconfig)
  190.         s.app.menu = [
  191.             (u'Save', s.saveconfig),
  192.             (u'Back [green]', s.main),
  193.             (u'Exit', s.exit)]
  194.         s.box.bind(63557, lambda: None)
  195.         s.box.bind(63586, s.main)
  196.    
  197.     def apply(s):
  198.         if len(s.box) > 0:
  199.             pos = s.box.current()
  200.             if appuifw2.query(u'Apply %s' % (s.box[pos].title), 'query'):
  201.                 s.tmp = eval(open(s.cf[pos]).read())
  202.                 del pos
  203.             else:
  204.                 return None
  205.  
  206.     def saveconfig(s):
  207.         name = appuifw2.query(u'Name', 'text', unicode(s.tmp.get('01. http').replace('://', '_'))[:20])
  208.         if name:
  209.             file = os.path.join(s.path, name)
  210.             o = open(file, 'w')
  211.             o.write(str(s.tmp))
  212.             o.close()
  213.             del file
  214.             e32.ao_sleep(0.2, s.config)
  215.         else:
  216.             return None
  217.    
  218.     def delconfig(s):
  219.         if len(s.box) > 0:
  220.             pos = s.box.current()
  221.             if appuifw2.query(u'Remove %s?' % (s.box[pos].title) , 'query'):
  222.                 os.remove(s.cf[pos])
  223.                 #s.box.remove(s.box[pos])
  224.                 e32.ao_sleep(0.2, s.config)
  225.                 del pos
  226.             else:
  227.                 return None
  228.  
  229.  
  230.  
  231. lock = e32.Ao_lock()
  232. Editor().main()
  233. lock.wait()
  234. #del (appuifw2, e32, os)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement