script.py 4.4 KB

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