script.py 4.1 KB

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