script.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # coding:utf8
  2. import os
  3. import xml.etree.ElementTree as ET
  4. import logging
  5. import re
  6. import codecs
  7. import distutils.dir_util
  8. import gw_file_system
  9. ANDROID_NAMESPACE = 'http://schemas.android.com/apk/res/android'
  10. logger = logging.getLogger('script.py')
  11. def script_second(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  12. logging.info('script_second: ' + str(channel_sdk_info))
  13. # 逆向渠道id
  14. public_xml = os.path.join(extract_dir, "res/values/public.xml")
  15. handle_public_xml(public_xml, "smssdk_country_group")
  16. return
  17. def script_last(workspace_sdk_dir, extract_dir, channel_sdk_info, new_game_channel_info, game_info):
  18. sdk_id = channel_sdk_info['id']
  19. if sdk_id == "512":
  20. s1 = os.path.join(extract_dir, "smali")
  21. smali_classes2_dir = create_mutil_smali(extract_dir)
  22. s3 = smali_classes2_dir
  23. list_package = ["androidx"]
  24. if not os.path.exists(s3):
  25. distutils.dir_util.mkpath(s3)
  26. move_package(s1, s3, list_package)
  27. if sdk_id == "549":
  28. s1 = os.path.join(extract_dir, "smali_classes3/com")
  29. smali_classes2_dir = create_mutil_smali(extract_dir)
  30. s3 = os.path.join(smali_classes2_dir, "com")
  31. list_package = ["example", "excelliance", "facebook", "flurry", "getui", "google"]
  32. if not os.path.exists(s3):
  33. distutils.dir_util.mkpath(s3)
  34. move_package(s1, s3, list_package)
  35. s1 = os.path.join(extract_dir, "smali_classes5/androidx")
  36. smali_classes2_dir = create_mutil_smali(extract_dir)
  37. s3 = os.path.join(smali_classes2_dir, "androidx")
  38. list_package = ["interpolator", "loader", "multidex", "slidingpanelayout", "versionedparcelable", "legacy",
  39. "localbroadcastmanager", "print", "swiperefreshlayout", "viewpager", "lifecycle", "media",
  40. "savedstate", "vectordrawable"]
  41. if not os.path.exists(s3):
  42. distutils.dir_util.mkpath(s3)
  43. move_package(s1, s3, list_package)
  44. return
  45. def move_package(s1, s3, list_package):
  46. for d in list_package:
  47. src = os.path.join(s1, d)
  48. if os.path.exists(src):
  49. dst = os.path.join(s3, d)
  50. distutils.dir_util.copy_tree(src, dst)
  51. distutils.dir_util.remove_tree(src)
  52. def create_mutil_smali(decompileDir):
  53. f_idx = 2
  54. while True:
  55. tmp = gw_file_system.get_full_path(os.path.join(decompileDir, 'smali_classes%d' % f_idx))
  56. tmp = tmp.replace('\\', '/')
  57. tmp = re.sub('/+', '/', tmp)
  58. if os.path.exists(tmp):
  59. files = os.listdir(tmp)
  60. if len(files) == 0:
  61. smali_classes2_dir = tmp
  62. break
  63. f_idx += 1
  64. else:
  65. smali_classes2_dir = tmp
  66. break
  67. # endwhile
  68. os.mkdir(smali_classes2_dir)
  69. return smali_classes2_dir
  70. def handle_public_xml(public_xml_path, remove_node):
  71. if not os.path.exists(public_xml_path):
  72. logging.info('public_xml is null: ' + public_xml_path)
  73. return
  74. new_lines = []
  75. with open(public_xml_path, 'r+') as f:
  76. for line in f.readlines():
  77. # l = line.strip()
  78. if line.find(remove_node) > -1:
  79. continue
  80. new_lines.append(line)
  81. f.seek(0)
  82. f.truncate()
  83. f.writelines(new_lines)
  84. return
  85. if __name__ == '__main__':
  86. script_last('', 'E:/script_test', {}, {}, {})