script.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. modify_manifest(decompileDir, "com.excelliance.lbsdk.debug.LBSdkCrashReportService", "foregroundServiceType")
  13. modify_manifest(decompileDir, "com.excelliance.lbsdk.base.AssistService", "foregroundServiceType")
  14. modify_manifest(decompileDir, "com.excelliance.lbsdk.base.BaseService", "foregroundServiceType")
  15. modify_manifest(decompileDir, "com.excelliance.lbsdk.main.BGService", "foregroundServiceType")
  16. # modify_manifest_common(decompileDir, "dataExtractionRules")
  17. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  18. # decompile_dir_path = os.path.join(decompileDir )
  19. fix_coolyun_application_getinstance_null_bug(decompileDir)
  20. def modify_manifest(decompileDir, serviceName, key):
  21. ET.register_namespace('android', ANDROID_NS)
  22. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  23. root_node = ET.parse(xmlparse)
  24. root = root_node.getroot()
  25. name = '{' + ANDROID_NS + '}name'
  26. authorities = '{' + ANDROID_NS + '}' + key
  27. package_name = root.attrib.get('package')
  28. if package_name == None:
  29. return
  30. providers = root.findall('./application/service')
  31. if providers != None:
  32. for provider in providers:
  33. providerName = provider.attrib.get(name)
  34. if serviceName == providerName:
  35. try:
  36. del provider.attrib[authorities]
  37. # del provider.attrib[authoritiesTwo]
  38. except:
  39. ""
  40. root_node.write(xmlparse, 'utf-8')
  41. def modify_manifest_common(decompileDir, removeKey):
  42. ET.register_namespace('android', ANDROID_NS)
  43. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  44. logging.info(xmlparse)
  45. root_node = ET.parse(xmlparse)
  46. root = root_node.getroot()
  47. name = '{' + ANDROID_NS + '}name'
  48. authorities = '{' + ANDROID_NS + '}' + removeKey
  49. package_name = root.attrib.get('package')
  50. if package_name == None:
  51. return
  52. providers = root.findall('./application')
  53. if providers != None:
  54. for provider in providers:
  55. try:
  56. del provider.attrib[authorities]
  57. except:
  58. ""
  59. root_node.write(xmlparse, 'utf-8')
  60. def fix_coolyun_application_getinstance_null_bug(decompile_dir):
  61. insert_str_list = [
  62. '\n\t.locals 1\n\n',
  63. '\tsget-object v0, Lcom/coolyun/framework/CoolYunApplication;->application:Landroid/content/Context;\n\n',
  64. '\tcheck-cast v0, Lcom/coolyun/framework/CoolYunApplication;\n\n',
  65. '\treturn-object v0\n\n']
  66. for dirpath, dirnames, filenames in os.walk(decompile_dir):
  67. if r'com\coolyun\framework' in dirpath and 'CoolYunApplication.smali' in filenames:
  68. smali_path = os.path.join(dirpath, 'CoolYunApplication.smali')
  69. with open(smali_path, 'r') as f:
  70. smali_str_arr = f.readlines()
  71. index_str = '.method public static getInstance()Lcom/coolyun/framework/CoolYunApplication;'
  72. end_method_str = '.end method'
  73. insert_str = ''.join(insert_str_list)
  74. on_create_index = 0
  75. insert_index = 0
  76. for line in smali_str_arr:
  77. if index_str in line:
  78. on_create_index = smali_str_arr.index(line)
  79. print('on_create_index', on_create_index, line)
  80. break
  81. for index, value in enumerate(smali_str_arr):
  82. if index > on_create_index and end_method_str in value:
  83. insert_index = index
  84. print('insert_index', index)
  85. break
  86. print(on_create_index, insert_index)
  87. del smali_str_arr[on_create_index + 1:insert_index]
  88. smali_str_arr.insert(on_create_index + 1, insert_str)
  89. with open(smali_path, 'w') as f:
  90. f.write(''.join(smali_str_arr))
  91. break
  92. if __name__ == '__main__':
  93. ""