script.py 3.5 KB

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