script.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # coding:utf8
  2. __author__ = 'dong'
  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 os
  11. # import gw_apk_tool
  12. from xml.etree import ElementTree as ET
  13. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  14. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  15. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  16. if channelSdkInfo['id'] == '597':
  17. logging.info("remove_navigate")
  18. remove_navigate(decompileDir)
  19. public_xml = os.path.join(decompileDir, "res/layout/activity_live_login.xml")
  20. handle_public_xml(public_xml, "navGraph")
  21. handle_public_xml(public_xml, "nav_main")
  22. # android_manifest_xml = os.path.join(decompileDir, "AndroidManifest.xml")
  23. # handle_public_xml(android_manifest_xml, "allowNativeHeapPointerTagging")
  24. # modify_manifest_common(decompileDir, "allowNativeHeapPointerTagging")
  25. def remove_navigate(decompileDir):
  26. tmp_res = os.path.join(decompileDir, "res", "navigation")
  27. tmp_public_xml = os.path.join(decompileDir, "res", "values", "public.xml")
  28. if os.path.exists(tmp_res):
  29. distutils.dir_util.remove_tree(tmp_res)
  30. if os.path.exists(tmp_public_xml):
  31. os.remove(tmp_public_xml)
  32. def handle_public_xml(public_xml_path, remove_node):
  33. if not os.path.exists(public_xml_path):
  34. logging.info('public_xml is null: ' + public_xml_path)
  35. return
  36. new_lines = []
  37. with open(public_xml_path, 'r+') as f:
  38. for line in f.readlines():
  39. # l = line.strip()
  40. if line.find(remove_node) > -1:
  41. continue
  42. new_lines.append(line)
  43. f.seek(0)
  44. f.truncate()
  45. f.writelines(new_lines)
  46. return
  47. def modify_manifest_common(decompileDir, removeKey):
  48. ET.register_namespace('android', ANDROID_NS)
  49. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  50. logging.info(xmlparse)
  51. root_node = ET.parse(xmlparse)
  52. root = root_node.getroot()
  53. name = '{' + ANDROID_NS + '}name'
  54. authorities = '{' + ANDROID_NS + '}' + removeKey
  55. package_name = root.attrib.get('package')
  56. if package_name == None:
  57. return
  58. providers = root.findall('./application')
  59. if providers != None:
  60. for provider in providers:
  61. # providerName = provider.attrib.get(name)
  62. # if 'com.netease.ntunisdk.CcMomentRecordingForegroundService' == providerName:
  63. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  64. try:
  65. del provider.attrib[authorities]
  66. except:
  67. ""
  68. root_node.write(xmlparse, 'utf-8')
  69. if __name__ == '__main__':
  70. # del_qihoo("C:\\Users\\Administrator\\Desktop\\zt")
  71. # remove_navigate("G:\\autopack2.0_kuaifa\\tool\\workspace\\lrs360\\13651\\extract")
  72. modify_manifest_common("E:\\apk\\youhua\\HXHLGKzX7ZgyxZ0RcZ61RDnnhVCPpfxG",
  73. "allowNativeHeapPointerTagging")