script.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. # -*- coding:utf-8 -*-
  2. __author__ = 'ALIXie'
  3. import logging
  4. import shutil
  5. import os
  6. import re
  7. import distutils.dir_util
  8. import gw_file_system
  9. import gw_data_center
  10. import gw_apk_tool
  11. import xml.etree.ElementTree as ET
  12. ANDROID_NS = 'http://schemas.android.com/apk/res/android'
  13. def script_init(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  14. gw_data_center.pack_small = False
  15. def script_pre(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  16. sdk_id = channel_sdk_info['id']
  17. if sdk_id == "512" or sdk_id=="589" or sdk_id=="597":
  18. modify_manifest(extract_dir)
  19. game_mode_config = os.path.join(extract_dir, "res/xml-v22/game_mode_config.xml")
  20. os.remove(game_mode_config)
  21. return
  22. def script(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  23. return
  24. def script_last(workspace_sdk_dir, decompileDir, channel_sdk_info, new_game_channel_info, game_info):
  25. if channel_sdk_info['id'] == "512":
  26. s1 = os.path.join(decompileDir, "smali_classes5")
  27. smali_classes_new = create_mutil_smali(decompileDir)
  28. s3 = os.path.join(decompileDir, smali_classes_new)
  29. list_package = ["androidx"]
  30. if not os.path.exists(s3):
  31. distutils.dir_util.mkpath(s3)
  32. move_package(s1, s3, list_package)
  33. s1 = os.path.join(decompileDir, "smali_classes6","com","netease")
  34. smali_classes_new = create_mutil_smali(decompileDir)
  35. s3 = os.path.join(decompileDir, smali_classes_new,"com","netease")
  36. list_package = ["dtws0mobilecfs","ntunisdk","pharos"]
  37. if not os.path.exists(s3):
  38. distutils.dir_util.mkpath(s3)
  39. move_package(s1, s3, list_package)
  40. move(decompileDir)
  41. else:
  42. move_smallsheep(decompileDir)
  43. if channel_sdk_info['id'] == "549":
  44. s1 = os.path.join(decompileDir, "smali_classes3")
  45. smali_classes_new = create_mutil_smali(decompileDir)
  46. s3 = os.path.join(decompileDir, smali_classes_new)
  47. list_package = ["androidx"]
  48. if not os.path.exists(s3):
  49. distutils.dir_util.mkpath(s3)
  50. move_package(s1, s3, list_package)
  51. return
  52. def move_smallsheep(extract_dir):
  53. s1 = os.path.join(extract_dir, "smali_classes5","com/netease")
  54. smali_classes2_dir = gw_apk_tool.create_mutil_smali(extract_dir)
  55. s3 = os.path.join(smali_classes2_dir,"com/netease")
  56. list_package = ["android","cc","download","environment","httpdns","mobsec","neox","androidcrashhandler","ccrlsdk","downunifix","glide","loginapi","mpay"]
  57. if not os.path.exists(s3):
  58. distutils.dir_util.mkpath(s3)
  59. gw_apk_tool.move_package(s1, s3, list_package)
  60. def move(extract_dir):
  61. s1 = os.path.join(extract_dir, "smali_classes4")
  62. smali_classes2_dir = gw_apk_tool.create_mutil_smali(extract_dir)
  63. s3 = os.path.join(smali_classes2_dir)
  64. if not os.path.exists(s3):
  65. distutils.dir_util.mkpath(s3)
  66. gw_apk_tool.move_package(s1, s3, ["androidx"])
  67. s1 = os.path.join(extract_dir, "smali_classes7","androidx")
  68. smali_classes2_dir = gw_apk_tool.create_mutil_smali(extract_dir)
  69. s3 = os.path.join(smali_classes2_dir,"androidx")
  70. list_package = ["activity","appcompat","asynclayoutinflater","core","customview","interpolator","lifecycle","localbroadcastmanager","annotation","arch","cardview","cursoradapter","documentfile","legacy","loader","media"]
  71. if not os.path.exists(s3):
  72. distutils.dir_util.mkpath(s3)
  73. gw_apk_tool.move_package(s1, s3, list_package)
  74. s1 = os.path.join(extract_dir, "smali_classes8","com/netease/ntunisdk")
  75. smali_classes2_dir = gw_apk_tool.create_mutil_smali(extract_dir)
  76. s3 = os.path.join(smali_classes2_dir,"com/netease/ntunisdk")
  77. list_package = ["application","base","child","coolpad_sdk","extend","gamemode","langutil","ngshare","okio","picedit","atr","cclive","common","cutout","external","glide","modules","okhttp3","permissionkit","piclib"]
  78. if not os.path.exists(s3):
  79. distutils.dir_util.mkpath(s3)
  80. gw_apk_tool.move_package(s1, s3, list_package)
  81. def add_checkSelfPermission(extract_dir):
  82. goal_file = os.path.join(extract_dir, 'smali/android/support/v4/content/ContextCompat.smali')
  83. add_method(goal_file)
  84. def add_hjr_checkSelfPermission(extract_dir):
  85. goal_file = os.path.join(extract_dir, 'smali/android/support/haojieru/v4/content/ContextCompat.smali')
  86. add_method(goal_file)
  87. def add_method(goal_file):
  88. if os.path.isfile(goal_file):
  89. with open(goal_file, 'r+') as f:
  90. lines = f.readlines()
  91. method = ['.method public static checkSelfPermission(Landroid/content/Context;Ljava/lang/String;)I\n',
  92. ' .locals 2\n',
  93. ' .param p0, "context" # Landroid/content/Context;\n',
  94. ' .annotation build Landroid/support/annotation/NonNull;\n',
  95. ' .end annotation\n',
  96. ' .end param\n',
  97. ' .param p1, "permission" # Ljava/lang/String;\n',
  98. ' .annotation build Landroid/support/annotation/NonNull;\n',
  99. ' .end annotation\n',
  100. ' .end param\n',
  101. ' if-eqz p1, :cond_0\n',
  102. ' invoke-static {}, Landroid/os/Process;->myPid()I\n',
  103. ' move-result v0\n',
  104. ' invoke-static {}, Landroid/os/Process;->myUid()I\n',
  105. ' move-result v1\n',
  106. ' invoke-virtual {p0, p1, v0, v1}, Landroid/content/Context;->checkPermission(Ljava/lang/String;II)I\n',
  107. ' move-result v0\n',
  108. ' return v0\n',
  109. ' :cond_0\n',
  110. ' new-instance v0, Ljava/lang/IllegalArgumentException;\n',
  111. ' const-string v1, "permission is null"\n',
  112. ' invoke-direct {v0, v1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V\n',
  113. ' throw v0\n',
  114. '.end method']
  115. for i in method:
  116. lines.append(i)
  117. with open(goal_file, 'w') as fl:
  118. fl.write(''.join(lines))
  119. def modify_manifest(decompileDir):
  120. ET.register_namespace('android', ANDROID_NS)
  121. xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml')
  122. root_node = ET.parse(xmlparse)
  123. root = root_node.getroot()
  124. name = '{' + ANDROID_NS + '}name'
  125. authorities = '{' + ANDROID_NS + '}foregroundServiceType'
  126. package_name = root.attrib.get('package')
  127. if package_name == None:
  128. return
  129. providers = root.findall('./application/service')
  130. if providers != None:
  131. for provider in providers:
  132. providerName = provider.attrib.get(name)
  133. if 'com.netease.ntunisdk.CcMomentRecordingForegroundService' == providerName:
  134. # 使用try 主要是为了 防止此属性不在时,导致的错误,而程序终止
  135. try:
  136. del provider.attrib[authorities]
  137. except:
  138. ""
  139. root_node.write(xmlparse, 'utf-8')
  140. def move_package(s1, s3, list_package):
  141. for d in list_package:
  142. src = os.path.join(s1, d)
  143. if os.path.exists(src):
  144. dst = os.path.join(s3, d)
  145. distutils.dir_util.copy_tree(src, dst)
  146. distutils.dir_util.remove_tree(src)
  147. def create_mutil_smali(decompileDir):
  148. f_idx = 2
  149. while True:
  150. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  151. tmp = tmp.replace('\\', '/')
  152. tmp = re.sub('/+', '/', tmp)
  153. if os.path.exists(tmp):
  154. f_idx += 1
  155. else:
  156. smali_classes2_dir = tmp
  157. break
  158. # endwhile
  159. os.mkdir(smali_classes2_dir)
  160. return smali_classes2_dir
  161. if __name__ == "__main__":
  162. add_hjr_checkSelfPermission("C:\\Users\\Administrator\\Desktop\\dtws")