script.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # coding:utf8
  2. __author__ = 'tianshuqitan'
  3. import os
  4. import logging
  5. import shutil
  6. from xml.etree import ElementTree as ET
  7. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  8. def script_second(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  9. if channelSdkInfo['id'] == '587':
  10. progress_png = os.path.join(decompileDir, "res/drawable/progress.png")
  11. if os.path.exists(progress_png):
  12. os.remove(progress_png)
  13. return
  14. def script_second(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  15. modify_manifest_common(decompileDir, "allowNativeHeapPointerTagging")
  16. return
  17. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  18. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  19. if channelSdkInfo['id'] == '549':
  20. del_coolcloud(decompileDir)
  21. modify_manifest_common(decompileDir, "allowNativeHeapPointerTagging")
  22. app_theme(decompileDir)
  23. def del_coolcloud(decompileDir):
  24. coolcloud = os.path.join(decompileDir, 'smali_classes3/com/coolcloud')
  25. if os.path.exists(coolcloud):
  26. shutil.rmtree(coolcloud)
  27. def replace_Theme(extract_dir):
  28. goal_file = os.path.join(extract_dir, 'res/values/styles.xml')
  29. print(os.path.isfile(goal_file))
  30. if os.path.isfile(goal_file):
  31. logging.info('method_proceed: ' + 'goal_file')
  32. print(goal_file)
  33. with open(goal_file, 'r+') as f:
  34. cont = f.read()
  35. change_str = '@android:style/Theme.Light'
  36. str = '@android:style/Theme.Light.NoTitleBar'
  37. cont = cont.replace(change_str, str)
  38. logging.info('replace_str: ' + cont)
  39. with open(goal_file, 'w+') as tf:
  40. tf.write(cont)
  41. def app_theme(decompile_dir_path):
  42. style_xml_path = os.path.join(decompile_dir_path, 'res', 'values', 'styles.xml')
  43. xml_tree = ET.parse(style_xml_path)
  44. xml_root = xml_tree.getroot()
  45. style_roots = xml_root.findall('./style')
  46. for style_root in style_roots:
  47. if style_root.get('name') == 'AppTheme':
  48. print style_root.get('parent')
  49. style_root.set('parent', '@android:style/Theme.NoTitleBar.Fullscreen')
  50. # 在 Python 2 中,需要手动处理编码
  51. with open(style_xml_path, 'w') as f:
  52. f.write('<?xml version="1.0" encoding="utf-8"?>\n')
  53. f.write(ET.tostring(xml_root, encoding='utf-8'))
  54. break
  55. def handle_public_xml(public_xml_path, remove_node):
  56. if not os.path.exists(public_xml_path):
  57. logging.info('public_xml is null: ' + public_xml_path)
  58. return
  59. new_lines = []
  60. with open(public_xml_path, 'r+') as f:
  61. for line in f.readlines():
  62. # l = line.strip()
  63. if line.find(remove_node) > -1:
  64. continue
  65. new_lines.append(line)
  66. f.seek(0)
  67. f.truncate()
  68. f.writelines(new_lines)
  69. return
  70. def modify_manifest_common(decompileDir, removeKey):
  71. ET.register_namespace('android', ANDROID_NS)
  72. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  73. logging.info(xmlparse)
  74. root_node = ET.parse(xmlparse)
  75. root = root_node.getroot()
  76. name = '{' + ANDROID_NS + '}name'
  77. authorities = '{' + ANDROID_NS + '}' + removeKey
  78. package_name = root.attrib.get('package')
  79. if package_name == None:
  80. return
  81. providers = root.findall('./application')
  82. if providers != None:
  83. for provider in providers:
  84. try:
  85. del provider.attrib[authorities]
  86. except:
  87. ""
  88. root_node.write(xmlparse, 'utf-8')
  89. if __name__ == '__main__':
  90. d="D://work//autopack3//tool//outputGame//admin@163.com//xinxiaaojianghukp//1.0.260//xinxiaaojianghukp_39"
  91. app_theme(d)