ChannelReplace.py 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406
  1. # -*-coding:utf-8-*-
  2. import os
  3. import xml.etree.ElementTree as ET
  4. import re
  5. import hashlib
  6. import shutil
  7. import json
  8. from V1.PrintLog import printlog
  9. from V1 import Contants, File, GeneralModifySmali, Replace, Aapt_Util, apk_utils
  10. from xml.etree.ElementTree import Element
  11. # 联想
  12. def LenovoReplace(prj_path, dir_split, key, value):
  13. if (key == "OPENAPPID"):
  14. # 替换联想id
  15. replaceLeonovoIdShell = 'sed -i "1,\\$s/lenovo_id/%s/g" %s/AndroidManifest.xml ' % (value, prj_path)
  16. printlog("replaceLeonovoIdShell: %s" % replaceLeonovoIdShell)
  17. os.system(replaceLeonovoIdShell)
  18. manifestRootExt = r'<application android:networkSecurityConfig="@xml/network_security_config"'
  19. replacePkgNameShell = "sed -i 's!<application!%s!g' %s/AndroidManifest.xml" % (manifestRootExt, prj_path)
  20. printlog("LenovoReplace replace add application root point shell: %s" % replacePkgNameShell)
  21. os.system(replacePkgNameShell)
  22. pass
  23. # 豌豆荚
  24. def WandoujiaReplace(prj_path, dir_split, key, value):
  25. printlog("specail replace : wdj")
  26. if (key == "APPKEY_ID"):
  27. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  28. printlog("prj_am_path :%s" % prj_am_path)
  29. lines = open(prj_am_path).readlines()
  30. fp = open(prj_am_path, 'w')
  31. for s in lines:
  32. if (s.find("Wandoujia-PaySdk-") != -1):
  33. printlog("replace Wandoujia-PaySdk-%s" % value)
  34. s = re.sub('Wandoujia-PaySdk-.*\"', 'Wandoujia-PaySdk-' + value + '\"', s)
  35. fp.write(s)
  36. fp.close()
  37. pass
  38. # 虫虫
  39. def ChongchongReplace(prj_path, dir_split, key, value):
  40. printlog("specail replace : Chongchong")
  41. if (key == "app_id"):
  42. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  43. printlog("prj_am_path :%s" % prj_am_path)
  44. lines = open(prj_am_path).readlines()
  45. fp = open(prj_am_path, 'w')
  46. for s in lines:
  47. if (s.find("qqPay") != -1):
  48. printlog("replace qqPay:%s" % value)
  49. s = re.sub('qqPay.*\"', 'qqPay' + value + '\"', s);
  50. fp.write(s)
  51. fp.close()
  52. # 360
  53. def QihuReplace(prj_path, dir_split, key, value):
  54. global appkey
  55. printlog("specail replace : 360")
  56. if (key == "QHOPENSDK_APPKEY"):
  57. replacePkgNameShell = 'sed -i "s/qihu_appkey/%s/g" %s/AndroidManifest.xml' % (value, prj_path)
  58. printlog("QihuReplace replace qihu_appkey shell: %s" % replacePkgNameShell)
  59. os.system(replacePkgNameShell)
  60. if (key == "QHOPENSDK_APPSECRET"):
  61. prj_param = "%s/assets/YyrhParam.cnf" % prj_path
  62. prj_am_path = "%s/AndroidManifest.xml" % prj_path
  63. appsecret = value
  64. metadatas = ET.parse(prj_am_path).getroot().find("application").findall("meta-data")
  65. for meta in metadatas:
  66. if (meta.attrib["{http://schemas.android.com/apk/res/android}name"] == "QHOPENSDK_APPKEY"):
  67. appkey = meta.attrib["{http://schemas.android.com/apk/res/android}value"]
  68. printlog("prj_am_path:%s" % prj_am_path)
  69. m = hashlib.md5()
  70. printlog("appsecret :%s" % appsecret)
  71. printlog("appkey: %s" % appkey)
  72. md5value = "%s#%s" % (appsecret, appkey)
  73. printlog("md5value :%s" % md5value)
  74. m.update(md5value)
  75. privatekey = m.hexdigest()
  76. printlog("privatekey:%s" % privatekey)
  77. Replace.replaceAM_Meta_data(prj_am_path, 'QHOPENSDK_PRIVATEKEY', privatekey)
  78. manifestRootExt = r'<application android:networkSecurityConfig="@xml/network_security_config"'
  79. replacePkgNameShell = "sed -i 's!<application!%s!g' %s/AndroidManifest.xml" % (manifestRootExt, prj_path)
  80. printlog("qihu360 replace add application root point shell: %s" % replacePkgNameShell)
  81. os.system(replacePkgNameShell)
  82. pass
  83. def OppoReplace(prj_path, dir_split, key, value):
  84. printlog("specail replace : oppo")
  85. if (key == "APPKEY"):
  86. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  87. printlog("prj_am_path: %s" % prj_am_path)
  88. # 替换app_key
  89. Replace.replaceAM_Meta_data(prj_am_path, 'app_key', value)
  90. printlog("appkey: %s" % value)
  91. pass
  92. def OppoMlReplace(prj_path, dir_split, key, value):
  93. printlog("specail replace : oppoml")
  94. if (key == "APPKEY"):
  95. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  96. printlog("prj_am_path: %s" % prj_am_path)
  97. # 替换app_key
  98. Replace.replaceAM_Meta_data(prj_am_path, 'app_key', value)
  99. printlog("appkey: %s" % value)
  100. pass
  101. def downjoyReplace(prj_path, dir_split, key, value):
  102. printlog("specail replace : downjoy")
  103. if (key == "APP_ID"):
  104. splash_activity = "com.downjoy.activity.SdkLoadActivity"
  105. prj_am_path = "%s/AndroidManifest.xml" % prj_path
  106. game_activity = Replace.replaceGameActivityLaunchAttribute(splash_activity, prj_am_path)
  107. printlog(game_activity)
  108. Replace.replaceAM_Meta_data(prj_am_path, 'CP_ACTIVITY', game_activity)
  109. lines = open(prj_am_path).readlines()
  110. fp = open(prj_am_path, 'w')
  111. for s in lines:
  112. if (s.find("dcnngsdk") != -1):
  113. printlog("replace dcnngsdk:%s" % value)
  114. s = re.sub('dcnngsdk.*\"', 'dcnngsdk' + value + '\"', s)
  115. fp.write(s)
  116. fp.close()
  117. pass
  118. def YYBReplace(prj_path, dir_split, key, value):
  119. if (key == "QQ_APP_ID"):
  120. # 替换qq app id
  121. replaceQQAPPIDShell = 'sed -i "s/qq_app_id/%s/g" %s/AndroidManifest.xml' % (value, prj_path)
  122. printlog("yingyongbao qq app id shell: %s" % replaceQQAPPIDShell)
  123. os.system(replaceQQAPPIDShell)
  124. # 替换ysdkconf.ini
  125. printlog("path ysdkconfig.ini:%s/assets/ysdkconf.ini" % prj_path)
  126. Replace.replaceAssets_Param("%s/assets/ysdkconf.ini" % prj_path, key, value)
  127. Replace.replaceAssets_Param("%s/assets/ysdkconf.ini" % prj_path, "OFFER_ID", value)
  128. prj_am_path = "%s/AndroidManifest.xml" % prj_path
  129. game_activity = Replace.getLauchActivityName(prj_path)
  130. Replace.replaceAM_Meta_data(prj_am_path, 'MAIN_ACTIVITY', game_activity)
  131. if (key == "WX_APP_ID"):
  132. replaceWXAPPIDShell = 'sed -i "s/wx_app_id/%s/g" %s/AndroidManifest.xml' % (value, prj_path)
  133. printlog("yingyongbao wx app id shell: %s" % replaceWXAPPIDShell)
  134. os.system(replaceWXAPPIDShell)
  135. # 替换ysdkconf.ini
  136. Replace.replaceAssets_Param("%s/assets/ysdkconf.ini" % prj_path, key, value)
  137. if (key == "IS_SAND_BOX"):
  138. ysdk_sand_url = "https://ysdktest.qq.com"
  139. ysdk_online_url = "https://ysdk.qq.com"
  140. if value == "1":
  141. ysdk_url = ysdk_sand_url
  142. else:
  143. ysdk_url = ysdk_online_url
  144. Replace.replaceAssets_Param("%s/assets/ysdkconf.ini" % prj_path, "YSDK_URL", ysdk_url)
  145. pass
  146. def HuaweiReplace(prj_path, dir_split, key, value):
  147. if (key == "APP_ID"):
  148. replaceAppidShell = '/bin/sed -i "s/APP_ID/%s/g" %s/AndroidManifest.xml' % (value, prj_path)
  149. printlog("huawei replace appid shell: %s" % replaceAppidShell)
  150. os.system(replaceAppidShell)
  151. if (key == "PAY_ID"):
  152. replacePayidShell = '/bin/sed -i "s/PAY_ID/%s/g" %s/AndroidManifest.xml' % (value, prj_path)
  153. printlog("huawei replace payid shell: %s" % replacePayidShell)
  154. os.system(replacePayidShell)
  155. pass
  156. def AnzhiReplace(prj_path, dir_split, key, value):
  157. printlog("specail replace : anzhi")
  158. prj_am_path = "%s/AndroidManifest.xml" % prj_path
  159. pkgName = ET.parse(prj_am_path).getroot().attrib["package"]
  160. if (key == "APP_KEY"):
  161. lines = open(prj_am_path).readlines()
  162. fp = open(prj_am_path, 'w')
  163. for s in lines:
  164. if (s.find("packagename") != -1):
  165. s = re.sub('packagename', pkgName, s);
  166. fp.write(s)
  167. fp.close()
  168. pass
  169. def GuopanReplace(prj_path, dir_split, key, value):
  170. printlog("specail replace : guopan")
  171. prj_am_path = "%s/AndroidManifest.xml" % prj_path
  172. pkgName = ET.parse(prj_am_path).getroot().attrib["package"]
  173. if (key == "APP_ID"):
  174. lines = open(prj_am_path).readlines()
  175. fp = open(prj_am_path, 'w')
  176. for s in lines:
  177. if (s.find("gp_packagename") != -1):
  178. s = re.sub('gp_packagename', pkgName + ".StubContentProvider", s);
  179. fp.write(s)
  180. fp.close()
  181. pass
  182. def LeshiReplace(prj_path, dir_split, key, value):
  183. printlog("specail replace : leshi")
  184. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  185. if (key == "LEPAY_APPID"):
  186. Replace.replaceAM_Meta_data(prj_am_path, 'lepay_appid', value)
  187. if (key == "LEPAY_APPKEY"):
  188. Replace.replaceAM_Meta_data(prj_am_path, 'lepay_appkey', value)
  189. pass
  190. def QuickReplace(prj_path, dir_split, key, value):
  191. printlog("specail replace : Quick")
  192. if (key == "PRODUCT_CODE"):
  193. splashactivity = "com.yythird.sdk.SplashActivity"
  194. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  195. prj_param = "%s/assets/YyrhParam.cnf" % prj_path
  196. game_activity = Replace.replaceGameActivityLaunchAttribute(splashactivity, prj_am_path)
  197. printlog("GAMEACTIVITY :%s" % game_activity)
  198. Replace.replaceAssets_Param(prj_param, "GAMEACTIVITY", game_activity)
  199. if (key == "SDK_TYPE"):
  200. printlog("merge qitian Smali")
  201. if value == "qitian":
  202. printlog("merge qitian Smali")
  203. sdk_root_dir = apk_utils.getCutSdkRootHome()
  204. ret = 0
  205. ret = ret | File.mergeDir("%s/quick/quick/qitian_smali" % sdk_root_dir, "%s/smali" % prj_path)
  206. pass
  207. def LjsdkReplace(prj_path, dir_split, key, value):
  208. printlog("specail replace : LjsdkReplace")
  209. if (key == "XMGAME_PRODUCT_CODE"):
  210. prj_param = "%s/assets/param.cnf" % prj_path
  211. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  212. splashactivity = "third.sdk.SplashActivity"
  213. game_activity = Replace.replaceGameActivityLaunchAttribute(splashactivity, prj_am_path)
  214. printlog("GAMEACTIVITY :%s" % game_activity)
  215. Replace.replaceAssets_Param(prj_param, "GAMEACTIVITY", game_activity)
  216. pkgName = ET.parse(prj_am_path).getroot().attrib["package"]
  217. pkgLine = 'package="' + pkgName + '"'
  218. printlog("pkgValue :%s" % pkgLine)
  219. addPkgLine = ' xmlns:tools="http://schemas.android.com/tools" '
  220. addPerLine = ' tools:ignore="ProtectedPermissions" '
  221. permissionName = 'android:name="android.permission.PACKAGE_USAGE_STATS"'
  222. lines = open(prj_am_path).readlines()
  223. fp = open(prj_am_path, 'w')
  224. for s in lines:
  225. if (s.find(pkgLine) != -1):
  226. s = re.sub(pkgLine, pkgLine + addPkgLine, s);
  227. printlog("pkgLine :%s" % s)
  228. if (s.find(permissionName) != -1):
  229. s = re.sub(permissionName, permissionName + addPerLine, s);
  230. printlog("permissionName :%s" % s)
  231. fp.write(s)
  232. fp.close()
  233. pass
  234. def UcsdkReplace(prj_path, dir_split, key, value):
  235. printlog("specail replace : UcsdkReplace")
  236. if (key == "GAME_ID"):
  237. replaceGidShell = 'sed -i "s/GAME_ID/%s/g" %s/AndroidManifest.xml' % (value, prj_path)
  238. printlog("uc replace GAME_ID shell: %s" % replaceGidShell)
  239. os.system(replaceGidShell)
  240. # GeneralModifySmali.modifyLauchSmali(prj_path)
  241. pass
  242. def XiaomisdkReplace(prj_path, dir_split, key, value):
  243. printlog("specail replace : XiaomisdkReplace")
  244. if (key == "APP_ID"):
  245. # 获取包名
  246. sdk_root_dir = apk_utils.getCutSdkRootHome()
  247. Replace.modifyRfileSmaliPath("xiaomi", prj_path);
  248. printlog(" xiaomi begin replace game package v4 smali -------------------------------")
  249. pkgV4Path = "%s/smali/android/support/v4" % prj_path
  250. printlog("pkgV4Path:%s" % pkgV4Path)
  251. sdkV4Path = "%s/xiaomi/xiaomi/smali/android/support/v4" % sdk_root_dir
  252. printlog("sdkV4Path:%s" % sdkV4Path)
  253. if os.path.exists(pkgV4Path):
  254. File.copyAllFile(sdkV4Path, pkgV4Path)
  255. pkgAnnotation = "%s/smali/android/support/annotation" % prj_path
  256. printlog("pkgV4Path:%s" % pkgAnnotation)
  257. sdkAnnotation = "%s/xiaomi/xiaomi/smali/android/support/annotation" % sdk_root_dir
  258. if os.path.exists(pkgAnnotation):
  259. File.copyAllFile(sdkAnnotation, pkgAnnotation)
  260. pass
  261. # 百度
  262. def BaiduReplace(prj_path, dir_split, key, value):
  263. printlog("specail replace : baidu")
  264. if (key == "APP_ID"):
  265. GeneralModifySmali.modifyLauchSmali(prj_path)
  266. pass
  267. # 圣本
  268. def ShengbensdkReplace(prj_path, dir_split, key, value):
  269. printlog("specail replace : ShengbensdkReplace")
  270. if (key == "AGENT"):
  271. jsonFilePath = prj_path + dir_split + "assets" + dir_split + "hnsb_config.json"
  272. printlog("path hnsb_config.json :%s" % jsonFilePath)
  273. with open(jsonFilePath, 'r') as fp:
  274. jsonData = json.load(fp)
  275. jsonData['sdk']["ver"] = value
  276. newJsonData = jsonData
  277. fp.close()
  278. with open(jsonFilePath, 'w') as fp:
  279. json.dump(newJsonData, fp)
  280. fp.close()
  281. if (key == "APP_ID"):
  282. jsonFilePath = prj_path + dir_split + "assets" + dir_split + "hnsb_config.json"
  283. with open(jsonFilePath, 'r') as fp:
  284. jsonData = json.load(fp)
  285. jsonData['sdk']["appid"] = value
  286. newJsonData = jsonData
  287. fp.close()
  288. with open(jsonFilePath, 'w') as fp:
  289. json.dump(newJsonData, fp)
  290. fp.close()
  291. pass
  292. def JinkuosdkReplace(prj_path, dir_split, key, value):
  293. printlog("specail replace : JinkuosdkReplace")
  294. printlog("path yy.properties :%s/assets/u8_developer_config.properties" % prj_path)
  295. Replace.replaceAssets_Param("%s/assets/u8_developer_config.properties" % prj_path, key, value)
  296. pass
  297. def HdhdsdkReplace(prj_path, dir_split, key, value):
  298. printlog("specail replace : HdhdsdkReplace")
  299. if (key == "APP_ID"):
  300. GeneralModifySmali.modifyLauchSmali(prj_path)
  301. pass
  302. def SamsungReplace(prj_path, dir_split, key, value):
  303. printlog("specail replace : SamsungReplace")
  304. if (key == "APPV_KEY"):
  305. ptKey = value[0:99]
  306. pvData = value[99:len(value)]
  307. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  308. printlog("prj_am_path: %s" % prj_am_path)
  309. # 替换app_key
  310. Replace.replaceAM_Meta_data(prj_am_path, 'ptKey', ptKey)
  311. prj_param = "%s/assets/YyrhParam.cnf" % prj_path
  312. Replace.replaceAssets_Param(prj_param, "pvData", pvData)
  313. pass
  314. def TTReplace(prj_path, dir_split, key, value):
  315. printlog("specail replace : TTReplace")
  316. if (key == "GAME_ID"):
  317. Replace.replaceAssets_Param("%s/assets/tt_game_sdk_opt.properties" % prj_path, "gameId", value)
  318. if (key == "GAME_KEY"):
  319. replaceKeyShell = 'sed -i "s/@WSX3edc/%s/g" %s/assets/TTGameSDKConfig.cfg' % (value, prj_path)
  320. printlog("replaceMainLineShell:%s" % replaceKeyShell)
  321. os.system(replaceKeyShell)
  322. pass
  323. def YXFReplace(prj_path, dir_split, key, value):
  324. printlog("specail replace : YXFReplace")
  325. if (key == "YGAPPID"):
  326. replacePkgNameShell = '/bin/sed -i "1,\\$s/YXFAPPID/%s/g" %s/AndroidManifest.xml' % (value, prj_path)
  327. printlog("replacePkgNameShell:%s" % replacePkgNameShell)
  328. os.system(replacePkgNameShell)
  329. manifestRootExt = r'<application android:usesCleartextTraffic="true"'
  330. replacePkgNameShell = "sed -i 's!<application!%s!g' %s/AndroidManifest.xml" % (manifestRootExt, prj_path)
  331. printlog("youxiFan replace add application root point shell: %s" % replacePkgNameShell)
  332. os.system(replacePkgNameShell)
  333. if (key == "IS_SPLASH"):
  334. if (value == "0"):
  335. GeneralModifySmali.modifyYXFLauchSmali(prj_path)
  336. if (key == "screenOrientation"):
  337. sdk_root_dir = apk_utils.getCutSdkRootHome()
  338. if (value == "screenOrientation:0"):
  339. splash = "%s/yxf/yxf/extension/sp_landscape.png" % sdk_root_dir
  340. apkres = "%s/res/drawable/crash_screen.png" % prj_path
  341. shutil.copy(splash, apkres)
  342. if (value == "screenOrientation:1"):
  343. splash = "%s/yxf/yxf/extension/sp_portrait.png" % sdk_root_dir
  344. apkres = "%s/res/drawable/crash_screen.png" % prj_path
  345. shutil.copy(splash, apkres)
  346. pass
  347. def VivosdkReplace(prj_path, dir_split, key, value):
  348. printlog("specail replace : VivosdkReplace")
  349. if (key == "APP_ID"):
  350. printlog("path supplierconfig.json :%s/assets/supplierconfig.json" % prj_path)
  351. replaceConfigShell = '/bin/sed -i "1,\\$s/APP_ID/%s/g" %s/assets/supplierconfig.json' % (value, prj_path)
  352. printlog("replaceConfigShell APP_ID:%s" % replaceConfigShell)
  353. os.system(replaceConfigShell)
  354. jsonFilePath = prj_path + dir_split + "assets" + dir_split + "supplierconfig.json"
  355. printlog("path supplierconfig.json :%s" % jsonFilePath)
  356. with open(jsonFilePath, 'r') as fp:
  357. jsonData = json.load(fp)
  358. jsonData['supplier']["vivo"]["appid"] = value
  359. newJsonData = jsonData
  360. fp.close()
  361. with open(jsonFilePath, 'w') as fp:
  362. json.dump(newJsonData, fp)
  363. fp.close()
  364. pass
  365. def XTsdkReplace(prj_path, dir_split, key, value):
  366. printlog("specail replace : Xiantu3011sdkReplace")
  367. if (key == "GAME_ID"):
  368. # 获取包名
  369. Replace.modifyRfileSmaliPath("3011", prj_path);
  370. pass
  371. def DDTsdkReplace(prj_path, dir_split, key, value):
  372. printlog("specail replace : DDTsdkReplace")
  373. if (key == "APP_ID"):
  374. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  375. splashactivity = "com.ddtsdk.ui.activity.MHPerActivity"
  376. game_activity = Replace.replaceGameActivityLaunchAttribute(splashactivity, prj_am_path)
  377. printlog("GAMEACTIVITY :%s" % game_activity)
  378. Replace.replaceAM_Meta_data(prj_am_path, "mainAct", game_activity)
  379. if (key == "agent"):
  380. Replace.replaceAssets_Param("%s/assets/ddt.properties" % prj_path, key, value)
  381. pass
  382. def QiyuReplace(prj_path, dir_split, key, value):
  383. if (key == "APP_ID"):
  384. manifestRootExt = r'<application android:usesCleartextTraffic="true"'
  385. replacePkgNameShell = "sed -i 's!<application!%s!g' %s/AndroidManifest.xml" % (manifestRootExt, prj_path)
  386. printlog("QiyuReplace add application root point shell: %s" % replacePkgNameShell)
  387. os.system(replacePkgNameShell)
  388. pass
  389. def WankaReplace(prj_path, dir_split, key, value):
  390. if (key == "APPID"):
  391. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  392. namespace = '{http://schemas.android.com/apk/res/android}'
  393. manifestRootExt = r'<application xmlns:tools="http://schemas.android.com/tools" tools:replace="android:theme,android:name"'
  394. replacePkgNameShell = "sed -i 's!<application!%s!g' %s/AndroidManifest.xml" % (manifestRootExt, prj_path)
  395. printlog("WankaReplace replace add application root point shell: %s" % replacePkgNameShell)
  396. os.system(replacePkgNameShell)
  397. tree = ET.parse(prj_am_path)
  398. activitys = tree.getroot().find("application").findall("activity")
  399. for activity in activitys:
  400. filters = activity.findall('intent-filter')
  401. for filter in filters:
  402. categorys = filter.findall('category')
  403. for category in categorys:
  404. categoryname = category.attrib[namespace + "name"]
  405. if (categoryname == "android.intent.category.LAUNCHER"):
  406. element = Element('intent-filter')
  407. el1 = Element('action android:name="android.intent.action.VIEW"')
  408. el2 = Element('category android:name="android.intent.category.DEFAULT"')
  409. el3 = Element('category android:name="android.intent.category.BROWSABLE"')
  410. el4_value = 'data android:scheme="app%s"' % value
  411. el4 = Element(el4_value)
  412. element.append(el1)
  413. element.append(el2)
  414. element.append(el3)
  415. element.append(el4)
  416. activity.append(element)
  417. activity.set(namespace + 'launchMode', "singleTask")
  418. tree.write(prj_am_path, "UTF-8", xml_declaration=True, method='xml')
  419. pkgName = ET.parse(prj_am_path).getroot().attrib["package"]
  420. Aapt_Util.createRFile(prj_path, False, pkgName)
  421. sdkRpath = "android/support/v7/appcompat"
  422. pkgRpath = pkgName.replace(".", "/")
  423. sdkAbsoluteRpath = "%s/smali/%s" % (prj_path, sdkRpath)
  424. pkgAbsoluteRpath = "%s/smali/%s" % (prj_path, pkgRpath)
  425. Replace.createRFile2Sdk(pkgAbsoluteRpath, sdkAbsoluteRpath, pkgRpath, sdkRpath)
  426. pass
  427. def DDDReplace(prj_path, dir_split, key, value):
  428. if (key == "channelId"):
  429. Replace.replaceAssets_Param("%s/assets/dingdd.properties" % prj_path, 'channelId', value)
  430. if (key == "adId"):
  431. Replace.replaceAssets_Param("%s/assets/dingdd.properties" % prj_path, 'adId', value)
  432. if (key == "adFlag"):
  433. Replace.replaceAssets_Param("%s/assets/dingdd.properties" % prj_path, 'adFlag', value)
  434. pass
  435. def LZYXReplace(prj_path, dir_split, key, value):
  436. if (key == "ML_Channel"):
  437. Replace.replaceAssets_Param("%s/assets/mlgame_developer_config.properties" % prj_path, 'ML_Channel', value)
  438. if (key == "ML_APPKEY"):
  439. Replace.replaceAssets_Param("%s/assets/mlgame_developer_config.properties" % prj_path, 'ML_APPKEY', value)
  440. pass
  441. def WSReplace(prj_path, dir_split, key, value):
  442. if (key == "HS_APPID"):
  443. manifestRootExt = r'<application android:networkSecurityConfig="@xml/huosdk_network_security_config"'
  444. replacePkgNameShell = "sed -i 's!<application!%s!g' %s/AndroidManifest.xml" % (manifestRootExt, prj_path)
  445. printlog("qihu360 replace add application root point shell: %s" % replacePkgNameShell)
  446. os.system(replacePkgNameShell)
  447. pass
  448. def XBReplace(prj_path, dir_split, key, value):
  449. if (key == "GID"):
  450. printlog("path gameshaiApp.ini :%s/assets/gameshaiApp.ini" % prj_path)
  451. Replace.replaceAssets_Param("%s/assets/gameshaiApp.ini" % prj_path, 'gid', value)
  452. if (key == "PID"):
  453. printlog("path gameshaiApp.ini :%s/assets/gameshaiApp.ini" % prj_path)
  454. Replace.replaceAssets_Param("%s/assets/gameshaiApp.ini" % prj_path, 'pid', value)
  455. pass
  456. def YoudianReplace(prj_path, dir_split, key, value):
  457. if (key == "APPID"):
  458. apkPkgDir = ET.parse("%s/AndroidManifest.xml" % prj_path).getroot().attrib["package"].replace(".", "/")
  459. apkRfilePath = "%s/smali/%s" % (prj_path, apkPkgDir)
  460. Replace.modifyRfileSmaliPath("youdian", prj_path);
  461. publicXml = "%s/res/values/public.xml" % prj_path
  462. sdk_jar_dir = apk_utils.getToolsJarHome()
  463. jarPath = "%s/MergeSamli.jar" % sdk_jar_dir
  464. javaMerCm = 'java -jar %s %s %s' % (jarPath, publicXml, apkRfilePath)
  465. printlog("javaMerCm:%s" % javaMerCm)
  466. os.system(javaMerCm)
  467. pass
  468. def Xiao7Replace(prj_path, dir_split, key, value):
  469. if (key == "APPKEY"):
  470. apkRfilePath = "%s/smali_classes2/com/smwl/smsdk" % prj_path
  471. publicXml = "%s/res/values/public.xml" % prj_path
  472. sdk_jar_dir = apk_utils.getToolsJarHome()
  473. jarPath = "%s/MergeSamli.jar" % sdk_jar_dir
  474. javaMerCm = 'java -jar %s %s %s' % (jarPath, publicXml, apkRfilePath)
  475. printlog("javaMerCm:%s" % javaMerCm)
  476. os.system(javaMerCm)
  477. printlog(" Xiao7Replace begin replace game package v4 smali -------------------------------")
  478. sdk_root_dir = apk_utils.getCutSdkRootHome()
  479. pkgV4Path = "%s/smali/android/support/v4" % prj_path
  480. printlog("pkgV4Path:%s" % pkgV4Path)
  481. sdkV4Path = "%s/x7sy/x7sy/smali/android/support/v4" % sdk_root_dir
  482. printlog("sdkV4Path:%s" % sdkV4Path)
  483. if os.path.exists(pkgV4Path):
  484. File.copyAllFile(sdkV4Path, pkgV4Path)
  485. pkgName = ET.parse("%s/AndroidManifest.xml" % prj_path).getroot().attrib["package"]
  486. Aapt_Util.createRFile(prj_path, False, pkgName)
  487. pkgName = "android.support.constraint"
  488. Aapt_Util.createRFile(prj_path, False, pkgName)
  489. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  490. prj_param = "%s/assets/YyrhParam.cnf" % prj_path
  491. splashactivity = "com.yythird.sdk.SplashActivity"
  492. game_activity = Replace.replaceGameActivityLaunchAttribute(splashactivity, prj_am_path)
  493. Replace.replaceAssets_Param(prj_param, "GAME_ACTIVITY", game_activity)
  494. printlog("xiaoqi GAME_ACTIVITY :%s" % game_activity)
  495. pass
  496. def NwanKaReplace(prj_path, dir_split, key, value):
  497. if (key == "channelId"):
  498. Replace.replaceAssets_Param("%s/assets/wk.properties" % prj_path, 'channelId', value)
  499. if (key == "adId"):
  500. Replace.replaceAssets_Param("%s/assets/wk.properties" % prj_path, 'adId', value)
  501. if (key == "adFlag"):
  502. Replace.replaceAssets_Param("%s/assets/wk.properties" % prj_path, 'adFlag', value)
  503. manifestRootExt = r'<application xmlns:tools="http://schemas.android.com/tools" tools:replace="android:theme,android:name"'
  504. replacePkgNameShell = "sed -i 's!<application!%s!g' %s/AndroidManifest.xml" % (manifestRootExt, prj_path)
  505. printlog("WankaReplace replace add application root point shell: %s" % replacePkgNameShell)
  506. os.system(replacePkgNameShell)
  507. pass
  508. def MBaiduReplace(prj_path, dir_split, key, value):
  509. if (key == "APP_ID"):
  510. manifestRootExt = r'<application android:networkSecurityConfig="@xml/network_security_config"'
  511. replacePkgNameShell = "sed -i 's!<application!%s!g' %s/AndroidManifest.xml" % (manifestRootExt, prj_path)
  512. printlog("MbaiduReplace replace add application root point shell: %s" % replacePkgNameShell)
  513. os.system(replacePkgNameShell)
  514. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali/com/baidu/passport/sapi2")
  515. pass
  516. def ShenshouReplace(prj_path, dir_split, key, value):
  517. if (key == "BALANCENAME"):
  518. prj_style_path = prj_path + dir_split + "res/values-v28/styles.xml"
  519. printlog("prj_style_path: %s" % prj_style_path)
  520. File.safeFileDelete(prj_style_path)
  521. pass
  522. def DaYanReplace(prj_path, dir_split, key, value):
  523. if (key == "GD"):
  524. filepath = "%s/assets/sdkchannel.txt" % prj_path
  525. replacePdShell = 'sed -i "s#%s#%s#g" %s' % ("PD", value, filepath)
  526. printlog(replacePdShell)
  527. os.system(replacePdShell)
  528. pass
  529. def DaLanReplace(prj_path, dir_split, key, value):
  530. printlog("specail replace : DaLanReplace")
  531. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  532. if (key == "DL_APPID"):
  533. splashactivity = "com.dalan.dl_assembly.SplashScreenActivity"
  534. game_activity = Replace.replaceGameActivityLaunchAttribute(splashactivity, prj_am_path)
  535. printlog("GAMEACTIVITY :%s" % game_activity)
  536. Replace.replaceAM_Meta_data(prj_am_path, "dalan_union_main_activity", game_activity)
  537. pass
  538. def KSyxReplace(prj_path, dir_split, key, value):
  539. if (key == "kwai_app_id"):
  540. Replace.replaceAssets_Param("%s/assets/allin_developer_config.properties" % prj_path, 'kwai_app_id', value)
  541. printlog(" KSyxReplace begin replace game package v4 smali -------------------------------")
  542. sdk_root_dir = apk_utils.getCutSdkRootHome()
  543. pkgV4Path = "%s/smali/android/support/v4" % prj_path
  544. printlog("pkgV4Path:%s" % pkgV4Path)
  545. sdkV4Path = "%s/ksyx/ksyx/smali/android/support/v4" % sdk_root_dir
  546. printlog("sdkV4Path:%s" % sdkV4Path)
  547. if os.path.exists(pkgV4Path):
  548. File.copyAllFile(sdkV4Path, pkgV4Path)
  549. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  550. Replace.replaceAM_AllowBackup(prj_am_path)
  551. pass
  552. def LlhyReplace(prj_path, dir_split, key, value):
  553. printlog("specail replace : LlhyReplace")
  554. if (key == "LLHY_APP_ID"):
  555. metaKey = "unityplayer.SkipPermissionsDialog"
  556. Replace.replaceAM_Meta_data("%s/AndroidManifest.xml" % prj_path, metaKey,
  557. "true")
  558. pass
  559. def HnqsReplace(prj_path, dir_split, key, value):
  560. printlog("specail replace : HnqsReplace")
  561. if (key == "agent"):
  562. Replace.replaceAssets_Param("%s/assets/jmhy.properties" % prj_path, 'agent', value)
  563. metaKey = "unityplayer.SkipPermissionsDialog"
  564. Replace.replaceAM_Meta_data("%s/AndroidManifest.xml" % prj_path, metaKey,
  565. "true")
  566. sdk_root_dir = apk_utils.getCutSdkRootHome()
  567. sdk_smali_dir = "%s/hnqs/hnqs/extension/yyrh" % sdk_root_dir
  568. temp_old_smali_dir = "%s/smali/com/yyrh" % prj_path
  569. if os.path.exists(sdk_smali_dir):
  570. File.copyAllFile(sdk_smali_dir, temp_old_smali_dir)
  571. pass
  572. def SogouReplace(prj_path, dir_split, key, value):
  573. if (key == "GID"):
  574. printlog(" SogouReplace begin replace game package v4 smali -------------------------------")
  575. sdk_root_dir = apk_utils.getCutSdkRootHome()
  576. pkgV4Path = "%s/smali/android/support/v4" % prj_path
  577. printlog("pkgV4Path:%s" % pkgV4Path)
  578. sdkV4Path = "%s/sogou/sogou/smali/android/support/v4" % sdk_root_dir
  579. printlog("sdkV4Path:%s" % sdkV4Path)
  580. if os.path.exists(pkgV4Path):
  581. File.copyAllFile(sdkV4Path, pkgV4Path)
  582. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  583. Replace.replaceAM_AllowBackup(prj_am_path)
  584. pass
  585. def JinRiTouTiaoReplace(prj_path, dir_split, key, value):
  586. jsonFilePath = prj_path + dir_split + "assets" + dir_split + "config.json"
  587. if key == 'APP_ID':
  588. with open(jsonFilePath, 'r') as fp:
  589. jsonData = json.load(fp)
  590. jsonData['app']["app_id"] = value
  591. jsonData['app']['main_activity'] = GeneralModifySmali.getLauchActivityName(prj_path)
  592. orientation = GeneralModifySmali.getLauchActivityScreenOrientation(prj_path)
  593. if orientation == "landscape" or orientation == "sensorLandscape":
  594. screen_orientation = "sensorLandscape"
  595. else:
  596. screen_orientation = "sensorPortrait"
  597. jsonData['app']['screen_orientation'] = screen_orientation
  598. newJsonData = jsonData
  599. fp.close()
  600. with open(jsonFilePath, 'w') as fp:
  601. json.dump(newJsonData, fp)
  602. fp.close()
  603. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali/game_sdk/packers/rocket_sdk")
  604. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali_classes2/game_sdk/packers/rocket_sdk")
  605. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali/androidx/navigation/ui")
  606. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali_classes3/android/support/design")
  607. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali_classes3/android/support/v7/appcompat")
  608. # GeneralModifySmali.replaceSdkV4Smali(prj_path,"jrtt/jrtt/smali/android/support/v4")
  609. sdk_root_dir = apk_utils.getCutSdkRootHome()
  610. pkgV4Path = "%s/smali/android/support/v4" % prj_path
  611. printlog("pkgV4Path:%s" % pkgV4Path)
  612. sdkV4Path = "%s/jrtt/jrtt/smali_classes3/android/support/v4" % sdk_root_dir
  613. printlog("sdkV4Path:%s" % sdkV4Path)
  614. if os.path.exists(pkgV4Path):
  615. File.copyAllFile(sdkV4Path, pkgV4Path)
  616. GeneralModifySmali.modifyJrttV7ResIdSmali(prj_path)
  617. else:
  618. Replace.replaceJsonValue(jsonFilePath, "app", key, value)
  619. pass
  620. def FengQiReplace(prj_path, dir_split, key, value):
  621. if (key == "channelId") or (key == "adId") or (key == "adFlag"):
  622. # 替换fq.properties
  623. printlog("path fq.properties:%s/assets/fq.properties" % prj_path)
  624. Replace.replaceAssets_Param("%s/assets/fq.properties" % prj_path, key, value)
  625. pass
  626. pass
  627. def BlueStackReplace(prj_path, dir_split, key, value):
  628. if key == "APP_ID":
  629. replaceBlueStackIdShell = 'sed -i "1,\\$s/APP_ID/%s/g" %s/assets/BSSDKConfig.xml ' % (value, prj_path)
  630. printlog("replaceBlueStackIdShell: %s" % replaceBlueStackIdShell)
  631. os.system(replaceBlueStackIdShell)
  632. pass
  633. # 司墨
  634. def SiMoReplace(prj_path, dir_split, key, value):
  635. if key == "APP_ID":
  636. config_path = prj_path + '/assets/SIMgame_config.xml'
  637. tree = ET.parse(config_path)
  638. root = tree.getroot()
  639. for elem in root.iter('appid'):
  640. elem.text = value
  641. tree.write(config_path, "UTF-8", xml_declaration=True, method='xml')
  642. pass
  643. # 乘龙
  644. def ChenLongReplace(prj_path, dir_split, key, value):
  645. if key == "CL_PID":
  646. Replace.replaceAssets_Param("%s/assets/_cl_developer_config.properties" % prj_path, 'CL_PID', value)
  647. if key == "CL_KEY":
  648. Replace.replaceAssets_Param("%s/assets/_cl_developer_config.properties" % prj_path, 'CL_KEY', value)
  649. if key == "CL_DEBUG_GD":
  650. Replace.replaceAssets_Param("%s/assets/_cl_developer_config.properties" % prj_path, 'CL_DEBUG_GD', value)
  651. pass
  652. def JiuZiReplace(prj_path, dir_split, key, value):
  653. printlog("specail replace : JiuZiReplace")
  654. if (key == "gid"):
  655. prj_param = "%s/assets/YyrhParam.cnf" % prj_path
  656. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  657. splash_activity = "com.yythird.sdk.SplashActivity"
  658. game_activity = Replace.replaceGameActivityLaunchAttribute(splash_activity, prj_am_path)
  659. printlog("GAMEACTIVITY :%s" % game_activity)
  660. Replace.replaceAssets_Param(prj_param, "GAMEACTIVITY", game_activity)
  661. pkgName = ET.parse(prj_am_path).getroot().attrib["package"]
  662. Aapt_Util.createRFile(prj_path, False, pkgName)
  663. apkRfilePath = "%s/smali/com/jzyx/sdk" % prj_path
  664. printlog("apkRfilePath:%s" % apkRfilePath)
  665. publicXml = "%s/res/values/public.xml" % prj_path
  666. sdk_jar_dir = apk_utils.getToolsJarHome()
  667. jarPath = "%s/MergeSamli.jar" % sdk_jar_dir
  668. javaMerCm = 'java -jar %s %s %s' % (jarPath, publicXml, apkRfilePath)
  669. printlog("javaMerCm:%s" % javaMerCm)
  670. os.system(javaMerCm)
  671. pass
  672. def BingNiaoReplace(prj_path, dir_split, key, value):
  673. printlog("specail replace : DaLanReplace")
  674. if (key == "YH_GAME_ID"):
  675. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  676. splashactivity = "prj.iyinghun.platform.sdk.SplashScreenActivity"
  677. game_activity = Replace.replaceGameActivityLaunchAttribute(splashactivity, prj_am_path)
  678. printlog("GAMEACTIVITY :%s" % game_activity)
  679. Replace.replaceAM_Meta_data(prj_am_path, "prj.chameleon.intent.main", game_activity)
  680. pass
  681. def BingChengReplace(prj_path, dir_split, key, value):
  682. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  683. namespace = '{http://schemas.android.com/apk/res/android}'
  684. ET.register_namespace('android', "http://schemas.android.com/apk/res/android")
  685. if (key == "BC_GAME_ID"):
  686. tree = ET.parse(prj_am_path)
  687. pkgName = tree.getroot().attrib["package"]
  688. activitys = tree.getroot().find("application").findall("activity")
  689. for activity in activitys:
  690. filters = activity.findall('intent-filter')
  691. for filter in filters:
  692. categorys = filter.findall('category')
  693. for category in categorys:
  694. categoryname = category.attrib[namespace + "name"]
  695. if (categoryname == "android.intent.category.LAUNCHER"):
  696. element = Element('intent-filter')
  697. el1 = Element('action android:name="android.intent.action.VIEW"')
  698. el2 = Element('category android:name="android.intent.category.DEFAULT"')
  699. el3 = Element('category android:name="android.intent.category.BROWSABLE"')
  700. el4_value = 'data android:host="%s" android:scheme="%s"' % (value, pkgName)
  701. el4 = Element(el4_value)
  702. element.append(el1)
  703. element.append(el2)
  704. element.append(el3)
  705. element.append(el4)
  706. activity.append(element)
  707. tree.write(prj_am_path, "UTF-8", xml_declaration=True, method='xml')
  708. def SuixingHuYuReplace(prj_path, dir_split, key, value):
  709. if (key == "game_id"):
  710. Replace.replaceAssets_Param("%s/assets/suixin/suixin_sdk.ini" % prj_path, key, value)
  711. if (key == "pid"):
  712. Replace.replaceAssets_Param("%s/assets/suixin/suixin_sdk.ini" % prj_path, key, value)
  713. if (key == "is_land"):
  714. Replace.replaceAssets_Param("%s/assets/suixin/suixin_sdk.ini" % prj_path, key, value)
  715. pass
  716. def ShouQuReplace(prj_path, dir_split, key, value):
  717. config_path = "%s/assets/sqsdk_config" % prj_path
  718. with open(config_path, "r") as f:
  719. content = f.read()
  720. json_data = json.loads(content)
  721. json_data[key] = value
  722. with open(config_path, "w") as f:
  723. f.write(json.dumps(json_data))
  724. if key == "app_key":
  725. manifest_path = prj_path + dir_split + "AndroidManifest.xml"
  726. param_cnf = "%s/assets/YyrhParam.cnf" % prj_path
  727. splash_activity = "com.yythird.sdk.SplashActivity"
  728. game_activity = Replace.replaceGameActivityLaunchAttribute(splash_activity, manifest_path)
  729. Replace.replaceAssets_Param(param_cnf, "GAMEACTIVITY", game_activity)
  730. printlog("GAMEACTIVITY :%s" % game_activity)
  731. def HaiNanQiJingReplace(prj_path, dir_split, key, value):
  732. if key == "PACKAGE_TAG":
  733. sdk_root_dir = apk_utils.getCutSdkRootHome()
  734. sdkSmaliPath = "%s/hnqj/hnqj/smali/com" % sdk_root_dir
  735. pkgSmaliPath = "%s/smali/com" % prj_path
  736. printlog("sdkSmaliPath :%s" % sdkSmaliPath)
  737. printlog("pkgSmaliPath :%s" % pkgSmaliPath)
  738. if os.path.exists(pkgSmaliPath):
  739. File.copyAllFile(sdkSmaliPath, pkgSmaliPath)
  740. if Contants.isTestEnvironment():
  741. key = "https://fxsy.qijinghao.com"
  742. value = "http://testsdkapi.yyxxgame.com"
  743. file = "%s/smali/com/yyrh/c/a.smali" % prj_path
  744. Replace.replaceKeyword(key, value, file)
  745. file = "%s/smali/com/yyrh/ui/a.smali" % prj_path
  746. Replace.replaceKeyword(key, value, file)
  747. file = "%s/smali/com/yyrh/a/d.smali" % prj_path
  748. Replace.replaceKeyword(key, value, file)
  749. file = "%s/smali/com/yyrh/sdk/SDKEntry.smali" % prj_path
  750. Replace.replaceKeyword(key, value, file)
  751. pass
  752. def HongGuoReplace(prj_path, dir_split, key, value):
  753. config_path = "%s/assets/gameInfo.json" % prj_path
  754. with open(config_path, "r") as f:
  755. content = f.read()
  756. json_data = json.loads(content)
  757. json_data[key] = value
  758. with open(config_path, "w") as f:
  759. f.write(json.dumps(json_data))
  760. if key == "game_id":
  761. manifest_path = prj_path + dir_split + "AndroidManifest.xml"
  762. param_cnf = "%s/assets/YyrhParam.cnf" % prj_path
  763. splash_activity = "com.yythird.sdk.SplashActivity"
  764. game_activity = Replace.replaceGameActivityLaunchAttribute(splash_activity, manifest_path)
  765. Replace.replaceAssets_Param(param_cnf, "GAMEACTIVITY", game_activity)
  766. sdk_root_dir = apk_utils.getCutSdkRootHome()
  767. printlog(" HongGuoReplace begin replace game package v4 smali -------------------------------")
  768. pkgV4Path = "%s/smali/android/support/v4" % prj_path
  769. printlog("pkgV4Path:%s" % pkgV4Path)
  770. sdkV4Path = "%s/hg/hg/smali/android/support/v4" % sdk_root_dir
  771. printlog("sdkV4Path:%s" % sdkV4Path)
  772. if os.path.exists(pkgV4Path):
  773. File.copyAllFile(sdkV4Path, pkgV4Path)
  774. pass
  775. def BaizeReplace(prj_path, dir_split, key, value):
  776. if key == "APP_ID":
  777. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  778. param_cnf = "%s/assets/YyrhParam.cnf" % prj_path
  779. splashactivity = "com.yythird.sdk.SplashActivity"
  780. game_activity = Replace.replaceGameActivityLaunchAttribute(splashactivity, prj_am_path)
  781. printlog("GAMEACTIVITY :%s" % game_activity)
  782. Replace.replaceAssets_Param(param_cnf, "GAMEACTIVITY", game_activity)
  783. pass
  784. def YanXinReplace(prj_path, dir_split, key, value):
  785. if key == "ProductCode":
  786. Replace.modifyRfileSmaliPath("yx", prj_path)
  787. pass
  788. def ZhangShangHuYuReplace(prj_path, dir_split, key, value):
  789. Replace.replaceAssets_Param("%s/assets/yy.properties" % prj_path, key, value)
  790. if key == "channelId":
  791. sdk_root_dir = apk_utils.getCutSdkRootHome()
  792. printlog(" ZhangShangHuYuReplace begin replace game package v4 smali -------------------------------")
  793. pkgV4Path = "%s/smali/android/support/v7" % prj_path
  794. printlog("pkgV4Path:%s" % pkgV4Path)
  795. sdkV4Path = "%s/zshy/zshy/smali/android/support/v7" % sdk_root_dir
  796. printlog("sdkV4Path:%s" % sdkV4Path)
  797. if os.path.exists(pkgV4Path):
  798. File.copyAllFile(sdkV4Path, pkgV4Path)
  799. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali/android/support/v7/cardview")
  800. printlog(" HongGuoReplace begin replace game package v4 smali -------------------------------")
  801. pkgV4Path = "%s/smali/android/support/v4" % prj_path
  802. printlog("pkgV4Path:%s" % pkgV4Path)
  803. sdkV4Path = "%s/zshy/zshy/smali/android/support/v4" % sdk_root_dir
  804. printlog("sdkV4Path:%s" % sdkV4Path)
  805. if os.path.exists(pkgV4Path):
  806. File.copyAllFile(sdkV4Path, pkgV4Path)
  807. apkRfilePath = "%s/smali/com/zshy/zshysdk" % prj_path
  808. printlog("apkRfilePath:%s" % apkRfilePath)
  809. publicXml = "%s/res/values/public.xml" % prj_path
  810. sdk_jar_dir = apk_utils.getToolsJarHome()
  811. jarPath = "%s/MergeSamli.jar" % sdk_jar_dir
  812. javaMerCm = 'java -jar %s %s %s' % (jarPath, publicXml, apkRfilePath)
  813. printlog("javaMerCm:%s" % javaMerCm)
  814. os.system(javaMerCm)
  815. Replace.modifyRfileSmaliPath("zshy", prj_path);
  816. pass
  817. def XiYouWangReplace(prj_path, dir_split, key, value):
  818. Replace.replaceAssets_Param("%s/assets/xy_developer_config.properties" % prj_path, key, value)
  819. if key == "XY_APP_ID":
  820. splash_activity = "com.xiyou.sdk.XiYouSplashActivity"
  821. manifest_path = prj_path + dir_split + "AndroidManifest.xml"
  822. game_activity = Replace.replaceGameActivityLaunchAttribute(splash_activity, manifest_path)
  823. Replace.replaceAM_Meta_data(manifest_path, 'XY_GAME_MAIN_ACTIVITY_NAME', game_activity)
  824. sdk_root_dir = apk_utils.getCutSdkRootHome()
  825. printlog(" xiyouwang begin replace game package v4 smali -------------------------------")
  826. pkgV4Path = "%s/smali/android/support/v4" % prj_path
  827. printlog("pkgV4Path:%s" % pkgV4Path)
  828. sdkV4Path = "%s/xiyou/xiyou/smali/android/support/v4" % sdk_root_dir
  829. printlog("sdkV4Path:%s" % sdkV4Path)
  830. if os.path.exists(pkgV4Path):
  831. File.copyAllFile(sdkV4Path, pkgV4Path)
  832. prj_am_path = "%s/AndroidManifest.xml" % prj_path
  833. pkgName = ET.parse(prj_am_path).getroot().attrib["package"]
  834. Aapt_Util.createRFile(prj_path, False, pkgName)
  835. pass
  836. def XunLeiReplace(prj_path, dir_split, key, value):
  837. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  838. namespace = '{http://schemas.android.com/apk/res/android}'
  839. ET.register_namespace('android', "http://schemas.android.com/apk/res/android")
  840. if (key == "schemeCallback"):
  841. tree = ET.parse(prj_am_path)
  842. activitys = tree.getroot().find("application").findall("activity")
  843. for activity in activitys:
  844. activityName = activity.attrib[namespace + "name"]
  845. printlog("activityName:%s" % activityName)
  846. if (activityName == "com.xovs.common.auth.processor.XLAuthBackActivity"):
  847. filters = activity.findall('intent-filter')
  848. for filter in filters:
  849. datas = filter.findall('data')
  850. for data in datas:
  851. printlog("data:%s" % data)
  852. data.set(namespace + "scheme", value)
  853. tree.write(prj_am_path, "UTF-8", xml_declaration=True, method='xml')
  854. pass
  855. def CanLongReplace(prj_path, dir_split, key, value):
  856. if key == "PRODUCT_CODE":
  857. Replace.modifyRfileSmaliPath("canlong", prj_path);
  858. pass
  859. def ShangHaiXiYuanReplace(prj_path, dir_split, key, value):
  860. if key == "PACKAGE_TAG":
  861. sdk_root_dir = apk_utils.getCutSdkRootHome()
  862. sdkSmaliPath = "%s/shxy/shxy/smali/com/yyrh" % sdk_root_dir
  863. pkgSmaliPath = "%s/smali/com/yyrh" % prj_path
  864. printlog("sdkSmaliPath :%s" % sdkSmaliPath)
  865. printlog("pkgSmaliPath :%s" % pkgSmaliPath)
  866. if os.path.exists(pkgSmaliPath):
  867. File.copyAllFile(sdkSmaliPath, pkgSmaliPath)
  868. if Contants.isTestEnvironment():
  869. key = "https://sdkapi.bklinok.com"
  870. value = "http://testsdkapi.yyxxgame.com"
  871. file = "%s/smali/com/yyrh/c/a.smali" % prj_path
  872. Replace.replaceKeyword(key, value, file)
  873. file = "%s/smali/com/yyrh/a/d.smali" % prj_path
  874. Replace.replaceKeyword(key, value, file)
  875. file = "%s/smali/com/yyrh/sdk/SDKEntry.smali" % prj_path
  876. Replace.replaceKeyword(key, value, file)
  877. pass
  878. def YuanYouRongHeReplace(prj_path, dir_split, key, value):
  879. if key == "PACKAGE_TAG":
  880. sdk_root_dir = apk_utils.getCutSdkRootHome()
  881. sdkSmaliPath = "%s/mixsdk/mixsdk/smali/com/yyrh" % sdk_root_dir
  882. pkgSmaliPath = "%s/smali/com/yyrh" % prj_path
  883. printlog("sdkSmaliPath :%s" % sdkSmaliPath)
  884. printlog("pkgSmaliPath :%s" % pkgSmaliPath)
  885. if os.path.exists(pkgSmaliPath):
  886. File.copyAllFile(sdkSmaliPath, pkgSmaliPath)
  887. sdkSmaliPath = "%s/mixsdk/mixsdk/smali/com/yythird/base" % sdk_root_dir
  888. pkgSmaliPath = "%s/smali/com/yythird/base" % prj_path
  889. printlog("sdkSmaliPath :%s" % sdkSmaliPath)
  890. printlog("pkgSmaliPath :%s" % pkgSmaliPath)
  891. if os.path.exists(pkgSmaliPath):
  892. File.copyAllFile(sdkSmaliPath, pkgSmaliPath)
  893. if Contants.isTestEnvironment():
  894. key = "https://sdkapi.yyxxgame.com"
  895. value = "http://testsdkapi.yyxxgame.com"
  896. file = "%s/smali/com/yyrh/c/a.smali" % prj_path
  897. Replace.replaceKeyword(key, value, file)
  898. file = "%s/smali/com/yyrh/sdk/SDKEntry.smali" % prj_path
  899. Replace.replaceKeyword(key, value, file)
  900. pass
  901. def BaLeReplace(prj_path, dir_split, key, value):
  902. if key == "CHANNEL_ID":
  903. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali/com/sdk/douyou")
  904. pass
  905. def QiPaReplace(prj_path, dir_split, key, value):
  906. if key == "Super_Game_ID":
  907. splash_activity = "com.supersdk.application.MySplashActivity"
  908. prj_am_path = "%s/AndroidManifest.xml" % prj_path
  909. game_activity = Replace.replaceGameActivityLaunchAttribute(splash_activity, prj_am_path)
  910. tree = ET.parse(prj_am_path)
  911. activitys = tree.getroot().find("application").findall("activity")
  912. for activity in activitys:
  913. namespace = '{http://schemas.android.com/apk/res/android}'
  914. xml_activity_name = activity.attrib[namespace + "name"]
  915. if xml_activity_name == game_activity:
  916. filter = activity.find('intent-filter')
  917. el1 = Element('action android:name="com.super.sdk.MAIN"')
  918. filter.append(el1)
  919. tree.write(prj_am_path, "UTF-8", xml_declaration=True, method='xml')
  920. pass
  921. def DouyinReplace(prj_path, dir_split, key, value):
  922. jsonFilePath = prj_path + dir_split + "assets" + dir_split + "config.json"
  923. if key == 'app_id':
  924. with open(jsonFilePath, 'r') as fp:
  925. jsonData = json.load(fp)
  926. jsonData["app_id"] = value
  927. jsonData['screen_orientation'] = GeneralModifySmali.getLauchActivityName(prj_path)
  928. orientation = GeneralModifySmali.getLauchActivityScreenOrientation(prj_path)
  929. if orientation == "landscape" or orientation == "sensorLandscape":
  930. screen_orientation = "sensorLandscape"
  931. else:
  932. screen_orientation = "sensorPortrait"
  933. jsonData['screen_orientation'] = screen_orientation
  934. newJsonData = jsonData
  935. fp.close()
  936. with open(jsonFilePath, 'w') as fp:
  937. json.dump(newJsonData, fp)
  938. fp.close()
  939. printlog(" douyin begin replace game package v4 smali -------------------------------")
  940. pkgV4Path = "%s/smali/android/support/v4" % prj_path
  941. printlog("pkgV4Path:%s" % pkgV4Path)
  942. File.del_file(pkgV4Path)
  943. prj_am_path = "%s/AndroidManifest.xml" % prj_path
  944. pkgName = ET.parse(prj_am_path).getroot().attrib["package"]
  945. Aapt_Util.createRFile(prj_path, False, pkgName)
  946. sdkRpath = "android/support/v7/appcompat"
  947. pkgRpath = pkgName.replace(".", "/")
  948. sdkAbsoluteRpath = "%s/smali_classes3/%s" % (prj_path, sdkRpath)
  949. pkgAbsoluteRpath = "%s/smali/%s" % (prj_path, pkgRpath)
  950. Replace.createRFile2Sdk(pkgAbsoluteRpath, sdkAbsoluteRpath, pkgRpath, sdkRpath)
  951. pass
  952. def MoMoYuReplace(prj_path, dir_split, key, value):
  953. xml_path = "%s/res/values/strings.xml" % prj_path
  954. Replace.replaceXmlValue(xml_path, key, value)
  955. pass
  956. def QuxuanReplace(prj_path, dir_split, key, value):
  957. if key == "app_id":
  958. prj_am_path = "%s/AndroidManifest.xml" % prj_path
  959. value = "Qdazzle_%s" % value
  960. Replace.replaceAM_Meta_data(prj_am_path, "CommonSDK_AppID", value)
  961. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali/com/qdazzle/sdk")
  962. if key == "app_key":
  963. prj_am_path = "%s/AndroidManifest.xml" % prj_path
  964. value = "Qdazzle_%s" % value
  965. Replace.replaceAM_Meta_data(prj_am_path, "CommonSDK_AppKey", value)
  966. pass
  967. def MuMuReplace(prj_path, dir_split, key, value):
  968. if key == "YOFUN_APP_ID":
  969. printlog("specail replace : MuMuReplace")
  970. splashactivity = "com.yythird.sdk.SplashActivity"
  971. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  972. prj_param = "%s/assets/YyrhParam.cnf" % prj_path
  973. game_activity = Replace.replaceGameActivityLaunchAttribute(splashactivity, prj_am_path)
  974. printlog("GAMEACTIVITY :%s" % game_activity)
  975. Replace.replaceAssets_Param(prj_param, "GAMEACTIVITY", game_activity)
  976. pass
  977. def HeFengReplace(prj_path, dir_split, key, value):
  978. if key == "ver":
  979. printlog("specail replace : HeFengReplace")
  980. printlog("path hf.properties :%s/assets/hf.properties" % prj_path)
  981. Replace.replaceAssets_Param("%s/assets/hf.properties" % prj_path, "agent", value)
  982. pass
  983. def ShengBenFuliReplace(prj_path, dir_split, key, value):
  984. if key == "appid":
  985. printlog("specail replace : ShengBenFuliReplace")
  986. splash_activity = "com.fysdk.activity.FyGuideActivity"
  987. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  988. namespace = '{http://schemas.android.com/apk/res/android}'
  989. ET.register_namespace('android', "http://schemas.android.com/apk/res/android")
  990. tree = ET.parse(prj_am_path)
  991. activitys = tree.getroot().find("application").findall("activity")
  992. for activity in activitys:
  993. filters = activity.findall('intent-filter')
  994. for filter in filters:
  995. categorys = filter.findall('category')
  996. actions = filter.findall('action')
  997. for category in categorys:
  998. category_name = category.attrib[namespace + "name"]
  999. if category_name == "android.intent.category.LAUNCHER":
  1000. action_name = activity.attrib[namespace + "name"]
  1001. if action_name != splash_activity:
  1002. printlog("delete :%s" % category_name)
  1003. category.attrib[namespace + "name"] = "android.intent.category.DEFAULT"
  1004. printlog("LAUNCHER replace DEFAULT :%s" % category.attrib[namespace + "name"])
  1005. for action in actions:
  1006. action_name = action.attrib[namespace + "name"]
  1007. if action_name == "android.intent.action.MAIN":
  1008. printlog("delete :%s" % action_name)
  1009. action.attrib[namespace + "name"] = "game.MAIN"
  1010. tree.write(prj_am_path, "UTF-8", xml_declaration=True, method='xml')
  1011. pass
  1012. def MuXueReplace(prj_path, dir_split, key, value):
  1013. printlog("specail replace : MuXueReplace")
  1014. Replace.replaceAssets_Param("%s/assets/gs.properties" % prj_path, key, value)
  1015. pass
  1016. def QiYouReplace(prj_path, dir_split, key, value):
  1017. if (key == "blgame_gameid"):
  1018. prj_am_path = prj_path + dir_split + "AndroidManifest.xml"
  1019. pkgName = ET.parse(prj_am_path).getroot().attrib["package"]
  1020. sdk_root_dir = apk_utils.getCutSdkRootHome()
  1021. pkgV4Path = "%s/smali/android/support/design" % prj_path
  1022. printlog("pkgV4Path:%s" % pkgV4Path)
  1023. sdkV4Path = "%s/7you/7you/smali/android/support/design" % sdk_root_dir
  1024. printlog("sdkV4Path:%s" % sdkV4Path)
  1025. if os.path.exists(pkgV4Path):
  1026. File.copyAllFile(sdkV4Path, pkgV4Path)
  1027. Aapt_Util.createRFile(prj_path, False, pkgName)
  1028. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali/android/support/v7/appcompat")
  1029. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali/android/support/design")
  1030. GeneralModifySmali.modifyRfileIdSmali(prj_path, "/smali/android/support/v7/cardview")
  1031. pass
  1032. def YueWanReplace(prj_path, dir_split, key, value):
  1033. printlog("specail replace : YueWanReplace")
  1034. if (key == "J_GAME_ID"):
  1035. sdk_root_dir = apk_utils.getCutSdkRootHome()
  1036. printlog(" YueWanReplace begin replace game package v4 smali -------------------------------")
  1037. pkgV4Path = "%s/smali/android/support/v4" % prj_path
  1038. printlog("pkgV4Path:%s" % pkgV4Path)
  1039. sdkV4Path = "%s/yuewan/yuewan/smali/android/support/v4" % sdk_root_dir
  1040. printlog("sdkV4Path:%s" % sdkV4Path)
  1041. if os.path.exists(pkgV4Path):
  1042. File.copyAllFile(sdkV4Path, pkgV4Path)
  1043. pass
  1044. def ShengYueReplace(prj_path, dir_split, key, value):
  1045. printlog("specail replace : ShengYueReplace")
  1046. jsonFilePath = prj_path + dir_split + "assets" + dir_split + "UUConfig.json"
  1047. Replace.replaceJsonValue(jsonFilePath, "", key, value)
  1048. pass
  1049. def JiZhiHuiReplace(prj_path, dir_split, key, value):
  1050. printlog("specail replace : JiZhiHuiReplace")
  1051. config_path = "%s/assets/xggameinfo.txt" % prj_path
  1052. with open(config_path, "r") as f:
  1053. content = f.read()
  1054. json_data = json.loads(content)
  1055. json_data[key] = value
  1056. with open(config_path, "w") as f:
  1057. f.write(json.dumps(json_data))
  1058. def JiMiReplace(prj_path, dir_split, key, value):
  1059. Replace.replaceAssets_Param("%s/assets/jmhy.properties" % prj_path, key, value)
  1060. specialReplace = {
  1061. "lenovo": LenovoReplace,
  1062. "baidu": BaiduReplace,
  1063. "wandoujia": WandoujiaReplace,
  1064. "qh360": QihuReplace,
  1065. "oppo": OppoReplace,
  1066. "oppoml": OppoMlReplace,
  1067. "chongchong": ChongchongReplace,
  1068. "yingyongbao": YYBReplace,
  1069. "downjoy": downjoyReplace,
  1070. "huawei": HuaweiReplace,
  1071. "anzhi": AnzhiReplace,
  1072. "leshi": LeshiReplace,
  1073. "quick": QuickReplace,
  1074. "guopan": GuopanReplace,
  1075. "ljsdk": LjsdkReplace,
  1076. "uc": UcsdkReplace,
  1077. "xiaomi": XiaomisdkReplace,
  1078. "hnshengben": ShengbensdkReplace,
  1079. "jk": JinkuosdkReplace,
  1080. "hd": HdhdsdkReplace,
  1081. "samsung": SamsungReplace,
  1082. "ttyy": TTReplace,
  1083. "yxf": YXFReplace,
  1084. "vivo": VivosdkReplace,
  1085. "3011": XTsdkReplace,
  1086. "ddt": DDTsdkReplace,
  1087. "wanka": WankaReplace,
  1088. "ddd": DDDReplace,
  1089. "lzyx": LZYXReplace,
  1090. "ws": WSReplace,
  1091. "xb": XBReplace,
  1092. "youdian": YoudianReplace,
  1093. "x7sy": Xiao7Replace,
  1094. "nwanka": NwanKaReplace,
  1095. "mbaidu": MBaiduReplace,
  1096. "shenshou": ShenshouReplace,
  1097. "dyyx": DaYanReplace,
  1098. "dl": DaLanReplace,
  1099. "ksyx": KSyxReplace,
  1100. "llhy": LlhyReplace,
  1101. "hnqs": HnqsReplace,
  1102. "sogou": SogouReplace,
  1103. "jrtt": JinRiTouTiaoReplace,
  1104. "fq": FengQiReplace,
  1105. "bs": BlueStackReplace,
  1106. "simo": SiMoReplace,
  1107. "cl": ChenLongReplace,
  1108. "qianmian": JinRiTouTiaoReplace,
  1109. "jiuzi": JiuZiReplace,
  1110. "bingniao": BingNiaoReplace,
  1111. "bingcheng": BingChengReplace,
  1112. "sxhy": SuixingHuYuReplace,
  1113. "shouqu": ShouQuReplace,
  1114. "hnqj": HaiNanQiJingReplace,
  1115. "hg": HongGuoReplace,
  1116. "baize": BaizeReplace,
  1117. "yx": YanXinReplace,
  1118. "zshy": ZhangShangHuYuReplace,
  1119. "xiyou": XiYouWangReplace,
  1120. "xunlei": XunLeiReplace,
  1121. "canlong": CanLongReplace,
  1122. "shxy": ShangHaiXiYuanReplace,
  1123. "mixsdk": YuanYouRongHeReplace,
  1124. "bale": BaLeReplace,
  1125. "7pa": QiPaReplace,
  1126. "dymmy": MoMoYuReplace,
  1127. "dyly": DouyinReplace,
  1128. "qx": QuxuanReplace,
  1129. "wymumu": MuMuReplace,
  1130. "hf": HeFengReplace,
  1131. "sbfl": ShengBenFuliReplace,
  1132. "muxue": MuXueReplace,
  1133. "7you": QiYouReplace,
  1134. "yuewan": YueWanReplace,
  1135. "shengyue": ShengYueReplace,
  1136. "jzh": JiZhiHuiReplace,
  1137. "jmhy": JiMiReplace
  1138. }
  1139. def getSpecilReplace(sdk_name):
  1140. if sdk_name in specialReplace:
  1141. return specialReplace[sdk_name]
  1142. else:
  1143. return None
  1144. pass