script.py 4.2 KB

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