GeneralModifySmali.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import xml.etree.ElementTree as ET
  2. from V1 import File, apk_utils
  3. import os
  4. import re
  5. from V1.PrintLog import printlog
  6. def getLauchActivityName(apkPath):
  7. sdkAM = "%s/AndroidManifest.xml" % apkPath
  8. namespace = '{http://schemas.android.com/apk/res/android}'
  9. ET.register_namespace('android', "http://schemas.android.com/apk/res/android")
  10. tree = ET.parse(sdkAM)
  11. activitys = tree.getroot().find("application").findall("activity");
  12. for activity in activitys:
  13. filters = activity.findall('intent-filter')
  14. for filter in filters:
  15. categorys = filter.findall('category')
  16. for category in categorys:
  17. categoryname = category.attrib[namespace + "name"]
  18. if (categoryname == "android.intent.category.LAUNCHER"):
  19. actname = activity.attrib[namespace + "name"]
  20. return actname
  21. def getLauchActivityScreenOrientation(apkPath):
  22. sdkAM = "%s/AndroidManifest.xml" % apkPath
  23. namespace = '{http://schemas.android.com/apk/res/android}'
  24. ET.register_namespace('android', "http://schemas.android.com/apk/res/android")
  25. tree = ET.parse(sdkAM)
  26. activitys = tree.getroot().find("application").findall("activity");
  27. for activity in activitys:
  28. filters = activity.findall('intent-filter')
  29. for filter in filters:
  30. categorys = filter.findall('category')
  31. for category in categorys:
  32. categoryname = category.attrib[namespace + "name"]
  33. if (categoryname == "android.intent.category.LAUNCHER"):
  34. screenOrientation = activity.attrib[namespace + "screenOrientation"]
  35. return screenOrientation
  36. def modifyLauchSmali(apkPath):
  37. TAG = "Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V"
  38. fc = "invoke-static {p0}, Lcom/yythird/sdk/BDInitAct;->initBD(Landroid/app/Activity;)V"
  39. smalipath = getLauchSmaliPath(apkPath)
  40. printlog("baidu smalipath: %s" % smalipath)
  41. lines = open(smalipath, "r").readlines()
  42. f = open(smalipath, "w")
  43. for line in lines:
  44. if line.find(TAG) != -1:
  45. line = line + '\n' + fc + '\n';
  46. f.write(line)
  47. f.close()
  48. def getLauchSmaliPath(apkPath):
  49. sdkAM = "%s/AndroidManifest.xml"%apkPath
  50. tree = ET.parse(sdkAM)
  51. namespace = '{http://schemas.android.com/apk/res/android}'
  52. ET.register_namespace('android',"http://schemas.android.com/apk/res/android")
  53. activitys = tree.getroot().find("application").findall("activity");
  54. for activity in activitys:
  55. filters = activity.findall('intent-filter')
  56. for filter in filters:
  57. categorys = filter.findall('category')
  58. actions = filter.findall('action')
  59. for category in categorys:
  60. categoryname = category.attrib[namespace + "name"]
  61. if(categoryname =="android.intent.category.LAUNCHER"):
  62. actname = activity.attrib[namespace + "name"].replace(".", "/")
  63. return "%s/smali/%s.smali"%(apkPath,actname)
  64. pass
  65. def modifyTTLauchSmali(apkPath):
  66. TAG = "invoke-super {p0, p1, p2, p3}, Landroid/app/Activity;->onRequestPermissionsResult(I[Ljava/lang/String;[I)V"
  67. TTSmali = "invoke-static {}, Lcom/wett/cooperation/container/TTSDKV2;->getInstance()Lcom/wett/cooperation/container/TTSDKV2;"
  68. smalipath = getLauchSmaliPath(apkPath)
  69. printlog("TT smalipath: %s" % smalipath)
  70. lines = open(smalipath, "r").readlines()
  71. if lines.find(TTSmali) != -1:
  72. f = open(smalipath, "w")
  73. for line in lines:
  74. if line.find(TTSmali) != -1:
  75. line = line + '\n' + TTSmali + '\n';
  76. f.write(line)
  77. f.close()
  78. pass
  79. def modifyYXFLauchSmali(apkPath):
  80. oldText = ".super Landroid/app/Activity;"
  81. newText = ".super Lcom/yaoyue/release/YYSplashActivity;"
  82. oldActPkg = "Landroid/app/Activity;"
  83. newActPkg = "Lcom/yaoyue/release/YYSplashActivity;"
  84. smalipath = getLauchSmaliPath(apkPath)
  85. printlog("YXF smalipath: %s" % smalipath)
  86. lines = open(smalipath, "r").readlines()
  87. f = open(smalipath, "w")
  88. for line in lines:
  89. if line.find(oldText) != -1:
  90. line = re.sub(oldText,newText, line)
  91. if line.find(oldActPkg) != -1:
  92. line = re.sub(oldActPkg,newActPkg, line)
  93. f.write(line)
  94. f.close()
  95. pass
  96. def modifyQuickLauchSmali(apkPath):
  97. oldText = ".super Landroid/app/Activity;"
  98. newText = ".super Lcom/quicksdk/QuickSdkSplashActivity;"
  99. oldActPkg = "Landroid/app/Activity;"
  100. newActPkg = "Lcom/quicksdk/QuickSdkSplashActivity;"
  101. smalipath = getLauchSmaliPath(apkPath)
  102. printlog("Quick smalipath: %s" % smalipath)
  103. lines = open(smalipath, "r").readlines()
  104. f = open(smalipath, "w")
  105. for line in lines:
  106. if line.find(oldText) != -1:
  107. line = re.sub(oldText,newText, line)
  108. if line.find(oldActPkg) != -1:
  109. line = re.sub(oldActPkg,newActPkg, line)
  110. f.write(line)
  111. f.close()
  112. pass
  113. def modifyRfileIdSmali(prj_path,r_path):
  114. apkRfilePath = "%s%s" %(prj_path,r_path)
  115. publicXml = "%s/res/values/public.xml" % prj_path
  116. sdk_jar_dir = apk_utils.getToolsJarHome()
  117. jarPath = "%s/MergeSamli.jar" % sdk_jar_dir
  118. javaMerCm = 'java -jar %s %s %s' % (jarPath, publicXml, apkRfilePath)
  119. printlog("javaMerCm:%s" % javaMerCm)
  120. os.system(javaMerCm)
  121. pass
  122. def replaceSdkV4Smali(prj_path,v4_path):
  123. sdk_root_dir = apk_utils.getCutSdkRootHome()
  124. pkgV4Path = "%s/smali/android/support/v4" % prj_path
  125. printlog("pkgV4Path:%s" % pkgV4Path)
  126. sdkV4Path = "%s/%s" % (sdk_root_dir,v4_path)
  127. printlog("sdkV4Path:%s" % sdkV4Path)
  128. if os.path.exists(pkgV4Path):
  129. File.copyAllFile(sdkV4Path, pkgV4Path)
  130. pass
  131. def modifyJrttV7ResIdSmali(prj_path):
  132. pkgV7AttrPath = "%s/smali_classes3/android/support/v7/appcompat/R$attr.smali" % prj_path
  133. if os.path.exists(pkgV7AttrPath):
  134. pkgV7StyleablePath = r"%s/smali_classes3/android/support/v7/appcompat/R\$styleable.smali" % prj_path
  135. data = ["windowActionBar:I", "windowActionBarOverlay:I", "windowActionModeOverlay:I",
  136. "windowFixedHeightMajor:I", "windowFixedHeightMinor:I", "windowFixedWidthMajor:I",
  137. "windowFixedWidthMinor:I", "windowMinWidthMajor:I", "windowMinWidthMinor:I", "windowNoTitle:I"]
  138. with open(pkgV7AttrPath, "r") as f:
  139. for line in f.readlines():
  140. if data[0] in line:
  141. value = line.split("=")
  142. replaceShell = 'sed -i "s/0x7f040245/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath)
  143. os.system(replaceShell)
  144. elif data[1] in line:
  145. value = line.split("=")
  146. replaceShell = 'sed -i "s/0x7f040246/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath)
  147. os.system(replaceShell)
  148. elif data[2] in line:
  149. value = line.split("=")
  150. replaceShell = 'sed -i "s/0x7f040247/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath)
  151. os.system(replaceShell)
  152. elif data[3] in line:
  153. value = line.split("=")
  154. replaceShell = 'sed -i "s/0x7f040248/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath)
  155. os.system(replaceShell)
  156. elif data[4] in line:
  157. value = line.split("=")
  158. replaceShell = 'sed -i "s/0x7f040249/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath)
  159. os.system(replaceShell)
  160. elif data[5] in line:
  161. value = line.split("=")
  162. replaceShell = 'sed -i "s/0x7f04024a/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath)
  163. os.system(replaceShell)
  164. elif data[6] in line:
  165. value = line.split("=")
  166. replaceShell = 'sed -i "s/0x7f04024b/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath)
  167. os.system(replaceShell)
  168. elif data[7] in line:
  169. value = line.split("=")
  170. replaceShell = 'sed -i "s/0x7f04024c/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath)
  171. os.system(replaceShell)
  172. elif data[8] in line:
  173. value = line.split("=")
  174. replaceShell = 'sed -i "s/0x7f04024d/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath)
  175. os.system(replaceShell)
  176. elif data[9] in line:
  177. value = line.split("=")
  178. replaceShell = 'sed -i "s/0x7f04024e/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath)
  179. os.system(replaceShell)
  180. pass