channel_action.py
6.0 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
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 execute(channel, decompileDir, packageName):
replace_applicationId_to_AndroidManifest(decompileDir, packageName)
# write_params_to_config(channel, decompileDir)
modify_main_activity_smali(decompileDir)
# addWXEntryActivity(channel, decompileDir, packageName)
return 0
def replace_applicationId_to_AndroidManifest(decompileDir, packageName):
manifestPath = decompileDir + '/AndroidManifest.xml'
manifest_file = open(manifestPath, 'r+', encoding='Utf-8')
manifestContent = str(manifest_file.read())
manifest_file.close()
# 4、replace "${applicationId}" "${JPUSH_PKGNAME}" with packname in AndroidManifest.xml
manifestContent = manifestContent.replace('${applicationId}', packageName)
manifest_new_file = open(manifestPath, 'w', encoding='Utf-8')
manifest_new_file.write(manifestContent)
manifest_new_file.close()
return 0
def write_params_to_config(channel, decompileDir):
Pid = '104136'
PKey = 'ISw/GOMBIDOSCzcXLy/XA5/DgXGKsA8Syzikka0V/41T2EPWCYAV0d5lcz1enF62'
AppVersion = '1.0'
ScreenType = '1'
if channel['params'] != None and len(channel['params']) > 0:
for param in channel['params']:
if param['name'] == 'Pid':
Pid = param['value']
elif param['name'] == 'PKey':
PKey = param['value']
elif param['name'] == 'AppVersion':
AppVersion = param['value']
elif param['name'] == 'ScreenType':
ScreenType = param['value']
developer_config_path = decompileDir + '/assets/ouni_config.info'
euConfigFile = open(developer_config_path, 'r+', encoding='Utf-8')
configContent = str(euConfigFile.read())
euConfigFile.close()
configContent = configContent.replace('youlong_Pid_104136', Pid)
configContent = configContent.replace('youlong_PKey_ISw/GOMBIDOSCzcXLy/XA5/DgXGKsA8Syzikka0V/41T2EPWCYAV0d5lcz1enF62', PKey)
configContent = configContent.replace('youlong_AppVersion_1.0', AppVersion)
configContent = configContent.replace('youlong_ScreenType_1', ScreenType)
developer_config_file = open(developer_config_path, 'w', encoding='Utf-8')
developer_config_file.write(configContent)
developer_config_file.close()
return 0
def modify_main_activity_smali(decompileDir):
manifestFile = decompileDir + "/AndroidManifest.xml"
# manifestFile = file_utils.getFullPath(manifestFile)
ET.register_namespace('android', androidNS)
key = '{' + androidNS + '}name'
tree = ET.parse(manifestFile)
root = tree.getroot()
applicationNode = root.find('application')
if applicationNode is None:
return
activityNodeLst = applicationNode.findall('activity')
if activityNodeLst is None:
return
mainActivityName = ''
for activityNode in activityNodeLst:
bMain = False
intentNodeLst = activityNode.findall('intent-filter')
if intentNodeLst is None:
break
for intentNode in intentNodeLst:
bFindAction = False
bFindCategory = False
actionNodeLst = intentNode.findall('action')
if actionNodeLst is None:
break
for actionNode in actionNodeLst:
if actionNode.attrib[key] == 'android.intent.action.MAIN':
bFindAction = True
break
categoryNodeLst = intentNode.findall('category')
if categoryNodeLst is None:
break
for categoryNode in categoryNodeLst:
if categoryNode.attrib[key] == 'android.intent.category.LAUNCHER':
bFindCategory = True
break
if bFindAction and bFindCategory:
bMain = True
break
if bMain:
mainActivityName = activityNode.attrib[key]
break
if len(mainActivityName) == 0:
return
mainActivityPath = mainActivityName.replace(".", "/")
mainActivityPath = decompileDir + '/smali/' + mainActivityPath + '.smali'
f = open(mainActivityPath, 'r+', encoding='Utf-8')
mainActivityContent = str(f.read())
f.close()
fl = open(mainActivityPath, 'r+')
lines = fl.readlines()
fl.close()
superClassLine = lines[1]
superClassLine.strip()
superClassName = 'Landroid/app/Activity;'
if superClassLine.startswith(".super"):
blocks = superClassLine.split()
superClassName = blocks[len(blocks)-1]
replaceTxt = 'invoke-super {p0, p1, p2, p3}, ' + superClassName + '->onRequestPermissionsResult(I[Ljava/lang/String;[I)V'
idx = mainActivityContent.find(replaceTxt)
if idx == -1:
targetTxt = "\n.method public onRequestPermissionsResult(I[Ljava/lang/String;[I)V\n .locals 2\n\n invoke-super {p0, p1, p2, p3}, " + superClassName + "->onRequestPermissionsResult(I[Ljava/lang/String;[I)V\n\n invoke-static {p1, p2, p3}, Lcom/stss/sdk/STSSAggGame;->onRequestPermissionsResult(I[Ljava/lang/String;[I)V\n\n return-void\n.end method"
mainActivityContent = mainActivityContent + targetTxt
else:
targetTxt = " invoke-super {p0, p1, p2, p3}, " + superClassName + "->onRequestPermissionsResult(I[Ljava/lang/String;[I)V\n\n invoke-static {p1, p2, p3}, Lcom/stss/sdk/STSSAggGame;->onRequestPermissionsResult(I[Ljava/lang/String;[I)V"
mainActivityContent = mainActivityContent[:idx] + targetTxt + mainActivityContent[(idx + len(replaceTxt)):]
f2 = open(mainActivityPath, 'w', encoding='Utf-8')
f2.write(mainActivityContent)
f2.close()
return 0