script.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # coding:utf8
  2. import os
  3. import xml.etree.ElementTree as ET
  4. import logging
  5. import re
  6. import codecs
  7. ANDROID_NAMESPACE = 'http://schemas.android.com/apk/res/android'
  8. logger = logging.getLogger('script.py')
  9. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  10. def script_second(sdk, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  11. sdk_id = channelSdkInfo["id"]
  12. if sdk_id == "512":
  13. update_applicationName(decompileDir)
  14. modify_manifest(decompileDir, "requestLegacyExternalStorage")
  15. modify_manifest(decompileDir, "hasFragileUserData")
  16. remove_public(decompileDir)
  17. def remove_public(decompileDir):
  18. tmp_public_xml = os.path.join(decompileDir, "res", "values", "public.xml")
  19. if os.path.exists(tmp_public_xml):
  20. os.remove(tmp_public_xml)
  21. def update_applicationName(decompileDir):
  22. manifestFile = decompileDir + '/AndroidManifest.xml'
  23. ET.register_namespace('android', ANDROID_NAMESPACE)
  24. key = '{' + ANDROID_NAMESPACE + '}name'
  25. targetTree = ET.parse(manifestFile)
  26. targetRoot = targetTree.getroot()
  27. applicationNode = targetRoot.find('application')
  28. if applicationNode is not None:
  29. applicationNode.set(key, "com.minitech.miniworld.coolpad" + ".MyWrapperProxyApplication")
  30. targetTree.write(manifestFile, 'UTF-8')
  31. return
  32. def handle_public_xml(public_xml_path, remove_node):
  33. if not os.path.exists(public_xml_path):
  34. logging.info('public_xml is null: ' + public_xml_path)
  35. return
  36. new_lines = []
  37. with open(public_xml_path, 'r+') as f:
  38. for line in f.readlines():
  39. # l = line.strip()
  40. if line.find(remove_node) > -1:
  41. continue
  42. new_lines.append(line)
  43. f.seek(0)
  44. f.truncate()
  45. f.writelines(new_lines)
  46. return
  47. def modify_manifest(decompileDir, removeKey):
  48. ET.register_namespace('android', ANDROID_NS)
  49. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  50. root_node = ET.parse(xmlparse)
  51. root = root_node.getroot()
  52. name = '{' + ANDROID_NS + '}name'
  53. authorities = '{' + ANDROID_NS + '}' + removeKey
  54. package_name = root.attrib.get('package')
  55. if package_name == None:
  56. return
  57. providers = root.findall('./application')
  58. if providers != None:
  59. for provider in providers:
  60. # providerName = provider.attrib.get(name)
  61. # if 'com.netease.ntunisdk.CcMomentRecordingForegroundService' == providerName:
  62. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  63. try:
  64. del provider.attrib[authorities]
  65. except:
  66. ""
  67. root_node.write(xmlparse, 'utf-8')
  68. if __name__ == '__main__':
  69. script_last('', 'E:/script_test', {}, {}, {})