script.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # encoding: utf-8
  2. import logging
  3. import os
  4. import yaml
  5. import xml.etree.ElementTree as ET
  6. import re
  7. __author__ = 'billyyoyo'
  8. ANDROID_NAMESPACE = 'http://schemas.android.com/apk/res/android'
  9. def change_application_id(extra_dir, packageName):
  10. fname = extra_dir + '/AndroidManifest.xml'
  11. with open(fname, 'r+') as f:
  12. cont = f.read()
  13. findstr = '#applicationId#'
  14. rStr = packageName+'.smallsheep'
  15. cont = cont.replace(findstr, rStr)
  16. f.seek(0)
  17. f.truncate(len(cont))
  18. f.write(cont)
  19. f.close()
  20. def fix_xmy_recharge_screen_orientation(decompile_dir_path):
  21. developer_path = os.path.join(decompile_dir_path, 'assets', 'developer.properties')
  22. print(developer_path)
  23. is_landscape = True
  24. with open(developer_path, 'r') as f:
  25. smali_str_arr = f.readlines()
  26. for line in smali_str_arr:
  27. if 'screen_oriention' in line:
  28. results = re.findall(re.compile(r'\d'), line)
  29. if len(results) != 0:
  30. orientation_value = results[0]
  31. print('orientation_value', orientation_value)
  32. is_landscape = int(orientation_value) == 0
  33. break
  34. print('is_landscape', is_landscape)
  35. if not is_landscape:
  36. return
  37. namespace = '{http://schemas.android.com/apk/res/android}'
  38. ET.register_namespace('android', 'http://schemas.android.com/apk/res/android')
  39. manifest_path = os.path.join(decompile_dir_path, 'AndroidManifest.xml')
  40. xml_tree = ET.parse(manifest_path)
  41. xml_root = xml_tree.getroot()
  42. activity_nodes = xml_root.findall('.//activity')
  43. print(activity_nodes)
  44. for activity_node in activity_nodes:
  45. print(activity_node.attrib)
  46. activity_name = activity_node.get('%sname' % namespace)
  47. print(activity_name)
  48. if 'com.yog.kothoth.view.activity.SSRechargeActivity' == activity_name:
  49. activity_node.set('%sscreenOrientation' % namespace, 'landscape')
  50. xml_tree.write(manifest_path, encoding='utf-8', xml_declaration=True)
  51. break
  52. def fix_install_fail_bug(decompile_dir_path):
  53. namespace = '{http://schemas.android.com/apk/res/android}'
  54. ET.register_namespace('android', 'http://schemas.android.com/apk/res/android')
  55. manifest_path = os.path.join(decompile_dir_path, 'AndroidManifest.xml')
  56. xml_tree = ET.parse(manifest_path)
  57. xml_root = xml_tree.getroot()
  58. application_node = xml_root.find('./application')
  59. etract_value = application_node.get('%sextractNativeLibs' % namespace)
  60. if etract_value is not None and etract_value == 'false':
  61. # 修改extractNativeLib
  62. application_node.set('%sextractNativeLibs' % namespace, 'true')
  63. xml_tree.write(manifest_path, encoding='utf-8', xml_declaration=True)
  64. yaml_path = os.path.join(decompile_dir_path, 'apktool.yml')
  65. file = open(yaml_path, 'r')
  66. yaml_result = yaml.load(file, Loader=yaml.BaseLoader)
  67. sdk_info = yaml_result['sdkInfo']
  68. yaml_result['packageInfo']['renameManifestPackage'] = None
  69. print(sdk_info)
  70. if sdk_info.has_key('targetSdkVersion') and int(sdk_info['targetSdkVersion']) > 29:
  71. sdk_info['targetSdkVersion'] = '29'
  72. print(sdk_info)
  73. file.close()
  74. with open(yaml_path, 'w') as f:
  75. # yaml.dump(yaml_result, f)
  76. yaml.safe_dump(yaml_result, f,allow_unicode=True, default_flow_style=False)
  77. def fix_android8_bug_xmy(decompile_dir):
  78. style_xml_path = os.path.join(decompile_dir, 'res', 'values', 'styles.xml')
  79. xml_tree = ET.parse(style_xml_path)
  80. xml_root = xml_tree.getroot()
  81. style_roots = xml_root.findall('./style')
  82. for style_root in style_roots:
  83. if style_root.get('name') == 'kf_splash_translucent':
  84. items = style_root.findall('./item')
  85. for item in items:
  86. print('item name', item.get('name'))
  87. print(item.findtext('.'))
  88. if item.get('name') == 'android:windowIsTranslucent':
  89. item.text = 'false'
  90. xml_tree.write(style_xml_path, encoding='utf-8', xml_declaration=True)
  91. break
  92. namespace = '{http://schemas.android.com/apk/res/android}'
  93. ET.register_namespace('android', 'http://schemas.android.com/apk/res/android')
  94. manifest_path = os.path.join(decompile_dir, 'AndroidManifest.xml')
  95. xml_tree = ET.parse(manifest_path)
  96. xml_root = xml_tree.getroot()
  97. act_list = xml_root.findall('.//activity')
  98. for act in act_list:
  99. act_name = act.get('%sname' % namespace)
  100. print(act_name)
  101. if 'com.yog.kothoth.view.activity.SSShoppingMallActivity' == act_name or 'com.yog.kothoth.view.activity.SSRechargeActivity' == act_name:
  102. act_theme = act.get('%stheme' % namespace)
  103. print('act_theme', act_theme)
  104. act.set('%stheme' % namespace, '@style/kf_splash_translucent')
  105. xml_tree.write(manifest_path, encoding='utf-8', xml_declaration=True)
  106. break
  107. def script(work_sdk_dir, extra_dir, channel_sdk_info, new_game_channel_info, game_info):
  108. logging.info("---------------channel_sdk_info-------------")
  109. logging.info(channel_sdk_info)
  110. logging.info("---------------new_game_channel_info-------------")
  111. logging.info(new_game_channel_info)
  112. logging.info("---------------game_info-------------")
  113. logging.info(game_info)
  114. applicationId = channel_sdk_info["packNameSuffix"]
  115. change_application_id(extra_dir, applicationId)
  116. fix_install_fail_bug(extra_dir)
  117. fix_xmy_recharge_screen_orientation(extra_dir)
  118. fix_android8_bug_xmy(extra_dir)
  119. if __name__ == '__main__':
  120. script("", ".", {'package_name':'com.netease.dwrg.yl.ludashi'}, {}, {})