script.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. modify_manifest(extract_dir, "hasFragileUserData")
  18. remove_value(extract_dir, "values-v31")
  19. remove_value(extract_dir, "color-v31")
  20. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  21. handle_public_xml(public_xml ,"m3_ref_palette_dynamic_neutral")
  22. handle_public_xml(public_xml ,"m3_ref_palette_dynamic_primary")
  23. handle_public_xml(public_xml ,"m3_ref_palette_dynamic_secondary")
  24. handle_public_xml(public_xml ,"m3_ref_palette_dynamic_tertiary")
  25. handle_public_xml(public_xml ,"m3_sys_color_dynamic_dark")
  26. handle_public_xml(public_xml ,"m3_sys_color_dynamic_light")
  27. handle_public_xml(public_xml ,"material_dynamic_neutral")
  28. handle_public_xml(public_xml ,"material_dynamic_primary")
  29. handle_public_xml(public_xml ,"material_dynamic_secondary")
  30. handle_public_xml(public_xml ,"material_dynamic_tertiary")
  31. handle_public_xml(public_xml ,"m3_dynamic")
  32. handle_public_xml(public_xml, "cache_measures")
  33. handle_public_xml(public_xml, "dependency_ordering")
  34. handle_public_xml(public_xml, "graph")
  35. handle_public_xml(public_xml, "graph_wrap")
  36. handle_public_xml(public_xml, "grouping")
  37. handle_public_xml(public_xml, "ratio")
  38. sdk_id = channel_sdk_info['id']
  39. if sdk_id == "597" :#深圳 成都都是用这个id
  40. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  41. handle_public_xml(public_xml, "attr-private")
  42. public_xml = os.path.join(extract_dir, "res/layout/design_bottom_sheet_dialog.xml")
  43. handle_public_xml(public_xml, "attr-private")
  44. public_xml = os.path.join(extract_dir, "res/layout/mtrl_layout_snackbar.xml")
  45. # handle_public_xml(public_xml, "attr-private")
  46. os.remove(public_xml)
  47. public_xml = os.path.join(extract_dir, "res/layout-sw600dp/mtrl_layout_snackbar.xml")
  48. # handle_public_xml(public_xml, "attr-private")
  49. os.remove(public_xml)
  50. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  51. handle_public_xml(public_xml, "mtrl_layout_snackbar")
  52. public_xml = os.path.join(extract_dir, "res/layout/mtrl_layout_snackbar_include.xml")
  53. handle_public_xml(public_xml, "attr-private")
  54. public_xml = os.path.join(extract_dir, "res/drawable-v21/abc_dialog_material_background.xml")
  55. handle_public_xml(public_xml, "attr-private")
  56. public_xml = os.path.join(extract_dir, "res/values/styles.xml")
  57. handle_public_xml(public_xml, "attr-private")
  58. public_xml = os.path.join(extract_dir, "res/values-v21/styles.xml")
  59. handle_public_xml(public_xml, "attr-private")
  60. return
  61. def handle_public_xml(public_xml_path, remove_node):
  62. if not os.path.exists(public_xml_path):
  63. logging.info('public_xml is null: ' + public_xml_path)
  64. return
  65. new_lines = []
  66. with open(public_xml_path, 'r+') as f:
  67. for line in f.readlines():
  68. # l = line.strip()
  69. if line.find(remove_node) > -1:
  70. continue
  71. new_lines.append(line)
  72. f.seek(0)
  73. f.truncate()
  74. f.writelines(new_lines)
  75. return
  76. def modify_manifest(decompileDir, removeKey):
  77. ET.register_namespace('android', ANDROID_NS)
  78. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  79. root_node = ET.parse(xmlparse)
  80. root = root_node.getroot()
  81. name = '{' + ANDROID_NS + '}name'
  82. authorities = '{' + ANDROID_NS + '}' + removeKey
  83. package_name = root.attrib.get('package')
  84. if package_name == None:
  85. return
  86. providers = root.findall('./application')
  87. if providers != None:
  88. for provider in providers:
  89. # providerName = provider.attrib.get(name)
  90. # if 'com.netease.ntunisdk.CcMomentRecordingForegroundService' == providerName:
  91. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  92. try:
  93. del provider.attrib[authorities]
  94. except:
  95. ""
  96. root_node.write(xmlparse, 'utf-8')
  97. def remove_value(decompileDir, remove_dir):
  98. tmp_res = os.path.join(decompileDir, "res", remove_dir)
  99. if os.path.exists(tmp_res):
  100. distutils.dir_util.remove_tree(tmp_res)
  101. if __name__ == '__main__':
  102. # replace_super_application("D:\work\wzdq")
  103. modify_manifest("E:\\apk\\youhua\\youhua.zip.out", "requestLegacyExternalStorage")