script.py 4.9 KB

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