script.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # coding:utf8
  2. __author__ = 'Snow'
  3. import os
  4. import logging
  5. import xml.dom.minidom
  6. import re
  7. import shutil
  8. import glob
  9. import distutils.dir_util
  10. import gw_file_system
  11. from xml.etree import ElementTree as ET
  12. import gw_data_center
  13. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  14. def script_init(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  15. # gw_data_center.pack_small = False
  16. return
  17. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  18. return
  19. sdk_id = channelSdkInfo['id']
  20. if sdk_id == "512":
  21. modify_manifest(decompileDir)
  22. modify_manifest_requestLegacyExternalStorage(decompileDir)
  23. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  24. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  25. # smali_classes4
  26. s1 = os.path.join(decompileDir, "smali")
  27. if not os.path.exists(s1):
  28. return
  29. smali_classes2_dir = create_mutil_smali(decompileDir)
  30. s3 = smali_classes2_dir
  31. list_package = ["androidx"]
  32. if not os.path.exists(s3):
  33. distutils.dir_util.mkpath(s3)
  34. move_package(s1, s3, list_package)
  35. sdk_id = channelSdkInfo['id']
  36. if sdk_id == "549":
  37. s1 = os.path.join(decompileDir, "smali_classes4", "com")
  38. if not os.path.exists(s1):
  39. return
  40. smali_classes2_dir = create_mutil_smali(decompileDir)
  41. s3 = smali_classes2_dir
  42. list_package = ["meizu", "netease"]
  43. if not os.path.exists(s3):
  44. distutils.dir_util.mkpath(s3)
  45. move_package(s1, s3, list_package)
  46. def move_package(s1, s3, list_package):
  47. for d in list_package:
  48. src = os.path.join(s1, d)
  49. if os.path.exists(src):
  50. dst = os.path.join(s3, d)
  51. distutils.dir_util.copy_tree(src, dst)
  52. distutils.dir_util.remove_tree(src)
  53. def create_mutil_smali(decompileDir):
  54. f_idx = 2
  55. while True:
  56. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  57. tmp = tmp.replace('\\', '/')
  58. tmp = re.sub('/+', '/', tmp)
  59. if os.path.exists(tmp):
  60. files = os.listdir(tmp)
  61. if len(files) == 0:
  62. smali_classes2_dir = tmp
  63. break
  64. f_idx += 1
  65. else:
  66. smali_classes2_dir = tmp
  67. break
  68. # endwhile
  69. if not os.path.exists(smali_classes2_dir):
  70. os.mkdir(smali_classes2_dir)
  71. return smali_classes2_dir
  72. def modify_manifest(decompileDir):
  73. ET.register_namespace('android', ANDROID_NS)
  74. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  75. root_node = ET.parse(xmlparse)
  76. root = root_node.getroot()
  77. name = '{' + ANDROID_NS + '}name'
  78. authorities = '{' + ANDROID_NS + '}foregroundServiceType'
  79. package_name = root.attrib.get('package')
  80. if package_name == None:
  81. return
  82. providers = root.findall('./application/service')
  83. if providers != None:
  84. for provider in providers:
  85. providerName = provider.attrib.get(name)
  86. if 'com.netease.cc.screen_record.codec.screencapture.ScreenCaptureService' == providerName:
  87. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  88. try:
  89. del provider.attrib[authorities]
  90. except:
  91. ""
  92. root_node.write(xmlparse, 'utf-8')
  93. def modify_manifest_requestLegacyExternalStorage(decompileDir):
  94. ET.register_namespace('android', ANDROID_NS)
  95. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  96. root_node = ET.parse(xmlparse)
  97. root = root_node.getroot()
  98. name = '{' + ANDROID_NS + '}name'
  99. authorities = '{' + ANDROID_NS + '}requestLegacyExternalStorage'
  100. package_name = root.attrib.get('package')
  101. if package_name == None:
  102. return
  103. providers = root.findall('./application')
  104. if providers != None:
  105. for provider in providers:
  106. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  107. try:
  108. del provider.attrib[authorities]
  109. except:
  110. ""
  111. root_node.write(xmlparse, 'utf-8')
  112. if __name__ == '__main__':
  113. ""