script.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. def script_second(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  12. logging.info('script_second: ' + str(channel_sdk_info))
  13. # 逆向渠道id
  14. public_xml = os.path.join(extract_dir, "res/values/drawables.xml")
  15. handle_public_xml(public_xml, "APKTOOL")
  16. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  17. handle_public_xml(public_xml, "APKTOOL")
  18. return
  19. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  20. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  21. if channelSdkInfo['SDKName'] == 'reverseforkupai':
  22. del_coolcloud(decompileDir)
  23. if channelSdkInfo['id'] == '549':
  24. replace_life_method(decompileDir)
  25. sdk_id = channelSdkInfo['id']
  26. if sdk_id == "597":
  27. # s1 = os.path.join(decompileDir, "smali_classes2")
  28. # if os.path.exists(s1):
  29. # smali_classes2_dir = create_mutil_smali(decompileDir)
  30. # s3 = smali_classes2_dir
  31. # if not os.path.exists(s3):
  32. # distutils.dir_util.mkpath(s3)
  33. # move_package(s1, s3, ["androidx"])
  34. extract_dir = decompileDir
  35. s1 = os.path.join(extract_dir, "smali_classes2", "androidx")
  36. smali_dir = create_mutil_smali(extract_dir)
  37. s3 = os.path.join(smali_dir, "androidx")
  38. list_package = ["legacy", "lifecycle", "loader", "localbroadcastmanager", "media", "print", "slidingpanelayout",
  39. "swiperefreshlayout", "vectordrawable", "versionedparcelable", "viewpager"]
  40. if not os.path.exists(s3):
  41. distutils.dir_util.mkpath(s3)
  42. move_package(s1, s3, list_package)
  43. s1 = os.path.join(extract_dir, "smali_classes2", "androidx")
  44. smali_dir = create_mutil_smali(extract_dir)
  45. s3 = os.path.join(smali_dir, "androidx")
  46. list_package = ["annotation", "appcompat", "arch", "asynclayoutinflater", "browser", "collection", "concurrent",
  47. "coordinatorlayout", "core", "cursoradapter", "customview", "documentfile", "drawerlayout",
  48. "fragment", "interpolator"]
  49. if not os.path.exists(s3):
  50. distutils.dir_util.mkpath(s3)
  51. move_package(s1, s3, list_package)
  52. move_597(decompileDir)
  53. def move_597(decompileDir):
  54. s1 = os.path.join(decompileDir, "smali_classes2/com")
  55. smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
  56. s3 = os.path.join(decompileDir, smali_classes_new, "com")
  57. list_package = ["qiniu","reyun","squareup","tencent","tools","unity","uwa","youme","RenderHeads","sina","taiyouxi","tendcloud","twobigears","unity3d","yingxiong"]
  58. if not os.path.exists(s3):
  59. distutils.dir_util.mkpath(s3)
  60. gw_apk_tool.move_package(s1, s3, list_package)
  61. def replace_life_method(extract_dir):
  62. goal_file = glob.glob(os.path.join(extract_dir, 'smali*/com/taiyouxi/a3k/MainActivity.smali'))[0]
  63. goal_file1 = glob.glob(os.path.join(extract_dir, 'smali*/com/yog/kothoth/utils/RequestParamUtil.smali'))[0]
  64. goal_file2 = glob.glob(os.path.join(extract_dir, 'smali*/com/yog/kothoth/data/JsonResult.smali'))[0]
  65. print(os.path.isfile(goal_file))
  66. if os.path.isfile(goal_file):
  67. logging.info('method_proceed: ' + 'goal_file')
  68. print(goal_file)
  69. with open(goal_file, 'r+') as f:
  70. cont = f.read()
  71. change_str = '.method protected onResume()V'
  72. str = '.method public onResume()V\n' \
  73. 'invoke-static {}, Lcom/kf/framework/SDKPluginWrapper;->onResume()V'
  74. cont = cont.replace(change_str, str)
  75. change_str_1 = '.method protected onPause()V'
  76. str_1 = '.method public onPause()V\n' \
  77. 'invoke-static {}, Lcom/kf/framework/SDKPluginWrapper;->onPause()V'
  78. cont = cont.replace(change_str_1, str_1)
  79. logging.info('replace_str: ' + cont)
  80. with open(goal_file, 'w+') as tf:
  81. tf.write(cont)
  82. if os.path.isfile(goal_file1):
  83. logging.info('method_proceed: ' + 'goal_file1')
  84. print(goal_file1)
  85. with open(goal_file1, 'r+') as f:
  86. cont = f.read()
  87. change_str = 'Lcom/hjr/gameplatform/aes/AESUtil'
  88. str = 'Lcom/kf/framework/util/AESUtil'
  89. cont = cont.replace(change_str, str)
  90. logging.info('replace_str: ' + cont)
  91. with open(goal_file1, 'w+') as tf:
  92. tf.write(cont)
  93. if os.path.isfile(goal_file2):
  94. logging.info('method_proceed: ' + 'goal_file2')
  95. print(goal_file2)
  96. with open(goal_file2, 'r+') as f:
  97. cont = f.read()
  98. change_str = 'Lcom/hjr/gameplatform/aes/AESUtil'
  99. str = 'Lcom/kf/framework/util/AESUtil'
  100. cont = cont.replace(change_str, str)
  101. logging.info('replace_str: ' + cont)
  102. with open(goal_file2, 'w+') as tf:
  103. tf.write(cont)
  104. def is_reverse_coolcloud(file):
  105. with open(file, 'r+') as f:
  106. file_str = f.read()
  107. if 'KFSDK' in file_str:
  108. return True
  109. else:
  110. return False
  111. def del_coolcloud(decompileDir):
  112. smali_files = glob.glob(os.path.join(decompileDir, 'smali*/com/coolcloud/'))
  113. if len(smali_files) > 1:
  114. iter_smali = iter(smali_files)
  115. while True:
  116. try:
  117. coolcloud_file_path = iter_smali.next()
  118. file = os.path.join(coolcloud_file_path, 'uac/android/api/Coolcloud.smali')
  119. if os.path.exists(file):
  120. logging.info('Coolcloud exits in %s' % coolcloud_file_path)
  121. if not is_reverse_coolcloud(file):
  122. logging.info("delete coolcloud in %s" % coolcloud_file_path)
  123. shutil.rmtree(coolcloud_file_path)
  124. else:
  125. pass
  126. else:
  127. logging.info('Coolcloud not exits in %s' % coolcloud_file_path)
  128. shutil.rmtree(coolcloud_file_path)
  129. except StopIteration:
  130. break
  131. def handle_public_xml(public_xml_path, remove_node):
  132. if not os.path.exists(public_xml_path):
  133. logging.info('public_xml is null: ' + public_xml_path)
  134. return
  135. new_lines = []
  136. with open(public_xml_path, 'r+') as f:
  137. for line in f.readlines():
  138. # l = line.strip()
  139. if line.find(remove_node) > -1:
  140. continue
  141. new_lines.append(line)
  142. f.seek(0)
  143. f.truncate()
  144. f.writelines(new_lines)
  145. return
  146. def move_package(s1, s3, list_package):
  147. for d in list_package:
  148. src = os.path.join(s1, d)
  149. if os.path.exists(src):
  150. dst = os.path.join(s3, d)
  151. distutils.dir_util.copy_tree(src, dst)
  152. distutils.dir_util.remove_tree(src)
  153. def create_mutil_smali(decompileDir):
  154. f_idx = 2
  155. while True:
  156. tmp = os.path.join(decompileDir, 'smali_classes%d' % f_idx)
  157. tmp = tmp.replace('\\', '/')
  158. tmp = re.sub('/+', '/', tmp)
  159. if os.path.exists(tmp):
  160. f_idx += 1
  161. else:
  162. smali_classes2_dir = tmp
  163. break
  164. # endwhile
  165. os.mkdir(smali_classes2_dir)
  166. return smali_classes2_dir
  167. if __name__ == '__main__':
  168. replace_life_method("D:\\work\\jws")