script.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. sdk_id = channelSdkInfo['id']
  16. if sdk_id == "512":
  17. gw_data_center.pack_small = False
  18. if sdk_id == "549":
  19. gw_data_center.pack_small = False
  20. gw_apk_tool.__apk_tool__ = 'apktool_2.6.0.jar'
  21. def script_first(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  22. return
  23. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  24. return
  25. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  26. sdk_id = channelSdkInfo['id']
  27. if sdk_id == "597":
  28. # f_idx = 3
  29. # tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  30. # tmp = tmp.replace('\\', '/')
  31. # tmp = re.sub('/+', '/', tmp)
  32. # androidx = tmp + '/androidx'
  33. #
  34. # if os.path.exists(androidx):
  35. # new_dex_dir = create_mutil_smali(decompileDir)
  36. # move_package(tmp, new_dex_dir, ["androidx"])
  37. #
  38. move_androidx(decompileDir,"smali_classes3")
  39. move_androidx(decompileDir,"smali_classes4")
  40. # endwhile
  41. if sdk_id == "549" or sdk_id == "591":
  42. f_idx = 5
  43. # while True:
  44. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  45. tmp = tmp.replace('\\', '/')
  46. tmp = re.sub('/+', '/', tmp)
  47. androidx = tmp + '/com/netease'
  48. if os.path.exists(androidx):
  49. new_dex_dir = create_mutil_smali(decompileDir)
  50. dst = new_dex_dir + '/com/netease'
  51. move_package(androidx, dst, ["pharos", "stzb", "unisdk"])
  52. # break
  53. # if not os.path.exists(tmp):
  54. # break
  55. return
  56. def create_mutil_smali(decompileDir):
  57. f_idx = 2
  58. while True:
  59. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  60. tmp = tmp.replace('\\', '/')
  61. tmp = re.sub('/+', '/', tmp)
  62. if os.path.exists(tmp):
  63. f_idx += 1
  64. else:
  65. smali_classes2_dir = tmp
  66. break
  67. # endwhile
  68. os.mkdir(smali_classes2_dir)
  69. return smali_classes2_dir
  70. def move_package(s1, s3, list_package):
  71. for d in list_package:
  72. src = os.path.join(s1, d)
  73. if os.path.exists(src):
  74. dst = os.path.join(s3, d)
  75. distutils.dir_util.copy_tree(src, dst)
  76. distutils.dir_util.remove_tree(src)
  77. def is_reverse_qihoo(file):
  78. with open(file, 'r+') as f:
  79. file_str = f.read()
  80. if 'KFSDK' in file_str:
  81. return True
  82. else:
  83. return False
  84. def replace_init_code(decompileDir):
  85. smali_files = glob.glob(os.path.join(decompileDir, 'smali*/com/qihoo/'))
  86. if len(smali_files) >= 1:
  87. iter_smali = iter(smali_files)
  88. while True:
  89. try:
  90. qihoo_file_path = iter_smali.next()
  91. file = os.path.join(qihoo_file_path, 'gamecenter/sdk/matrix/Matrix.smali')
  92. if os.path.exists(file):
  93. logging.info('Matrix exits in %s' % qihoo_file_path)
  94. if is_reverse_qihoo(file):
  95. with open(file, 'r+') as f:
  96. cont = f.read()
  97. change_str = '0x82c'
  98. str = '0x82b'
  99. cont = cont.replace(change_str, str)
  100. logging.info('replace_str: ' + cont)
  101. with open(file, 'w+') as tf:
  102. tf.write(cont)
  103. except StopIteration:
  104. break
  105. def replace_application(extract_dir):
  106. goal_file = os.path.join(extract_dir, 'smali_classes3/com/lilithgame/sgame/wxapi/QihooApplication.smali')
  107. print(os.path.isfile(goal_file))
  108. if os.path.isfile(goal_file):
  109. logging.info('method_proceed: ' + 'goal_file')
  110. print(goal_file)
  111. with open(goal_file, 'r+') as f:
  112. cont = f.read()
  113. change_str = 'Landroid/support/multidex/MultiDexApplication'
  114. str = 'Lcom/kf/framework/KFApplication'
  115. cont = cont.replace(change_str, str)
  116. logging.info('replace_str: ' + cont)
  117. with open(goal_file, 'w+') as tf:
  118. tf.write(cont)
  119. # 移动androidx
  120. def move_androidx(decompileDir, smali_dir):
  121. s1 = os.path.join(decompileDir, smali_dir, "androidx")
  122. if os.path.exists(s1):
  123. smali_classes2_dir = create_mutil_smali(decompileDir)
  124. s3 = os.path.join(smali_classes2_dir, "androidx")
  125. if not os.path.exists(s3):
  126. distutils.dir_util.mkpath(s3)
  127. move_package(s1, s3, ["activity", "annotation", "appcompat", "arch", "asynclayoutinflater", "browser"])
  128. s1 = os.path.join(decompileDir, smali_dir, "androidx")
  129. if os.path.exists(s1):
  130. smali_classes2_dir = create_mutil_smali(decompileDir)
  131. s3 = os.path.join(smali_classes2_dir, "androidx")
  132. if not os.path.exists(s3):
  133. distutils.dir_util.mkpath(s3)
  134. move_package(s1, s3,
  135. ["tracing", "transition", "vectordrawable", "versionedparcelable", "viewpager", "viewpager2",
  136. "webkit", "work"])
  137. s1 = os.path.join(decompileDir, smali_dir, "androidx")
  138. if os.path.exists(s1):
  139. smali_classes2_dir = create_mutil_smali(decompileDir)
  140. s3 = os.path.join(smali_classes2_dir, "androidx")
  141. if not os.path.exists(s3):
  142. distutils.dir_util.mkpath(s3)
  143. move_package(s1, s3, ["cardview", "collection", "concurrent", "constraintlayout", "coordinatorlayout", "core",
  144. "cursoradapter", "customview", "documentfile", "drawerlayout", "dynamicanimation"])
  145. s1 = os.path.join(decompileDir, smali_dir, "androidx")
  146. if os.path.exists(s1):
  147. smali_classes2_dir = create_mutil_smali(decompileDir)
  148. s3 = os.path.join(smali_classes2_dir, "androidx")
  149. if not os.path.exists(s3):
  150. distutils.dir_util.mkpath(s3)
  151. move_package(s1, s3, ["emoji2", "fragment", "inspection", "interpolator"])
  152. s1 = os.path.join(decompileDir, smali_dir, "androidx")
  153. if os.path.exists(s1):
  154. smali_classes2_dir = create_mutil_smali(decompileDir)
  155. s3 = os.path.join(smali_classes2_dir, "androidx")
  156. if not os.path.exists(s3):
  157. distutils.dir_util.mkpath(s3)
  158. move_package(s1, s3, ["print", "recyclerview", "resourceinspection", "room", "savedstate", "security",
  159. "slidingpanelayout", "sqlite", "startup", "swiperefreshlayout"])
  160. s1 = os.path.join(decompileDir, smali_dir, "androidx")
  161. if os.path.exists(s1):
  162. smali_classes2_dir = create_mutil_smali(decompileDir)
  163. s3 = os.path.join(smali_classes2_dir, "androidx")
  164. if not os.path.exists(s3):
  165. distutils.dir_util.mkpath(s3)
  166. move_package(s1, s3, ["media", "multidex", "navigation"])
  167. s1 = os.path.join(decompileDir, smali_dir, "androidx")
  168. if os.path.exists(s1):
  169. smali_classes2_dir = create_mutil_smali(decompileDir)
  170. s3 = os.path.join(smali_classes2_dir, "androidx")
  171. if not os.path.exists(s3):
  172. distutils.dir_util.mkpath(s3)
  173. move_package(s1, s3, ["legacy", "lifecycle", "loader", "localbroadcastmanager"])
  174. # androidx 移动完毕
  175. if __name__ == '__main__':
  176. replace_init_code("D:\work\lyjymb")