script.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # coding:utf8
  2. __author__ = '极无双'
  3. import os
  4. import logging
  5. import xml.dom.minidom
  6. import re
  7. import shutil
  8. import glob
  9. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  10. from xml.etree import ElementTree as ET
  11. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  12. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  13. if channelSdkInfo['SDKName'] != 'reverseforkupai':
  14. del_coolcloud(decompileDir)
  15. modify_manifest(decompileDir)
  16. modify_manifest_common(decompileDir, "allowNativeHeapPointerTagging")
  17. def is_reverse_coolcloud(file):
  18. with open(file,'r+') as f:
  19. file_str = f.read()
  20. if 'KFSDK' in file_str:
  21. return True
  22. else:
  23. return False
  24. def del_coolcloud(decompileDir):
  25. smali_files = glob.glob(os.path.join(decompileDir,'smali*/com/coolcloud/'))
  26. if len(smali_files) > 1:
  27. iter_smali = iter(smali_files)
  28. while True:
  29. try:
  30. coolcloud_file_path = iter_smali.next()
  31. file = os.path.join(coolcloud_file_path,'uac/android/api/Coolcloud.smali')
  32. if os.path.exists(file):
  33. logging.info('Coolcloud exits in %s' % coolcloud_file_path)
  34. if not is_reverse_coolcloud(file):
  35. logging.info("delete coolcloud in %s" % coolcloud_file_path)
  36. shutil.rmtree(coolcloud_file_path)
  37. else:
  38. pass
  39. else:
  40. logging.info('Coolcloud not exits in %s' % coolcloud_file_path)
  41. shutil.rmtree(coolcloud_file_path)
  42. except StopIteration:
  43. break
  44. def modify_manifest(decompileDir):
  45. ET.register_namespace('android', ANDROID_NS)
  46. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  47. root_node = ET.parse(xmlparse)
  48. root = root_node.getroot()
  49. name = '{' + ANDROID_NS + '}name'
  50. authorities = '{' + ANDROID_NS + '}foregroundServiceType'
  51. authoritiesTwo = '{' + ANDROID_NS + '}requestLegacyExternalStorage'
  52. package_name = root.attrib.get('package')
  53. if package_name == None:
  54. return
  55. providers = root.findall('./application/service')
  56. if providers != None:
  57. for provider in providers:
  58. providerName = provider.attrib.get(name)
  59. if 'com.hbisoft.hbrecorder.ScreenRecordService' == providerName:
  60. try:
  61. del provider.attrib[authorities]
  62. # del provider.attrib[authoritiesTwo]
  63. except:
  64. ""
  65. root_node.write(xmlparse, 'utf-8')
  66. def modify_manifest_common(decompileDir, removeKey):
  67. ET.register_namespace('android', ANDROID_NS)
  68. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  69. logging.info(xmlparse)
  70. root_node = ET.parse(xmlparse)
  71. root = root_node.getroot()
  72. name = '{' + ANDROID_NS + '}name'
  73. authorities = '{' + ANDROID_NS + '}' + removeKey
  74. package_name = root.attrib.get('package')
  75. if package_name == None:
  76. return
  77. providers = root.findall('./application')
  78. if providers != None:
  79. for provider in providers:
  80. try:
  81. del provider.attrib[authorities]
  82. except:
  83. ""
  84. root_node.write(xmlparse, 'utf-8')
  85. if __name__ == '__main__':
  86. ""