script.py 4.4 KB

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