Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- ED.py
- opmin 7.1.32444
- ibnu wahyudi
- 11/03/2014
- """
- import appuifw2
- import e32
- import os
- exe_name = 'OperaMini.exe'
- h0 = 817569
- h1 = 405144
- h2 = 405120
- h3 = 817925
- p0 = 95
- p1 = 15
- p2 = 22
- p3 = 216
- class ExeRead:
- def __init__(s):
- s.exe = 'C:\\sys\\bin\\' + exe_name
- s.server = {}
- if not os.path.exists(s.exe):
- s.exe = 'E' + s.exe[1:]
- #s.cek()
- def cek(s):
- if s.server == {}:
- a = open(s.exe)
- b = a.read()
- a.close()
- s.server.update({
- '01. http': b[h0:h0+p0].replace('\x00', ''),
- '02. header': b[h1:h1+p1].replace('\x00', ''),
- '03. header_value': b[h2:h2+p2].replace('\x00', ''),
- '04. server_key': b[h3:h3+p3].replace('\x00', '')})
- del b
- else:
- pass
- def write(path, pos, input, max):
- bin = open(path, 'a+')
- bin.seek(pos)
- bin.write(input + ((max - len(input))*'\x00'))
- bin.close()
- class Editor(ExeRead):
- def __init__(s):
- s.t, s.k, s.cf, s.tmp = [], [], [], {}
- ExeRead.__init__(s)
- s.cek()
- s.app = appuifw2.app
- s.box = appuifw2.Listbox2(double=1)
- s.tx = appuifw2.Text(skinned=1, edit_callback=s.count)
- s.item = appuifw2.Item
- for i in s.server.keys():
- s.t.append(i.upper().replace('_', ' '))
- s.k.append(i)
- s.tmp.update({i : s.server.get(i)})
- e32.ao_yield()
- s.t.sort()
- s.k.sort()
- s.path = os.path.join(os.getcwd(), 'config')
- if not os.path.exists(s.path):
- os.makedirs(s.path)
- def main(s):
- del s.box[:]
- s.app.title = u'EDITOR'
- s.app.body = s.box
- for i in range(len(s.t)):
- s.box.append(s.item(title=u''+s.t[i], subtitle=u''+s.tmp.get(s.k[i])))
- e32.ao_yield()
- s.softkey('main')
- s.app.menu = [
- (u'Config [green]', s.config),
- (u'Exit', s.exit)]
- s.app.exit_key_handler = s.launch
- s.box.bind(63557, s.to_edit)
- s.box.bind(63586, s.config)
- s.box.bind(8, lambda: None)
- def exit(s):
- lock.signal()
- s.softkey()
- os.abort()
- def to_edit(s):
- s.tx.clear()
- pos = s.box.current()
- max = eval('p%s' % (s.box.current()))
- s.app.title = u'Max = %s chars' % (max)
- s.app.body = s.tx
- s.app.menu = [(u'Save', s.save), (u'Back', s.main)]
- s.app.exit_key_handler = s.save
- s.softkey('text')
- s.tx.add(unicode(s.box[pos].subtitle))
- s.tx.select_all()
- s.tx.set_limit(max)
- def count(s, pos=None, anchor=None):
- max = eval('p%s' % (s.box.current()))
- cur = max - len(s.tx.get())
- if cur == 0:
- ind = u'Less'
- elif cur == 1:
- ind = u'1 Chr'
- else:
- ind = u'%s Chrs' % (cur)
- s.tx.indicator_text = ind
- def save(s):
- pos = s.box.current()
- old = s.tmp.get(s.k[pos])
- new = s.tx.get()
- if new != old and new != '':
- if appuifw2.query(u'Save changes?', 'query'):
- s.tmp.update({s.k[pos] : new})
- e32.ao_sleep(0.1)
- #print 'temp updated'
- pass
- pass
- del (old, new, pos)
- s.main()
- def preLaunch(s):
- s.app.title = u'Launch...'
- for i in range(len(s.k)):
- #s.app.title = u'Writing ' + ('.'*(i+1))
- #print s.server.get(s.k[i])
- #print s.tmp.get(s.k[i])
- if s.server.get(s.k[i]) != s.tmp.get(s.k[i]):
- #print i
- write(s.exe, eval('h%s' % (i)), s.tmp.get(s.k[i]), eval('p%s' % (i)))
- else:
- pass
- e32.ao_yield()
- def launch(s):
- s.preLaunch()
- e32.ao_sleep(0.5)
- #s.app.title = u'Launch...'
- e32.start_exe(s.exe, '', 0)
- s.exit()
- def softkey(s, x=None):
- if x == None:
- l = u'Option'
- r = u'Exit'
- elif x == 'main':
- l = u'Option'
- r = u'Launch'
- elif x == 'text':
- l = u'Option'
- r = u'Save'
- elif x == 'config':
- l = u'Option'
- r = u'Apply'
- elif x == 'back':
- l = u'Option'
- r = u'Back'
- s.app.menu_key_text = l
- s.app.exit_key_text = r
- def config(s):
- del s.box[:]
- del s.cf[:]
- s.cf = [os.path.join(s.path, i) for i in os.listdir(s.path)]
- s.app.title = u'CONFIG'
- s.app.body = s.box
- #print s.cf
- if s.cf != []:
- for i in range(len(s.cf)):
- s.box.append(s.item(title=u''+os.path.basename(s.cf[i]), subtitle=u'' + eval(open(s.cf[i]).read()).get('01. http') ))
- e32.ao_yield()
- s.box.sort()
- s.cf.sort()
- if s.cf == []:
- s.softkey('back')
- s.app.exit_key_handler = s.main
- s.box.bind(8, lambda: None)
- else:
- s.softkey('config')
- s.app.exit_key_handler = s.apply
- s.box.bind(8, s.delconfig)
- s.app.menu = [
- (u'Save', s.saveconfig),
- (u'Back [green]', s.main),
- (u'Exit', s.exit)]
- s.box.bind(63557, lambda: None)
- s.box.bind(63586, s.main)
- def apply(s):
- if len(s.box) > 0:
- pos = s.box.current()
- if appuifw2.query(u'Apply %s' % (s.box[pos].title), 'query'):
- s.tmp = eval(open(s.cf[pos]).read())
- del pos
- else:
- return None
- def saveconfig(s):
- name = appuifw2.query(u'Name', 'text', unicode(s.tmp.get('01. http').replace('://', '_'))[:20])
- if name:
- file = os.path.join(s.path, name)
- o = open(file, 'w')
- o.write(str(s.tmp))
- o.close()
- del file
- e32.ao_sleep(0.2, s.config)
- else:
- return None
- def delconfig(s):
- if len(s.box) > 0:
- pos = s.box.current()
- if appuifw2.query(u'Remove %s?' % (s.box[pos].title) , 'query'):
- os.remove(s.cf[pos])
- #s.box.remove(s.box[pos])
- e32.ao_sleep(0.2, s.config)
- del pos
- else:
- return None
- lock = e32.Ao_lock()
- Editor().main()
- lock.wait()
- #del (appuifw2, e32, os)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement