script.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_apk_tool
  14. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  15. def script_second(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  16. logging.info('script_second: ' + str(channel_sdk_info))
  17. # 逆向渠道id
  18. if channel_sdk_info['id'] == '597':
  19. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  20. handle_public_xml(public_xml, "attr-private")
  21. handle_public_xml(public_xml, "mtrl_layout_snackbar")
  22. public_xml = os.path.join(extract_dir, "res/values/styles.xml")
  23. handle_public_xml(public_xml, "attr-private")
  24. public_xml = os.path.join(extract_dir, "res/values-v21/styles.xml")
  25. handle_public_xml(public_xml, "attr-private")
  26. public_xml = os.path.join(extract_dir, "res/layout/design_bottom_sheet_dialog.xml")
  27. handle_public_xml(public_xml, "bottomSheetStyle")
  28. public_xml = os.path.join(extract_dir, "res/layout/mtrl_layout_snackbar.xml")
  29. os.remove(public_xml)
  30. # handle_public_xml(public_xml, "snackbarStyle")
  31. public_xml = os.path.join(extract_dir, "res/layout-sw600dp/mtrl_layout_snackbar.xml")
  32. os.remove(public_xml)
  33. # handle_public_xml(public_xml, "snackbarStyle")
  34. public_xml = os.path.join(extract_dir, "res/layout/mtrl_layout_snackbar_include.xml")
  35. handle_public_xml(public_xml, "textAppearanceBody2")
  36. public_xml = os.path.join(extract_dir, "res/layout/mtrl_layout_snackbar_include.xml")
  37. handle_public_xml(public_xml, "snackbarButtonStyle")
  38. # handle_public_xml(public_xml, "sobot_fileEndingImage")
  39. # handle_public_xml(public_xml, "sobot_fileEndingPPT")
  40. # handle_public_xml(public_xml, "sobot_fileEndingPackage")
  41. # handle_public_xml(public_xml, "sobot_fileEndingPdf")
  42. # handle_public_xml(public_xml, "sobot_fileEndingText")
  43. # handle_public_xml(public_xml, "sobot_fileEndingVideo")
  44. # handle_public_xml(public_xml, "sobot_fileEndingWord")
  45. return
  46. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  47. logging.info("-----debug-----")
  48. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  49. if channelSdkInfo['id'] == '597':
  50. move(decompileDir)
  51. else:
  52. return
  53. def move(decompileDir):
  54. s1 = os.path.join(decompileDir, "smali/androidx")
  55. smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
  56. s3 = os.path.join(decompileDir, smali_classes_new, "androidx")
  57. list_package = ["activity","arch","constraintlayout","cursoradapter","drawerlayout","legacy"]
  58. if not os.path.exists(s3):
  59. distutils.dir_util.mkpath(s3)
  60. gw_apk_tool.move_package(s1, s3, list_package)
  61. s1 = os.path.join(decompileDir, "smali/androidx")
  62. smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
  63. s3 = os.path.join(decompileDir, smali_classes_new, "androidx")
  64. list_package = ["localbroadcastmanager","annotation","asynclayoutinflater","coordinatorlayout"]
  65. if not os.path.exists(s3):
  66. distutils.dir_util.mkpath(s3)
  67. gw_apk_tool.move_package(s1, s3, list_package)
  68. s1 = os.path.join(decompileDir, "smali/androidx")
  69. smali_classes_new = gw_apk_tool.create_mutil_smali(decompileDir)
  70. s3 = os.path.join(decompileDir, smali_classes_new, "androidx")
  71. list_package = ["customview","fragment","lifecycle","appcompat","collection","core","documentfile","interpolator","loader"]
  72. if not os.path.exists(s3):
  73. distutils.dir_util.mkpath(s3)
  74. gw_apk_tool.move_package(s1, s3, list_package)
  75. def handle_public_xml(public_xml_path, remove_node):
  76. if not os.path.exists(public_xml_path):
  77. logging.info('public_xml is null: ' + public_xml_path)
  78. return
  79. new_lines = []
  80. with open(public_xml_path, 'r+') as f:
  81. for line in f.readlines():
  82. # l = line.strip()
  83. if line.find(remove_node) > -1:
  84. continue
  85. new_lines.append(line)
  86. f.seek(0)
  87. f.truncate()
  88. f.writelines(new_lines)
  89. return
  90. if __name__ == '__main__':
  91. # replace_super_application("D:\work\wzdq")
  92. modify_manifest("E:\\apk\\youhua\\youhua.zip.out", "requestLegacyExternalStorage")