script.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # coding:utf8
  2. __author__ = '灌篮高手酷派'
  3. import os
  4. import logging
  5. import xml.dom.minidom
  6. import re
  7. import shutil
  8. import glob
  9. import distutils.dir_util
  10. import gw_apk_tool
  11. import gw_data_center
  12. def replace_life_method(extract_dir):
  13. goal_files = glob.glob(os.path.join(extract_dir, 'smali*/com/yingxiong/hero/UnityPlayerActivity.smali'))
  14. if len(goal_files) == 0:
  15. return
  16. goal_file = goal_files[0]
  17. print(os.path.isfile(goal_file))
  18. if os.path.isfile(goal_file):
  19. logging.info('method_proceed: ' + 'goal_file')
  20. print(goal_file)
  21. with open(goal_file, 'r+') as f:
  22. cont = f.read()
  23. change_str = '.method protected onResume()V'
  24. str = '.method public onResume()V\n' \
  25. 'invoke-static {}, Lcom/kf/framework/SDKPluginWrapper;->onResume()V'
  26. cont = cont.replace(change_str, str)
  27. change_str_1 = '.method protected onPause()V'
  28. str_1 = '.method public onPause()V\n' \
  29. 'invoke-static {}, Lcom/kf/framework/SDKPluginWrapper;->onPause()V'
  30. cont = cont.replace(change_str_1, str_1)
  31. logging.info('replace_str: ' + cont)
  32. with open(goal_file, 'w+') as tf:
  33. tf.write(cont)
  34. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  35. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  36. if channelSdkInfo['id'] == '549':
  37. replace_life_method(decompileDir)
  38. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  39. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  40. if channelSdkInfo['id'] == '591' or channelSdkInfo['id'] == '549':
  41. s1 = os.path.join(decompileDir, "smali_classes2")
  42. if os.path.exists(s1):
  43. smali_classes_new = create_mutil_smali(decompileDir)
  44. s3 = os.path.join(decompileDir, smali_classes_new)
  45. list_package = ["com"]
  46. if not os.path.exists(s3):
  47. distutils.dir_util.mkpath(s3)
  48. move_package(s1, s3, list_package)
  49. if channelSdkInfo['id'] == '512' or channelSdkInfo['id'] == '589':
  50. s1 = os.path.join(decompileDir, "smali_classes2","com")
  51. if os.path.exists(s1):
  52. smali_classes_new = create_mutil_smali(decompileDir)
  53. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  54. list_package = ["netease","qiniu","sina","squareup","tencent","thinking","unity3d","wechat","yingxiong"]
  55. if not os.path.exists(s3):
  56. distutils.dir_util.mkpath(s3)
  57. move_package(s1, s3, list_package)
  58. if channelSdkInfo['id'] == '597':
  59. move(decompileDir)
  60. else:
  61. ""
  62. def move(decompileDir):
  63. s1 = os.path.join(decompileDir, "smali_classes2/com")
  64. smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
  65. s3 = os.path.join(decompileDir, smali_classes_new, "com")
  66. list_package = ["alibaba","aliyun","baidu","bdchero","bloc","crisisfire","example","gme","google","hero","hu","netease","qiniu","sina","squareup"]
  67. if not os.path.exists(s3):
  68. distutils.dir_util.mkpath(s3)
  69. gw_apk_tool.move_package(s1, s3, list_package)
  70. def create_mutil_smali(decompileDir):
  71. f_idx = 2
  72. while True:
  73. # tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  74. tmp = os.path.join(decompileDir, 'smali_classes%d' % f_idx)
  75. tmp = tmp.replace('\\', '/')
  76. tmp = re.sub('/+', '/', tmp)
  77. if os.path.exists(tmp):
  78. f_idx += 1
  79. else:
  80. smali_classes2_dir = tmp
  81. break
  82. # endwhile
  83. os.mkdir(smali_classes2_dir)
  84. return smali_classes2_dir
  85. def move_package(s1, s3, list_package):
  86. for d in list_package:
  87. src = os.path.join(s1, d)
  88. if os.path.exists(src):
  89. dst = os.path.join(s3, d)
  90. distutils.dir_util.copy_tree(src, dst)
  91. distutils.dir_util.remove_tree(src)
  92. if __name__ == '__main__':
  93. replace_life_method("D:\\work\\xmy")