script.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. from xml.etree import ElementTree as ET
  12. import gw_file_system
  13. import gw_data_center
  14. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  15. def script_init(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  16. # gw_data_center.pack_small=True
  17. return
  18. def script_second(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  19. logging.info('script_second: ' + str(channel_sdk_info))
  20. # 逆向渠道id
  21. if channel_sdk_info['id'] == '549':
  22. # public_xml = os.path.join(extract_dir, "res/values/public.xml")
  23. # handle_public_xml(public_xml, "abc_list_pressed_holo_dark")
  24. #
  25. #
  26. # public_xml = os.path.join(extract_dir, "res/values/public.xml")
  27. # handle_public_xml(public_xml, "abc_list_selector_disabled_holo_dark")
  28. # public_xml = os.path.join(extract_dir, "res/layout/design_bottom_sheet_dialog.xml")
  29. # handle_public_xml(public_xml, "attr-private")
  30. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/public.xml")
  31. handle_public_xml(public_xml, "abc_list_pressed_holo_dark")
  32. #
  33. #
  34. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/public.xml")
  35. handle_public_xml(public_xml, "abc_list_selector_disabled_holo_dark")
  36. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/public.xml")
  37. handle_public_xml(public_xml, "abc_list_selector_background_transition_holo_dark")
  38. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/public.xml")
  39. handle_public_xml(public_xml, "abc_list_selector_holo_dark")
  40. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/public.xml")
  41. handle_public_xml(public_xml, "abc_item_background_holo_dark")
  42. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/styles.xml")
  43. handle_public_xml(public_xml, "abc_list_selector_holo_dark")
  44. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/styles.xml")
  45. handle_public_xml(public_xml, "abc_item_background_holo_dark")
  46. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable/abc_item_background_holo_dark.xml")
  47. if os.path.exists(public_xml):
  48. os.remove(public_xml)
  49. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable/abc_list_selector_background_transition_holo_dark.xml")
  50. if os.path.exists(public_xml):
  51. os.remove(public_xml)
  52. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable/abc_list_selector_holo_dark.xml")
  53. if os.path.exists(public_xml):
  54. os.remove(public_xml)
  55. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable-mdpi/abc_list_pressed_holo_dark.9.png")
  56. logging.info("public_xml:"+public_xml)
  57. if os.path.exists(public_xml):
  58. os.remove(public_xml)
  59. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable-hdpi/abc_list_pressed_holo_dark.9.png")
  60. if os.path.exists(public_xml):
  61. os.remove(public_xml)
  62. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable-xhdpi/abc_list_pressed_holo_dark.9.png")
  63. if os.path.exists(public_xml):
  64. os.remove(public_xml)
  65. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable-xxhdpi/abc_list_pressed_holo_dark.9.png")
  66. if os.path.exists(public_xml):
  67. os.remove(public_xml)
  68. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable-mdpi/abc_list_selector_disabled_holo_dark.9.png")
  69. if os.path.exists(public_xml):
  70. os.remove(public_xml)
  71. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable-hdpi/abc_list_selector_disabled_holo_dark.9.png")
  72. if os.path.exists(public_xml):
  73. os.remove(public_xml)
  74. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable-xhdpi/abc_list_selector_disabled_holo_dark.9.png")
  75. if os.path.exists(public_xml):
  76. os.remove(public_xml)
  77. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable-xxhdpi/abc_list_selector_disabled_holo_dark.9.png")
  78. if os.path.exists(public_xml):
  79. os.remove(public_xml)
  80. return
  81. def handle_public_xml(public_xml_path, remove_node):
  82. if not os.path.exists(public_xml_path):
  83. logging.info('public_xml is null: ' + public_xml_path)
  84. return
  85. new_lines = []
  86. with open(public_xml_path, 'r+') as f:
  87. for line in f.readlines():
  88. # l = line.strip()
  89. if line.find(remove_node) > -1:
  90. continue
  91. new_lines.append(line)
  92. f.seek(0)
  93. f.truncate()
  94. f.writelines(new_lines)
  95. return
  96. def script_after(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  97. if channel_sdk_info['id'] == '549':
  98. logging.info("-----after info-----")
  99. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  100. handle_public_xml(public_xml, "abc_list_pressed_holo_dark")
  101. #
  102. #
  103. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  104. handle_public_xml(public_xml, "abc_list_selector_disabled_holo_dark")
  105. logging.info("-----debug-----")
  106. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  107. logging.info("-----debug-----")
  108. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  109. if channelSdkInfo['id'] == '597':
  110. s1 = os.path.join(decompileDir, "smali_classes3")
  111. if os.path.exists(s1):
  112. smali_classes_new = create_mutil_smali(decompileDir)
  113. s3 = os.path.join(decompileDir, smali_classes_new)
  114. list_package = ["androidx"]
  115. if not os.path.exists(s3):
  116. distutils.dir_util.mkpath(s3)
  117. move_package(s1, s3, list_package)
  118. s1 = os.path.join(decompileDir, "smali_classes3","com")
  119. if os.path.exists(s1):
  120. smali_classes_new = create_mutil_smali(decompileDir)
  121. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  122. list_package = ["facebook","google","tencent","unity3d"]
  123. if not os.path.exists(s3):
  124. distutils.dir_util.mkpath(s3)
  125. move_package(s1, s3, list_package)
  126. s1 = os.path.join(decompileDir, "smali_classes4","com")
  127. if os.path.exists(s1):
  128. smali_classes_new = create_mutil_smali(decompileDir)
  129. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  130. list_package = ["sigmob","ss","tan"]
  131. if not os.path.exists(s3):
  132. distutils.dir_util.mkpath(s3)
  133. move_package(s1, s3, list_package)
  134. s1 = os.path.join(decompileDir, "smali_classes4","com")
  135. if os.path.exists(s1):
  136. smali_classes_new = create_mutil_smali(decompileDir)
  137. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  138. list_package = ["google","iab","ihoc"]
  139. if not os.path.exists(s3):
  140. distutils.dir_util.mkpath(s3)
  141. move_package(s1, s3, list_package)
  142. s1 = os.path.join(decompileDir, "smali_classes4","com")
  143. if os.path.exists(s1):
  144. smali_classes_new = create_mutil_smali(decompileDir)
  145. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  146. list_package = ["mbridge","platformad","qq"]
  147. if not os.path.exists(s3):
  148. distutils.dir_util.mkpath(s3)
  149. move_package(s1, s3, list_package)
  150. if channelSdkInfo['id'] == '591' or channelSdkInfo['id'] == '549':
  151. s1 = os.path.join(decompileDir, "smali_classes5","androidx")
  152. if os.path.exists(s1):
  153. smali_classes_new = create_mutil_smali(decompileDir)
  154. s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
  155. list_package = ["fragment","legacy","loader","media","recyclerview"," swiperefreshlayout","versionedparcelable","interpolator","lifecycle","localbroadcastmanager","print","slidingpanelayout","vectordrawable","viewpager"]
  156. if not os.path.exists(s3):
  157. distutils.dir_util.mkpath(s3)
  158. move_package(s1, s3, list_package)
  159. s1 = os.path.join(decompileDir, "smali_classes5")
  160. if os.path.exists(s1):
  161. smali_classes_new = create_mutil_smali(decompileDir)
  162. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  163. list_package = ["fragment","legacy","loader","media","recyclerview"," swiperefreshlayout","versionedparcelable","interpolator","lifecycle","localbroadcastmanager","print","slidingpanelayout","vectordrawable","viewpager"]
  164. if not os.path.exists(s3):
  165. distutils.dir_util.mkpath(s3)
  166. move_package(s1, s3, list_package)
  167. s1 = os.path.join(decompileDir, "smali_classes9","com/mbridge/msdk")
  168. if os.path.exists(s1):
  169. smali_classes_new = create_mutil_smali(decompileDir)
  170. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  171. list_package = ["optimize","out","playercommon","pluginFramework","reward","rover","shake","shell","splash","system","thrid","video","videocommon","widget"]
  172. if not os.path.exists(s3):
  173. distutils.dir_util.mkpath(s3)
  174. move_package(s1, s3, list_package)
  175. s1 = os.path.join(decompileDir, "smali_classes9","com/mbridge/msdk")
  176. if os.path.exists(s1):
  177. smali_classes_new = create_mutil_smali(decompileDir)
  178. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  179. list_package = ["a","b","click","e","interstitial"," mbbanner","mbjscommon","nativex","activity","banner","d","f","interstitialvideo","mbbid","mbnative","newinterstitial","advanced","c","dycreator","foundation","intervideo","mbdownload","mbsignalcommon"]
  180. if not os.path.exists(s3):
  181. distutils.dir_util.mkpath(s3)
  182. move_package(s1, s3, list_package)
  183. s1 = os.path.join(decompileDir, "smali_classes3","com/bytedance") # 从第11个开始都是移动的
  184. if os.path.exists(s1):
  185. smali_classes_new = create_mutil_smali(decompileDir)
  186. s3 = os.path.join(decompileDir, smali_classes_new,"com/bytedance")
  187. list_package = ["notpluginpro","pangle","sdk","tea"]
  188. if not os.path.exists(s3):
  189. distutils.dir_util.mkpath(s3)
  190. move_package(s1, s3, list_package)
  191. smali_classes_new = create_mutil_smali(decompileDir)
  192. s3 = os.path.join(decompileDir, smali_classes_new,"com/bytedance")
  193. list_package = ["ad","android","mapplog","mapplog_dr","msdk"]
  194. if not os.path.exists(s3):
  195. distutils.dir_util.mkpath(s3)
  196. move_package(s1, s3, list_package)
  197. s1 = os.path.join(decompileDir, "smali_classes3","com") # 从第11个开始都是移动的
  198. if os.path.exists(s1):
  199. smali_classes_new = create_mutil_smali(decompileDir)
  200. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  201. list_package = ["czhj"]
  202. if not os.path.exists(s3):
  203. distutils.dir_util.mkpath(s3)
  204. move_package(s1, s3, list_package)
  205. smali_classes_new = create_mutil_smali(decompileDir)
  206. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  207. list_package = ["mbridge"]
  208. if not os.path.exists(s3):
  209. distutils.dir_util.mkpath(s3)
  210. move_package(s1, s3, list_package)
  211. s1 = os.path.join(decompileDir, "smali_classes6","androidx") # 从第11个开始都是移动的
  212. if os.path.exists(s1):
  213. smali_classes_new = create_mutil_smali(decompileDir)
  214. s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
  215. list_package = ["interpolator","lifecycle","localbroadcastmanager","print","slidingpanelayout","vectordrawable","viewpager","legacy","loader","media","recyclerview","swiperefreshlayout","versionedparcelable"]
  216. if not os.path.exists(s3):
  217. distutils.dir_util.mkpath(s3)
  218. move_package(s1, s3, list_package)
  219. return
  220. def create_mutil_smali(decompileDir):
  221. f_idx = 2
  222. while True:
  223. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  224. tmp = tmp.replace('\\', '/')
  225. tmp = re.sub('/+', '/', tmp)
  226. if os.path.exists(tmp):
  227. f_idx += 1
  228. else:
  229. smali_classes2_dir = tmp
  230. break
  231. # endwhile
  232. os.mkdir(smali_classes2_dir)
  233. return smali_classes2_dir
  234. def move_package(s1, s3, list_package):
  235. for d in list_package:
  236. src = os.path.join(s1, d)
  237. if os.path.exists(src):
  238. dst = os.path.join(s3, d)
  239. distutils.dir_util.copy_tree(src, dst)
  240. distutils.dir_util.remove_tree(src)
  241. def move_package_one(src, dst):
  242. if os.path.exists(src):
  243. distutils.dir_util.copy_tree(src, dst)
  244. distutils.dir_util.remove_tree(src)
  245. change_map = {".super Landroid/app/Application;": ".super Lcom/kf/framework/KFApplication;",
  246. "invoke-direct {p0}, Landroid/app/Application;-><init>()V": "invoke-direct {p0}, Lcom/kf/framework/KFApplication;-><init>()V",
  247. "invoke-super {p0, p1}, Landroid/app/Application;->attachBaseContext(Landroid/content/Context;)V": "invoke-super {p0, p1}, Lcom/kf/framework/KFApplication;->attachBaseContext(Landroid/content/Context;)V",
  248. "invoke-super {p0}, Landroid/app/Application;->onCreate()V": "invoke-super {p0}, Lcom/kf/framework/KFApplication;->onCreate()V", }
  249. def replace_super_application(decompileDir):
  250. smali_files = glob.glob(
  251. os.path.join(decompileDir, 'smali*/com/radical/huangshangjixiang/qh360/CoronaApplication.smali'))
  252. if len(smali_files) == 1:
  253. game_application_file = smali_files[0];
  254. print game_application_file
  255. if os.path.isfile(game_application_file):
  256. with open(game_application_file, "r+") as f:
  257. file_str = f.read()
  258. for k, v in change_map.items():
  259. file_str = file_str.replace(k, v)
  260. with open(game_application_file, "w+") as f:
  261. f.write(file_str)
  262. def modify_manifest(decompileDir, removeKey):
  263. ET.register_namespace('android', ANDROID_NS)
  264. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  265. root_node = ET.parse(xmlparse)
  266. root = root_node.getroot()
  267. name = '{' + ANDROID_NS + '}name'
  268. authorities = '{' + ANDROID_NS + '}' + removeKey
  269. package_name = root.attrib.get('package')
  270. if package_name == None:
  271. return
  272. providers = root.findall('./application')
  273. if providers != None:
  274. for provider in providers:
  275. # providerName = provider.attrib.get(name)
  276. # if 'com.netease.ntunisdk.CcMomentRecordingForegroundService' == providerName:
  277. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  278. try:
  279. del provider.attrib[authorities]
  280. except:
  281. ""
  282. root_node.write(xmlparse, 'utf-8')
  283. if __name__ == '__main__':
  284. # replace_super_application("D:\work\wzdq")
  285. modify_manifest("E:\\apk\\youhua\\youhua.zip.out", "requestLegacyExternalStorage")