script.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  14. def script_second(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  15. logging.info('script_second: ' + str(channel_sdk_info))
  16. # 逆向渠道id
  17. sdk_id = channel_sdk_info['id']
  18. if sdk_id == "597" :#深圳 成都都是用这个id
  19. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  20. handle_public_xml(public_xml, "attr-private")
  21. public_xml = os.path.join(extract_dir, "res/color-v23/abc_btn_colored_borderless_text_material.xml")
  22. handle_public_xml(public_xml, "attr-private")
  23. public_xml = os.path.join(extract_dir, "res/color/abc_btn_colored_borderless_text_material.xml")
  24. handle_public_xml(public_xml, "attr-private")
  25. #
  26. # public_xml = os.path.join(extract_dir, "res/layout/mtrl_layout_snackbar.xml")
  27. # # handle_public_xml(public_xml, "attr-private")
  28. # os.remove(public_xml)
  29. #
  30. # public_xml = os.path.join(extract_dir, "res/layout-sw600dp/mtrl_layout_snackbar.xml")
  31. # # handle_public_xml(public_xml, "attr-private")
  32. # os.remove(public_xml)
  33. #
  34. # public_xml = os.path.join(extract_dir, "res/values/public.xml")
  35. # handle_public_xml(public_xml, "mtrl_layout_snackbar")
  36. #
  37. # public_xml = os.path.join(extract_dir, "res/layout/mtrl_layout_snackbar_include.xml")
  38. # handle_public_xml(public_xml, "attr-private")
  39. #
  40. # public_xml = os.path.join(extract_dir, "res/drawable-v21/abc_dialog_material_background.xml")
  41. # handle_public_xml(public_xml, "attr-private")
  42. #
  43. public_xml = os.path.join(extract_dir, "res/values/styles.xml")
  44. handle_public_xml(public_xml, "attr-private")
  45. #
  46. # public_xml = os.path.join(extract_dir, "res/values-v21/styles.xml")
  47. # handle_public_xml(public_xml, "attr-private")
  48. return
  49. def handle_public_xml(public_xml_path, remove_node):
  50. if not os.path.exists(public_xml_path):
  51. logging.info('public_xml is null: ' + public_xml_path)
  52. return
  53. new_lines = []
  54. with open(public_xml_path, 'r+') as f:
  55. for line in f.readlines():
  56. # l = line.strip()
  57. if line.find(remove_node) > -1:
  58. continue
  59. new_lines.append(line)
  60. f.seek(0)
  61. f.truncate()
  62. f.writelines(new_lines)
  63. return
  64. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  65. logging.info("-----debug-----")
  66. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  67. return
  68. sdk_id = channelSdkInfo['id']
  69. if sdk_id == "597":
  70. s1 = os.path.join(decompileDir, "smali","androidx")
  71. if os.path.exists(s1):
  72. smali_classes_new = create_mutil_smali(decompileDir)
  73. s3 = os.path.join(decompileDir, smali_classes_new,"androidx")
  74. list_package = ["activity","appcompat","collection","core","customview","exifinterface","interpolator","lifecycle","annotation","arch","constraintlayout","cursoradapter","drawerlayout","fragment","legacy","loader"]
  75. if not os.path.exists(s3):
  76. distutils.dir_util.mkpath(s3)
  77. move_package(s1, s3, list_package)
  78. s1 = os.path.join(decompileDir, "smali_classes2")
  79. if os.path.exists(s1):
  80. smali_classes2_dir = create_mutil_smali(decompileDir)
  81. s3 = os.path.join(smali_classes2_dir)
  82. list_package = ["androidx"]
  83. if not os.path.exists(s3):
  84. distutils.dir_util.mkpath(s3)
  85. move_package(s1, s3, list_package)
  86. s1 = os.path.join(decompileDir, "smali_classes2","com")
  87. if os.path.exists(s1):
  88. smali_classes2_dir = create_mutil_smali(decompileDir)
  89. s3 = os.path.join(smali_classes2_dir,"com")
  90. list_package = ["albaba","alipay","android","asus","bumptech","bun","ccsingle","cmge","facebook"]
  91. list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  92. list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  93. if not os.path.exists(s3):
  94. distutils.dir_util.mkpath(s3)
  95. move_package(s1, s3, list_package)
  96. s1 = os.path.join(decompileDir, "smali_classes3","com")
  97. if os.path.exists(s1):
  98. smali_classes2_dir = create_mutil_smali(decompileDir)
  99. s3 = os.path.join(smali_classes2_dir,"com")
  100. list_package = ["albaba","alipay"]
  101. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  102. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  103. if not os.path.exists(s3):
  104. distutils.dir_util.mkpath(s3)
  105. move_package(s1, s3, list_package)
  106. s1 = os.path.join(decompileDir, "smali_classes3","com")
  107. if os.path.exists(s1):
  108. smali_classes2_dir = create_mutil_smali(decompileDir)
  109. s3 = os.path.join(smali_classes2_dir,"com")
  110. list_package = ["android","asus"]
  111. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  112. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  113. if not os.path.exists(s3):
  114. distutils.dir_util.mkpath(s3)
  115. move_package(s1, s3, list_package)
  116. s1 = os.path.join(decompileDir, "smali_classes3","com")
  117. if os.path.exists(s1):
  118. smali_classes2_dir = create_mutil_smali(decompileDir)
  119. s3 = os.path.join(smali_classes2_dir,"com")
  120. list_package = ["bumptech","bun"]
  121. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  122. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  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_classes3","com")
  127. if os.path.exists(s1):
  128. smali_classes2_dir = create_mutil_smali(decompileDir)
  129. s3 = os.path.join(smali_classes2_dir,"com")
  130. list_package = ["ccsingle","cmge"]
  131. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  132. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  133. if not os.path.exists(s3):
  134. distutils.dir_util.mkpath(s3)
  135. move_package(s1, s3, list_package)
  136. s1 = os.path.join(decompileDir, "smali_classes3","com")
  137. if os.path.exists(s1):
  138. smali_classes2_dir = create_mutil_smali(decompileDir)
  139. s3 = os.path.join(smali_classes2_dir,"com")
  140. list_package = ["facebook"]
  141. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  142. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  143. if not os.path.exists(s3):
  144. distutils.dir_util.mkpath(s3)
  145. move_package(s1, s3, list_package)
  146. s1 = os.path.join(decompileDir, "smali_classes3","com")
  147. if os.path.exists(s1):
  148. smali_classes2_dir = create_mutil_smali(decompileDir)
  149. s3 = os.path.join(smali_classes2_dir,"com")
  150. list_package = []
  151. list_package.extend(["google","heytap"])
  152. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  153. if not os.path.exists(s3):
  154. distutils.dir_util.mkpath(s3)
  155. move_package(s1, s3, list_package)
  156. s1 = os.path.join(decompileDir, "smali_classes3","com")
  157. if os.path.exists(s1):
  158. smali_classes2_dir = create_mutil_smali(decompileDir)
  159. s3 = os.path.join(smali_classes2_dir,"com")
  160. list_package = []
  161. list_package.extend(["hihonor","huawei"])
  162. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  163. if not os.path.exists(s3):
  164. distutils.dir_util.mkpath(s3)
  165. move_package(s1, s3, list_package)
  166. s1 = os.path.join(decompileDir, "smali_classes3","com")
  167. if os.path.exists(s1):
  168. smali_classes2_dir = create_mutil_smali(decompileDir)
  169. s3 = os.path.join(smali_classes2_dir,"com")
  170. list_package = []
  171. list_package.extend(["ipaynow","jtly","koushikdutta"])
  172. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  173. if not os.path.exists(s3):
  174. distutils.dir_util.mkpath(s3)
  175. move_package(s1, s3, list_package)
  176. s1 = os.path.join(decompileDir, "smali_classes3","com")
  177. if os.path.exists(s1):
  178. smali_classes2_dir = create_mutil_smali(decompileDir)
  179. s3 = os.path.join(smali_classes2_dir,"com")
  180. list_package = []
  181. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  182. list_package.extend(["lzy","mcs"])
  183. if not os.path.exists(s3):
  184. distutils.dir_util.mkpath(s3)
  185. move_package(s1, s3, list_package)
  186. s1 = os.path.join(decompileDir, "smali_classes3","com")
  187. if os.path.exists(s1):
  188. smali_classes2_dir = create_mutil_smali(decompileDir)
  189. s3 = os.path.join(smali_classes2_dir,"com")
  190. list_package = []
  191. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  192. list_package.extend(["meizu","onevcat","renderheads"])
  193. if not os.path.exists(s3):
  194. distutils.dir_util.mkpath(s3)
  195. move_package(s1, s3, list_package)
  196. s1 = os.path.join(decompileDir, "smali_classes3")
  197. if os.path.exists(s1):
  198. smali_classes2_dir = create_mutil_smali(decompileDir)
  199. s3 = os.path.join(smali_classes2_dir,)
  200. list_package = []
  201. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  202. list_package.extend(["androidx"])
  203. if not os.path.exists(s3):
  204. distutils.dir_util.mkpath(s3)
  205. move_package(s1, s3, list_package)
  206. s1 = os.path.join(decompileDir, "smali_classes4","com")
  207. if os.path.exists(s1):
  208. smali_classes2_dir = create_mutil_smali(decompileDir)
  209. s3 = os.path.join(smali_classes2_dir,"com")
  210. list_package = ["albaba","alipay"]
  211. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  212. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  213. if not os.path.exists(s3):
  214. distutils.dir_util.mkpath(s3)
  215. move_package(s1, s3, list_package)
  216. s1 = os.path.join(decompileDir, "smali_classes4","com")
  217. if os.path.exists(s1):
  218. smali_classes2_dir = create_mutil_smali(decompileDir)
  219. s3 = os.path.join(smali_classes2_dir,"com")
  220. list_package = ["android","asus"]
  221. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  222. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  223. if not os.path.exists(s3):
  224. distutils.dir_util.mkpath(s3)
  225. move_package(s1, s3, list_package)
  226. s1 = os.path.join(decompileDir, "smali_classes4","com")
  227. if os.path.exists(s1):
  228. smali_classes2_dir = create_mutil_smali(decompileDir)
  229. s3 = os.path.join(smali_classes2_dir,"com")
  230. list_package = ["bumptech","bun"]
  231. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  232. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  233. if not os.path.exists(s3):
  234. distutils.dir_util.mkpath(s3)
  235. move_package(s1, s3, list_package)
  236. s1 = os.path.join(decompileDir, "smali_classes4","com")
  237. if os.path.exists(s1):
  238. smali_classes2_dir = create_mutil_smali(decompileDir)
  239. s3 = os.path.join(smali_classes2_dir,"com")
  240. list_package = ["ccsingle","cmge"]
  241. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  242. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  243. if not os.path.exists(s3):
  244. distutils.dir_util.mkpath(s3)
  245. move_package(s1, s3, list_package)
  246. s1 = os.path.join(decompileDir, "smali_classes4","com")
  247. if os.path.exists(s1):
  248. smali_classes2_dir = create_mutil_smali(decompileDir)
  249. s3 = os.path.join(smali_classes2_dir,"com")
  250. list_package = ["facebook"]
  251. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  252. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  253. if not os.path.exists(s3):
  254. distutils.dir_util.mkpath(s3)
  255. move_package(s1, s3, list_package)
  256. s1 = os.path.join(decompileDir, "smali_classes4","com")
  257. if os.path.exists(s1):
  258. smali_classes2_dir = create_mutil_smali(decompileDir)
  259. s3 = os.path.join(smali_classes2_dir,"com")
  260. list_package = []
  261. list_package.extend(["google","heytap"])
  262. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  263. if not os.path.exists(s3):
  264. distutils.dir_util.mkpath(s3)
  265. move_package(s1, s3, list_package)
  266. s1 = os.path.join(decompileDir, "smali_classes4","com")
  267. if os.path.exists(s1):
  268. smali_classes2_dir = create_mutil_smali(decompileDir)
  269. s3 = os.path.join(smali_classes2_dir,"com")
  270. list_package = []
  271. list_package.extend(["hihonor","huawei"])
  272. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  273. if not os.path.exists(s3):
  274. distutils.dir_util.mkpath(s3)
  275. move_package(s1, s3, list_package)
  276. s1 = os.path.join(decompileDir, "smali_classes4","com")
  277. if os.path.exists(s1):
  278. smali_classes2_dir = create_mutil_smali(decompileDir)
  279. s3 = os.path.join(smali_classes2_dir,"com")
  280. list_package = []
  281. list_package.extend(["ipaynow","jtly","koushikdutta"])
  282. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  283. if not os.path.exists(s3):
  284. distutils.dir_util.mkpath(s3)
  285. move_package(s1, s3, list_package)
  286. s1 = os.path.join(decompileDir, "smali_classes4","com")
  287. if os.path.exists(s1):
  288. smali_classes2_dir = create_mutil_smali(decompileDir)
  289. s3 = os.path.join(smali_classes2_dir,"com")
  290. list_package = []
  291. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  292. list_package.extend(["lzy","mcs"])
  293. if not os.path.exists(s3):
  294. distutils.dir_util.mkpath(s3)
  295. move_package(s1, s3, list_package)
  296. s1 = os.path.join(decompileDir, "smali_classes4","com")
  297. if os.path.exists(s1):
  298. smali_classes2_dir = create_mutil_smali(decompileDir)
  299. s3 = os.path.join(smali_classes2_dir,"com")
  300. list_package = []
  301. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  302. list_package.extend(["meizu","onevcat","renderheads"])
  303. if not os.path.exists(s3):
  304. distutils.dir_util.mkpath(s3)
  305. move_package(s1, s3, list_package)
  306. s1 = os.path.join(decompileDir, "smali_classes4")
  307. if os.path.exists(s1):
  308. smali_classes2_dir = create_mutil_smali(decompileDir)
  309. s3 = os.path.join(smali_classes2_dir,)
  310. list_package = []
  311. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  312. list_package.extend(["androidx"])
  313. if not os.path.exists(s3):
  314. distutils.dir_util.mkpath(s3)
  315. move_package(s1, s3, list_package)
  316. s1 = os.path.join(decompileDir, "smali_classes5","com")
  317. if os.path.exists(s1):
  318. smali_classes2_dir = create_mutil_smali(decompileDir)
  319. s3 = os.path.join(smali_classes2_dir,"com")
  320. list_package = ["albaba","alipay"]
  321. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  322. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  323. if not os.path.exists(s3):
  324. distutils.dir_util.mkpath(s3)
  325. move_package(s1, s3, list_package)
  326. s1 = os.path.join(decompileDir, "smali_classes5","com")
  327. if os.path.exists(s1):
  328. smali_classes2_dir = create_mutil_smali(decompileDir)
  329. s3 = os.path.join(smali_classes2_dir,"com")
  330. list_package = ["android","asus"]
  331. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  332. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  333. if not os.path.exists(s3):
  334. distutils.dir_util.mkpath(s3)
  335. move_package(s1, s3, list_package)
  336. s1 = os.path.join(decompileDir, "smali_classes5","com")
  337. if os.path.exists(s1):
  338. smali_classes2_dir = create_mutil_smali(decompileDir)
  339. s3 = os.path.join(smali_classes2_dir,"com")
  340. list_package = ["bumptech","bun"]
  341. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  342. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  343. if not os.path.exists(s3):
  344. distutils.dir_util.mkpath(s3)
  345. move_package(s1, s3, list_package)
  346. s1 = os.path.join(decompileDir, "smali_classes5","com")
  347. if os.path.exists(s1):
  348. smali_classes2_dir = create_mutil_smali(decompileDir)
  349. s3 = os.path.join(smali_classes2_dir,"com")
  350. list_package = ["ccsingle","cmge"]
  351. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  352. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  353. if not os.path.exists(s3):
  354. distutils.dir_util.mkpath(s3)
  355. move_package(s1, s3, list_package)
  356. s1 = os.path.join(decompileDir, "smali_classes5","com")
  357. if os.path.exists(s1):
  358. smali_classes2_dir = create_mutil_smali(decompileDir)
  359. s3 = os.path.join(smali_classes2_dir,"com")
  360. list_package = ["facebook"]
  361. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  362. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  363. if not os.path.exists(s3):
  364. distutils.dir_util.mkpath(s3)
  365. move_package(s1, s3, list_package)
  366. s1 = os.path.join(decompileDir, "smali_classes5","com")
  367. if os.path.exists(s1):
  368. smali_classes2_dir = create_mutil_smali(decompileDir)
  369. s3 = os.path.join(smali_classes2_dir,"com")
  370. list_package = []
  371. list_package.extend(["google","heytap"])
  372. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  373. if not os.path.exists(s3):
  374. distutils.dir_util.mkpath(s3)
  375. move_package(s1, s3, list_package)
  376. s1 = os.path.join(decompileDir, "smali_classes5","com")
  377. if os.path.exists(s1):
  378. smali_classes2_dir = create_mutil_smali(decompileDir)
  379. s3 = os.path.join(smali_classes2_dir,"com")
  380. list_package = []
  381. list_package.extend(["hihonor","huawei"])
  382. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  383. if not os.path.exists(s3):
  384. distutils.dir_util.mkpath(s3)
  385. move_package(s1, s3, list_package)
  386. s1 = os.path.join(decompileDir, "smali_classes5","com")
  387. if os.path.exists(s1):
  388. smali_classes2_dir = create_mutil_smali(decompileDir)
  389. s3 = os.path.join(smali_classes2_dir,"com")
  390. list_package = []
  391. list_package.extend(["ipaynow","jtly","koushikdutta"])
  392. # list_package.extend(["lzy","mcs","meizu","onevcat","renderheads"])
  393. if not os.path.exists(s3):
  394. distutils.dir_util.mkpath(s3)
  395. move_package(s1, s3, list_package)
  396. s1 = os.path.join(decompileDir, "smali_classes5","com")
  397. if os.path.exists(s1):
  398. smali_classes2_dir = create_mutil_smali(decompileDir)
  399. s3 = os.path.join(smali_classes2_dir,"com")
  400. list_package = []
  401. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  402. list_package.extend(["lzy","mcs"])
  403. if not os.path.exists(s3):
  404. distutils.dir_util.mkpath(s3)
  405. move_package(s1, s3, list_package)
  406. s1 = os.path.join(decompileDir, "smali_classes5","com")
  407. if os.path.exists(s1):
  408. smali_classes2_dir = create_mutil_smali(decompileDir)
  409. s3 = os.path.join(smali_classes2_dir,"com")
  410. list_package = []
  411. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  412. list_package.extend(["meizu","onevcat","renderheads"])
  413. if not os.path.exists(s3):
  414. distutils.dir_util.mkpath(s3)
  415. move_package(s1, s3, list_package)
  416. s1 = os.path.join(decompileDir, "smali_classes5")
  417. if os.path.exists(s1):
  418. smali_classes2_dir = create_mutil_smali(decompileDir)
  419. s3 = os.path.join(smali_classes2_dir,)
  420. list_package = []
  421. # list_package.extend(["google","heytap","hihonor","huawei","ipaynow","jtly","koushikdutta"])
  422. list_package.extend(["androidx"])
  423. if not os.path.exists(s3):
  424. distutils.dir_util.mkpath(s3)
  425. move_package(s1, s3, list_package)
  426. s1 = os.path.join(decompileDir, "smali_classes7","com")
  427. if os.path.exists(s1):
  428. smali_classes2_dir = create_mutil_smali(decompileDir)
  429. s3 = os.path.join(smali_classes2_dir,)
  430. list_package = []
  431. list_package.extend(["facebook","google","heytap"])
  432. if not os.path.exists(s3):
  433. distutils.dir_util.mkpath(s3)
  434. move_package(s1, s3, list_package)
  435. s1 = os.path.join(decompileDir, "smali_classes7","com")
  436. if os.path.exists(s1):
  437. smali_classes2_dir = create_mutil_smali(decompileDir)
  438. s3 = os.path.join(smali_classes2_dir,)
  439. list_package = []
  440. list_package.extend(["hihonor","huawei"])
  441. if not os.path.exists(s3):
  442. distutils.dir_util.mkpath(s3)
  443. move_package(s1, s3, list_package)
  444. return
  445. def create_mutil_smali(decompileDir):
  446. f_idx = 2
  447. while True:
  448. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  449. tmp = tmp.replace('\\', '/')
  450. tmp = re.sub('/+', '/', tmp)
  451. if os.path.exists(tmp):
  452. f_idx += 1
  453. else:
  454. smali_classes2_dir = tmp
  455. break
  456. # endwhile
  457. os.mkdir(smali_classes2_dir)
  458. return smali_classes2_dir
  459. def move_package(s1, s3, list_package):
  460. for d in list_package:
  461. src = os.path.join(s1, d)
  462. if os.path.exists(src):
  463. dst = os.path.join(s3, d)
  464. distutils.dir_util.copy_tree(src, dst)
  465. distutils.dir_util.remove_tree(src)
  466. def move_package_one(src, dst):
  467. if os.path.exists(src):
  468. distutils.dir_util.copy_tree(src, dst)
  469. distutils.dir_util.remove_tree(src)
  470. change_map = {".super Landroid/app/Application;": ".super Lcom/kf/framework/KFApplication;",
  471. "invoke-direct {p0}, Landroid/app/Application;-><init>()V": "invoke-direct {p0}, Lcom/kf/framework/KFApplication;-><init>()V",
  472. "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",
  473. "invoke-super {p0}, Landroid/app/Application;->onCreate()V": "invoke-super {p0}, Lcom/kf/framework/KFApplication;->onCreate()V", }
  474. def replace_super_application(decompileDir):
  475. smali_files = glob.glob(
  476. os.path.join(decompileDir, 'smali*/com/radical/huangshangjixiang/qh360/CoronaApplication.smali'))
  477. if len(smali_files) == 1:
  478. game_application_file = smali_files[0];
  479. print game_application_file
  480. if os.path.isfile(game_application_file):
  481. with open(game_application_file, "r+") as f:
  482. file_str = f.read()
  483. for k, v in change_map.items():
  484. file_str = file_str.replace(k, v)
  485. with open(game_application_file, "w+") as f:
  486. f.write(file_str)
  487. def modify_manifest(decompileDir, removeKey):
  488. ET.register_namespace('android', ANDROID_NS)
  489. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  490. root_node = ET.parse(xmlparse)
  491. root = root_node.getroot()
  492. name = '{' + ANDROID_NS + '}name'
  493. authorities = '{' + ANDROID_NS + '}' + removeKey
  494. package_name = root.attrib.get('package')
  495. if package_name == None:
  496. return
  497. providers = root.findall('./application')
  498. if providers != None:
  499. for provider in providers:
  500. # providerName = provider.attrib.get(name)
  501. # if 'com.netease.ntunisdk.CcMomentRecordingForegroundService' == providerName:
  502. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  503. try:
  504. del provider.attrib[authorities]
  505. except:
  506. ""
  507. root_node.write(xmlparse, 'utf-8')
  508. if __name__ == '__main__':
  509. # replace_super_application("D:\work\wzdq")
  510. modify_manifest("E:\\apk\\youhua\\youhua.zip.out", "requestLegacyExternalStorage")