script.py 7.1 KB

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