script.py
3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import file_utils
import os
import os.path
from xml.etree import ElementTree as ET
from xml.etree.ElementTree import SubElement
from xml.etree.ElementTree import Element
from xml.etree.ElementTree import ElementTree
import os
import os.path
import zipfile
import re
import subprocess
import platform
from xml.dom import minidom
import codecs
import sys
androidNS = 'http://schemas.android.com/apk/res/android'
def generateShareSDKXmlFile(pluginInfo, decompileDir):
assetsPath = file_utils.getFullPath(decompileDir) + "/assets"
if not os.path.exists(assetsPath):
os.makedirs(assetsPath)
shareSdkXml = assetsPath + "/ShareSDK.xml"
if os.path.exists(shareSdkXml):
os.remove(shareSdkXml)
tree = ElementTree()
root = Element('DevInfor')
tree._setroot(root)
shareNode = SubElement(root, 'ShareSDK')
if 'params' in pluginInfo and pluginInfo['params'] != None and len(pluginInfo['params']) > 0:
for param in pluginInfo['params']:
paramName = param.get('name')
if paramName == 'AppKey':
paramValue = param.get('value')
shareNode.set('AppKey', paramValue)
break
subplugins = pluginInfo.get('subplugins')
if subplugins != None and len(subplugins) > 0:
index = 1
for subplg in subplugins:
subplgNode = SubElement(root, subplg['name'])
subparams = subplg.get('params')
if subparams != None and len(subparams) > 0:
for subparam in subparams:
subplgNode.set(subparam['name'], subparam['value'])
if subplgNode.get('Id') == None:
subplgNode.set('Id', str(index))
else:
subplgNode.attrib['Id'] = str(index)
if subplgNode.get('Enable') == None:
subplgNode.set('Enable', 'true')
else:
subplgNode.attrib['Enable'] = 'true'
index = index + 1
tree.write(shareSdkXml, 'UTF-8')
def appendAppIdForQZone(pluginInfo, decompileDir):
qzoneAppID = None
subplugins = pluginInfo.get('subplugins')
appId = 0
if subplugins != None and len(subplugins) > 0:
for subplg in subplugins:
if subplg['name'] == "QZone":
params = subplg.get('params')
for param in params:
if param['name'] == 'AppId':
appId = int(param['value'])
break
if appId > 0:
break
if appId == 0:
return
manifestFile = decompileDir + "/AndroidManifest.xml"
manifestFile = file_utils.getFullPath(manifestFile)
ET.register_namespace('android', androidNS)
tree = ET.parse(manifestFile)
root = tree.getroot()
applicationNode = root.find('application')
if applicationNode is None:
return
key = '{'+androidNS+'}name'
scheme = '{'+androidNS+'}scheme'
activityNodes = applicationNode.findall('activity')
if activityNodes != None and len(activityNodes) > 0:
for activityNode in activityNodes:
name = activityNode.get(key)
if name == 'cn.sharesdk.framework.ShareSDKUIShell':
intentNodes = activityNode.findall('intent-filter')
if intentNodes != None and len(intentNodes) > 0:
for intentNode in intentNodes:
dataNode = SubElement(intentNode, 'data')
dataNode.set(scheme, 'tencent'+str(appId))
break
else:
intentNode = SubElement(activityNode, 'intent-filter')
dataNode = SubElement(intentNode, 'data')
dataNode.set(scheme, 'tencent'+str(appId))
actionNode = SubElement(intentNode, 'action')
actionNode.set(key, 'android.intent.action.VIEW')
categoryNode = SubElement(intentNode, 'category')
categoryNode.set(key, 'android.intent.category.DEFAULT')
categoryNode2 = SubElement(intentNode, 'category')
categoryNode2.set(key, 'android.intent.category.BROWSABLE')
tree.write(manifestFile, 'UTF-8')
def execute(channel, pluginInfo, decompileDir, packageName):
generateShareSDKXmlFile(pluginInfo, decompileDir)
appendAppIdForQZone(pluginInfo, decompileDir)