script.py 4.5 KB

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