script.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # coding:utf8
  2. import os
  3. import logging
  4. import re
  5. import glob
  6. import shutil
  7. import xml.etree.ElementTree as ET
  8. import distutils.dir_util
  9. import gw_file_system
  10. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  11. def script(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  12. return
  13. def script_second(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  14. logging.info('script_second: ' + str(channel_sdk_info))
  15. return
  16. def script_pre(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  17. return
  18. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  19. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  20. # if channelSdkInfo['id'] == "597":
  21. remove_false_string(decompileDir+"/res/values/ids.xml")
  22. s1 = os.path.join(decompileDir, "smali_classes3/androidx")
  23. if channelSdkInfo['id'] == "597" and os.path.exists(s1):
  24. smali_classes2_dir = create_mutil_smali(decompileDir)
  25. s3 = os.path.join(smali_classes2_dir, "androidx")
  26. list_package = ["preference", "print", "recyclerview", "room", "savedstate", "slidingpanelayout", "sqlite",
  27. "swiperefreshlayout", "vectordrawable", "versionedparcelable", "viewpager", "work"]
  28. if not os.path.exists(s3):
  29. distutils.dir_util.mkpath(s3)
  30. move_package(s1, s3, list_package)
  31. s1 = os.path.join(decompileDir, "smali_classes3/androidx")
  32. smali_classes2_dir = create_mutil_smali(decompileDir)
  33. s3 = os.path.join(smali_classes2_dir, "androidx")
  34. list_package = ["activity", "appcompat", "asynclayoutinflater", "constraintlayout", "core", "customview",
  35. "drawerlayout", "fragment", "interpolator", "lifecycle", "localbroadcastmanager", "multidex",
  36. "annotation", "arch", "collection", "coordinatorlayout", "cursoradapter", "documentfile",
  37. "exifinterface", "inspection", "legacy", "loader", " media"]
  38. if not os.path.exists(s3):
  39. distutils.dir_util.mkpath(s3)
  40. move_package(s1, s3, list_package)
  41. if channelSdkInfo['id'] == "549" or channelSdkInfo['id'] == "591":
  42. s1 = os.path.join(decompileDir, "smali_classes5/androidx")
  43. smali_classes2_dir = create_mutil_smali(decompileDir)
  44. s3 = os.path.join(smali_classes2_dir, "androidx")
  45. list_package = ["documentfile", "drawerlayout", "fragment", "interpolator", "legacy", "lifecycle", "loader",
  46. "localbroadcastmanager", "multidex"]
  47. if not os.path.exists(s3):
  48. distutils.dir_util.mkpath(s3)
  49. move_package(s1, s3, list_package)
  50. def move_package(s1, s3, list_package):
  51. for d in list_package:
  52. src = os.path.join(s1, d)
  53. if os.path.exists(src):
  54. dst = os.path.join(s3, d)
  55. distutils.dir_util.copy_tree(src, dst)
  56. distutils.dir_util.remove_tree(src)
  57. def create_mutil_smali(decompileDir):
  58. f_idx = 2
  59. while True:
  60. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  61. tmp = tmp.replace('\\', '/')
  62. tmp = re.sub('/+', '/', tmp)
  63. if os.path.exists(tmp):
  64. files = os.listdir(tmp)
  65. if len(files) == 0:
  66. smali_classes2_dir = tmp
  67. break
  68. f_idx += 1
  69. else:
  70. smali_classes2_dir = tmp
  71. break
  72. # endwhile
  73. if not os.path.exists(smali_classes2_dir):
  74. os.mkdir(smali_classes2_dir)
  75. return smali_classes2_dir
  76. def handle_public_xml_param(public_xml_path, remove_node):
  77. if not os.path.exists(public_xml_path):
  78. logging.info('public_xml is null: ' + public_xml_path)
  79. return
  80. new_lines = []
  81. with open(public_xml_path, 'r+') as f:
  82. for line in f.readlines():
  83. # l = line.strip()
  84. if line.find(remove_node) > -1:
  85. continue
  86. new_lines.append(line)
  87. f.seek(0)
  88. f.truncate()
  89. f.writelines(new_lines)
  90. return
  91. def handle_public_xml(public_xml_path):
  92. if not os.path.exists(public_xml_path):
  93. logging.info('public_xml is null: ' + public_xml_path)
  94. return
  95. new_lines = []
  96. with open(public_xml_path, 'r+') as f:
  97. for line in f.readlines():
  98. # l = line.strip()
  99. if line.find("offline_banners") > -1 or line.find("outfit7") > -1 or line.find(
  100. "countries") > -1 or line.find(
  101. "county_codes") > -1 or line.find("felis_error_reporting_files") > -1:
  102. continue
  103. new_lines.append(line)
  104. f.seek(0)
  105. f.truncate()
  106. f.writelines(new_lines)
  107. return
  108. def remove_navigate(decompileDir):
  109. tmp_res = os.path.join(decompileDir, "res", "navigation")
  110. tmp_public_xml = os.path.join(decompileDir, "res", "values", "public.xml")
  111. if os.path.exists(tmp_res):
  112. distutils.dir_util.remove_tree(tmp_res)
  113. if os.path.exists(tmp_public_xml):
  114. os.remove(tmp_public_xml)
  115. def remove_false_string(file_path):
  116. # 打开文本文件并读取内容
  117. with open(file_path, 'r') as file:
  118. lines = file.readlines()
  119. # 删除每一行中的指定字符串
  120. filtered_lines = [line.replace('false', '') for line in lines]
  121. # 打开文本文件以写入模式,将修改后的内容写回原文件
  122. with open(file_path, 'w') as file:
  123. file.writelines(filtered_lines)
  124. if __name__ == '__main__':
  125. script_last("/tmp/ss", "G:/autopack2.0_kuaifa/tool/workspace/wdajl/15957/extract/", {"id": "309"}, "", "")
  126. # xml_path = "E:/apk/youhua/jingmenfengyue_216122/res/values/public.xml"
  127. # handle_public_xml(xml_path)
  128. # hideSplash("/mnt/share/yanghuang/python_test/cr")