channel_action.py
2.9 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
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
namespace = 'http://schemas.android.com/apk/res/android'
androidNS = 'http://schemas.android.com/apk/res/android'
def execute(channel, decompileDir, packageName):
sdkDir = decompileDir + '/../sdk/' + channel['sdk']
print("The sdk temp folder is path: "+sdkDir)
if not os.path.exists(sdkDir):
print("The sdk temp folder is not exists. path:"+sdkDir)
return 1
if channel['params'] != None and len(channel['params']) > 0:
for param in channel['params']:
if param['name'] == 'permissStatement':
needshow = param['value']
if needshow=='true':
manifest_path = decompileDir + '/AndroidManifest.xml'
modify_manifest(manifest_path)
return 0
def modify_manifest(manifest_path):
ET.register_namespace("android", namespace)
tree = ET.parse(manifest_path)
root = tree.getroot()
for activity in root.findall('.//activity'):
intent_filter = activity.find('.//intent-filter')
if intent_filter is not None:
action = intent_filter.find('.//action')
if action is not None and action.get('{' + namespace + '}name') == 'android.intent.action.MAIN':
origin_activity_name = activity.get('{' + namespace + '}name')
print(origin_activity_name)
activity.remove(intent_filter)
tree.write(manifest_path)
manifest_add(manifest_path, tree, root, origin_activity_name)
break
def manifest_add(manifest_path, tree, root, origin_activity_name):
namespace2 = {'android': 'http://schemas.android.com/apk/res/android'}
target_activity = root.find(".//activity[@android:name='com.zhenwan.sdk.activity.ZWSplashActivity']",
namespace2)
if target_activity is None:
return "PermissionStatementActivity不存在"
intent_filter = target_activity.find('intent-filter')
if intent_filter is None:
intent_filter = ET.SubElement(target_activity, 'intent-filter')
action_element = ET.SubElement(intent_filter, 'action')
action_element.set('{' + namespace + '}name', 'android.intent.action.MAIN')
category_element = ET.SubElement(intent_filter, 'category')
category_element.set('{' + namespace + '}name', 'android.intent.category.LAUNCHER')
meta_data = ET.SubElement(target_activity, 'meta-data')
meta_data.set('android:name', "GAME_ACTIVITY")
meta_data.set('android:value', origin_activity_name)
tree.write(manifest_path)