script.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # coding:utf8
  2. __author__ = 'dong'
  3. import os
  4. import logging
  5. import xml.dom.minidom
  6. import re
  7. import shutil
  8. import glob
  9. from xml.etree.ElementTree import ElementTree, Element
  10. import distutils.dir_util
  11. import gw_file_system
  12. import gw_data_center
  13. import gw_apk_tool
  14. def script_init(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  15. return
  16. def script_first(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  17. return
  18. def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  19. # logging.info('------------SDK:'+SDK)
  20. # logging.info('------------decompileDir:'+decompileDir)
  21. # logging.info('------------channelSdkInfo:'+str(channelSdkInfo))
  22. # logging.info('------------new_game_channel_info:'+str(new_game_channel_info))
  23. # logging.info('------------gameInfo:'+str(gameInfo))
  24. # logging.info("------rm baidu smali------")
  25. # restdir = decompileDir+"/"+"smali_classes2/com/baidu/gamesdk"
  26. # if os.path.exists(restdir):
  27. # shutil.rmtree(restdir)
  28. return
  29. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  30. sdk_name = channelSdkInfo['sdk_name']
  31. if sdk_name == "reverseforachannel_ydzs":
  32. s1 = os.path.join(decompileDir, "smali_classes4")
  33. if os.path.exists(s1):
  34. smali_classes2_dir = create_mutil_smali(decompileDir)
  35. s3 = smali_classes2_dir
  36. if not os.path.exists(s3):
  37. distutils.dir_util.mkpath(s3)
  38. move_package(s1, s3, ["androidx", "android"])
  39. s1 = os.path.join(decompileDir, "smali_classes4", "com")
  40. if os.path.exists(s1):
  41. smali_classes2_dir = create_mutil_smali(decompileDir)
  42. s3 = os.path.join(smali_classes2_dir, "com")
  43. if not os.path.exists(s3):
  44. distutils.dir_util.mkpath(s3)
  45. move_package_one(s1, s3)
  46. return
  47. def create_mutil_smali(decompileDir):
  48. f_idx = 2
  49. while True:
  50. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  51. tmp = tmp.replace('\\', '/')
  52. tmp = re.sub('/+', '/', tmp)
  53. if os.path.exists(tmp):
  54. f_idx += 1
  55. else:
  56. smali_classes2_dir = tmp
  57. break
  58. # endwhile
  59. os.mkdir(smali_classes2_dir)
  60. return smali_classes2_dir
  61. def move_package(s1, s3, list_package):
  62. for d in list_package:
  63. src = os.path.join(s1, d)
  64. if os.path.exists(src):
  65. dst = os.path.join(s3, d)
  66. distutils.dir_util.copy_tree(src, dst)
  67. distutils.dir_util.remove_tree(src)
  68. def is_reverse_qihoo(file):
  69. with open(file, 'r+') as f:
  70. file_str = f.read()
  71. if 'KFSDK' in file_str:
  72. return True
  73. else:
  74. return False
  75. def replace_init_code(decompileDir):
  76. smali_files = glob.glob(os.path.join(decompileDir, 'smali*/com/qihoo/'))
  77. if len(smali_files) >= 1:
  78. iter_smali = iter(smali_files)
  79. while True:
  80. try:
  81. qihoo_file_path = iter_smali.next()
  82. file = os.path.join(qihoo_file_path, 'gamecenter/sdk/matrix/Matrix.smali')
  83. if os.path.exists(file):
  84. logging.info('Matrix exits in %s' % qihoo_file_path)
  85. if is_reverse_qihoo(file):
  86. with open(file, 'r+') as f:
  87. cont = f.read()
  88. change_str = '0x82c'
  89. str = '0x82b'
  90. cont = cont.replace(change_str, str)
  91. logging.info('replace_str: ' + cont)
  92. with open(file, 'w+') as tf:
  93. tf.write(cont)
  94. except StopIteration:
  95. break
  96. def replace_application(extract_dir):
  97. goal_file = os.path.join(extract_dir, 'smali_classes3/com/lilithgame/sgame/wxapi/QihooApplication.smali')
  98. print(os.path.isfile(goal_file))
  99. if os.path.isfile(goal_file):
  100. logging.info('method_proceed: ' + 'goal_file')
  101. print(goal_file)
  102. with open(goal_file, 'r+') as f:
  103. cont = f.read()
  104. change_str = 'Landroid/support/multidex/MultiDexApplication'
  105. str = 'Lcom/kf/framework/KFApplication'
  106. cont = cont.replace(change_str, str)
  107. logging.info('replace_str: ' + cont)
  108. with open(goal_file, 'w+') as tf:
  109. tf.write(cont)
  110. def move_package(s1, s3, list_package):
  111. for d in list_package:
  112. src = os.path.join(s1, d)
  113. if os.path.exists(src):
  114. dst = os.path.join(s3, d)
  115. distutils.dir_util.copy_tree(src, dst)
  116. distutils.dir_util.remove_tree(src)
  117. def move_package_one(src, dst):
  118. if os.path.exists(src):
  119. distutils.dir_util.copy_tree(src, dst)
  120. distutils.dir_util.remove_tree(src)
  121. if __name__ == '__main__':
  122. replace_init_code("D:\work\lyjymb")