script.py 26 KB

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