script.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # coding:utf8
  2. import os
  3. import logging
  4. import re
  5. import glob
  6. import shutil
  7. import gw_data_center
  8. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  9. def script_init(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  10. gw_data_center.pack_small = True
  11. return
  12. def script(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  13. logging.info('game_pack_info: ' + str(channel_sdk_info))
  14. # 逆向渠道id
  15. if channel_sdk_info['id'] == "323":
  16. fixLifecycleMethod(extract_dir)
  17. hideSplash(extract_dir)
  18. return
  19. def script_pre(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  20. return
  21. def hideSplash(preDir):
  22. tfile = preDir + "/assets/bin/Data/splash.png"
  23. picDir = os.path.dirname(tfile)
  24. if not os.path.exists(picDir):
  25. os.makedirs(picDir)
  26. shutil.copyfile(os.path.dirname(os.path.abspath(__file__)) + '/FFFFFF-0.png', tfile)
  27. else:
  28. if os.path.isfile(tfile):
  29. shutil.copyfile(os.path.dirname(os.path.abspath(__file__)) + '/FFFFFF-0.png', tfile)
  30. else:
  31. logging.info('game_pack_info: ' + tfile + 'is not exists!')
  32. tfile = preDir + "/res/drawable/youkia_splash.png"
  33. picDir = os.path.dirname(tfile)
  34. if not os.path.exists(picDir):
  35. os.makedirs(picDir)
  36. shutil.copyfile(os.path.dirname(os.path.abspath(__file__)) + '/FFFFFF-0.png', tfile)
  37. else:
  38. if os.path.isfile(tfile):
  39. shutil.copyfile(os.path.dirname(os.path.abspath(__file__)) + '/FFFFFF-0.png', tfile)
  40. else:
  41. logging.info('game_pack_info: ' + tfile + 'is not exists!')
  42. tfile = preDir + "/res/values/styles.xml"
  43. if os.path.isfile(tfile):
  44. with open(tfile, 'r+') as f:
  45. cont = f.read()
  46. cont = cont.replace('<item name="android:windowBackground">@drawable/youkia_splash</item>'
  47. , '<item name="android:windowBackground">@color/transparent</item>')
  48. f.truncate(len(cont))
  49. f.seek(0)
  50. f.write(cont)
  51. f.close()
  52. else:
  53. logging.info('game_pack_info: ' + tfile + 'is not exists!')
  54. return
  55. def intoFirstLine(target, repl, cont, superclass):
  56. # srcStr = "onBackPressed"
  57. # regexp = '.method (?:public|protected) +?'+target+"\([^.]+?\.locals +[0-9]{1,2}"
  58. regexp = '.method (?:public|protected) +?' + target + "\([^.]+?\.locals +([0-9]{1,2})"
  59. # print(regexp)
  60. reObj = re.compile(regexp)
  61. matchO = reObj.search(cont)
  62. if matchO:
  63. # print(matchO.group(0))
  64. methodHead = matchO.group(0)
  65. if matchO.group(1) == "0":
  66. methodHead = re.sub("locals +0", "locals 1", methodHead)
  67. repl = methodHead + r'\n\n ' + repl + r'\n\n'
  68. cont = reObj.sub(repl, cont)
  69. else:
  70. # do call .super method
  71. isuper = "invoke-super {p0}, " + superclass + "->" + target + "()V"
  72. cont += "\n\n.method protected " + target + "()V\n .locals 0\n\n " + repl + "\n\n " + isuper + "\n\n return-void\n.end method"
  73. return cont
  74. def fixLifecycleMethod(preDir):
  75. for tfile in glob.glob(preDir + "/" + "smali*/com/youkia/gamecenter/GameCenterActivity.smali"):
  76. if os.path.isfile(tfile):
  77. with open(tfile, 'r+') as f:
  78. cont = f.read()
  79. changes = {
  80. "onPause": "invoke-static {}, Lcom/qihoo/gamecenter/sdk/matrix/Matrix;->onPause()V",
  81. "onResume": "invoke-static {}, Lcom/qihoo/gamecenter/sdk/matrix/Matrix;->onResume()V",
  82. "onDestroy": "invoke-static {p0}, Lcom/qihoo/gamecenter/sdk/matrix/Matrix;->destroy(Landroid/content/Context;)V",
  83. "onStop": "invoke-static {}, Lcom/qihoo/gamecenter/sdk/matrix/Matrix;->onStop()V"
  84. }
  85. mas = re.search('^.super L([^;]*);?', cont, re.MULTILINE)
  86. superclass = ""
  87. if mas:
  88. superclass = 'L' + mas.group(1) + ';'
  89. for k, v in changes.iteritems():
  90. cont = intoFirstLine(k, v, cont, superclass)
  91. f.seek(0)
  92. f.truncate(len(cont))
  93. f.write(cont)
  94. f.close()
  95. if __name__ == '__main__':
  96. script("/tmp/ss", "/mnt/share/yanghuang/python_test/any_dir", {"id": "323"}, "", "")
  97. # hideSplash("/mnt/share/yanghuang/python_test/cr")