script.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # coding:utf8
  2. import os
  3. import logging
  4. import xml.dom.minidom
  5. import re
  6. import shutil
  7. import glob
  8. from xml.etree.ElementTree import ElementTree, Element
  9. import distutils.dir_util
  10. import gw_data_center
  11. import gw_file_system
  12. import gw_apk_tool
  13. from xml.etree import ElementTree as ET
  14. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  15. def script_init(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  16. return
  17. def script_first(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  18. return
  19. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  20. return
  21. def script_last(SDK, extract_dir, channelSdkInfo, new_game_channel_info, gameInfo):
  22. s1 = os.path.join(extract_dir, "smali_classes3", "com")
  23. s3 = create_mutil_smali(extract_dir)
  24. s3 = os.path.join(s3, "com")
  25. list_package = ["huawei", "ironhidegames", "kingdomrush4", "loopj", "miui", "sdk", "ta", "unikuwei", "ut", "yulong"]
  26. if not os.path.exists(s3):
  27. distutils.dir_util.mkpath(s3)
  28. move_package(s1, s3, list_package)
  29. return
  30. def create_mutil_smali(decompileDir):
  31. f_idx = 2
  32. while True:
  33. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  34. tmp = tmp.replace('\\', '/')
  35. tmp = re.sub('/+', '/', tmp)
  36. if os.path.exists(tmp):
  37. f_idx += 1
  38. else:
  39. smali_classes2_dir = tmp
  40. break
  41. # endwhile
  42. os.mkdir(smali_classes2_dir)
  43. return smali_classes2_dir
  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 modify_manifest(decompileDir):
  52. ET.register_namespace('android', ANDROID_NS)
  53. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  54. root_node = ET.parse(xmlparse)
  55. root = root_node.getroot()
  56. name = '{' + ANDROID_NS + '}name'
  57. authorities = '{' + ANDROID_NS + '}foregroundServiceType'
  58. package_name = root.attrib.get('package')
  59. if package_name == None:
  60. return
  61. providers = root.findall('./application/service')
  62. if providers != None:
  63. for provider in providers:
  64. providerName = provider.attrib.get(name)
  65. if 'com.netease.ntunisdk.CcMomentRecordingForegroundService' == providerName:
  66. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  67. try:
  68. del provider.attrib[authorities]
  69. except:
  70. ""
  71. root_node.write(xmlparse, 'utf-8')
  72. if __name__ == '__main__':
  73. # script("", "E:\\apk\\youhua\\LYJY360_12412_360逆向_1.23.00", "", "", "")
  74. modify_manifest("G:\\autopack2.0_kuaifa\\tool\\workspace\\mhlskp\\15377\\extract\\")