script.py 26 KB

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