script.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. def script_first(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  17. return
  18. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  19. # logging.info('------------SDK:'+SDK)
  20. # logging.info('------------decompileDir:'+decompileDir)
  21. # logging.info('------------channelSdkInfo:'+str(channelSdkInfo))
  22. # logging.info('------------new_game_channel_info:'+str(new_game_channel_info))
  23. # logging.info('------------gameInfo:'+str(gameInfo))
  24. # logging.info("------rm baidu smali------")
  25. # restdir = decompileDir+"/"+"smali_classes2/com/baidu/gamesdk"
  26. # if os.path.exists(restdir):
  27. # shutil.rmtree(restdir)
  28. return
  29. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  30. sdk_id = channelSdkInfo['id']
  31. if sdk_id == "597":
  32. s1 = os.path.join(decompileDir, "smali_classes4")
  33. if os.path.exists(s1):
  34. smali_classes2_dir = create_mutil_smali(decompileDir)
  35. s3 = smali_classes2_dir
  36. if not os.path.exists(s3):
  37. distutils.dir_util.mkpath(s3)
  38. move_package(s1, s3, ["androidx", "android"])
  39. s1 = os.path.join(decompileDir, "smali_classes4", "com")
  40. if os.path.exists(s1):
  41. smali_classes2_dir = create_mutil_smali(decompileDir)
  42. s3 = os.path.join(smali_classes2_dir, "com")
  43. if not os.path.exists(s3):
  44. distutils.dir_util.mkpath(s3)
  45. move_package_one(s1, s3)
  46. s1 = os.path.join(decompileDir, "smali_classes5","com","netease")
  47. if os.path.exists(s1):
  48. smali_classes2_dir = create_mutil_smali(decompileDir)
  49. s3 = os.path.join(smali_classes2_dir,"com","netease")
  50. if not os.path.exists(s3):
  51. distutils.dir_util.mkpath(s3)
  52. move_package(s1, s3, ["mpay", "ngpush", "ntunisdk", "party", "unisdk"])
  53. if sdk_id == "549" or sdk_id=="591":
  54. s1 = os.path.join(decompileDir, "smali_classes7", "com")
  55. if os.path.exists(s1):
  56. smali_classes2_dir = create_mutil_smali(decompileDir)
  57. s3 = os.path.join(smali_classes2_dir, "com")
  58. if not os.path.exists(s3):
  59. distutils.dir_util.mkpath(s3)
  60. move_package(s1, s3, ["netease"])
  61. # s1 = os.path.join(decompileDir, "smali_classes8", "com")
  62. # if os.path.exists(s1):
  63. # smali_classes2_dir = create_mutil_smali(decompileDir)
  64. # s3 = os.path.join(smali_classes2_dir, "com")
  65. # if not os.path.exists(s3):
  66. # distutils.dir_util.mkpath(s3)
  67. # move_package(s1, s3, ["netease"])
  68. return
  69. def create_mutil_smali(decompileDir):
  70. f_idx = 2
  71. while True:
  72. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  73. tmp = tmp.replace('\\', '/')
  74. tmp = re.sub('/+', '/', tmp)
  75. if os.path.exists(tmp):
  76. f_idx += 1
  77. else:
  78. smali_classes2_dir = tmp
  79. break
  80. # endwhile
  81. os.mkdir(smali_classes2_dir)
  82. return smali_classes2_dir
  83. def move_package(s1, s3, list_package):
  84. for d in list_package:
  85. src = os.path.join(s1, d)
  86. if os.path.exists(src):
  87. dst = os.path.join(s3, d)
  88. distutils.dir_util.copy_tree(src, dst)
  89. distutils.dir_util.remove_tree(src)
  90. def is_reverse_qihoo(file):
  91. with open(file, 'r+') as f:
  92. file_str = f.read()
  93. if 'KFSDK' in file_str:
  94. return True
  95. else:
  96. return False
  97. def replace_init_code(decompileDir):
  98. smali_files = glob.glob(os.path.join(decompileDir, 'smali*/com/qihoo/'))
  99. if len(smali_files) >= 1:
  100. iter_smali = iter(smali_files)
  101. while True:
  102. try:
  103. qihoo_file_path = iter_smali.next()
  104. file = os.path.join(qihoo_file_path, 'gamecenter/sdk/matrix/Matrix.smali')
  105. if os.path.exists(file):
  106. logging.info('Matrix exits in %s' % qihoo_file_path)
  107. if is_reverse_qihoo(file):
  108. with open(file, 'r+') as f:
  109. cont = f.read()
  110. change_str = '0x82c'
  111. str = '0x82b'
  112. cont = cont.replace(change_str, str)
  113. logging.info('replace_str: ' + cont)
  114. with open(file, 'w+') as tf:
  115. tf.write(cont)
  116. except StopIteration:
  117. break
  118. def replace_application(extract_dir):
  119. goal_file = os.path.join(extract_dir, 'smali_classes3/com/lilithgame/sgame/wxapi/QihooApplication.smali')
  120. print(os.path.isfile(goal_file))
  121. if os.path.isfile(goal_file):
  122. logging.info('method_proceed: ' + 'goal_file')
  123. print(goal_file)
  124. with open(goal_file, 'r+') as f:
  125. cont = f.read()
  126. change_str = 'Landroid/support/multidex/MultiDexApplication'
  127. str = 'Lcom/kf/framework/KFApplication'
  128. cont = cont.replace(change_str, str)
  129. logging.info('replace_str: ' + cont)
  130. with open(goal_file, 'w+') as tf:
  131. tf.write(cont)
  132. def move_package(s1, s3, list_package):
  133. for d in list_package:
  134. src = os.path.join(s1, d)
  135. if os.path.exists(src):
  136. dst = os.path.join(s3, d)
  137. distutils.dir_util.copy_tree(src, dst)
  138. distutils.dir_util.remove_tree(src)
  139. def move_package_one(src, dst):
  140. if os.path.exists(src):
  141. distutils.dir_util.copy_tree(src, dst)
  142. distutils.dir_util.remove_tree(src)
  143. if __name__ == '__main__':
  144. replace_init_code("D:\work\lyjymb")