script.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # coding:utf8
  2. __author__ = 'dong'
  3. import os
  4. import logging
  5. import xml.dom.minidom
  6. import re
  7. import shutil
  8. import glob
  9. from xml.etree.ElementTree import ElementTree, Element
  10. import distutils.dir_util
  11. import gw_file_system
  12. import gw_data_center
  13. import gw_apk_tool
  14. def script_init(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  15. return
  16. sdk_id = channelSdkInfo['id']
  17. # if sdk_id == "544":
  18. # gw_data_center.pack_small = False
  19. # gw_apk_tool.__apk_tool__ = 'apktool_2.3.4.jar'
  20. # gw_apk_tool.__apk_tool__ = 'apktool_2.4.1.jar'
  21. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  22. # logging.info('------------SDK:'+SDK)
  23. # logging.info('------------decompileDir:'+decompileDir)
  24. # logging.info('------------channelSdkInfo:'+str(channelSdkInfo))
  25. # logging.info('------------new_game_channel_info:'+str(new_game_channel_info))
  26. # logging.info('------------gameInfo:'+str(gameInfo))
  27. # logging.info("------rm baidu smali------")
  28. # restdir = decompileDir+"/"+"smali_classes2/com/baidu/gamesdk"
  29. # if os.path.exists(restdir):
  30. # shutil.rmtree(restdir)
  31. sdk_id = channelSdkInfo['id']
  32. if sdk_id == '512': # A渠道
  33. s1 = os.path.join(decompileDir, "smali", "com")
  34. smali_classes2_dir = create_mutil_smali(decompileDir)
  35. s3 = os.path.join(smali_classes2_dir, "com")
  36. list_package = ["coolcloud", "dataeye", "example"]
  37. if not os.path.exists(s3):
  38. distutils.dir_util.mkpath(s3)
  39. move_package(s1, s3, list_package)
  40. if sdk_id == '549':
  41. s1 = os.path.join(decompileDir, "smali_classes4", "com")
  42. smali_classes2_dir = create_mutil_smali(decompileDir)
  43. s3 = os.path.join(smali_classes2_dir, "com")
  44. list_package = ["netease"]
  45. if not os.path.exists(s3):
  46. distutils.dir_util.mkpath(s3)
  47. move_package(s1, s3, list_package)
  48. logging.info("-----debug-----")
  49. def create_mutil_smali(decompileDir):
  50. f_idx = 2
  51. while True:
  52. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  53. tmp = tmp.replace('\\', '/')
  54. tmp = re.sub('/+', '/', tmp)
  55. if os.path.exists(tmp):
  56. f_idx += 1
  57. else:
  58. smali_classes2_dir = tmp
  59. break
  60. # endwhile
  61. os.mkdir(smali_classes2_dir)
  62. return smali_classes2_dir
  63. def move_package(s1, s3, list_package):
  64. for d in list_package:
  65. src = os.path.join(s1, d)
  66. if os.path.exists(src):
  67. dst = os.path.join(s3, d)
  68. distutils.dir_util.copy_tree(src, dst)
  69. distutils.dir_util.remove_tree(src)
  70. def is_reverse_qihoo(file):
  71. with open(file, 'r+') as f:
  72. file_str = f.read()
  73. if 'KFSDK' in file_str:
  74. return True
  75. else:
  76. return False
  77. def replace_init_code(decompileDir):
  78. smali_files = glob.glob(os.path.join(decompileDir, 'smali*/com/qihoo/'))
  79. if len(smali_files) >= 1:
  80. iter_smali = iter(smali_files)
  81. while True:
  82. try:
  83. qihoo_file_path = iter_smali.next()
  84. file = os.path.join(qihoo_file_path, 'gamecenter/sdk/matrix/Matrix.smali')
  85. if os.path.exists(file):
  86. logging.info('Matrix exits in %s' % qihoo_file_path)
  87. if is_reverse_qihoo(file):
  88. with open(file, 'r+') as f:
  89. cont = f.read()
  90. change_str = '0x82c'
  91. str = '0x82b'
  92. cont = cont.replace(change_str, str)
  93. logging.info('replace_str: ' + cont)
  94. with open(file, 'w+') as tf:
  95. tf.write(cont)
  96. except StopIteration:
  97. break
  98. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  99. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  100. if channelSdkInfo['SDKName'] == 'reversefor360':
  101. replace_application(decompileDir)
  102. replace_init_code(decompileDir)
  103. def replace_application(extract_dir):
  104. goal_file = os.path.join(extract_dir, 'smali_classes3/com/lilithgame/sgame/wxapi/QihooApplication.smali')
  105. print(os.path.isfile(goal_file))
  106. if os.path.isfile(goal_file):
  107. logging.info('method_proceed: ' + 'goal_file')
  108. print(goal_file)
  109. with open(goal_file, 'r+') as f:
  110. cont = f.read()
  111. change_str = 'Landroid/support/multidex/MultiDexApplication'
  112. str = 'Lcom/kf/framework/KFApplication'
  113. cont = cont.replace(change_str, str)
  114. logging.info('replace_str: ' + cont)
  115. with open(goal_file, 'w+') as tf:
  116. tf.write(cont)
  117. if __name__ == '__main__':
  118. replace_init_code("D:\work\lyjymb")