script.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. # 逆向渠道id
  16. if channel_sdk_info['id'] == "512":
  17. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  18. handle_public_xml(public_xml)
  19. if channel_sdk_info['id'] == "597":
  20. remove_navigate(extract_dir)
  21. public_xml = os.path.join(extract_dir, "res/values/arrays.xml")
  22. # handle_public_xml_param(public_xml, "com.jinke.mao.css.api")
  23. # handle_public_xml_param(public_xml, "outfit7")
  24. # handle_public_xml_param(public_xml, "kotlin")
  25. # handle_public_xml_param(public_xml, "acra")
  26. if os.path.exists(public_xml):
  27. os.remove(public_xml)
  28. public_xml = os.path.join(extract_dir, "res/layout/felis_navigation_container.xml")
  29. if os.path.exists(public_xml):
  30. os.remove(public_xml)
  31. return
  32. def script_pre(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  33. return
  34. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  35. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  36. s1 = os.path.join(decompileDir, "smali/androidx")
  37. if os.path.exists(s1):
  38. smali_classes2_dir = create_mutil_smali(decompileDir)
  39. s3 = os.path.join(smali_classes2_dir, "androidx")
  40. list_package = ["preference", "print", "recyclerview", "room", "savedstate", "slidingpanelayout", "sqlite",
  41. "swiperefreshlayout", "vectordrawable", "versionedparcelable", "viewpager", "work"]
  42. if not os.path.exists(s3):
  43. distutils.dir_util.mkpath(s3)
  44. move_package(s1, s3, list_package)
  45. s1 = os.path.join(decompileDir, "smali/androidx")
  46. smali_classes2_dir = create_mutil_smali(decompileDir)
  47. s3 = os.path.join(smali_classes2_dir, "androidx")
  48. list_package = ["activity", "appcompat", "asynclayoutinflater", "constraintlayout", "core", "customview",
  49. "drawerlayout", "fragment", "interpolator", "lifecycle", "localbroadcastmanager", "multidex",
  50. "annotation", "arch", "collection", "coordinatorlayout", "cursoradapter", "documentfile",
  51. "exifinterface", "inspection", "legacy", "loader", " media"]
  52. if not os.path.exists(s3):
  53. distutils.dir_util.mkpath(s3)
  54. move_package(s1, s3, list_package)
  55. s1 = os.path.join(decompileDir, "smali_classes2")
  56. if os.path.exists(s1):
  57. smali_classes2_dir = create_mutil_smali(decompileDir)
  58. s3 = os.path.join(smali_classes2_dir)
  59. list_package = ["dagger", "javax", "kotlinx", "kotlin", "okhttp3", "okio", "org", "retrofit2", "zzsvz", "zzviy",
  60. "zzzfy"]
  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_classes2/com")
  65. if os.path.exists(s1):
  66. smali_classes2_dir = create_mutil_smali(decompileDir)
  67. s3 = os.path.join(smali_classes2_dir, "com")
  68. list_package = ["track", "yulong", "zui"]
  69. if not os.path.exists(s3):
  70. distutils.dir_util.mkpath(s3)
  71. move_package(s1, s3, list_package)
  72. png = decompileDir + "/../agereminder_title.9.png"
  73. asserts = os.path.join(decompileDir, "res/drawable-xxhdpi/agereminder_title.9.png")
  74. if os.path.exists(asserts) and os.path.exists(os.path.join(png)):
  75. # distutils.dir_util.copy(png, asserts)
  76. shutil.copyfile(os.path.dirname(os.path.abspath(__file__)) + "/agereminder_title.9.png", asserts)
  77. if channelSdkInfo["id"] == "597":
  78. s1 = os.path.join(decompileDir, "smali_classes2", "com")
  79. smali_classes2_dir = create_mutil_smali(decompileDir)
  80. s3 = os.path.join(smali_classes2_dir, "com")
  81. list_package = ["jkjoy", "meizu", "outfit7"]
  82. if not os.path.exists(s3):
  83. distutils.dir_util.mkpath(s3)
  84. move_package(s1, s3, list_package)
  85. def move_package(s1, s3, list_package):
  86. for d in list_package:
  87. src = os.path.join(s1, d)
  88. if os.path.exists(src):
  89. dst = os.path.join(s3, d)
  90. distutils.dir_util.copy_tree(src, dst)
  91. distutils.dir_util.remove_tree(src)
  92. def create_mutil_smali(decompileDir):
  93. f_idx = 2
  94. while True:
  95. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  96. tmp = tmp.replace('\\', '/')
  97. tmp = re.sub('/+', '/', tmp)
  98. if os.path.exists(tmp):
  99. files = os.listdir(tmp)
  100. if len(files) == 0:
  101. smali_classes2_dir = tmp
  102. break
  103. f_idx += 1
  104. else:
  105. smali_classes2_dir = tmp
  106. break
  107. # endwhile
  108. if not os.path.exists(smali_classes2_dir):
  109. os.mkdir(smali_classes2_dir)
  110. return smali_classes2_dir
  111. def handle_public_xml_param(public_xml_path, remove_node):
  112. if not os.path.exists(public_xml_path):
  113. logging.info('public_xml is null: ' + public_xml_path)
  114. return
  115. new_lines = []
  116. with open(public_xml_path, 'r+') as f:
  117. for line in f.readlines():
  118. # l = line.strip()
  119. if line.find(remove_node) > -1:
  120. continue
  121. new_lines.append(line)
  122. f.seek(0)
  123. f.truncate()
  124. f.writelines(new_lines)
  125. return
  126. def handle_public_xml(public_xml_path):
  127. if not os.path.exists(public_xml_path):
  128. logging.info('public_xml is null: ' + public_xml_path)
  129. return
  130. new_lines = []
  131. with open(public_xml_path, 'r+') as f:
  132. for line in f.readlines():
  133. # l = line.strip()
  134. if line.find("offline_banners") > -1 or line.find("outfit7") > -1 or line.find(
  135. "countries") > -1 or line.find(
  136. "county_codes") > -1 or line.find("felis_error_reporting_files") > -1:
  137. continue
  138. new_lines.append(line)
  139. f.seek(0)
  140. f.truncate()
  141. f.writelines(new_lines)
  142. return
  143. def remove_navigate(decompileDir):
  144. tmp_res = os.path.join(decompileDir, "res", "navigation")
  145. tmp_public_xml = os.path.join(decompileDir, "res", "values", "public.xml")
  146. if os.path.exists(tmp_res):
  147. distutils.dir_util.remove_tree(tmp_res)
  148. if os.path.exists(tmp_public_xml):
  149. os.remove(tmp_public_xml)
  150. if __name__ == '__main__':
  151. script_last("/tmp/ss", "G:/autopack2.0_kuaifa/tool/workspace/wdajl/15957/extract/", {"id": "309"}, "", "")
  152. # xml_path = "E:/apk/youhua/jingmenfengyue_216122/res/values/public.xml"
  153. # handle_public_xml(xml_path)
  154. # hideSplash("/mnt/share/yanghuang/python_test/cr")