script.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # coding:utf8
  2. __author__ = '第五人格网易'
  3. import os
  4. import logging
  5. import xml.dom.minidom
  6. import re
  7. import shutil
  8. import glob
  9. import distutils.dir_util
  10. import gw_file_system
  11. import gw_data_center
  12. def script_init(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  13. # gw_data_center.pack_small = False
  14. return
  15. def script_pre(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  16. sdk_id = channelSdkInfo["id"]
  17. if sdk_id != '512': # 只有逆向渠道才需求这样
  18. return
  19. f_idx = 2
  20. dst = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali', 'com/example/qidaosdk'))
  21. while True:
  22. logging.info("-----f_idx-----"+str(f_idx))
  23. tmp_smali = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  24. tmp_smali =tmp_smali.replace('\\', '/')
  25. tmp_smali = re.sub('/+', '/',tmp_smali)
  26. if not os.path.exists(tmp_smali):
  27. logging.info("smali_not_exits:"+tmp_smali)
  28. break
  29. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx, 'com/example/qidaosdk/QidaoApplication.smali'))
  30. tmp = tmp.replace('\\', '/')
  31. tmp = re.sub('/+', '/', tmp)
  32. tmp_qidaosdk = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx, 'com/example/qidaosdk'))
  33. tmp_qidaosdk = tmp_qidaosdk.replace('\\', '/')
  34. tmp_qidaosdk = re.sub('/+', '/', tmp_qidaosdk)
  35. if os.path.exists(tmp):
  36. logging.info('tmp_smali:'+tmp)
  37. logging.info('dst:'+dst)
  38. distutils.dir_util.copy_tree(tmp_qidaosdk, dst)
  39. distutils.dir_util.remove_tree(tmp_qidaosdk)
  40. break
  41. else:
  42. f_idx += 1
  43. return
  44. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  45. return
  46. smali_classes2_dir = ''
  47. f_idx = 2
  48. while True:
  49. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  50. tmp = tmp.replace('\\', '/')
  51. tmp = re.sub('/+', '/', tmp)
  52. if os.path.exists(tmp):
  53. f_idx += 1
  54. else:
  55. smali_classes2_dir += tmp
  56. break
  57. # endwhile
  58. os.mkdir(smali_classes2_dir)
  59. s1 = os.path.join(decompileDir, "smali", "com")
  60. s3 = os.path.join(smali_classes2_dir, "com")
  61. list_package = ["netease"]
  62. if not os.path.exists(s3):
  63. distutils.dir_util.mkpath(s3)
  64. move_package(s1, s3, list_package)
  65. s1 = os.path.join(decompileDir, "smali_classes2", "com")
  66. smali_dir = create_mutil_smali(decompileDir)
  67. s3 = os.path.join(smali_dir, "com")
  68. list_package = ["netease", "nostra13", "sina", "ta", "unionpay", "yy"]
  69. if not os.path.exists(s3):
  70. distutils.dir_util.mkpath(s3)
  71. move_package(s1, s3, list_package)
  72. logging.info("-----debug-----")
  73. def move_package(s1, s3, list_package):
  74. for d in list_package:
  75. src = os.path.join(s1, d)
  76. if os.path.exists(src):
  77. dst = os.path.join(s3, d)
  78. distutils.dir_util.copy_tree(src, dst)
  79. distutils.dir_util.remove_tree(src)
  80. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  81. # logging.info('------------SDK:'+SDK)
  82. # logging.info('------------decompileDir:'+decompileDir)
  83. # logging.info('------------channelSdkInfo:'+str(channelSdkInfo))
  84. # logging.info('------------new_game_channel_info:'+str(new_game_channel_info))
  85. # logging.info('------------gameInfo:'+str(gameInfo))
  86. # logging.info("------rm baidu smali------")
  87. # restdir = decompileDir+"/"+"smali_classes2/com/baidu/gamesdk"
  88. # if os.path.exists(restdir):
  89. # shutil.rmtree(restdir)
  90. # s3 = decompileDir + "/smali_classes3"
  91. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  92. if channelSdkInfo['id'] == '549' or channelSdkInfo['id'] == '413' or channelSdkInfo['SDKName'] == 'ludashi':
  93. del_hjr(decompileDir)
  94. add_do_not_compress(decompileDir)
  95. def add_do_not_compress(extract_dir):
  96. goal_file = os.path.join(extract_dir, 'apktool.yml')
  97. print(os.path.isfile(goal_file))
  98. if os.path.isfile(goal_file):
  99. logging.info('method_proceed: ' + 'goal_file')
  100. print(goal_file)
  101. with open(goal_file, 'r+') as f:
  102. cont = f.read()
  103. print(cont)
  104. change_str = '- assets/res/video.mini.npk'
  105. str = '- assets/res/video.mini.npk\n' \
  106. '- assets'
  107. cont = cont.replace(change_str, str)
  108. with open(goal_file, 'w+') as tf:
  109. tf.write(cont)
  110. def del_hjr(decompileDir):
  111. x86 = os.path.join(decompileDir, 'smali_classes3/com/hjr')
  112. if os.path.exists(x86):
  113. shutil.rmtree(x86)
  114. def create_mutil_smali(decompileDir):
  115. f_idx = 2
  116. while True:
  117. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  118. tmp = tmp.replace('\\', '/')
  119. tmp = re.sub('/+', '/', tmp)
  120. if os.path.exists(tmp):
  121. f_idx += 1
  122. else:
  123. smali_classes2_dir = tmp
  124. break
  125. # endwhile
  126. os.mkdir(smali_classes2_dir)
  127. return smali_classes2_dir
  128. if __name__ == '__main__':
  129. del_hjr("C:\\Users\\Administrator\\Desktop\\identity")
  130. add_do_not_compress("C:\\Users\\Administrator\\Desktop\\identity")