script.py 4.2 KB

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