script.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. decompileDir=extract_dir
  18. if channel_sdk_info['id'] == '597':
  19. delete_file_path = os.path.join(extract_dir, "res/mipmap-mdpi/ic_launcher.webp")
  20. delete_file(delete_file_path)
  21. delete_file_path = os.path.join(extract_dir, "res/mipmap-hdpi/ic_launcher.webp")
  22. delete_file(delete_file_path)
  23. delete_file_path = os.path.join(extract_dir, "res/mipmap-xhdpi/ic_launcher.webp")
  24. delete_file(delete_file_path)
  25. delete_file_path = os.path.join(extract_dir, "res/mipmap-xxhdpi/ic_launcher.webp")
  26. delete_file(delete_file_path)
  27. delete_file_path = os.path.join(extract_dir, "res/mipmap-xxxhdpi/ic_launcher.webp")
  28. delete_file(delete_file_path)
  29. return
  30. def delete_file(file):
  31. if not os.path.exists(file):
  32. logging.info('public_xml is null: ' +file)
  33. return
  34. os.remove(file)
  35. return
  36. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  37. return
  38. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  39. if channelSdkInfo['id'] == '597':
  40. s1 = os.path.join(decompileDir, "smali_classes9","com")
  41. if os.path.exists(s1):
  42. smali_classes_new = create_mutil_smali(decompileDir)
  43. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  44. list_package = ["blankj","bumptech","bun","companyname","coolpad"]
  45. if not os.path.exists(s3):
  46. distutils.dir_util.mkpath(s3)
  47. move_package(s1, s3, list_package)
  48. s1 = os.path.join(decompileDir, "smali_classes9","com")
  49. if os.path.exists(s1):
  50. smali_classes_new = create_mutil_smali(decompileDir)
  51. s3 = os.path.join(decompileDir, smali_classes_new,"com")
  52. list_package = ["game","github","google"]
  53. if not os.path.exists(s3):
  54. distutils.dir_util.mkpath(s3)
  55. move_package(s1, s3, list_package)
  56. s1 = os.path.join(decompileDir, "smali_classes9","com","hzwx")
  57. if os.path.exists(s1):
  58. smali_classes_new = create_mutil_smali(decompileDir)
  59. s3 = os.path.join(decompileDir, smali_classes_new,"com","hzwx")
  60. list_package = ["am","android","androidutil","auto"]
  61. if not os.path.exists(s3):
  62. distutils.dir_util.mkpath(s3)
  63. move_package(s1, s3, list_package)
  64. s1 = os.path.join(decompileDir, "smali_classes9","com","hzwx")
  65. if os.path.exists(s1):
  66. smali_classes_new = create_mutil_smali(decompileDir)
  67. s3 = os.path.join(decompileDir, smali_classes_new,"com","hzwx")
  68. list_package = ["diy","fx","lib","sy","wx"]
  69. if not os.path.exists(s3):
  70. distutils.dir_util.mkpath(s3)
  71. move_package(s1, s3, list_package)
  72. return
  73. def create_mutil_smali(decompileDir):
  74. f_idx = 2
  75. while True:
  76. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  77. tmp = tmp.replace('\\', '/')
  78. tmp = re.sub('/+', '/', tmp)
  79. if os.path.exists(tmp):
  80. f_idx += 1
  81. else:
  82. smali_classes2_dir = tmp
  83. break
  84. # endwhile
  85. os.mkdir(smali_classes2_dir)
  86. return smali_classes2_dir
  87. def move_package(s1, s3, list_package):
  88. for d in list_package:
  89. src = os.path.join(s1, d)
  90. if os.path.exists(src):
  91. dst = os.path.join(s3, d)
  92. distutils.dir_util.copy_tree(src, dst)
  93. distutils.dir_util.remove_tree(src)
  94. def move_package_one(src, dst):
  95. if os.path.exists(src):
  96. distutils.dir_util.copy_tree(src, dst)
  97. distutils.dir_util.remove_tree(src)
  98. change_map = {".super Landroid/app/Application;": ".super Lcom/kf/framework/KFApplication;",
  99. "invoke-direct {p0}, Landroid/app/Application;-><init>()V": "invoke-direct {p0}, Lcom/kf/framework/KFApplication;-><init>()V",
  100. "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",
  101. "invoke-super {p0}, Landroid/app/Application;->onCreate()V": "invoke-super {p0}, Lcom/kf/framework/KFApplication;->onCreate()V", }
  102. def replace_super_application(decompileDir):
  103. smali_files = glob.glob(
  104. os.path.join(decompileDir, 'smali*/com/radical/huangshangjixiang/qh360/CoronaApplication.smali'))
  105. if len(smali_files) == 1:
  106. game_application_file = smali_files[0];
  107. print game_application_file
  108. if os.path.isfile(game_application_file):
  109. with open(game_application_file, "r+") as f:
  110. file_str = f.read()
  111. for k, v in change_map.items():
  112. file_str = file_str.replace(k, v)
  113. with open(game_application_file, "w+") as f:
  114. f.write(file_str)
  115. def modify_manifest(decompileDir, removeKey):
  116. ET.register_namespace('android', ANDROID_NS)
  117. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  118. root_node = ET.parse(xmlparse)
  119. root = root_node.getroot()
  120. name = '{' + ANDROID_NS + '}name'
  121. authorities = '{' + ANDROID_NS + '}' + removeKey
  122. package_name = root.attrib.get('package')
  123. if package_name == None:
  124. return
  125. providers = root.findall('./application')
  126. if providers != None:
  127. for provider in providers:
  128. # providerName = provider.attrib.get(name)
  129. # if 'com.netease.ntunisdk.CcMomentRecordingForegroundService' == providerName:
  130. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  131. try:
  132. del provider.attrib[authorities]
  133. except:
  134. ""
  135. root_node.write(xmlparse, 'utf-8')
  136. if __name__ == '__main__':
  137. # replace_super_application("D:\work\wzdq")
  138. modify_manifest("E:\\apk\\youhua\\youhua.zip.out", "requestLegacyExternalStorage")