script.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. import gw_data_center
  14. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  15. def script_init(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  16. # gw_data_center.pack_small=True
  17. return
  18. def script_second(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  19. logging.info('script_second: ' + str(channel_sdk_info))
  20. # 逆向渠道id
  21. if channel_sdk_info['id'] == '549':
  22. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/public.xml")
  23. handle_public_xml(public_xml, "abc_list_pressed_holo_dark")
  24. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/public.xml")
  25. handle_public_xml(public_xml, "abc_list_selector_disabled_holo_dark")
  26. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/public.xml")
  27. handle_public_xml(public_xml, "abc_list_selector_background_transition_holo_dark")
  28. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/public.xml")
  29. handle_public_xml(public_xml, "abc_list_selector_holo_dark")
  30. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/public.xml")
  31. handle_public_xml(public_xml, "abc_item_background_holo_dark")
  32. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/styles.xml")
  33. handle_public_xml(public_xml, "abc_list_selector_holo_dark")
  34. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/values/styles.xml")
  35. handle_public_xml(public_xml, "abc_item_background_holo_dark")
  36. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable/abc_item_background_holo_dark.xml")
  37. if os.path.exists(public_xml):
  38. os.remove(public_xml)
  39. public_xml = os.path.join(extract_dir,
  40. "../sdk/smallsheep/ForRes/drawable/abc_list_selector_background_transition_holo_dark.xml")
  41. if os.path.exists(public_xml):
  42. os.remove(public_xml)
  43. public_xml = os.path.join(extract_dir, "../sdk/smallsheep/ForRes/drawable/abc_list_selector_holo_dark.xml")
  44. if os.path.exists(public_xml):
  45. os.remove(public_xml)
  46. public_xml = os.path.join(extract_dir,
  47. "../sdk/smallsheep/ForRes/drawable-mdpi/abc_list_pressed_holo_dark.9.png")
  48. logging.info("public_xml:" + public_xml)
  49. if os.path.exists(public_xml):
  50. os.remove(public_xml)
  51. public_xml = os.path.join(extract_dir,
  52. "../sdk/smallsheep/ForRes/drawable-hdpi/abc_list_pressed_holo_dark.9.png")
  53. if os.path.exists(public_xml):
  54. os.remove(public_xml)
  55. public_xml = os.path.join(extract_dir,
  56. "../sdk/smallsheep/ForRes/drawable-xhdpi/abc_list_pressed_holo_dark.9.png")
  57. if os.path.exists(public_xml):
  58. os.remove(public_xml)
  59. public_xml = os.path.join(extract_dir,
  60. "../sdk/smallsheep/ForRes/drawable-xxhdpi/abc_list_pressed_holo_dark.9.png")
  61. if os.path.exists(public_xml):
  62. os.remove(public_xml)
  63. public_xml = os.path.join(extract_dir,
  64. "../sdk/smallsheep/ForRes/drawable-mdpi/abc_list_selector_disabled_holo_dark.9.png")
  65. if os.path.exists(public_xml):
  66. os.remove(public_xml)
  67. public_xml = os.path.join(extract_dir,
  68. "../sdk/smallsheep/ForRes/drawable-hdpi/abc_list_selector_disabled_holo_dark.9.png")
  69. if os.path.exists(public_xml):
  70. os.remove(public_xml)
  71. public_xml = os.path.join(extract_dir,
  72. "../sdk/smallsheep/ForRes/drawable-xhdpi/abc_list_selector_disabled_holo_dark.9.png")
  73. if os.path.exists(public_xml):
  74. os.remove(public_xml)
  75. public_xml = os.path.join(extract_dir,
  76. "../sdk/smallsheep/ForRes/drawable-xxhdpi/abc_list_selector_disabled_holo_dark.9.png")
  77. if os.path.exists(public_xml):
  78. os.remove(public_xml)
  79. def handle_public_xml(public_xml_path, remove_node):
  80. if not os.path.exists(public_xml_path):
  81. logging.info('public_xml is null: ' + public_xml_path)
  82. return
  83. new_lines = []
  84. with open(public_xml_path, 'r+') as f:
  85. for line in f.readlines():
  86. # l = line.strip()
  87. if line.find(remove_node) > -1:
  88. continue
  89. new_lines.append(line)
  90. f.seek(0)
  91. f.truncate()
  92. f.writelines(new_lines)
  93. return
  94. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  95. logging.info("-----debug-----")
  96. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  97. return
  98. def create_mutil_smali(decompileDir):
  99. f_idx = 2
  100. while True:
  101. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  102. tmp = tmp.replace('\\', '/')
  103. tmp = re.sub('/+', '/', tmp)
  104. if os.path.exists(tmp):
  105. f_idx += 1
  106. else:
  107. smali_classes2_dir = tmp
  108. break
  109. # endwhile
  110. os.mkdir(smali_classes2_dir)
  111. return smali_classes2_dir
  112. def move_package(s1, s3, list_package):
  113. for d in list_package:
  114. src = os.path.join(s1, d)
  115. if os.path.exists(src):
  116. dst = os.path.join(s3, d)
  117. distutils.dir_util.copy_tree(src, dst)
  118. distutils.dir_util.remove_tree(src)
  119. def move_package_one(src, dst):
  120. if os.path.exists(src):
  121. distutils.dir_util.copy_tree(src, dst)
  122. distutils.dir_util.remove_tree(src)
  123. change_map = {".super Landroid/app/Application;": ".super Lcom/kf/framework/KFApplication;",
  124. "invoke-direct {p0}, Landroid/app/Application;-><init>()V": "invoke-direct {p0}, Lcom/kf/framework/KFApplication;-><init>()V",
  125. "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",
  126. "invoke-super {p0}, Landroid/app/Application;->onCreate()V": "invoke-super {p0}, Lcom/kf/framework/KFApplication;->onCreate()V", }
  127. def replace_super_application(decompileDir):
  128. smali_files = glob.glob(
  129. os.path.join(decompileDir, 'smali*/com/radical/huangshangjixiang/qh360/CoronaApplication.smali'))
  130. if len(smali_files) == 1:
  131. game_application_file = smali_files[0];
  132. print game_application_file
  133. if os.path.isfile(game_application_file):
  134. with open(game_application_file, "r+") as f:
  135. file_str = f.read()
  136. for k, v in change_map.items():
  137. file_str = file_str.replace(k, v)
  138. with open(game_application_file, "w+") as f:
  139. f.write(file_str)
  140. def modify_manifest(decompileDir, removeKey):
  141. ET.register_namespace('android', ANDROID_NS)
  142. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  143. root_node = ET.parse(xmlparse)
  144. root = root_node.getroot()
  145. name = '{' + ANDROID_NS + '}name'
  146. authorities = '{' + ANDROID_NS + '}' + removeKey
  147. package_name = root.attrib.get('package')
  148. if package_name == None:
  149. return
  150. providers = root.findall('./application')
  151. if providers != None:
  152. for provider in providers:
  153. # providerName = provider.attrib.get(name)
  154. # if 'com.netease.ntunisdk.CcMomentRecordingForegroundService' == providerName:
  155. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  156. try:
  157. del provider.attrib[authorities]
  158. except:
  159. ""
  160. root_node.write(xmlparse, 'utf-8')
  161. def handle_public_xml(public_xml_path, remove_node):
  162. if not os.path.exists(public_xml_path):
  163. logging.info('public_xml is null: ' + public_xml_path)
  164. return
  165. new_lines = []
  166. with open(public_xml_path, 'r+') as f:
  167. for line in f.readlines():
  168. # l = line.strip()
  169. if line.find(remove_node) > -1:
  170. continue
  171. new_lines.append(line)
  172. f.seek(0)
  173. f.truncate()
  174. f.writelines(new_lines)
  175. return
  176. if __name__ == '__main__':
  177. # replace_super_application("D:\work\wzdq")
  178. modify_manifest("E:\\apk\\youhua\\youhua.zip.out", "requestLegacyExternalStorage")