script.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  15. # logging.info('------------SDK:'+SDK)
  16. # logging.info('------------decompileDir:'+decompileDir)
  17. # logging.info('------------channelSdkInfo:'+str(channelSdkInfo))
  18. # logging.info('------------new_game_channel_info:'+str(new_game_channel_info))
  19. # logging.info('------------gameInfo:'+str(gameInfo))
  20. # logging.info("------rm baidu smali------")
  21. # restdir = decompileDir+"/"+"smali_classes2/com/baidu/gamesdk"
  22. # if os.path.exists(restdir):
  23. # shutil.rmtree(restdir)
  24. # s3 = decompileDir + "/smali_classes3"
  25. s1 = os.path.join(decompileDir, "smali", "com")
  26. smali_classes2_dir = ''
  27. f_idx = 2
  28. while True:
  29. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  30. tmp = tmp.replace('\\', '/')
  31. tmp = re.sub('/+', '/', tmp)
  32. if os.path.exists(tmp):
  33. f_idx += 1
  34. else:
  35. smali_classes2_dir += tmp
  36. break
  37. # endwhile
  38. os.mkdir(smali_classes2_dir)
  39. s1 = os.path.join(decompileDir, "smali", "com")
  40. s3 = os.path.join(smali_classes2_dir, "com")
  41. list_package = ["netease"]
  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_classes2", "com")
  46. smali_dir = create_mutil_smali(decompileDir)
  47. s3 = os.path.join(smali_dir, "com")
  48. list_package = ["netease", "nostra13", "sina", "ta", "unionpay", "yy"]
  49. if not os.path.exists(s3):
  50. distutils.dir_util.mkpath(s3)
  51. move_package(s1, s3, list_package)
  52. logging.info("-----debug-----")
  53. def move_package(s1, s3, list_package):
  54. for d in list_package:
  55. src = os.path.join(s1, d)
  56. if os.path.exists(src):
  57. dst = os.path.join(s3, d)
  58. distutils.dir_util.copy_tree(src, dst)
  59. distutils.dir_util.remove_tree(src)
  60. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  61. # logging.info('------------SDK:'+SDK)
  62. # logging.info('------------decompileDir:'+decompileDir)
  63. # logging.info('------------channelSdkInfo:'+str(channelSdkInfo))
  64. # logging.info('------------new_game_channel_info:'+str(new_game_channel_info))
  65. # logging.info('------------gameInfo:'+str(gameInfo))
  66. # logging.info("------rm baidu smali------")
  67. # restdir = decompileDir+"/"+"smali_classes2/com/baidu/gamesdk"
  68. # if os.path.exists(restdir):
  69. # shutil.rmtree(restdir)
  70. # s3 = decompileDir + "/smali_classes3"
  71. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  72. if channelSdkInfo['id'] == '549' or channelSdkInfo['id'] == '413' or channelSdkInfo['SDKName'] == 'ludashi':
  73. del_hjr(decompileDir)
  74. add_do_not_compress(decompileDir)
  75. def add_do_not_compress(extract_dir):
  76. goal_file = os.path.join(extract_dir, 'apktool.yml')
  77. print(os.path.isfile(goal_file))
  78. if os.path.isfile(goal_file):
  79. logging.info('method_proceed: ' + 'goal_file')
  80. print(goal_file)
  81. with open(goal_file, 'r+') as f:
  82. cont = f.read()
  83. print(cont)
  84. change_str = '- assets/res/video.mini.npk'
  85. str = '- assets/res/video.mini.npk\n' \
  86. '- assets'
  87. cont = cont.replace(change_str, str)
  88. with open(goal_file, 'w+') as tf:
  89. tf.write(cont)
  90. def del_hjr(decompileDir):
  91. x86 = os.path.join(decompileDir, 'smali_classes3/com/hjr')
  92. if os.path.exists(x86):
  93. shutil.rmtree(x86)
  94. def create_mutil_smali(decompileDir):
  95. f_idx = 2
  96. while True:
  97. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  98. tmp = tmp.replace('\\', '/')
  99. tmp = re.sub('/+', '/', tmp)
  100. if os.path.exists(tmp):
  101. f_idx += 1
  102. else:
  103. smali_classes2_dir = tmp
  104. break
  105. # endwhile
  106. os.mkdir(smali_classes2_dir)
  107. return smali_classes2_dir
  108. if __name__ == '__main__':
  109. del_hjr("C:\\Users\\Administrator\\Desktop\\identity")
  110. add_do_not_compress("C:\\Users\\Administrator\\Desktop\\identity")