script.py 4.5 KB

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