script.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. from xml.etree.ElementTree import ElementTree, Element
  10. import distutils.dir_util
  11. from xml.etree import ElementTree as ET
  12. import gw_file_system
  13. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  14. def script_second(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  15. logging.info('script_second: ' + str(channel_sdk_info))
  16. # 逆向渠道id
  17. sdk_id = channel_sdk_info['id']
  18. if sdk_id == "597" :#深圳 成都都是用这个id
  19. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  20. if os.path.exists(public_xml):
  21. handle_public_xml(public_xml, "attr-private")
  22. public_xml = os.path.join(extract_dir, "res/layout/design_bottom_sheet_dialog.xml")
  23. if os.path.exists(public_xml):
  24. handle_public_xml(public_xml, "attr-private")
  25. public_xml = os.path.join(extract_dir, "res/layout/mtrl_layout_snackbar.xml")
  26. # handle_public_xml(public_xml, "attr-private")
  27. if os.path.exists(public_xml):
  28. os.remove(public_xml)
  29. public_xml = os.path.join(extract_dir, "res/layout-sw600dp/mtrl_layout_snackbar.xml")
  30. # handle_public_xml(public_xml, "attr-private")
  31. if os.path.exists(public_xml):
  32. os.remove(public_xml)
  33. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  34. if os.path.exists(public_xml):
  35. handle_public_xml(public_xml, "mtrl_layout_snackbar")
  36. public_xml = os.path.join(extract_dir, "res/layout/mtrl_layout_snackbar_include.xml")
  37. if os.path.exists(public_xml):
  38. handle_public_xml(public_xml, "attr-private")
  39. public_xml = os.path.join(extract_dir, "res/drawable-v21/abc_dialog_material_background.xml")
  40. if os.path.exists(public_xml):
  41. handle_public_xml(public_xml, "attr-private")
  42. public_xml = os.path.join(extract_dir, "res/values/styles.xml")
  43. if os.path.exists(public_xml):
  44. handle_public_xml(public_xml, "attr-private")
  45. public_xml = os.path.join(extract_dir, "res/values-v21/styles.xml")
  46. if os.path.exists(public_xml):
  47. handle_public_xml(public_xml, "attr-private")
  48. return
  49. def handle_public_xml(public_xml_path, remove_node):
  50. if not os.path.exists(public_xml_path):
  51. logging.info('public_xml is null: ' + public_xml_path)
  52. return
  53. new_lines = []
  54. with open(public_xml_path, 'r+') as f:
  55. for line in f.readlines():
  56. # l = line.strip()
  57. if line.find(remove_node) > -1:
  58. continue
  59. new_lines.append(line)
  60. f.seek(0)
  61. f.truncate()
  62. f.writelines(new_lines)
  63. return
  64. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  65. logging.info("-----debug-----")
  66. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  67. return
  68. def create_mutil_smali(decompileDir):
  69. f_idx = 2
  70. while True:
  71. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  72. tmp = tmp.replace('\\', '/')
  73. tmp = re.sub('/+', '/', tmp)
  74. if os.path.exists(tmp):
  75. f_idx += 1
  76. else:
  77. smali_classes2_dir = tmp
  78. break
  79. # endwhile
  80. os.mkdir(smali_classes2_dir)
  81. return smali_classes2_dir
  82. def move_package(s1, s3, list_package):
  83. for d in list_package:
  84. src = os.path.join(s1, d)
  85. if os.path.exists(src):
  86. dst = os.path.join(s3, d)
  87. distutils.dir_util.copy_tree(src, dst)
  88. distutils.dir_util.remove_tree(src)
  89. def move_package_one(src, dst):
  90. if os.path.exists(src):
  91. distutils.dir_util.copy_tree(src, dst)
  92. distutils.dir_util.remove_tree(src)
  93. change_map = {".super Landroid/app/Application;": ".super Lcom/kf/framework/KFApplication;",
  94. "invoke-direct {p0}, Landroid/app/Application;-><init>()V": "invoke-direct {p0}, Lcom/kf/framework/KFApplication;-><init>()V",
  95. "invoke-super {p0, p1}, Landroid/app/Application;->attachBaseContext(Landroid/content/Context;)V": "invoke-super {p0, p1}, Lcom/kf/framework/KFApplication;->attachBaseContext(Landroid/content/Context;)V",
  96. "invoke-super {p0}, Landroid/app/Application;->onCreate()V": "invoke-super {p0}, Lcom/kf/framework/KFApplication;->onCreate()V", }
  97. def replace_super_application(decompileDir):
  98. smali_files = glob.glob(
  99. os.path.join(decompileDir, 'smali*/com/radical/huangshangjixiang/qh360/CoronaApplication.smali'))
  100. if len(smali_files) == 1:
  101. game_application_file = smali_files[0];
  102. print game_application_file
  103. if os.path.isfile(game_application_file):
  104. with open(game_application_file, "r+") as f:
  105. file_str = f.read()
  106. for k, v in change_map.items():
  107. file_str = file_str.replace(k, v)
  108. with open(game_application_file, "w+") as f:
  109. f.write(file_str)
  110. def modify_manifest(decompileDir, removeKey):
  111. ET.register_namespace('android', ANDROID_NS)
  112. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  113. root_node = ET.parse(xmlparse)
  114. root = root_node.getroot()
  115. name = '{' + ANDROID_NS + '}name'
  116. authorities = '{' + ANDROID_NS + '}' + removeKey
  117. package_name = root.attrib.get('package')
  118. if package_name == None:
  119. return
  120. providers = root.findall('./application')
  121. if providers != None:
  122. for provider in providers:
  123. # providerName = provider.attrib.get(name)
  124. # if 'com.netease.ntunisdk.CcMomentRecordingForegroundService' == providerName:
  125. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  126. try:
  127. del provider.attrib[authorities]
  128. except:
  129. ""
  130. root_node.write(xmlparse, 'utf-8')
  131. if __name__ == '__main__':
  132. # replace_super_application("D:\work\wzdq")
  133. modify_manifest("E:\\apk\\youhua\\youhua.zip.out", "requestLegacyExternalStorage")