script.py 3.9 KB

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