script.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. # coding:utf8
  2. __author__ = 'yiqibuyu360'
  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. from xml.etree import ElementTree as ET
  14. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  15. def script_init(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  16. gw_data_center.pack_small = False
  17. def script_first(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  18. logging.info("-----debug exec first func-----")
  19. # game_apk = os.path.join(decompileDir, "game.apk")
  20. game_apk = decompileDir + "/../game.apk"
  21. if os.path.exists(game_apk):
  22. gw_file_system.delete_apk_file_by_aapt(game_apk, "assets/39285EFA.dex")
  23. logging.info("-----debug-----")
  24. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  25. assets_dex = os.path.join(decompileDir, "../39285EFA.dex")
  26. assets_dir = os.path.join(decompileDir, "assets/39285EFA.dex")
  27. logging.info(assets_dex)
  28. logging.info(assets_dir)
  29. logging.info(SDK)
  30. if os.path.exists(assets_dex):
  31. gw_file_system.copy_file(assets_dex, assets_dir)
  32. def create_mutil_smali(decompileDir):
  33. f_idx = 2
  34. while True:
  35. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  36. tmp = tmp.replace('\\', '/')
  37. tmp = re.sub('/+', '/', tmp)
  38. if os.path.exists(tmp):
  39. f_idx += 1
  40. else:
  41. smali_classes2_dir = tmp
  42. break
  43. # endwhile
  44. os.mkdir(smali_classes2_dir)
  45. return smali_classes2_dir
  46. def move_package(s1, s3, list_package):
  47. for d in list_package:
  48. src = os.path.join(s1, d)
  49. if os.path.exists(src):
  50. dst = os.path.join(s3, d)
  51. distutils.dir_util.copy_tree(src, dst)
  52. distutils.dir_util.remove_tree(src)
  53. def modify_manifest(decompileDir):
  54. ET.register_namespace('android', ANDROID_NS)
  55. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  56. root_node = ET.parse(xmlparse)
  57. root = root_node.getroot()
  58. name = '{' + ANDROID_NS + '}name'
  59. authorities = '{' + ANDROID_NS + '}authorities'
  60. package_name = root.attrib.get('package')
  61. if package_name == None:
  62. return
  63. providers = root.findall('./application/provider')
  64. if providers != None:
  65. for provider in providers:
  66. providerName = provider.attrib.get(name)
  67. if 'com.game.sdk.provider.GameFileProvider' == providerName:
  68. provider.set(authorities, package_name + ".sdkinsapk")
  69. if 'android.support.v4.content.FileProvider' == providerName:
  70. root.find('./application').remove(provider)
  71. root_node.write(xmlparse, 'utf-8')
  72. def del_android(decompileDir):
  73. android = os.path.join(decompileDir, 'smali/android/support/v4')
  74. if os.path.exists(android):
  75. shutil.rmtree(android)
  76. def add_checkSelfPermission(extract_dir):
  77. goal_file = os.path.join(extract_dir, 'smali/android/support/haojieru/v4/content/ContextCompat.smali')
  78. if os.path.isfile(goal_file):
  79. with open(goal_file, 'r+') as f:
  80. lines = f.readlines()
  81. method = ['.method public static checkSelfPermission(Landroid/content/Context;Ljava/lang/String;)I\n',
  82. ' .locals 2\n',
  83. ' .param p0, "context" # Landroid/content/Context;\n',
  84. ' .annotation build Landroid/support/annotation/NonNull;\n',
  85. ' .end annotation\n',
  86. ' .end param\n',
  87. ' .param p1, "permission" # Ljava/lang/String;\n',
  88. ' .annotation build Landroid/support/annotation/NonNull;\n',
  89. ' .end annotation\n',
  90. ' .end param\n',
  91. ' if-eqz p1, :cond_0\n',
  92. ' invoke-static {}, Landroid/os/Process;->myPid()I\n',
  93. ' move-result v0\n',
  94. ' invoke-static {}, Landroid/os/Process;->myUid()I\n',
  95. ' move-result v1\n',
  96. ' invoke-virtual {p0, p1, v0, v1}, Landroid/content/Context;->checkPermission(Ljava/lang/String;II)I\n',
  97. ' move-result v0\n',
  98. ' return v0\n',
  99. ' :cond_0\n',
  100. ' new-instance v0, Ljava/lang/IllegalArgumentException;\n',
  101. ' const-string v1, "permission is null"\n',
  102. ' invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V\n',
  103. ' throw v0\n',
  104. '.end method']
  105. for i in method:
  106. lines.append(i)
  107. with open(goal_file, 'w') as fl:
  108. fl.write(''.join(lines))
  109. def del_okhttp_okio(extract_dir):
  110. okhttp3 = os.path.join(extract_dir, 'smali/okhttp3')
  111. if os.path.exists(okhttp3):
  112. shutil.rmtree(okhttp3)
  113. okio = os.path.join(extract_dir, 'smali/okio')
  114. if os.path.exists(okio):
  115. shutil.rmtree(okio)
  116. def replace_emoj_textview(extract_dir):
  117. goal_file = os.path.join(extract_dir, 'res/layout/recycler_mail_list_item.xml')
  118. print(os.path.isfile(goal_file))
  119. if os.path.isfile(goal_file):
  120. logging.info('method_proceed: ' + 'goal_file')
  121. print(goal_file)
  122. with open(goal_file, 'r+') as f:
  123. cont = f.read()
  124. change_str = 'com.elex.chatservice.view.emoj.EmojTextView'
  125. str = 'TextView'
  126. cont = cont.replace(change_str, str)
  127. logging.info('replace_str: ' + cont)
  128. with open(goal_file, 'w+') as tf:
  129. tf.write(cont)
  130. goal_file_2 = os.path.join(extract_dir, 'res/layout/msgitem_message_receive.xml')
  131. print(os.path.isfile(goal_file_2))
  132. if os.path.isfile(goal_file_2):
  133. logging.info('method_proceed: ' + 'goal_file')
  134. print(goal_file_2)
  135. with open(goal_file_2, 'r+') as f:
  136. cont = f.read()
  137. change_str = 'com.elex.chatservice.view.emoj.EmojTextView'
  138. str = 'TextView'
  139. cont = cont.replace(change_str, str)
  140. logging.info('replace_str: ' + cont)
  141. with open(goal_file_2, 'w+') as tf:
  142. tf.write(cont)
  143. goal_file_3 = os.path.join(extract_dir, 'res/layout/msgitem_message_send.xml')
  144. print(os.path.isfile(goal_file_3))
  145. if os.path.isfile(goal_file_3):
  146. logging.info('method_proceed: ' + 'goal_file')
  147. print(goal_file_3)
  148. with open(goal_file_3, 'r+') as f:
  149. cont = f.read()
  150. change_str = 'com.elex.chatservice.view.emoj.EmojTextView'
  151. str = 'TextView'
  152. cont = cont.replace(change_str, str)
  153. logging.info('replace_str: ' + cont)
  154. with open(goal_file_3, 'w+') as tf:
  155. tf.write(cont)
  156. def replace_weboshare(decompileDir):
  157. src = os.path.join(decompileDir.replace('extract', ''), 'WeiBoShare.smali')
  158. print(src)
  159. logging.info('--------------src path:' + src)
  160. dest = os.path.join(decompileDir, 'smali_classes4/com/clash/of/share/WeiBoShare.smali')
  161. print(dest)
  162. logging.info('--------------dest path:' + dest)
  163. shutil.copyfile(src, dest)
  164. def comment_logout_method(decompileDir):
  165. goal_file = os.path.join(decompileDir, 'smali/com/gameworks/sdk/standard/core/SDKKitCore.smali')
  166. print(os.path.isfile(goal_file))
  167. if os.path.isfile(goal_file):
  168. logging.info('method_proceed: ' + 'goal_file')
  169. print(goal_file)
  170. with open(goal_file, 'r+') as f:
  171. cont = f.read()
  172. change_str = 'invoke-virtual {v0}, Lcom/game/sdk/HuosdkManager;->logout()V'
  173. str = '#invoke-virtual {v0}, Lcom/game/sdk/HuosdkManager;->logout()V'
  174. cont = cont.replace(change_str, str)
  175. logging.info('replace_str: ' + cont)
  176. with open(goal_file, 'w+') as tf:
  177. tf.write(cont)
  178. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  179. sdk_id = channelSdkInfo['id']
  180. # 坚果渠道
  181. if (sdk_id == "413"):
  182. del_android(decompileDir)
  183. replace_emoj_textview(decompileDir)
  184. # 遥望渠道id
  185. if (sdk_id == "412"):
  186. add_checkSelfPermission(decompileDir)
  187. # 小七手游id 389
  188. if (sdk_id == "389"):
  189. del_okhttp_okio(decompileDir)
  190. # 游戏fan id 380
  191. if (sdk_id == '380'):
  192. replace_emoj_textview(decompileDir)
  193. modify_manifest(decompileDir)
  194. # 掌上科技
  195. if channelSdkInfo['SDKName'] == 'zskj':
  196. replace_weboshare(decompileDir)
  197. comment_logout_method(decompileDir)
  198. def handle_public_xml(public_xml_path):
  199. if not os.path.exists(public_xml_path):
  200. logging.info('public_xml is null: ' + public_xml_path)
  201. return
  202. new_lines = []
  203. with open(public_xml_path, 'r+') as f:
  204. for line in f.readlines():
  205. # l = line.strip()
  206. if line.find("wrap_content") > -1:
  207. continue
  208. new_lines.append(line)
  209. f.seek(0)
  210. f.truncate()
  211. f.writelines(new_lines)
  212. return
  213. if __name__ == '__main__':
  214. # script("", "E:\\apk\\youhua\\LYJY360_12412_360逆向_1.23.00", "", "", "")
  215. handle_public_xml("public.xml")