script.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. return
  17. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  18. sdk_id = channelSdkInfo['id']
  19. if sdk_id == "597":
  20. modify_manifest(decompileDir, "requestLegacyExternalStorage")
  21. logging.info("-----debug-----")
  22. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  23. return
  24. def handle_public_xml(public_xml_path, remove_node):
  25. if not os.path.exists(public_xml_path):
  26. logging.info('public_xml is null: ' + public_xml_path)
  27. return
  28. new_lines = []
  29. with open(public_xml_path, 'r+') as f:
  30. for line in f.readlines():
  31. # l = line.strip()
  32. if line.find(remove_node) > -1:
  33. continue
  34. new_lines.append(line)
  35. f.seek(0)
  36. f.truncate()
  37. f.writelines(new_lines)
  38. return
  39. def create_mutil_smali(decompileDir):
  40. f_idx = 2
  41. while True:
  42. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  43. tmp = tmp.replace('\\', '/')
  44. tmp = re.sub('/+', '/', tmp)
  45. if os.path.exists(tmp):
  46. f_idx += 1
  47. else:
  48. smali_classes2_dir = tmp
  49. break
  50. # endwhile
  51. os.mkdir(smali_classes2_dir)
  52. return smali_classes2_dir
  53. def move_package(s1, s3, list_package):
  54. for d in list_package:
  55. src = os.path.join(s1, d)
  56. if os.path.exists(src):
  57. dst = os.path.join(s3, d)
  58. distutils.dir_util.copy_tree(src, dst)
  59. distutils.dir_util.remove_tree(src)
  60. def move_package_one(src, dst):
  61. if os.path.exists(src):
  62. distutils.dir_util.copy_tree(src, dst)
  63. distutils.dir_util.remove_tree(src)
  64. def modify_manifest(decompileDir, removeKey):
  65. ET.register_namespace('android', ANDROID_NS)
  66. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  67. root_node = ET.parse(xmlparse)
  68. root = root_node.getroot()
  69. name = '{' + ANDROID_NS + '}name'
  70. authorities = '{' + ANDROID_NS + '}' + removeKey
  71. package_name = root.attrib.get('package')
  72. if package_name == None:
  73. return
  74. providers = root.findall('./application')
  75. if providers != None:
  76. for provider in providers:
  77. # providerName = provider.attrib.get(name)
  78. # if 'com.netease.ntunisdk.CcMomentRecordingForegroundService' == providerName:
  79. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  80. try:
  81. del provider.attrib[authorities]
  82. except:
  83. ""
  84. root_node.write(xmlparse, 'utf-8')
  85. if __name__ == '__main__':
  86. # replace_super_application("D:\work\wzdq")
  87. modify_manifest("E:\\apk\\youhua\\youhua.zip.out", "requestLegacyExternalStorage")