script.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. def script_second(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  10. logging.info('script_second: ' + str(channel_sdk_info))
  11. # 逆向渠道id
  12. public_xml = os.path.join(extract_dir, "res/values/drawables.xml")
  13. handle_public_xml(public_xml, "APKTOOL")
  14. return
  15. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  16. # logging.info('------------SDK:'+SDK)
  17. # logging.info('------------decompileDir:'+decompileDir)
  18. # logging.info('------------channelSdkInfo:'+str(channelSdkInfo))
  19. # logging.info('------------new_game_channel_info:'+str(new_game_channel_info))
  20. # logging.info('------------gameInfo:'+str(gameInfo))
  21. # logging.info("------rm baidu smali------")
  22. # restdir = decompileDir+"/"+"smali_classes2/com/baidu/gamesdk"
  23. # if os.path.exists(restdir):
  24. # shutil.rmtree(restdir)
  25. # s3 = decompileDir + "/smali_classes3"
  26. logging.info('------------channelSdkInfo:' + str(channelSdkInfo))
  27. if channelSdkInfo['SDKName'] == 'reverseforkupai':
  28. del_coolcloud(decompileDir)
  29. if channelSdkInfo['id'] == '549':
  30. replace_life_method(decompileDir)
  31. def replace_life_method(extract_dir):
  32. goal_file = glob.glob(os.path.join(extract_dir, 'smali*/com/taiyouxi/a3k/MainActivity.smali'))[0]
  33. goal_file1 = glob.glob(os.path.join(extract_dir, 'smali*/com/yog/kothoth/utils/RequestParamUtil.smali'))[0]
  34. goal_file2 = glob.glob(os.path.join(extract_dir, 'smali*/com/yog/kothoth/data/JsonResult.smali'))[0]
  35. print(os.path.isfile(goal_file))
  36. if os.path.isfile(goal_file):
  37. logging.info('method_proceed: ' + 'goal_file')
  38. print(goal_file)
  39. with open(goal_file, 'r+') as f:
  40. cont = f.read()
  41. change_str = '.method protected onResume()V'
  42. str = '.method public onResume()V\n' \
  43. 'invoke-static {}, Lcom/kf/framework/SDKPluginWrapper;->onResume()V'
  44. cont = cont.replace(change_str, str)
  45. change_str_1 = '.method protected onPause()V'
  46. str_1 = '.method public onPause()V\n' \
  47. 'invoke-static {}, Lcom/kf/framework/SDKPluginWrapper;->onPause()V'
  48. cont = cont.replace(change_str_1, str_1)
  49. logging.info('replace_str: ' + cont)
  50. with open(goal_file, 'w+') as tf:
  51. tf.write(cont)
  52. if os.path.isfile(goal_file1):
  53. logging.info('method_proceed: ' + 'goal_file1')
  54. print(goal_file1)
  55. with open(goal_file1, 'r+') as f:
  56. cont = f.read()
  57. change_str = 'Lcom/hjr/gameplatform/aes/AESUtil'
  58. str = 'Lcom/kf/framework/util/AESUtil'
  59. cont = cont.replace(change_str, str)
  60. logging.info('replace_str: ' + cont)
  61. with open(goal_file1, 'w+') as tf:
  62. tf.write(cont)
  63. if os.path.isfile(goal_file2):
  64. logging.info('method_proceed: ' + 'goal_file2')
  65. print(goal_file2)
  66. with open(goal_file2, 'r+') as f:
  67. cont = f.read()
  68. change_str = 'Lcom/hjr/gameplatform/aes/AESUtil'
  69. str = 'Lcom/kf/framework/util/AESUtil'
  70. cont = cont.replace(change_str, str)
  71. logging.info('replace_str: ' + cont)
  72. with open(goal_file2, 'w+') as tf:
  73. tf.write(cont)
  74. def is_reverse_coolcloud(file):
  75. with open(file, 'r+') as f:
  76. file_str = f.read()
  77. if 'KFSDK' in file_str:
  78. return True
  79. else:
  80. return False
  81. def del_coolcloud(decompileDir):
  82. smali_files = glob.glob(os.path.join(decompileDir, 'smali*/com/coolcloud/'))
  83. if len(smali_files) > 1:
  84. iter_smali = iter(smali_files)
  85. while True:
  86. try:
  87. coolcloud_file_path = iter_smali.next()
  88. file = os.path.join(coolcloud_file_path, 'uac/android/api/Coolcloud.smali')
  89. if os.path.exists(file):
  90. logging.info('Coolcloud exits in %s' % coolcloud_file_path)
  91. if not is_reverse_coolcloud(file):
  92. logging.info("delete coolcloud in %s" % coolcloud_file_path)
  93. shutil.rmtree(coolcloud_file_path)
  94. else:
  95. pass
  96. else:
  97. logging.info('Coolcloud not exits in %s' % coolcloud_file_path)
  98. shutil.rmtree(coolcloud_file_path)
  99. except StopIteration:
  100. break
  101. def handle_public_xml(public_xml_path, remove_node):
  102. if not os.path.exists(public_xml_path):
  103. logging.info('public_xml is null: ' + public_xml_path)
  104. return
  105. new_lines = []
  106. with open(public_xml_path, 'r+') as f:
  107. for line in f.readlines():
  108. # l = line.strip()
  109. if line.find(remove_node) > -1:
  110. continue
  111. new_lines.append(line)
  112. f.seek(0)
  113. f.truncate()
  114. f.writelines(new_lines)
  115. return
  116. if __name__ == '__main__':
  117. replace_life_method("D:\\work\\jws")