script.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. return
  20. def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo):
  21. sdk_id = channelSdkInfo['id']
  22. if sdk_id == "597":
  23. f_idx = 4
  24. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  25. tmp = tmp.replace('\\', '/')
  26. tmp = re.sub('/+', '/', tmp)
  27. if os.path.exists(tmp):
  28. new_dex_dir = create_mutil_smali(decompileDir)
  29. move_package(tmp, new_dex_dir, ["androidx"])
  30. # endwhile
  31. return
  32. def create_mutil_smali(decompileDir):
  33. f_idx = 2
  34. while True:
  35. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  36. tmp = tmp.replace('\\', '/')
  37. tmp = re.sub('/+', '/', tmp)
  38. if os.path.exists(tmp):
  39. f_idx += 1
  40. else:
  41. smali_classes2_dir = tmp
  42. break
  43. # endwhile
  44. os.mkdir(smali_classes2_dir)
  45. return smali_classes2_dir
  46. def move_package(s1, s3, list_package):
  47. for d in list_package:
  48. src = os.path.join(s1, d)
  49. if os.path.exists(src):
  50. dst = os.path.join(s3, d)
  51. distutils.dir_util.copy_tree(src, dst)
  52. distutils.dir_util.remove_tree(src)
  53. def is_reverse_qihoo(file):
  54. with open(file, 'r+') as f:
  55. file_str = f.read()
  56. if 'KFSDK' in file_str:
  57. return True
  58. else:
  59. return False
  60. def replace_init_code(decompileDir):
  61. smali_files = glob.glob(os.path.join(decompileDir, 'smali*/com/qihoo/'))
  62. if len(smali_files) >= 1:
  63. iter_smali = iter(smali_files)
  64. while True:
  65. try:
  66. qihoo_file_path = iter_smali.next()
  67. file = os.path.join(qihoo_file_path, 'gamecenter/sdk/matrix/Matrix.smali')
  68. if os.path.exists(file):
  69. logging.info('Matrix exits in %s' % qihoo_file_path)
  70. if is_reverse_qihoo(file):
  71. with open(file, 'r+') as f:
  72. cont = f.read()
  73. change_str = '0x82c'
  74. str = '0x82b'
  75. cont = cont.replace(change_str, str)
  76. logging.info('replace_str: ' + cont)
  77. with open(file, 'w+') as tf:
  78. tf.write(cont)
  79. except StopIteration:
  80. break
  81. def replace_application(extract_dir):
  82. goal_file = os.path.join(extract_dir, 'smali_classes3/com/lilithgame/sgame/wxapi/QihooApplication.smali')
  83. print(os.path.isfile(goal_file))
  84. if os.path.isfile(goal_file):
  85. logging.info('method_proceed: ' + 'goal_file')
  86. print(goal_file)
  87. with open(goal_file, 'r+') as f:
  88. cont = f.read()
  89. change_str = 'Landroid/support/multidex/MultiDexApplication'
  90. str = 'Lcom/kf/framework/KFApplication'
  91. cont = cont.replace(change_str, str)
  92. logging.info('replace_str: ' + cont)
  93. with open(goal_file, 'w+') as tf:
  94. tf.write(cont)
  95. if __name__ == '__main__':
  96. replace_init_code("D:\work\lyjymb")